Repository navigation
Implements LLM-as-Judge for Response Equivalence - #16
Conversation
|
The following JSONL contains examples of rollouts from https://huggingface.co/datasets/allenai/sciq Example of judgment (chatgpt 3.5) "content":
[
{
"annotations":
[],
"text": "The candidate has the correct answer but has capitalized the first letter, which is not necessary for equivalence. \n\n[[A=B]] they are equivalent\n\n===== Output =====\n\n[[A=B]] they are equivalent",
"type": "output_text",
"logprobs":
[]
}
] |
|
@jveronvialard Can you review it? I've upload the datasets to gitlab |
ec97e97 to
1529e34
Compare
| # Scientific Knowledge LLM-as-judge Resources Server | ||
|
|
||
| ### Overview | ||
| Uses an LLM as a judge to compare a model’s generated answer against the expected answer. |
There was a problem hiding this comment.
This seems relevant for other data types, not just scientific knowledge. Should you implement a generic LLM as a judge that can be reused elsewhere?
There was a problem hiding this comment.
That's a very good point.
I think something towards the lines of "Response Equivalence LLM-as-Judge" would be more appropriate.
I want to make sure that this is used only for when two responses are compared and a categorical (0,1) reward is assigned if they are equal or not.
| - `judge_system_message`: optional system message. If omitted, no system message is added. | ||
| - `judge_prompt_template` (required): user prompt template. Placeholders: `{question}`, `{expected_answer}`, `{generated_answer}`. | ||
| - `judge_equal_label` / `judge_not_equal_label`: labels the judge must output. Defaults to `[[A=B]]` and `[[A!=B]]`. | ||
| - `check_twice_swap` (bool, default false): if true, after an initial equal verdict, performs a second judge call swapping expected and generated answers to reduce bias. |
There was a problem hiding this comment.
Do you have a rough estimate of this bias (depends on model used too)? Depending on this estimate, should this be True by default?
| ### Notes | ||
| - By default (`check_twice_swap=false`), the server performs a single judge pass. If the verdict is equal, reward is 1 and one evaluation is returned; if not equal, reward is 0 and one evaluation is returned. | ||
| - If `check_twice_swap=true` and the first pass is equal, a second pass is performed with expected and generated answers swapped. Reward is 1 only if the second pass is also equal; in this case, two evaluations are returned. | ||
| - If the judge output doesn’t include either label, it defaults to not-equal. |
There was a problem hiding this comment.
Is there be a mechanism to track how often this happens? Also, would it make sense to mask this trajectory instead of giving it a reward of zero?
There was a problem hiding this comment.
This will depend on the interaction of dataset, judge, and prompt.
We still don't have OOTB integration with nemo-rl to pass a "ignore sample" sort of parameter.
I'll set it to -1.0 in this case so it is future-proof.
@bxyu-nvidia what do you think?
|
@bxyu-nvidia @banghuaz-nvidia can you review it? |
| @@ -0,0 +1,3 @@ | |||
| -e nemo-gym[dev] @ ../../ | |||
| datasets | |||
There was a problem hiding this comment.
Should you set the library version?
| @@ -0,0 +1,91 @@ | |||
| equivalence_llm_judge: | |||
There was a problem hiding this comment.
Should this be renamed sciq_equivalence_llm_judge?
There was a problem hiding this comment.
This should be generic and reflect the resources server. Even though the prompt is tailored for sci knowledge.
Signed-off-by: Brian Yu <[email protected]> Signed-off-by: soares-f <[email protected]>
Signed-off-by: soares-f <[email protected]>
Signed-off-by: soares-f <[email protected]>
Signed-off-by: soares-f <[email protected]>
Signed-off-by: soares-f <[email protected]>
Signed-off-by: soares-f <[email protected]>
Signed-off-by: soares-f <[email protected]>
Signed-off-by: Brian Yu <[email protected]> Signed-off-by: soares-f <[email protected]>
Signed-off-by: Brian Yu <[email protected]> Signed-off-by: soares-f <[email protected]>
Signed-off-by: Brian Yu <[email protected]> Signed-off-by: soares-f <[email protected]>
Signed-off-by: Brian Yu <[email protected]> Signed-off-by: soares-f <[email protected]>
Signed-off-by: Brian Yu <[email protected]> Signed-off-by: soares-f <[email protected]>
Signed-off-by: Brian Yu <[email protected]> Signed-off-by: soares-f <[email protected]>
Signed-off-by: Brian Yu <[email protected]> Signed-off-by: Khushi Bhardwaj <[email protected]> Co-authored-by: bxyu-nvidia <[email protected]> Signed-off-by: soares-f <[email protected]>
Migrated over from gitlab: - Display aggregate metrics - Aggregate generic keys using multineedle - Display other dynamic aggregations - Count string totals and unique values - Remove TrainDataProcessor dependency, add test - Remove dupe file read, fix arg types hints --------- Signed-off-by: Frankie Siino <[email protected]> Signed-off-by: soares-f <[email protected]>
Signed-off-by: Brian Yu <[email protected]> Signed-off-by: soares-f <[email protected]>
Signed-off-by: Brian Yu <[email protected]> Signed-off-by: soares-f <[email protected]>
Signed-off-by: soares-f <[email protected]>
Signed-off-by: Brian Yu <[email protected]> Signed-off-by: soares-f <[email protected]>
Signed-off-by: Brian Yu <[email protected]> Signed-off-by: soares-f <[email protected]>
Signed-off-by: soares-f <[email protected]>
Signed-off-by: soares-f <[email protected]>
Signed-off-by: soares-f <[email protected]>
Signed-off-by: soares-f <[email protected]>
Signed-off-by: soares-f <[email protected]>
Signed-off-by: soares-f <[email protected]>
Signed-off-by: soares-f <[email protected]>
7fe850f to
1984723
Compare
| judge_responses_create_params: | ||
| input: [] | ||
| judge_prompt_template: |- | ||
| ===== System role ===== |
There was a problem hiding this comment.
Shall we put these system role related stuff + examples directly into system message, instead of putting it here as part of user message? And anything after INPUTS shall go to user message.
There was a problem hiding this comment.
Resolved in an offline discussion. We'll keep the current format in case some other models may need system prompt to configure tools etc.
Add LLM-as-judge resources server
Introduce a resources server that uses an LLM as a judge to compare a
model’s generated answer against an expected (gold) answer.
### Details
- Only the last assistant message is graded;
- Optional regex extraction for both question and response:
- Uses the last regex match; returns the first non-empty capture group,
else the whole match.
- Optional second-pass verification to mitigate positional bias (swap
expected/generated).
### Configuration:
- judge_system_message (optional): system prompt for the judge.
- judge_prompt_template (required): must include {question},
{expected_answer}, {generated_answer}.
- judge_equal_label / judge_not_equal_label: defaults to [[A=B]] /
[[A!=B]].
- check_twice_swap (bool, default false): if true, on an initial equal
verdict, perform a second judge pass with expected/prediction swapped;
reward remains 1 only if the second pass is also equal.
- reward_if_swap_fails (float, default 0.0): reward to assign if the
second pass fails.
- Here the training framework will need to handle how to discard this
sample based on this reward.
- question_extract_regex (optional): extract from the last user message
(last match semantics).
- response_extract_regex (optional): extract from the last assistant
message (last match semantics).
The regex part can be helpful if for some reason the user decided to
train with in-context examples.
For the responses, this can be useful if the training specifically
expects the final response to be inside \boxed or \text, for instance.
### Steps
- Extracts question from the last user message; applies
question_extract_regex if provided.
- Extracts generated answer from the last assistant message; applies
response_extract_regex if provided.
- Calls the judge model with a configurable prompt and optional system
message.
- Parses the judge’s last message for judge_equal_label /
judge_not_equal_label to set reward and verdict.
### Running the server
```bash
config_paths="responses_api_models/openai_model/configs/openai_model.yaml, \
resources_servers/equivalence_llm_judge/configs/equivalence_llm_judge.yaml"
ng_run "+config_paths=[$config_paths]" \
+equivalence_llm_judge.resources_servers.equivalence_llm_judge.judge_model_server.name=openai_model
```
### Collecting rollouts
```bash
ng_collect_rollouts +agent_name=equivalence_llm_judge_simple_agent \
+input_jsonl_fpath=resources_servers/equivalence_llm_judge/data/example.jsonl \
+output_jsonl_fpath=results/example_rollouts.jsonl \
+limit=5
```
### Licensing
Code: Apache 2.0
Data: CC-BY-NC-3.0 (Examples from
https://huggingface.co/datasets/allenai/sciq)
---------
Signed-off-by: Brian Yu <[email protected]>
Signed-off-by: soares-f <[email protected]>
Signed-off-by: Khushi Bhardwaj <[email protected]>
Signed-off-by: Frankie Siino <[email protected]>
Co-authored-by: bxyu-nvidia <[email protected]>
Co-authored-by: Khushi Bhardwaj <[email protected]>
Co-authored-by: fsiino-nvidia <[email protected]>
Signed-off-by: Abhibha Gupta <[email protected]>
Add LLM-as-judge resources server
Introduce a resources server that uses an LLM as a judge to compare a
model’s generated answer against an expected (gold) answer.
### Details
- Only the last assistant message is graded;
- Optional regex extraction for both question and response:
- Uses the last regex match; returns the first non-empty capture group,
else the whole match.
- Optional second-pass verification to mitigate positional bias (swap
expected/generated).
### Configuration:
- judge_system_message (optional): system prompt for the judge.
- judge_prompt_template (required): must include {question},
{expected_answer}, {generated_answer}.
- judge_equal_label / judge_not_equal_label: defaults to [[A=B]] /
[[A!=B]].
- check_twice_swap (bool, default false): if true, on an initial equal
verdict, perform a second judge pass with expected/prediction swapped;
reward remains 1 only if the second pass is also equal.
- reward_if_swap_fails (float, default 0.0): reward to assign if the
second pass fails.
- Here the training framework will need to handle how to discard this
sample based on this reward.
- question_extract_regex (optional): extract from the last user message
(last match semantics).
- response_extract_regex (optional): extract from the last assistant
message (last match semantics).
The regex part can be helpful if for some reason the user decided to
train with in-context examples.
For the responses, this can be useful if the training specifically
expects the final response to be inside \boxed or \text, for instance.
### Steps
- Extracts question from the last user message; applies
question_extract_regex if provided.
- Extracts generated answer from the last assistant message; applies
response_extract_regex if provided.
- Calls the judge model with a configurable prompt and optional system
message.
- Parses the judge’s last message for judge_equal_label /
judge_not_equal_label to set reward and verdict.
### Running the server
```bash
config_paths="responses_api_models/openai_model/configs/openai_model.yaml, \
resources_servers/equivalence_llm_judge/configs/equivalence_llm_judge.yaml"
ng_run "+config_paths=[$config_paths]" \
+equivalence_llm_judge.resources_servers.equivalence_llm_judge.judge_model_server.name=openai_model
```
### Collecting rollouts
```bash
ng_collect_rollouts +agent_name=equivalence_llm_judge_simple_agent \
+input_jsonl_fpath=resources_servers/equivalence_llm_judge/data/example.jsonl \
+output_jsonl_fpath=results/example_rollouts.jsonl \
+limit=5
```
### Licensing
Code: Apache 2.0
Data: CC-BY-NC-3.0 (Examples from
https://huggingface.co/datasets/allenai/sciq)
---------
Signed-off-by: Brian Yu <[email protected]>
Signed-off-by: soares-f <[email protected]>
Signed-off-by: Khushi Bhardwaj <[email protected]>
Signed-off-by: Frankie Siino <[email protected]>
Co-authored-by: bxyu-nvidia <[email protected]>
Co-authored-by: Khushi Bhardwaj <[email protected]>
Co-authored-by: fsiino-nvidia <[email protected]>
Signed-off-by: Abhibha Gupta <[email protected]>
Add LLM-as-judge resources server
Introduce a resources server that uses an LLM as a judge to compare a
model’s generated answer against an expected (gold) answer.
### Details
- Only the last assistant message is graded;
- Optional regex extraction for both question and response:
- Uses the last regex match; returns the first non-empty capture group,
else the whole match.
- Optional second-pass verification to mitigate positional bias (swap
expected/generated).
### Configuration:
- judge_system_message (optional): system prompt for the judge.
- judge_prompt_template (required): must include {question},
{expected_answer}, {generated_answer}.
- judge_equal_label / judge_not_equal_label: defaults to [[A=B]] /
[[A!=B]].
- check_twice_swap (bool, default false): if true, on an initial equal
verdict, perform a second judge pass with expected/prediction swapped;
reward remains 1 only if the second pass is also equal.
- reward_if_swap_fails (float, default 0.0): reward to assign if the
second pass fails.
- Here the training framework will need to handle how to discard this
sample based on this reward.
- question_extract_regex (optional): extract from the last user message
(last match semantics).
- response_extract_regex (optional): extract from the last assistant
message (last match semantics).
The regex part can be helpful if for some reason the user decided to
train with in-context examples.
For the responses, this can be useful if the training specifically
expects the final response to be inside \boxed or \text, for instance.
### Steps
- Extracts question from the last user message; applies
question_extract_regex if provided.
- Extracts generated answer from the last assistant message; applies
response_extract_regex if provided.
- Calls the judge model with a configurable prompt and optional system
message.
- Parses the judge’s last message for judge_equal_label /
judge_not_equal_label to set reward and verdict.
### Running the server
```bash
config_paths="responses_api_models/openai_model/configs/openai_model.yaml, \
resources_servers/equivalence_llm_judge/configs/equivalence_llm_judge.yaml"
ng_run "+config_paths=[$config_paths]" \
+equivalence_llm_judge.resources_servers.equivalence_llm_judge.judge_model_server.name=openai_model
```
### Collecting rollouts
```bash
ng_collect_rollouts +agent_name=equivalence_llm_judge_simple_agent \
+input_jsonl_fpath=resources_servers/equivalence_llm_judge/data/example.jsonl \
+output_jsonl_fpath=results/example_rollouts.jsonl \
+limit=5
```
### Licensing
Code: Apache 2.0
Data: CC-BY-NC-3.0 (Examples from
https://huggingface.co/datasets/allenai/sciq)
---------
Signed-off-by: Brian Yu <[email protected]>
Signed-off-by: soares-f <[email protected]>
Signed-off-by: Khushi Bhardwaj <[email protected]>
Signed-off-by: Frankie Siino <[email protected]>
Co-authored-by: bxyu-nvidia <[email protected]>
Co-authored-by: Khushi Bhardwaj <[email protected]>
Co-authored-by: fsiino-nvidia <[email protected]>
Add LLM-as-judge resources server
Introduce a resources server that uses an LLM as a judge to compare a
model’s generated answer against an expected (gold) answer.
### Details
- Only the last assistant message is graded;
- Optional regex extraction for both question and response:
- Uses the last regex match; returns the first non-empty capture group,
else the whole match.
- Optional second-pass verification to mitigate positional bias (swap
expected/generated).
### Configuration:
- judge_system_message (optional): system prompt for the judge.
- judge_prompt_template (required): must include {question},
{expected_answer}, {generated_answer}.
- judge_equal_label / judge_not_equal_label: defaults to [[A=B]] /
[[A!=B]].
- check_twice_swap (bool, default false): if true, on an initial equal
verdict, perform a second judge pass with expected/prediction swapped;
reward remains 1 only if the second pass is also equal.
- reward_if_swap_fails (float, default 0.0): reward to assign if the
second pass fails.
- Here the training framework will need to handle how to discard this
sample based on this reward.
- question_extract_regex (optional): extract from the last user message
(last match semantics).
- response_extract_regex (optional): extract from the last assistant
message (last match semantics).
The regex part can be helpful if for some reason the user decided to
train with in-context examples.
For the responses, this can be useful if the training specifically
expects the final response to be inside \boxed or \text, for instance.
### Steps
- Extracts question from the last user message; applies
question_extract_regex if provided.
- Extracts generated answer from the last assistant message; applies
response_extract_regex if provided.
- Calls the judge model with a configurable prompt and optional system
message.
- Parses the judge’s last message for judge_equal_label /
judge_not_equal_label to set reward and verdict.
### Running the server
```bash
config_paths="responses_api_models/openai_model/configs/openai_model.yaml, \
resources_servers/equivalence_llm_judge/configs/equivalence_llm_judge.yaml"
ng_run "+config_paths=[$config_paths]" \
+equivalence_llm_judge.resources_servers.equivalence_llm_judge.judge_model_server.name=openai_model
```
### Collecting rollouts
```bash
ng_collect_rollouts +agent_name=equivalence_llm_judge_simple_agent \
+input_jsonl_fpath=resources_servers/equivalence_llm_judge/data/example.jsonl \
+output_jsonl_fpath=results/example_rollouts.jsonl \
+limit=5
```
### Licensing
Code: Apache 2.0
Data: CC-BY-NC-3.0 (Examples from
https://huggingface.co/datasets/allenai/sciq)
---------
Signed-off-by: Brian Yu <[email protected]>
Signed-off-by: soares-f <[email protected]>
Signed-off-by: Khushi Bhardwaj <[email protected]>
Signed-off-by: Frankie Siino <[email protected]>
Co-authored-by: bxyu-nvidia <[email protected]>
Co-authored-by: Khushi Bhardwaj <[email protected]>
Co-authored-by: fsiino-nvidia <[email protected]>
…masks and files - NDCG counts a repeated item once, at its first rank, so repeats can no longer score above a perfect ranking (review NVIDIA-NeMo#4). - The constant-prediction check uses the same numeric normalization as the content key, so 0.5, 0.50 and 5e-1 get the same grade (review NVIDIA-NeMo#5). - Run-length masks are scored as merged intervals, never expanded to pixels; negative, fractional or odd-length codes are no credit (NVIDIA-NeMo#15). - /submission_hash and /grade_submission check the task's byte limit on the open descriptor and while streaming; an oversized file is neither hashed in full nor copied, and grades no_credit (NVIDIA-NeMo#16). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Subhankar Ghosh <[email protected]>
Add LLM-as-judge resources server
Introduce a resources server that uses an LLM as a judge to compare a model’s generated answer against an expected (gold) answer.
Details
Configuration:
The regex part can be helpful if for some reason the user decided to train with in-context examples.
For the responses, this can be useful if the training specifically expects the final response to be inside \boxed or \text, for instance.
Steps
Running the server
Collecting rollouts
Licensing
Code: Apache 2.0
Data: CC-BY-NC-3.0 (Examples from https://huggingface.co/datasets/allenai/sciq)