Load Pretrained glove vectors in python

前端 未结 10 568
眼角桃花
眼角桃花 2021-01-29 22:12

I have downloaded pretrained glove vector file from the internet. It is a .txt file. I am unable to load and access it. It is easy to load and access a word vector binary file u

10条回答
  •  南方客
    南方客 (楼主)
    2021-01-29 22:41

    I found this approach faster.

    import pandas as pd
    
    df = pd.read_csv('glove.840B.300d.txt', sep=" ", quoting=3, header=None, index_col=0)
    glove = {key: val.values for key, val in df.T.items()}
    

    Save the dictionary:

    import pickle
    with open('glove.840B.300d.pkl', 'wb') as fp:
        pickle.dump(glove, fp)
    

提交回复
热议问题