RewardModelPT / README.md
nicholasKluge's picture
Upload 16 files
1d42d90
|
raw
history blame
5.51 kB
---
license: apache-2.0
datasets:
- nicholasKluge/reward-aira-dataset
language:
- en
metrics:
- accuracy
library_name: transformers
pipeline_tag: text-classification
tags:
- reward model
- alignment
- preference model
- RLHF
widget:
- text: "Por que a ética da IA é importante? [SEP] Quem se importa com a ética da IA? É apenas um monte de reclamações sobre os humanos que criam e usam IA e reclamam do que as máquinas fazem."
example_title: "Resposta Ruim"
- text: "Por que a ética da IA é importante? [SEP] O campo da ética da IA se aprofunda nas intrincadas considerações éticas que surgem com relação aos sistemas de IA. Isso inclui o papel da humanidade na criação e implantação desses sistemas, bem como a conduta das próprias máquinas. Em termos gerais, a ética da IA pode ser dividida em duas categorias principais: preocupações com a moralidade das ações humanas em relação à criação e ao uso da IA e preocupações com as implicações morais do comportamento da máquina."
example_title: "Resposta Boa"
---
# RewardModel (Portuguese)
The `RewardModelPT` is a [BERT](https://huggingface.co/neuralmind/bert-base-portuguese-cased) model that can be used to score the quality of a completion for a given prompt.
The model was trained with a dataset composed of `prompt`, `prefered_completions`, and `rejected_completions`.
These prompt + completions are samples of intruction datasets created via the [Self-Instruct](https://github.com/yizhongw/self-instruct) framework.
## Details
- **Size:** 109,038,209 parameters
- **Dataset:** [Reward-Aira Dataset](https://huggingface.co/datasets/nicholasKluge/reward-aira-dataset)
- **Language:** Portuguese
- **Number of Epochs:** 5
- **Batch size:** 42
- **Optimizer:** `torch.optim.AdamW`
- **Learning Rate:** 5e-5
- **GPU:** 1 NVIDIA A100-SXM4-40GB
- **Emissions:** 0.23 KgCO2
- **Total Energy Consumption:** 0.48 kWh
| Step|Training Loss|Validation Loss|Accuracy|
|---|---|---|---|
| 200 |0.079500|0.043422|0.986357|
| 400 |0.043400|0.035848|0.986955|
| 600 |0.037500|0.034161|0.987674|
| 800 |0.011200|0.039309|0.988511|
| 1000 |0.008900|0.043876|0.987793|
| 1200 |0.011700|0.041023|0.989588|
| 1400 |0.002800|0.055005|0.989588|
| 1600 |0.001400|0.054428|0.988990|
| 1800 |0.001100|0.053148|0.989588|
| 2000 |0.000200|0.058280|0.989469|
| 2200 |0.000200|0.054245|0.989708|
| 2400 |0.000200|0.058009|0.989588|
| 2600 |0.000200|0.059581|0.989349|
| 2800 |0.001100|0.057820|0.989110|
This repository has the notebook used to train this model.
## Usage
Here's an example of how to use the `RewardModelPT` to score the quality of a response to a given prompt:
```python
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
tokenizer = AutoTokenizer.from_pretrained("nicholasKluge/RewardModelPT")
rewardModel = AutoModelForSequenceClassification.from_pretrained("nicholasKluge/RewardModelPT")
rewardModel.eval()
rewardModel.to(device)
# Define the question and response
prompt = "Por que a ética da IA é importante?"
response_good = "O campo da ética da IA se aprofunda nas intrincadas considerações éticas que surgem com relação aos sistemas de IA. Isso inclui o papel da humanidade na criação e implantação desses sistemas, bem como a conduta das próprias máquinas. Em termos gerais, a ética da IA pode ser dividida em duas categorias principais: preocupações com a moralidade das ações humanas em relação à criação e ao uso da IA e preocupações com as implicações morais do comportamento da máquina."
response_bad = "Quem se importa com a ética da IA? É apenas um monte de reclamações sobre os humanos que criam e usam IA e reclamam do que as máquinas fazem."
# Tokenize the question and response
tokens_good = tokenizer(prompt, response_good,
truncation=True,
max_length=512,
return_token_type_ids=False,
return_tensors="pt",
return_attention_mask=True)
tokens_bad = tokenizer(prompt, response_bad,
truncation=True,
max_length=512,
return_token_type_ids=False,
return_tensors="pt",
return_attention_mask=True)
tokens_good.to(device)
tokens_bad.to(device)
score_good = rewardModel(**tokens_good)[0].item()
score_bad = rewardModel(**tokens_bad)[0].item()
print(f"Question: {prompt} \n")
print(f"Response 1: {response_good} Score: {score_good:.3f}")
print(f"Response 2: {response_bad} Score: {score_bad:.3f}")
```
This will output the following:
```markdown
>>> Question: Why is AI Ethics important?
>>>Response 1: The field of AI Ethics delves deeply into the intricate ethical considerations that arise with respect to AI systems. This includes the role of humanity in creating and deploying these systems, as well as the conduct of machines themselves. Broadly speaking, AI Ethics can be divided into two major categories : concerns surrounding the morality of human actions in relation to creating and using AI, and concerns regarding the moral implications of machine behavior. Score: 4.777
>>>Response 2: Who cares about AI Ethics? It's just a bunch of whining about humans making and using AI and bitching about what the machines do. Score: -11.582
```
## License
The `RewardModelPT` is licensed under the Apache License, Version 2.0. See the [LICENSE](LICENSE) file for more details.