-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patheval_bart_score.py
More file actions
26 lines (22 loc) · 879 Bytes
/
eval_bart_score.py
File metadata and controls
26 lines (22 loc) · 879 Bytes
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
import pandas as pd
from BARTScore.SUM.bart_score import BARTScorer
import numpy as np
device = "cuda"
bart_model_name = 'facebook/bart-large-cnn'
def compute_bart_score(df):
reference = df["Answer"].tolist()
prediction_1 = df["response (before)"].tolist()
prediction_2 = df["response (after)"].tolist()
bartscore = BARTScorer(device, max_length=512, checkpoint='facebook/bart-large-cnn')
bartscore.load()
results_gpt2 = bartscore.score(prediction_1, reference, batch_size=2)
results_rlhf = bartscore.score(prediction_2,reference,batch_size=2)
print("GPT2 Without RLHF")
print(results_gpt2)
print("Mean ", np.array(results_gpt2).mean())
print("GPT2 With RLHF")
print(results_rlhf)
print("Mean ", np.array(results_rlhf).mean())
if __name__ == "__main__":
df = pd.read_csv("full_out.csv")
compute_bart_score(df)