-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
55 lines (38 loc) · 1.27 KB
/
test.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
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
import os
import torch
from tqdm import tqdm
@torch.no_grad()
def test_kobart(model, args, dataset):
if not os.path.exists("output"):
os.mkdir("output")
f = open(f"output/{args.ckpt[:-4]}.txt", "w")
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)
model.eval()
for i in tqdm(range(len(dataset))):
origin, answer, style = dataset[i]
content = f"""
origin: {origin}, style: {style}
generate: {model.generate([origin], [style])}
answer: {answer}
"""
f.write(content)
f.close()
def test_meta_kobart(model, args, dataset):
if not os.path.exists("checkpoint"):
os.mkdir("checkpoint")
f = open(f"output/{args.ckpt[:-4]}.txt", "w")
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)
model.eval()
for i in tqdm(range(len(dataset))):
spt, qry, style = dataset[i]
fast_weights = model.inner_loop(spt[0], spt[1])
with torch.no_grad():
content = f"""
origin: {qry[0][0]}, style: {style}
generate: {model.generate([qry[0][0]], fast_weights)}
answer: {qry[1][0]}
"""
f.write(content)
f.close()