-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_fake_named_entities.py
31 lines (24 loc) · 1.04 KB
/
extract_fake_named_entities.py
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
import json
import os
from dotenv import load_dotenv
load_dotenv()
DIR = os.getenv("DIR")
with open(f'{DIR}/fake_entities_generated.json') as fp:
all_responses = json.load(fp)
with open(f'{DIR}/fake_named_entities_openai_prompts.json') as fp:
all_things = json.load(fp)
all_named_entities = [[], []]
for thing, i in zip(all_things[0], all_responses[0]):
to_go_through = i["choices"][0]["message"]["content"].split("\n")
for named_ents in to_go_through:
if len(to_go_through) < 20:
print(thing["user_prompt"])
all_named_entities[0].append(named_ents[named_ents.rfind(":") + 1:].strip())
for thing, i in zip(all_things[1], all_responses[1]):
to_go_through = i["choices"][0]["message"]["content"].split("\n")
for named_ents in to_go_through:
if len(to_go_through) < 20:
print(thing["user_prompt"])
all_named_entities[1].append(named_ents[named_ents.rfind(":") + 1:].strip())
with open(f'{DIR}/all_fake_named_entities_extracted.json', 'w') as fp:
json.dump(all_named_entities, fp)