-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
52 lines (44 loc) · 1.08 KB
/
utils.py
File metadata and controls
52 lines (44 loc) · 1.08 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
import os
def save_assert_prompt(output_dir, template, suffix=""):
os.makedirs(output_dir, exist_ok=True)
prompt_template_filepath = os.path.join(output_dir, f"{suffix}prompt_template.txt")
if not os.path.exists(prompt_template_filepath):
with open(prompt_template_filepath, "w") as f:
f.write(template)
else:
with open(prompt_template_filepath, "r") as f:
assert template == f.read()
print(prompt_template_filepath)
def load_prompts(language, task, use_context=False):
prompts = []
if use_context:
filepath = f"prompt-templates/{task}+context/{language}_prompts.txt"
else:
filepath = f"prompt-templates/{task}/{language}_prompts.txt"
with open(filepath, "r") as f:
cache = []
for line in f:
line
if line.startswith("#"):
cache[-1] = cache[-1].strip()
prompts.append("".join(cache))
cache = []
else:
cache.append(line)
return prompts
pos_tagset = [
"NOUN",
"ADJ",
"ADV",
"VERB",
"PROPN",
"ADP",
"NUM",
"SCONJ",
"DET",
"AUX",
"PRON",
"CCONJ",
"X",
"INTJ"
]