Example #1
0
class Execute(object):
    def __init__(self):
        self.depnn = DepNN()
        self.depnn.extendLookUp('../data/depcheck2')
        self.depnn.load_wordvector('../data/word-vec.bin')
        self.deptree = DependencyTree()

    def build_model(self):
        self.depnn.build_AutoEncoder(200, '../data/compilation.bin')

    def load_model(self):
        self.depnn.load_AutoEncoder('../data/compilation.bin')


    def train_sentence(self, lines):
        w = self.deptree.read_sent(lines[0])
        y = self.deptree.read_dependency(lines[1])
        #self.depnn.saveRAE('../data/weights.bin')
        #self.depnn.loadRAE('../data/weights.bin')
        print ' '.join(x[0] for x in w)
        
        self.depnn.build_DepRNN_Tree(y)
    
    def dump_weights(self, db_file):
        self.depnn.saveRAE(db_file)
    
    def load_weights(self, db_file):
        self.depnn.loadRAE(db_file)
Example #2
0
def main():
    print 'ok.'
    lines = ('[(S (NP (DT Those) (NN space)) (VP (VBZ walks) (SBAR (S (VP (VBP are) (S (VP (TO to) (VP (VB be) (VP (VBN used) (PP (IN for) (S (VP (VBG preparing) (NP (NP (DT the) (NNP ISS)) (PP (IN for) (NP (NP (DT the) (VBN planned) (NN docking)) (NP (JJ next) (NN year)) (PP (IN of) (NP (DT the) (JJ new) (NNP European) (NNP ATV) (NN space) (NN cargo) (NN vessel))))))))))))))))) (. .))]','[det(space-2, Those-1), nsubj(walks-3, space-2), root(ROOT-0, walks-3), ccomp(walks-3, are-4), aux(used-7, to-5), auxpass(used-7, be-6), xcomp(are-4, used-7), prepc_for(used-7,preparing-9), det(ISS-11, the-10), dobj(preparing-9, ISS-11), det(docking-15, the-13), amod(docking-15, planned-14), prep_for(ISS-11, docking-15), amod(year-17, next-16), dep(docking-15, year-17), det(vessel-25, the-19), amod(vessel-25, new-20), nn(vessel-25, European-21), nn(vessel-25, ATV-22), nn(vessel-25, space-23), nn(vessel-25, cargo-24), prep_of(docking-15, vessel-25)]')

    D = DependencyTree()
    w = D.read_sent(lines[0])   
    print ' '.join([x[0]+'/'+x[1] for x in w])

    y = D.read_dependency(lines[1])
    for d in y:
        print d
    pass