-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdump_output.py
More file actions
executable file
·82 lines (56 loc) · 2.59 KB
/
dump_output.py
File metadata and controls
executable file
·82 lines (56 loc) · 2.59 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python
import pandas as pd
import sys
from collections import defaultdict
import argparse
def process_json(file_name, dump_models, model_filter):
score_gpt = defaultdict(lambda: [0, 0])
score_simple = defaultdict(lambda: [0, 0])
try:
# Reading the JSON file using Pandas
df = pd.read_json(file_name)
# Iterating over each row and printing the required format
for index, row in df.iterrows():
if model_filter is not None and model_filter not in row["model_tag"]:
continue
if dump_models:
gpt_response = row.get('score_gpt_response', None)
if gpt_response is None:
# Old version
print(row.keys())
gpt_response = row.get('score_response', "")
print(">>>> MODEL:", row["model_tag"])
print(">>>> MODIFICATION:", row["modification_tag"])
print(">>>> PROMPT:")
print(row['prompt'])
print(">>>> RESPONSE:")
print(row['response'])
print(">>>> SCORING:")
print(f"CORRECT = {row['known_answer']}; score_simple = {row['score_simple']}; score_gpt = {row['score_gpt']} ({gpt_response}); ")
print("======================\n\n")
model = row["model_tag"]
t = score_gpt[model]
t[0] += 1
t[1] += row["score_gpt"]
t = score_simple[model]
t[0] += 1
t[1] += row["score_simple"]
except Exception as e:
print(f"An error occurred: {e}")
for k in score_gpt.keys():
score_gpt_t = score_gpt[k]
score_simple_t = score_simple[k]
print(f"{k}: simple_score = {score_simple_t[1] / score_simple_t[0]}, score_gpt = {score_gpt_t[1] / score_gpt_t[0]}")
if __name__ == "__main__":
# Create the parser
parser = argparse.ArgumentParser(description='Process a file with an optional debug mode.')
# Add the positional argument for the file
parser.add_argument('file', type=str, help='The JSON model dump.')
# Add the optional argument '-d' for debug mode
parser.add_argument('-f', '--full', action='store_true', help='Dump full responses')
parser.add_argument('--model', type=str, help='The model to use (substring search in tag)', default= None)
# Parse the arguments
args = parser.parse_args()
# Now you can use args.file and args.debug in your script
print(f'Processing file: {args.file}')
process_json(args.file, args.full, args.model)