word2vec.py 文件源码

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

项目:ShallowLearn 作者: giacbrd 项目源码 文件源码
def score_cbow_labeled_pair(model, targets, l1):
        if model.hs:
            prob = []
            # FIXME this cycle should be executed internally in numpy
            for target in targets:
                l2a = model.syn1[target.point]
                sgn = (-1.0) ** target.code  # ch function, 0-> 1, 1 -> -1
                prob.append(prod(expit(sgn * dot(l1, l2a.T))))
        # Softmax
        else:
            def exp_dot(x):
                return exp(dot(l1, x.T))

            prob_num = exp_dot(model.syn1neg[[t.index for t in targets]])
            prob_den = np_sum(apply_along_axis(exp_dot, 1, model.syn1neg))
            prob = prob_num / prob_den
        return prob
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号