-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathexample.py
More file actions
36 lines (30 loc) · 1.26 KB
/
example.py
File metadata and controls
36 lines (30 loc) · 1.26 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
import chains
import json
from pprint import pprint
def parse_test_instance(story):
"""Returns TWO ParsedStory instances representing option 1 and 2"""
# this is very compressed
id = story.InputStoryid
story = list(story)
sentences = [chains.nlp(sentence) for sentence in story[2:6]]
alternatives = [story[6], story[7]]
return [chains.ParsedStory(id, id, chains.nlp(" ".join(story[2:6]+[a])), *(sentences+[chains.nlp(a)])) for a in alternatives]
def story_answer(story):
"""Tells you the correct answer. Return (storyid, index). 1 for the first ending, 2 for the second ending"""
#obviously you can't use this information until you've chosen your answer!
return story.InputStoryid, story.AnswerRightEnding
# Load training data and build the model
#data, table = chains.process_corpus("train.csv", 100)
#print(table.pmi("move", "nsubj", "move", "nsubj"))
# load the pre-built model
with open("all.json") as fp:
table = chains.ProbabilityTable(json.load(fp))
# load testing data
test = chains.load_data("val.csv")
for t in test:
one, two = parse_test_instance(t)
one_deps = chains.extract_dependency_pairs(one)
pprint(one[2:])
pprint(two[2:])
# logic to choose between one and two
pprint("answer:"+ str(story_answer(t)))