twitter_pos.py 文件源码

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

项目:GELUs 作者: hendrycks 项目源码 文件源码
def embeddings_to_dict(filename):
    '''
    :param filename: the file name of the word embeddings | file is assumed
    to follow this format: "word[tab]dimension 1[space]dimension 2[space]...[space]dimension 50"
    :return: a dictionary with keys that are words and values that are the embedding of a word
    '''
    with io.open(filename, 'r', encoding='utf-8') as f:
        word_vecs = {}
        for line in f:
            line = line.strip('\n').split()
            word_vecs[line[0]] = np.array([float(s) for s in line[1:]])

    return word_vecs
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号