示例#1
0
 def __init__(self, item_num, hash_u_num, hash_layers, tree_layers, transfer_att_size,
              cs_ratio, sample_max_n, sample_r_n,
              *args, **kwargs):
     self.item_num = item_num
     self.hash_u_num = hash_u_num
     self.hash_layers = hash_layers if type(hash_layers) == list else eval(hash_layers)
     self.tree_layers = tree_layers if type(tree_layers) == list else eval(tree_layers)
     self.transfer_att_size = transfer_att_size
     self.sample_max_n, self.sample_r_n = sample_max_n, sample_r_n
     self.cs_ratio = cs_ratio
     DeepModel.__init__(self, *args, **kwargs)
示例#2
0
文件: RNNLogic.py 项目: ZSCDumin/NLR
 def __init__(self,
              rnn_type,
              rnn_bi,
              variable_num,
              feature_num=-1,
              *args,
              **kwargs):
     self.rnn_type = rnn_type.lower()
     self.rnn_bi = rnn_bi
     DeepModel.__init__(self, feature_num=variable_num + 3, *args, **kwargs)
     assert self.label_min == 0
     assert self.label_max == 1
示例#3
0
文件: RNNLogic.py 项目: ZSCDumin/NLR
 def parse_model_args(parser, model_name='RNNLogic'):
     parser.add_argument('--rnn_type',
                         type=str,
                         default="LSTM",
                         help='RNN/LSTM/GRU.')
     parser.add_argument('--rnn_bi',
                         type=int,
                         default=0,
                         help='1=bi-rnn/lstm/gru')
     return DeepModel.parse_model_args(parser, model_name)
示例#4
0
 def __init__(self,
              filter_size,
              filter_num,
              pooling,
              variable_num,
              feature_num=-1,
              *args,
              **kwargs):
     self.pooling = pooling.lower()
     self.filter_size = filter_size if type(filter_size) == list else eval(
         filter_size)
     self.filter_num = filter_num if type(filter_num) == list else eval(
         filter_num)
     if type(self.filter_size) is int:
         self.filter_size = [self.filter_size]
     if type(self.filter_num) is int:
         self.filter_num = [self.filter_num]
     assert len(self.filter_size) == len(self.filter_num)
     assert len(self.filter_size) > 0
     DeepModel.__init__(self, feature_num=variable_num + 3, *args, **kwargs)
     assert self.label_min == 0
     assert self.label_max == 1
示例#5
0
 def parse_model_args(parser, model_name='CNNLogic'):
     parser.add_argument('--filter_size',
                         type=str,
                         default="[2,4,6,8]",
                         help='list or int, means the size of filters')
     parser.add_argument('--filter_num',
                         type=str,
                         default="[16,16,16,16]",
                         help='list or int, means the number of filters')
     parser.add_argument('--pooling',
                         type=str,
                         default="sum",
                         help='Pooling type: sum, min, max, mean')
     return DeepModel.parse_model_args(parser, model_name)
示例#6
0
 def parse_model_args(parser, model_name='PreHash'):
     parser.add_argument('--hash_u_num', type=int, default=128,
                         help='Size of user hash.')
     parser.add_argument('--sample_max_n', type=int, default=128,
                         help='Sample top-n when learn hash.')
     parser.add_argument('--sample_r_n', type=int, default=128,
                         help='Sample random-n when learn hash.')
     parser.add_argument('--hash_layers', type=str, default='[32]',
                         help='MLP layer sizes of hash')
     parser.add_argument('--tree_layers', type=str, default='[64]',
                         help='Number of branches in each level of the hash tree')
     parser.add_argument('--transfer_att_size', type=int, default=16,
                         help='Size of attention layer of transfer layer (combine the hash and cf vector)')
     parser.add_argument('--cs_ratio', type=float, default=0.1,
                         help='Cold-Sampling ratio of each batch.')
     return DeepModel.parse_model_args(parser, model_name)
示例#7
0
_w2v = Word2vecLoader(wordsFilePath=_path+"/data/word2vec/dim300vecs",
                     conceptsFilePath=_path+"/data/word2vec/dim300context_vecs")

_w2v.loadEmbeddings(conceptDict=cD)
#_w2v.randomEmbeddings(conceptDict=cD)
print 'wordEmbedding dict size: ', len(_w2v.wordEmbeddings)
print 'conceptEmbeddings dict size: ', len(_w2v.conceptEmbeddings), " wanted", len(cD)
print 'Done!'

#print 'Connecting to db'
#wikiDB = WikipediaDbWrapper(user='******', password='******', database='wiki20151002',
#                            concept_filter=_w2v.conceptDict)
#print 'Done!'

print 'loading model'
model = DeepModel(_path + '/models/conll_model.config', w2v=_w2v, stats=ppr_stats, db=wikiDB)
predictor = model.getPredictor()
print 'Done!'

# Pre training (fine tuning model using training set)
print 'pretraining'
model.model.compile(optimizer='adagrad', loss='binary_crossentropy')
train_iter = CoNLLIterator(_path+'/data/CoNLL/CoNLL_AIDA-YAGO2-dataset.tsv', split='train')
trainer = ModelTrainer(train_iter, candidator, ppr_stats, model, epochs=5, neg_sample='all')
trainer.train()
model.saveModel(_path + '/models/basic_model')
print 'Done!'

print_attn = False

tried = 0