尝试使用keras训练模型时遇到此错误。
InvalidArgumentError:索引[48,2] = 5388不在[0,5388)中
[[节点:embedding_1 / embedding_lookup = GatherV2 [Taxis = DT_INT32, Tindices = DT_INT32,Tparams = DT_FLOAT, _class = [“ loc:@ training / RMSprop / Assign_1”],_ device =“ / job:localhost /副本:0 / task:0 / device:CPU:0”](embedding_1 / embeddings / read, embedding_1 / Cast, 培训/ RMSprop / gradients / embedding_1 / embedding_lookup_grad / concat / axis)]
实际的线是这个...
model.fit_generator(generator = generate_batch(X_train, y_train, batch_size = batch_size),
steps_per_epoch = train_samples//batch_size,
epochs=epochs,
validation_data = generate_batch(X_test, y_test, batch_size = batch_size),
validation_steps = val_samples//batch_size)
时代1/50 73/237 [========> .....................]-预计时间:32:10- 损失:7.4517-累积:0.1711
整个代码在这里...
https://github.com/shantanuo/pandas_examples/blob/master/deep_learn/WordLevelEngMarNMT.ipynb
从...克隆的代码 https://github.com/hlamba28/Word-Level-Eng-Mar-NMT
答案 0 :(得分:2)
您的嵌入层定义为:
# Encoder
encoder_inputs = Input(shape=(None,))
enc_emb = Embedding(num_encoder_tokens, latent_dim, mask_zero = True)(encoder_inputs)
令牌索引0被认为是一个特殊值(无输入);因此您需要使用num_encoder_tokens + 1定义嵌入。
您已经在num_decoder_tokens中添加了1;您需要对num_encoder_tokens做同样的事情。