w2v.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:wtfrnn 作者: juliakreutzer 项目源码 文件源码
def build_eval_graph(self):
    """Build the eval graph."""
    # Eval graph

    # Normalized word embeddings of shape [vocab_size, emb_dim].
    nemb = tf.nn.l2_normalize(self._emb, 1)

    # Nodes for computing neighbors for a given word according to
    # their cosine distance.
    nearby_word = tf.placeholder(dtype=tf.int32)  # word id
    nearby_emb = tf.gather(nemb, nearby_word)
    nearby_dist = tf.matmul(nearby_emb, nemb, transpose_b=True)
    nearby_val, nearby_idx = tf.nn.top_k(nearby_dist,
                                         min(1000, self._options.vocab_size))
    self._nearby_word = nearby_word
    self._nearby_val = nearby_val
    self._nearby_idx = nearby_idx
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号