【问题标题】:InvalidArgumentError: indices[120,0] = 3080 is not in [0, 32) [[{{node embedding_6/embedding_lookup}}]]InvalidArgumentError: indices[120,0] = 3080 is not in [0, 32) [[{{node embedding_6/embedding_lookup}}]]
【发布时间】:2019-11-25 12:14:53
【问题描述】:

我看到其他人发布了类似的问题。但不同之处在于我运行的是 Keras 功能 API 而不是顺序模型。

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'])

向多输入模型提供数据

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)) 

使用输入列表进行拟合

model.fit([text, question], answers, epochs=10, batch_size=128)

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

InvalidArgumentError: indices[120,0] = 3080 is not in [0, 32)
     [[{{node embedding_6/embedding_lookup}}]]

【问题讨论】:

    标签: python keras nlp lstm


    【解决方案1】:

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

    【讨论】:

    • 谢谢,使用layers.Embedding(text_vocabulary_size, 64)(text_input)
    猜你喜欢
    • 2021-04-07
    • 1970-01-01
    • 2019-03-28
    • 1970-01-01
    • 1970-01-01
    • 2017-07-22
    • 1970-01-01
    • 2019-01-03
    • 1970-01-01
    相关资源
    最近更新 更多