Instructions to use RLHFlow/RewardModel-Mistral-7B-for-DPA-v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use RLHFlow/RewardModel-Mistral-7B-for-DPA-v1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="RLHFlow/RewardModel-Mistral-7B-for-DPA-v1", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("RLHFlow/RewardModel-Mistral-7B-for-DPA-v1", trust_remote_code=True) model = AutoModelForSequenceClassification.from_pretrained("RLHFlow/RewardModel-Mistral-7B-for-DPA-v1", trust_remote_code=True) - Notebooks
- Google Colab
- Kaggle
| import torch | |
| from torch.nn import functional as F | |
| from transformers.models.mistral.modeling_mistral import MistralForSequenceClassification | |
| class NormalizedLinear(torch.nn.Linear): | |
| def forward(self, x): | |
| x = F.normalize(x, p=2, dim=-1) | |
| return super().forward(x) | |
| class MistralForAttributePrediction(MistralForSequenceClassification): | |
| def __init__(self, config): | |
| super().__init__(config) | |
| del self.score | |
| self.score = NormalizedLinear(config.hidden_size, config.num_labels, bias=True) | |
| # Initialize weights and apply final processing | |
| self.post_init() |