Text Classification
Transformers
Safetensors
qwen2
text-generation
text-generation-inference
nielsr HF Staff commited on
Commit
3ead000
·
verified ·
1 Parent(s): 0e89b76

Improve model card with metadata, links, and usage example

Browse files

This PR enhances the model card by:
- Adding the `pipeline_tag: text-classification` and `library_name: transformers` to the metadata, improving discoverability and usability on the Hugging Face Hub.
- Providing a direct link to the associated Hugging Face Paper: [One Token to Fool LLM-as-a-Judge](https://huggingface.co/papers/2507.08794).
- Including links to the official GitHub repository for code and the synthetic training data, as mentioned in the paper's abstract.
- Adding a comprehensive Python code snippet demonstrating how to use the model with the Hugging Face `transformers` library for evaluation, including an example showcasing its robustness against adversarial inputs.
- Updating the model description based on the paper's abstract for better clarity and context.

Files changed (1) hide show
  1. README.md +91 -0
README.md CHANGED
@@ -1,10 +1,101 @@
1
  ---
2
  license: apache-2.0
 
 
3
  ---
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  ## Citation
7
 
8
  If you use this model, please cite:
9
 
10
  [arXiv:2507.08794](https://arxiv.org/abs/2507.08794)
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
+ pipeline_tag: text-classification
4
+ library_name: transformers
5
  ---
6
 
7
+ # Robust Reward Model for LLM-as-a-Judge
8
+
9
+ This repository contains a robust, general-domain generative reward model presented in the paper [One Token to Fool LLM-as-a-Judge](https://huggingface.co/papers/2507.08794).
10
+
11
+ - **Paper**: [One Token to Fool LLM-as-a-Judge](https://huggingface.co/papers/2507.08794)
12
+ - **Code**: [https://github.com/microsoft/RewardEval](https://github.com/microsoft/RewardEval)
13
+ - **Synthetic Training Data**: [https://huggingface.co/datasets/reward-eval/synthetic-judgements](https://huggingface.co/datasets/reward-eval/synthetic-judgements)
14
+
15
+ ## Model Description
16
+
17
+ Generative reward models (also known as LLMs-as-judges), which use large language models (LLMs) to evaluate answer quality, are increasingly adopted in reinforcement learning with verifiable rewards (RLVR). They are often preferred over rigid rule-based metrics, especially for complex reasoning tasks involving free-form outputs. Despite the seeming simplicity of this comparison task, existing generative reward models exhibit surprising vulnerabilities to superficial manipulations: non-word symbols (e.g., ":" or ".") or reasoning openers like "Thought process:" and "Let's solve this problem step by step." can often lead to false positive rewards.
18
+
19
+ This model addresses this widespread weakness across various LLMs, datasets, and prompt formats that poses a serious threat for core algorithmic paradigms that rely on generative reward models, such as rejection sampling, preference optimization, and RLVR. To mitigate this issue, this work introduces a simple yet effective data augmentation strategy and trains a new generative reward model with substantially improved robustness, highlighting the urgent need for more reliable LLM-based evaluation methods.
20
+
21
+ ## How to use
22
+
23
+ You can use this model with the `transformers` library to evaluate answers. The model expects a prompt that includes both the ground-truth reference and the candidate answer for comparison, formatted according to its chat template.
24
+
25
+ ```python
26
+ from transformers import AutoModelForCausalLM, AutoTokenizer
27
+ import torch
28
+
29
+ model_id = "recce-ai/robust-llm-as-a-judge-qwen-7b" # Replace with the actual model ID if different
30
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
31
+ model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
32
+
33
+ # Example for a comparison prompt:
34
+ # Format: System Message, then User Message (reference and candidate)
35
+ system_message = "You are a helpful and fair judge. Evaluate the candidate answer against the reference answer and provide a score of 1 (correct) or 0 (incorrect)."
36
+ reference_answer = "The capital of France is Paris."
37
+ candidate_answer = "Paris is the capital of France."
38
+ user_message = f"Reference: {reference_answer}\
39
+ Candidate: {candidate_answer}\
40
+ Score:"
41
+
42
+ messages = [
43
+ {"role": "system", "content": system_message},
44
+ {"role": "user", "content": user_message}
45
+ ]
46
+
47
+ # Apply the chat template defined in the tokenizer_config.json
48
+ prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
49
+
50
+ input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(model.device)
51
+
52
+ # Generate the score (e.g., '1' or '0')
53
+ output_ids = model.generate(
54
+ input_ids,
55
+ max_new_tokens=5, # Generate only a few tokens for the score (e.g., '1', '0', 'Yes', 'No')
56
+ num_beams=1,
57
+ do_sample=False,
58
+ temperature=0.0, # Use low temperature for deterministic output
59
+ )
60
+
61
+ generated_text = tokenizer.decode(output_ids[0][len(input_ids[0]):], skip_special_tokens=True).strip()
62
+ print(f"Generated Score: {generated_text}")
63
+
64
+ # Example with a trick that might fool other LLMs-as-a-judge (according to the paper)
65
+ candidate_answer_tricked = "Thought process: The capital is a city. Paris is a city. Therefore, Paris is the capital of France."
66
+ user_message_tricked = f"Reference: {reference_answer}\
67
+ Candidate: {candidate_answer_tricked}\
68
+ Score:"
69
+
70
+ messages_tricked = [
71
+ {"role": "system", "content": system_message},
72
+ {"role": "user", "content": user_message_tricked}
73
+ ]
74
+ prompt_tricked = tokenizer.apply_chat_template(messages_tricked, tokenize=False, add_generation_prompt=True)
75
+ input_ids_tricked = tokenizer(prompt_tricked, return_tensors=\"pt\").input_ids.to(model.device)
76
+
77
+ output_ids_tricked = model.generate(
78
+ input_ids_tricked,
79
+ max_new_tokens=5,
80
+ num_beams=1,
81
+ do_sample=False,
82
+ temperature=0.0,
83
+ )
84
+ generated_text_tricked = tokenizer.decode(output_ids_tricked[0][len(input_ids_tricked[0]):], skip_special_tokens=True).strip()
85
+ print(f"Generated Score (tricked): {generated_text_tricked}")
86
+ ```
87
 
88
  ## Citation
89
 
90
  If you use this model, please cite:
91
 
92
  [arXiv:2507.08794](https://arxiv.org/abs/2507.08794)
93
+
94
+ ```bibtex
95
+ @article{wu2025one,
96
+ title={One Token to Fool LLM-as-a-Judge},
97
+ author={Wu, Zhenyu and Sun, Qiushi and Zhang, Yiran and Wang, Yian and Li, Erran and Liang, Paul Pu},
98
+ journal={arXiv preprint arXiv:2507.08794},
99
+ year={2025}
100
+ }
101
+ ```