-
Notifications
You must be signed in to change notification settings - Fork 26
/
save.py
executable file
·46 lines (43 loc) · 1.63 KB
/
save.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
input=jacana formated text files
output=pickled q objects
"""
from basicgrad import ttlist
from vecfromtext import textArrays,shortGlove
from bow import prepForGrad
import pickle
import numpy as np
from const import *
def trecEval(li,count=True):
truth=open('truth.txt','w')
res=open('res.txt','w')
for i in range(0,len(li)):
for j in range(0,len(li[i].y)):
truth.write(' '.join(map(str,(i,0,j,int(li[i].y[j]),'\n'))))
if (count):
res.write(' '.join(map(str,(i,0,j,1,li[i].tcount[j],'glove','\n'))))
else:
res.write(' '.join(map(str,(i,0,j,1,li[i].t[j],'glove','\n'))))
truth.close()
res.close()
print 'trec_eval created'
return
def saveQlist(QPATH,APATH1,APATH0,GLOVEPATH,GLOVEPATH2,PLIST,PANS1,PANS0,new_dict=False,c1=False,c0=False):
"""From jacana formated documents of questions, true answers, false answers
saves list of Qs to PLIST path"""
(q,a1,a0,ans1,ans0)=textArrays(QPATH,APATH1,APATH0)
if new_dict==True:
shortGlove(q,a1,a0,GLOVEPATH,GLOVEPATH2)
(qa,a1a,a0a)=prepForGrad(q,a1,a0,ans1,ans0,GLOVEPATH2)
sentences=(q,a1,a0)
li=ttlist(qa,a1a,a0a,ans1,ans0,sentences,c1,c0)
pickle.dump( li, open( PLIST , "wb" ) )
np.savetxt(PANS1,ans1)
np.savetxt(PANS0,ans0)
return
saveQlist(QPATH,APATH1,APATH0,GLOVEPATH,GLOVEPATH2,LISTPATH,PANS1,PANS0,new_dict=True,c1=CPATH1,c0=CPATH0)
print 'training data saved'
#saveQlist(TQPATH,TAPATH1,TAPATH0,GLOVEPATH,TGLOVEPATH2,TLISTPATH,PTANS1,PTANS0,new_dict=True,c1=TCPATH1,c0=TCPATH0)
#print 'testing data saved'