This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
demo.py
41 lines (32 loc) · 1.2 KB
/
demo.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
import stst
# Define Model
gb = stst.Classifier(stst.GradientBoostingRegression())
model = stst.Model('S1-gb', gb)
# Add features to the Model
model.add(stst.WeightednGramOverlapFeature(type='lemma'))
model.add(stst.BOWFeature(stopwords=False))
model.add(stst.AlignmentFeature())
model.add(stst.IdfAlignmentFeature())
model.add(stst.NegativeFeature())
# train and test
train_file = './data/stsbenchmark/sts-train.csv'
dev_file = './data/stsbenchmark/sts-dev.csv'
test_file = './data/stsbenchmark/sts-test.csv'
# init the server and input the address
parser = stst.StanfordNLP('http://localhost:9000')
# parse data
train_instances = stst.load_parse_data(train_file, parser)
dev_instances = stst.load_parse_data(dev_file, parser)
# train and test
model.train(train_instances, train_file)
model.test(dev_instances, dev_file)
# evaluation
dev_pearsonr = stst.eval_output_file(model.output_file)
print('Dev:', dev_pearsonr)
# test on new data set
test_instances= stst.load_parse_data(test_file, parser)
model.test(test_instances, test_file)
test_pearsonr = stst.eval_output_file(model.output_file)
print('Test:', test_pearsonr)
recod_file = './data/records.csv'
stst.record(recod_file, dev_pearsonr, test_pearsonr, model)