gpt4 book ai didi

python - 无效参数 : indices[207, 1] = 1611 不在 [0, 240) - Tensorflow 2.x (Python)

转载 作者:行者123 更新时间:2023-12-04 10:29:18 26 4
gpt4 key购买 nike

我正在使用 RNN LSTM 模型 对人格类型进行分类。当我开始训练模型时,出现意外的索引错误。我尝试使用回溯使用一些解决方案,但没有使用 TF 2.0 的此问题的信息。
我会留下我的Google Colab如果你想看一看。

型号:

model = keras.Sequential()
model.add(keras.layers.Embedding(input_dim = 240, output_dim = 64)) # The maxlen of the training and validation data is 240.
model.add(keras.layers.Bidirectional(keras.layers.LSTM(64)))
model.add(keras.layers.Dense(64, activation = 'relu'))
model.add(keras.layers.Dense(16, activation = 'softmax'))
model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
model.summary()

训练模型:

fitModel = model.fit(train_data_padded, train_label_seq,
epochs = 10,
batch_size = 295, # The length of the data is 295
validation_data = (validation_padded, validation_label_seq),
verbose = 1)

追溯:
Train on 236 samples, validate on 59 samples
Epoch 1/10
236/236 [==============================] - 0s 71us/sample
---------------------------------------------------------------------------
InvalidArgumentError Traceback (most recent call last)
<ipython-input-33-48497b2e653e> in <module>()
3 batch_size = 295, #how many we will load it at once (number of samples per gradient)
4 validation_data = (validation_padded, validation_label_seq), #(x_val, y_val) validation_padded, validation_label_seq
----> 5 verbose = 1)

11 frames
/usr/local/lib/python3.6/dist-packages/six.py in raise_from(value, from_value)

InvalidArgumentError: 2 root error(s) found.
(0) Invalid argument: indices[207,1] = 1611 is not in [0, 240)
[[node sequential_3/embedding_3/embedding_lookup (defined at <ipython-input-31-bd83004f8334>:5) ]]
(1) Invalid argument: indices[207,1] = 1611 is not in [0, 240)
[[node sequential_3/embedding_3/embedding_lookup (defined at <ipython-input-31-bd83004f8334>:5) ]]
[[VariableShape/_22]]
0 successful operations.
0 derived errors ignored. [Op:__inference_distributed_function_22239]

Errors may have originated from an input operation.
Input Source operations connected to node sequential_3/embedding_3/embedding_lookup:
sequential_3/embedding_3/embedding_lookup/20179 (defined at /usr/lib/python3.6/contextlib.py:81)

Input Source operations connected to node sequential_3/embedding_3/embedding_lookup:
sequential_3/embedding_3/embedding_lookup/20179 (defined at /usr/lib/python3.6/contextlib.py:81)

Function call stack:
distributed_function -> distributed_function

最佳答案

使用 pd.DataFrame(x_train).max() 检查最大值
我得到了 32552,所以只需添加 32552+1 作为 input_dim

i.e input_dim  = 32553

关于python - 无效参数 : indices[207, 1] = 1611 不在 [0, 240) - Tensorflow 2.x (Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60480806/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com