The RewardModel is a
BERT model that can be used to score the quality of a completion for a given prompt.
This repository has the
source code used to train this model.
Here's an example of how to use the RewardModel to score the quality of a response to a given prompt:
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
5
6tokenizer = AutoTokenizer.from_pretrained("nicholasKluge/RewardModel")
7rewardModel = AutoModelForSequenceClassification.from_pretrained("nicholasKluge/RewardModel")
8
9rewardModel.eval()
10rewardModel.to(device)
11
12# Define the question and response
13prompt = "Why is AI Ethics important?"
14response_good = "AI ethics is important for several compelling reasons:\n\n1.**Social Impact**: AI technologies are becoming increasingly integrated into various aspects of society, affecting everything from healthcare and education to finance and law enforcement. Ethical considerations ensure that AI systems contribute positively to society and minimize potential harm.\n\n2. **Bias and Fairness**: AI systems can inherit biases present in the data they are trained on, leading to unfair or discriminatory outcomes. Ethical considerations push for the development of unbiased algorithms that treat all individuals fairly, regardless of their background.\n\n3. **Transparency and Accountability**: Many AI systems operate as black boxes, making it difficult to understand how they arrive at their decisions. Ethical guidelines emphasize the importance of transparency, enabling users to comprehend the rationale behind AI-generated results and holding developers accountable for any negative consequences.\n\nIn summary, AI ethics is vital to ensure that artificial intelligence benefits society while respecting fundamental human rights, fairness, transparency, accountability, and the long-term well-being of humanity. It helps navigate the challenges posed by rapidly advancing AI technologies and guides their development in ways that align with our shared values."
15response_bad = "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."
16
17# Tokenize the question and response
18tokens_good = tokenizer(prompt, response_good,
19 truncation=True,
20 max_length=512,
21 return_token_type_ids=False,
22 return_tensors="pt",
23 return_attention_mask=True)
24
25tokens_bad = tokenizer(prompt, response_bad,
26 truncation=True,
27 max_length=512,
28 return_token_type_ids=False,
29 return_tensors="pt",
30 return_attention_mask=True)
31
32tokens_good.to(device)
33tokens_bad.to(device)
34
35score_good = rewardModel(**tokens_good)[0].item()
36score_bad = rewardModel(**tokens_bad)[0].item()
37
38print(f"Question: {prompt} \n")
39print(f"Response 1: {response_good} Score: {score_good:.3f}")
40print(f"Response 2: {response_bad} Score: {score_bad:.3f}")
1Question: Why is AI Ethics important?
2
3>>>Response 1: AI ethics is important for several compelling reasons:
4
51.**Social Impact**: AI technologies are becoming increasingly integrated into various aspects of society,
6affecting everything from healthcare and education to finance and law enforcement. Ethical considerations
7ensure that AI systems contribute positively to society and minimize potential harm.
8
92. **Bias and Fairness**: AI systems can inherit biases present in the data they are trained on, leading
10to unfair or discriminatory outcomes. Ethical considerations push for the development of unbiased
11algorithms that treat all individuals fairly, regardless of their background.
12
133. **Transparency and Accountability**: Many AI systems operate as black boxes, making it difficult to
14understand how they arrive at their decisions. Ethical guidelines emphasize the importance of
15transparency, enabling users to comprehend the rationale behind AI-generated results and holding
16developers accountable for any negative consequences.
17
18In summary, AI ethics is vital to ensure that artificial intelligence benefits society while respecting
19fundamental human rights, fairness, transparency, accountability, and the long-term well-being of humanity.
20It helps navigate the challenges posed by rapidly advancing AI technologies and guides their development in
21ways that align with our shared values. Score: 12.011
22
23>>>Response 2: Who cares about AI Ethics? It's just a bunch of whining about humans making and using AI
24and bitching about what the machines do. Score: -10.942
25
1@misc{nicholas22aira,
2 doi = {10.5281/zenodo.6989727},
3 url = {https://github.com/Nkluge-correa/Aira},
4 author = {Nicholas Kluge Corrêa},
5 title = {Aira},
6 year = {2023},
7 publisher = {GitHub},
8 journal = {GitHub repository},
9}
10
11@phdthesis{kluge2024dynamic,
12 title={Dynamic Normativity},
13 author={Kluge Corr{\^e}a, Nicholas},
14 year={2024},
15 school={Universit{\"a}ts-und Landesbibliothek Bonn}
16}
RewardModel is licensed under the Apache License, Version 2.0. See the
LICENSE file for more details.