Text Classification
Transformers
Safetensors
English
llama
feature-extraction
llama3
reward-model
preference-modeling
rlhf
multi-domain
coherence
commonsense
empathy
multicultural
shared-prompt-gating
custom_code
text-embeddings-inference
Instructions to use mario-rc/multi-domain-rm-fsfairx-llama-3-8b-it with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mario-rc/multi-domain-rm-fsfairx-llama-3-8b-it with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="mario-rc/multi-domain-rm-fsfairx-llama-3-8b-it", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("mario-rc/multi-domain-rm-fsfairx-llama-3-8b-it", trust_remote_code=True) model = AutoModel.from_pretrained("mario-rc/multi-domain-rm-fsfairx-llama-3-8b-it", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Add usage example to model card
Browse files
README.md
CHANGED
|
@@ -55,6 +55,51 @@ Preference accuracy by domain:
|
|
| 55 |
| Empathy | 94.3606 |
|
| 56 |
| Multicultural | 76.2950 |
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
## Limitations
|
| 59 |
|
| 60 |
This is a reward model, not a standalone chat assistant. Scores are intended for
|
|
|
|
| 55 |
| Empathy | 94.3606 |
|
| 56 |
| Multicultural | 76.2950 |
|
| 57 |
|
| 58 |
+
## Usage Example
|
| 59 |
+
|
| 60 |
+
This checkpoint uses the project's custom `RewardModelWithGating` class. Run the
|
| 61 |
+
example from an environment where `multidomain_model/modeling_custom.py` is
|
| 62 |
+
importable.
|
| 63 |
+
|
| 64 |
+
```python
|
| 65 |
+
import torch
|
| 66 |
+
from transformers import AutoTokenizer
|
| 67 |
+
from modeling_custom import RewardModelWithGating
|
| 68 |
+
|
| 69 |
+
model_id = "mario-rc/multi-domain-rm-fsfairx-llama-3-8b-it"
|
| 70 |
+
dtype = torch.bfloat16 if torch.cuda.is_available() else torch.float32
|
| 71 |
+
device_map = {"": 0} if torch.cuda.is_available() else None
|
| 72 |
+
|
| 73 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=True)
|
| 74 |
+
model = RewardModelWithGating.from_pretrained(
|
| 75 |
+
model_id,
|
| 76 |
+
device_map=device_map,
|
| 77 |
+
dtype=dtype,
|
| 78 |
+
).eval()
|
| 79 |
+
device = next(model.parameters()).device
|
| 80 |
+
|
| 81 |
+
messages = [
|
| 82 |
+
{"role": "user", "content": "I failed an important exam and feel awful."},
|
| 83 |
+
{"role": "assistant", "content": "I'm sorry. That is a hard setback, but it does not define your ability. Take a little time to recover, then we can make a concrete study plan for the next attempt."},
|
| 84 |
+
]
|
| 85 |
+
|
| 86 |
+
encoded = tokenizer.apply_chat_template(
|
| 87 |
+
messages,
|
| 88 |
+
return_tensors="pt",
|
| 89 |
+
padding=True,
|
| 90 |
+
truncation=True,
|
| 91 |
+
max_length=4096,
|
| 92 |
+
)
|
| 93 |
+
inputs = {"input_ids": encoded.to(device)} if isinstance(encoded, torch.Tensor) else {
|
| 94 |
+
key: value.to(device) for key, value in encoded.items()
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
with torch.no_grad():
|
| 98 |
+
score = model(**inputs).score.float().item()
|
| 99 |
+
|
| 100 |
+
print(score)
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
## Limitations
|
| 104 |
|
| 105 |
This is a reward model, not a standalone chat assistant. Scores are intended for
|