-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsystem_1_baseline.py
64 lines (39 loc) · 1.87 KB
/
system_1_baseline.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
56
57
58
59
60
61
62
#coding=utf8
from tweetokenize import Tokenizer
from sklearn.decomposition import TruncatedSVD
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.feature_extraction.text import TfidfVectorizer
import configure
import semeval2016libs
#Load data , train , dev, devtest
ids,trainy,trainx=semeval2016libs.load_semeval_text_only(configure.SUBTASK_A_TRAIN_FILE)
idsdev,evaly,evalx=semeval2016libs.load_semeval_text_only(configure.SUBTASK_A_TRAIN_DEV)
idsdevtest,evaly2,evalx2=semeval2016libs.load_semeval_text_only(configure.SUBTASK_A_TRAIN_DEVTEST)
#load data test
ids,testy,testx=semeval2016libs.load_semeval_text_only(configure.SUBTASK_A_TEST)
gettokens = Tokenizer()
tfv = TfidfVectorizer(min_df=2,use_idf=1,smooth_idf=1,ngram_range=(1,10),analyzer=gettokens.tokenize) #,stop_words='english')
trainx=tfv.fit_transform(trainx)
rawevalx=evalx
evalx=tfv.transform(evalx)
print tfv.get_feature_names()
print trainx.shape,evalx.shape
tsvd=TruncatedSVD(n_components=400,random_state=2016) # this gives similar results as to Semeval , try n_components=600
trainx=tsvd.fit_transform(trainx)
evalx=tsvd.transform(evalx)
clf=LinearDiscriminantAnalysis()
clf.fit(trainx,trainy)
predictValue=clf.predict(evalx)
print semeval2016libs.scoreit(idsdev,predictValue,configure.SCORE_REF_DEV)
evalx2=tfv.transform(evalx2)
evalx2=tsvd.transform(evalx2)
predictValue=clf.predict(evalx2)
print semeval2016libs.scoreit(idsdevtest,predictValue,configure.SCORE_REF_DEVTEST)
testx=tfv.transform(testx)
testx=tsvd.transform(testx)
predictValue=clf.predict(testx)
print predictValue.shape
with open('results/scoring_test_data.sentence-three-point.subtaskA.pred.txt','w') as fout:
for lid,pvalue in zip(ids,predictValue):
fout.write('%s\t%s\n'%(lid,pvalue))
print semeval2016libs.scoreit(ids,predictValue,configure.SCORE_REF_TEST,score_script=configure.SCORE_SCRIPT_TEST)