other.py 文件源码

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

项目:StageDP 作者: EastonWang 项目源码 文件源码
def vectorize(features, vocab):
    """ Transform a features list into a numeric vector
        with a given vocab

    :type dpvocab: dict
    :param dpvocab: vocab for distributional representation

    :type projmat: scipy.lil_matrix
    :param projmat: projection matrix for disrep
    """
    vec = lil_matrix((1, len(vocab)))

    for feat in features:
        try:
            fidx = vocab[feat]
            vec[0, fidx] += 1.0
        except KeyError:
            pass
    # Normalization
    vec = normalize(vec)
    return vec
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号