首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >InvalidArgumentError:索引[120,0]= 3080不在[0,32] [[{{node embedding_6/embedding_lookup}}]]

InvalidArgumentError:索引[120,0]= 3080不在[0,32] [[{{node embedding_6/embedding_lookup}}]]
EN

Stack Overflow用户
提问于 2019-11-25 20:14:54
回答 1查看 529关注 0票数 1

我看到其他人也发布了类似的问题。但不同的是,我运行的是Keras函数式API,而不是顺序模型。

代码语言:javascript
复制
from keras.models import Model
from keras import layers
from keras import Input
text_vocabulary_size = 10000
question_vocabulary_size = 10000
answer_vocabulary_size = 500

text_input = Input(shape=(None,), dtype='int32', name='text')
embedded_text = layers.Embedding(64, text_vocabulary_size)(text_input)
encoded_text = layers.LSTM(32)(embedded_text)
question_input = Input(shape=(None,), dtype='int32', name='question')
embedded_question = layers.Embedding( 32, question_vocabulary_size)(question_input)
encoded_question = layers.LSTM(16)(embedded_question)

concatenated = layers.concatenate([encoded_text, encoded_question],axis=-1) 

## Concatenates the encoded question and encoded text

answer = layers.Dense(answer_vocabulary_size, activation='softmax')(concatenated)
model = Model([text_input, question_input], answer)
model.compile(optimizer='rmsprop', loss='categorical_crossentropy', metrics=['acc'])

将数据提供给多输入模型

代码语言:javascript
复制
import numpy as np
num_samples = 1000
max_length = 100

text = np.random.randint(1, text_vocabulary_size, size=(num_samples, max_length))

question = np.random.randint(1, question_vocabulary_size,  size=(num_samples, max_length))

answers = np.random.randint(0, 1, size=(num_samples, answer_vocabulary_size)) 

使用输入列表进行拟合

代码语言:javascript
复制
model.fit([text, question], answers, epochs=10, batch_size=128)

我在尝试拟合模型时得到的错误如下。

代码语言:javascript
复制
InvalidArgumentError: indices[120,0] = 3080 is not in [0, 32)
     [[{{node embedding_6/embedding_lookup}}]]
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-25 21:11:30

词汇表的维度是Embedding类的第一个参数,您将它们设置为第二个参数。您只需切换要提供给嵌入实例的参数。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59031625

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档