word_movers_knn.py 文件源码

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

项目:sentence-classification 作者: bgmartins 项目源码 文件源码
def _wmd(self, i, row, X_train):
        """Compute the WMD between training sample i and given test row.

        Assumes that `row` and train samples are sparse BOW vectors summing to 1.
        """
        union_idx = np.union1d(X_train[i].indices, row.indices) - 1
        W_minimal = self.W_embed[union_idx]
        W_dist = euclidean_distances(W_minimal)
        bow_i = X_train[i, union_idx].A.ravel()
        bow_j = row[:, union_idx].A.ravel()
        return emd(bow_i, bow_j, W_dist)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号