[tf]tensorflow embedding加载预训练好的
embedding_model = gensim.models.KeyedVectors.load_word2vec_format(FLAGS.glove_path,binary=True)
embedding_numpy = np.zeros((self.vocab_size,300))
for i in self.vocab_size:
this_word = self.vocab.id2word(i)
try :
this_vector = embedding_model[this_word]
except KeyError:
this_vector = None
if not this_vector:
embedding_numpy[i] = this_vector
W = tf.get_variable(name="W", shape=embedding.shape,
initializer=tf.constant_initializer(embedding_numpy),
trainable=False)
本文标题:[tf]tensorflow embedding加载预训练好的
本文链接:https://www.haomeiwen.com/subject/wwrfaqtx.html
网友评论