美文网首页
[tf]tensorflow embedding加载预训练好的

[tf]tensorflow embedding加载预训练好的

作者: VanJordan | 来源:发表于2019-05-11 20:01 被阅读0次
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