-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_responses.py
More file actions
25 lines (22 loc) · 888 Bytes
/
read_responses.py
File metadata and controls
25 lines (22 loc) · 888 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
import pickle as pkl
import pandas as pd
# open a pikcle file and read the responses that were appended to it until there are no more responses to read
def read_responses(file_name):
responses = []
with open(file_name, 'rb') as f:
while True:
try:
responses.append(pkl.load(f))
except EOFError:
break
return responses
responses = read_responses('data/10k_responses_gpt4.pkl')
# dictionary with sent as the key and rationale and label as the values
sent_rationale_label = {}
for response in responses:
if response[0] not in sent_rationale_label:
sent = response[0]
sent_rationale_label[sent] = {}
sent_rationale_label[sent]['rationale'] = response[1]
sent_rationale_label[sent]['label'] = response[2]
print("number of entries in the dictionary: ", len(sent_rationale_label))