AttributeError: The vocab attribute was removed from KeyedVector in Gensim 4.0.0.

  • 原因是因为 Gensim版本 提升, 启用了vocab这一接口
  • 解决办法:如果只需要key值,调用index_to_key
  • 如果需要键值对(key-value),调用key_to_index
  • 代码展示
print(model.wv.index_to_key)
print(model.wv.key_to_index)
  • 输出结果
['f', 'i', '_', 't', 'd', '1', '2', '3', '4', '5', 'l', 'r', 'm', 'p', '0', 'a', 'o', 'u', '6', '8', '7', 's', '9', 'I', 'e', 'n', 'U', 'b', 'j', 'c', ' ', ':', 'N', 'R', 'L']
{
    
    'f': 0, 'i': 1, '_': 2, 't': 3, 'd': 4, '1': 5, '2': 6, '3': 7, '4': 8, '5': 9, 'l': 10, 'r': 11, 'm': 12, 'p': 13, '0': 14, 'a': 15, 'o': 16, 'u': 17, '6': 18, '8': 19, '7': 20, 's': 21, '9': 22, 'I': 23, 'e': 24, 'n': 25, 'U': 26, 'b': 27, 'j': 28, 'c': 29, ' ': 30, ':': 31, 'N': 32, 'R': 33, 'L': 34}

猜你喜欢

转载自blog.csdn.net/weixin_42279212/article/details/120523923