File size: 916 Bytes
05922fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
from tools.framenet.naive_identifier import FrameIdentifier

test_file_path = '/home/gqin2/data/framenet/full/test.jsonl'
test_sentences = [
    json.loads(line) for line in open(test_file_path)
]
test_set = []
for ann in test_sentences:
    for fr in ann['frame']:
        test_set.append((fr['name'], ann['text'][fr['target'][0]: fr['target'][-1]+1], fr['lu']))

fi = FrameIdentifier()


tp = fp = fn = 0
fails = []
for frame, target_words, lu in test_set:
    pred = fi(target_words)
    if frame in pred:
        tp += 1
        fp += len(pred) - 1
    else:
        fp += len(pred)
        fn += 1
        fails.append((frame, target_words, pred, lu))

fails.sort(key=lambda x: x[0])
for frame, target_words, pred, lu in fails:
    print(frame, ' '.join(target_words), ' '.join(pred), lu, sep='\t')

print(f'tp={tp}, fp={fp}, fn={fn}')
print(f'precision={tp/(tp+fp)}')
print(f'recall={tp/(tp+fn)}')