File size: 5,788 Bytes
88a17d2 2c5e5ce 909bef4 2c5e5ce 909bef4 7be8f1c 88a17d2 2c5e5ce ad3e2d4 2c5e5ce 6bc4777 2c5e5ce 6bc4777 2c5e5ce 6bc4777 2c5e5ce 6bc4777 2c5e5ce 6bc4777 2c5e5ce 6bc4777 2c5e5ce 6bc4777 2c5e5ce 6bc4777 2c5e5ce 6bc4777 2c5e5ce 6bc4777 2c5e5ce 6bc4777 2c5e5ce |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
---
license: apache-2.0
datasets:
- openbmb/UltraInteract
- openbmb/UltraFeedback
- openbmb/UltraSafety
tags:
- reward_model
pipeline_tag: text-classification
---
# Links
- 📜 [Paper]()
- 🤗 [Eurus Collection](https://huggingface.co/collections/openbmb/eurus-660bc40bec5376b3adc9d1c5)
- 🤗 [UltraInteract](https://huggingface.co/datasets/openbmb/UltraInteract)
# Introduction
Eurus-RM-7B is trained on a mixture of [UltraInteract](https://huggingface.co/datasets/openbmb/UltraInteract), [UltraFeedback](https://huggingface.co/datasets/openbmb/UltraFeedback), and [UltraSafety](https://huggingface.co/datasets/openbmb/UltraSafety), with a specifically designed reward modeling objective for reasoning to directly increase.
- EURUS-RM-7B stands out as the best 7B RM overall and achieves similar or better performance than much larger baselines. Particularly, it outperforms GPT-4 in certain tasks.
- Our training objective is beneficial in improving RM performance on hard problems and reasoning.
- ULTRAINTERACT is compatible with other datasets like UltraFeedback and UltraSafety, and mixing these datasets can balance different RM abilities.
- EURUS-RM-7B improves LLMs’ reasoning performance by a large margin through reranking.
## Usage
```python
from transformers import PreTrainedModel, AutoModel, AutoTokenizer, MistralConfig
import torch.nn as nn
import torch
from typing import Optional, List
class EurusRewardModel(PreTrainedModel):
config_class = MistralConfig
def __init__(self, config):
super().__init__(config)
self.model = AutoModel.from_pretrained(config)
self.regression_head = nn.Linear(self.config.hidden_size, 1, bias=False)
def forward( # args are the same as LlamaForCausalLM
self,
input_ids: torch.LongTensor = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[List[torch.FloatTensor]] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
labels: Optional[torch.LongTensor] = None,
use_cache: Optional[bool] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
):
transformer_outputs = self.model(
input_ids,
attention_mask=attention_mask,
position_ids=position_ids,
past_key_values=past_key_values,
inputs_embeds=inputs_embeds,
)
hidden_states = transformer_outputs[0]
rewards = self.regression_head(hidden_states).squeeze(-1)
ends = attention_mask.cumsum(dim=1).argmax(dim=1).view(-1,1)
rewards = torch.gather(rewards, 1, ends)
return rewards
def test(model_path):
dataset = [ # cases in webgpt; we use the same template as Mistral-Instruct-v0.2
{"chosen":"[INST] \"Who orders martinis \"\"shaken, not stirred\"\"?\" [\INST] Sean Connery's character, fictional British Secret Service agent James Bond, in the movie Goldfinger, stated that he preferred his martini to be \"shaken, not stirred\". [1] Some believe that Bond ordered his martini shaken because of the vodka it contained, as vodka was, for the most part, refined from potatoes (cheaper brands) which made the vodka oily. To disperse the oil, Bond ordered his martinis shaken. [2]","rejected":"[INST] \"Who orders martinis \"\"shaken, not stirred\"\"?\" [\INST] Fleming's fictional British Secret Service agent James Bond orders his martini cocktail shaken, not stirred [1]. Bond's preferences for his martini are carried over to the films, where his orders are seen in both the 1961 film Dr. No and the 2006 film Casino Royale [1, 2]. In both films, Bond's subordinates copy his order, telling the bartender to keep the fruit with their drinks [2]. However, in the 2006 film, Bond appears irritated when the bartender asks if he would like his drink shaken or stirred [2]."},
{"chosen":"[INST] Sural relates to which part of the body? [\INST] The sural region is the muscular swelling of the back of the leg below the knee, formed chiefly by the bellies of the gastrocnemius and soleus muscles [1,2].","rejected":"[INST] Sural relates to which part of the body? [\INST] The Sural nerve runs down the side of the leg near the small saphenous vein, then passes forward below the lateral malleolus and continues on the outside of the foot as the lateral dorsal cutaneous nerve, which then communicates with the intermediate dorsal cutaneous nerve, which branches off to the side of the foot. [1]"}
]
tokenizer = AutoTokenizer.from_pretrained(model_path)
config = AutoConfig.from_pretrained(model_path)
model = EurusRewardModel(config)
for example in dataset:
inputs = tokenizer(example["chosen"], return_tensors="pt")
chosen_reward = model(**inputs).item()
inputs = tokenizer(example["rejected"], return_tensors="pt")
rejected_reward = model(**inputs).item()
print(chosen_reward - rejected_reward)
test("openbmb/Eurus-RM-7b")
# Output 1: 0.14470714330673218
# Output 2: 0.7317184507846832
```
## Citation
```
@misc{yuan2024advancing,
title={Advancing LLM Reasoning Generalists with Preference Trees},
author={Lifan Yuan and Ganqu Cui and Hanbin Wang and Ning Ding and Xingyao Wang and Jia Deng and Boji Shan and Huimin Chen and Ruobing Xie and Yankai Lin and Zhenghao Liu and Bowen Zhou and Hao Peng and Zhiyuan Liu and Maosong Sun},
year={2024},
primaryClass={cs.CL}
}
``` |