Ejemplo n.º 1
0
 def load(filename):
     self = AttentionalTranslationModel()
     with ModelFile(filename) as fp:
         self.__src_vocab = Vocabulary.load(fp.get_file_pointer())
         self.__trg_vocab = Vocabulary.load(fp.get_file_pointer())
         self.__n_embed = int(fp.read())
         self.__n_hidden = int(fp.read())
         self.__make_model()
         wrapper.begin_model_access(self.__model)
         fp.read_embed(self.__model.w_xi)
         fp.read_linear(self.__model.w_ia)
         fp.read_linear(self.__model.w_aa)
         fp.read_linear(self.__model.w_ib)
         fp.read_linear(self.__model.w_bb)
         fp.read_linear(self.__model.w_aw)
         fp.read_linear(self.__model.w_bw)
         fp.read_linear(self.__model.w_pw)
         fp.read_linear(self.__model.w_we)
         fp.read_linear(self.__model.w_ap)
         fp.read_linear(self.__model.w_bp)
         fp.read_embed(self.__model.w_yp)
         fp.read_linear(self.__model.w_pp)
         fp.read_linear(self.__model.w_cp)
         fp.read_linear(self.__model.w_dp)
         fp.read_linear(self.__model.w_py)
         wrapper.end_model_access(self.__model)
     return self
Ejemplo n.º 2
0
 def save(self, filename):
     with ModelFile(filename, 'w') as fp:
         self.__vocab.save(fp.get_file_pointer())
         fp.write(self.__n_context)
         fp.write(self.__n_hidden)
         wrapper.begin_model_access(self.__model)
         fp.write_embed(self.__model.w_xh)
         fp.write_linear(self.__model.w_hy)
         wrapper.end_model_access(self.__model)
Ejemplo n.º 3
0
 def load(filename):
     self = SegmentationModel()
     with ModelFile(filename) as fp:
         self.__vocab = Vocabulary.load(fp.get_file_pointer())
         self.__n_context = int(fp.read())
         self.__n_hidden = int(fp.read())
         self.__make_model()
         wrapper.begin_model_access(self.__model)
         fp.read_embed(self.__model.w_xh)
         fp.read_linear(self.__model.w_hy)
         wrapper.end_model_access(self.__model)
     return self
Ejemplo n.º 4
0
 def save(self, filename):
     with ModelFile(filename, 'w') as fp:
         self.__vocab.save(fp.get_file_pointer())
         fp.write(self.__n_embed)
         fp.write(self.__n_hidden)
         wrapper.begin_model_access(self.__model)
         fp.write_embed(self.__model.w_xe)
         fp.write_linear(self.__model.w_ea)
         fp.write_linear(self.__model.w_aa)
         fp.write_linear(self.__model.w_eb)
         fp.write_linear(self.__model.w_bb)
         fp.write_linear(self.__model.w_ay1)
         fp.write_linear(self.__model.w_by1)
         fp.write_linear(self.__model.w_ay2)
         fp.write_linear(self.__model.w_by2)
         wrapper.end_model_access(self.__model)
Ejemplo n.º 5
0
 def save(self, filename):
     with ModelFile(filename, 'w') as fp:
         self.__src_vocab.save(fp.get_file_pointer())
         self.__trg_vocab.save(fp.get_file_pointer())
         fp.write(self.__n_embed)
         fp.write(self.__n_hidden)
         wrapper.begin_model_access(self.__model)
         fp.write_embed(self.__model.w_xi)
         fp.write_linear(self.__model.w_ip)
         fp.write_linear(self.__model.w_pp)
         fp.write_linear(self.__model.w_pq)
         fp.write_linear(self.__model.w_qj)
         fp.write_linear(self.__model.w_jy)
         fp.write_embed(self.__model.w_yq)
         fp.write_linear(self.__model.w_qq)
         wrapper.end_model_access(self.__model)
Ejemplo n.º 6
0
 def load(filename):
     self = RNNSegmentationModel()
     with ModelFile(filename) as fp:
         self.__vocab = Vocabulary.load(fp.get_file_pointer())
         self.__n_embed = int(fp.read())
         self.__n_hidden = int(fp.read())
         self.__make_model()
         wrapper.begin_model_access(self.__model)
         fp.read_embed(self.__model.w_xe)
         fp.read_linear(self.__model.w_ea)
         fp.read_linear(self.__model.w_aa)
         fp.read_linear(self.__model.w_eb)
         fp.read_linear(self.__model.w_bb)
         fp.read_linear(self.__model.w_ay1)
         fp.read_linear(self.__model.w_by1)
         fp.read_linear(self.__model.w_ay2)
         fp.read_linear(self.__model.w_by2)
         wrapper.end_model_access(self.__model)
     return self
Ejemplo n.º 7
0
 def load(filename):
     self = EncoderDecoderModel()
     with ModelFile(filename) as fp:
         self.__src_vocab = Vocabulary.load(fp.get_file_pointer())
         self.__trg_vocab = Vocabulary.load(fp.get_file_pointer())
         self.__n_embed = int(fp.read())
         self.__n_hidden = int(fp.read())
         self.__make_model()
         wrapper.begin_model_access(self.__model)
         fp.read_embed(self.__model.w_xi)
         fp.read_linear(self.__model.w_ip)
         fp.read_linear(self.__model.w_pp)
         fp.read_linear(self.__model.w_pq)
         fp.read_linear(self.__model.w_qj)
         fp.read_linear(self.__model.w_jy)
         fp.read_embed(self.__model.w_yq)
         fp.read_linear(self.__model.w_qq)
         wrapper.end_model_access(self.__model)
     return self
Ejemplo n.º 8
0
 def save(self, filename):
     with ModelFile(filename, 'w') as fp:
         self.__src_vocab.save(fp.get_file_pointer())
         self.__trg_vocab.save(fp.get_file_pointer())
         fp.write(self.__n_embed)
         fp.write(self.__n_hidden)
         wrapper.begin_model_access(self.__model)
         fp.write_embed(self.__model.w_xi)
         fp.write_linear(self.__model.w_ia)
         fp.write_linear(self.__model.w_aa)
         fp.write_linear(self.__model.w_ib)
         fp.write_linear(self.__model.w_bb)
         fp.write_linear(self.__model.w_aw)
         fp.write_linear(self.__model.w_bw)
         fp.write_linear(self.__model.w_pw)
         fp.write_linear(self.__model.w_we)
         fp.write_linear(self.__model.w_ap)
         fp.write_linear(self.__model.w_bp)
         fp.write_embed(self.__model.w_yp)
         fp.write_linear(self.__model.w_pp)
         fp.write_linear(self.__model.w_cp)
         fp.write_linear(self.__model.w_dp)
         fp.write_linear(self.__model.w_py)
         wrapper.end_model_access(self.__model)