Artificial intelligence 弃用警告:调用弃用的`\u getitem__`

Artificial intelligence 弃用警告:调用弃用的`\u getitem__`,artificial-intelligence,lstm,google-colaboratory,chatbot,seq2seq,Artificial Intelligence,Lstm,Google Colaboratory,Chatbot,Seq2seq,我已经尝试解决这个错误好几天了,但我无法找到原因,我尝试将cod从嵌入_矩阵[I]=model[vocab[I]]更改为嵌入_矩阵[I]=model.wv[vocab[I]],在这种情况下,我没有得到不推荐的错误,但我仍然得到了该行的erorr(25),有人能告诉我怎么了吗 from gensim.models import Word2Vec import re vocab = [] for word in tokenizer.word_index: vocab.append( w

我已经尝试解决这个错误好几天了,但我无法找到原因,我尝试将cod从嵌入_矩阵[I]=model[vocab[I]]更改为嵌入_矩阵[I]=model.wv[vocab[I]],在这种情况下,我没有得到不推荐的错误,但我仍然得到了该行的erorr(25),有人能告诉我怎么了吗

  from gensim.models import Word2Vec
import re

vocab = []
for word in tokenizer.word_index:
    vocab.append( word )

def tokenize( sentences ):
    tokens_list = []
    vocabulary = []
    for sentence in sentences:
        sentence = sentence.lower()
        sentence = re.sub( '[^a-zA-Z]', ' ', sentence )
        tokens = sentence.split()
        vocabulary += tokens
        tokens_list.append( tokens )
    return tokens_list , vocabulary

p = tokenize( questions + answers )
model = Word2Vec( p[ 0 ] ) 

embedding_matrix = np.zeros( ( VOCAB_SIZE , 100 ) )
for i in range( len( tokenizer.word_index ) ):
    embedding_matrix[ i ] = model[vocab[i]]

# encoder_input_data
tokenized_questions = tokenizer.texts_to_sequences( questions )
maxlen_questions = max( [ len(x) for x in tokenized_questions ] )
padded_questions = preprocessing.sequence.pad_sequences( tokenized_questions , maxlen=maxlen_questions , padding='post' )
encoder_input_data = np.array( padded_questions )
print( encoder_input_data.shape , maxlen_questions )
我得到以下错误:

 /usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:25: DeprecationWarning: Call to deprecated `__getitem__` (Method will be removed in 4.0.0, use self.wv.__getitem__() instead).
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-11-29183abd3d2d> in <module>()
     23 embedding_matrix = np.zeros( ( VOCAB_SIZE , 100 ) )
     24 for i in range( len( tokenizer.word_index ) ):
---> 25     embedding_matrix[ i ] = model[vocab[i]]
     26 
     27 # encoder_input_data
/usr/local/lib/python3.6/dist packages/ipykernel\u launcher.py:25:DeprecationWarning:Call to deprecated`\uuuuu getitem\uuuuuuuu`(方法将在4.0.0中删除,改用self.wv.\uu getitem\uuuuuuuuu())。
---------------------------------------------------------------------------
KeyError回溯(最近一次呼叫最后一次)
在()
23嵌入矩阵=np.零((声音大小,100))
24表示范围内的i(len(tokenizer.word_索引)):
--->25嵌入矩阵[i]=模型[vocab[i]]
26
27#编码器#输入#数据

提前谢谢你

在新的gensim版本中,直接模型查看器被去除了润滑,而使用了辅助方法wv,这显然是这个错误。 根据文档,经过训练的单词向量存储在KeyedVectors实例中,如model.wv。 更改第25行中的代码:


embedded_matrix[i]=model.wv[vocab[i]

Direct model viewer在新的gensim版本中被删除,而使用了辅助方法wv,这显然是一个错误。 根据文档,经过训练的单词向量存储在KeyedVectors实例中,如model.wv。 更改第25行中的代码:


嵌入矩阵[i]=model.wv[vocab[i]

欢迎光临。谢谢你的贡献。由于SO上的低质量,不鼓励只使用代码的响应。请考虑编辑添加一个解释如何/为什么这解决了OP的问题,甚至链接到文档。请注意,随着时间的推移,大多数投票都来自高质量的答案,因为不同的用户从您的帖子中学到了一些东西,可以应用于他们自己的编码问题。谢谢!添加了说明和有用的信息欢迎使用。谢谢你的贡献。由于SO上的低质量,不鼓励只使用代码的响应。请考虑编辑添加一个解释如何/为什么这解决了OP的问题,甚至链接到文档。请注意,随着时间的推移,大多数投票都来自高质量的答案,因为不同的用户从您的帖子中学到了一些东西,可以应用于他们自己的编码问题。谢谢!添加了说明和有用信息