繁体   English   中英

InvalidArgumentError: indices[120,2] = -1 is not in [0, 10) in Keras

[英]InvalidArgumentError: indices[120,2] = -1 is not in [0, 10) in Keras

我是 Keras 的新手,我正在尝试使用以下参数训练 LSTM 网络,但是,我收到以下错误

InvalidArgumentError:  indices[120,2] = -1 is not in [0, 10)
     [[node sequential_3/embedding_3/embedding_lookup (defined at <ipython-input-65-50ea16cb11fb>:5) ]] [Op:__inference_train_function_13886]

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/12643 (defined at /home/jpandeinge/anaconda3/lib/python3.7/contextlib.py:112)

Function call stack:
train_function

这是我的代码片段;

# The next step is to split training and testing data. For this we will use sklearn function train_test_split().
features_train, features_test, labels_train, labels_test = train_test_split(features, labels, test_size=0.2)

# features and labels shape
features_train.shape, features_test.shape, labels_train.shape, labels_test.shape

((180568, 82), (45143, 82), (180568,), (45143,))

model = Sequential()
model.add(Embedding(10, 82, input_length=180568))
model.add(LSTM(10, return_sequences=True, input_shape=features_train))
model.add(Activation('sigmoid'))
model.add(Dropout(0.2))
model.build()

model.compile(loss = 'binary_crossentropy',  optimizer='adam', metrics = ['accuracy'])
model.summary()
Model: "sequential_3"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
embedding_3 (Embedding)      (None, 180568, 82)        820       
_________________________________________________________________
lstm_3 (LSTM)                (None, 180568, 10)        3720      
_________________________________________________________________
activation_3 (Activation)    (None, 180568, 10)        0         
_________________________________________________________________
dropout_3 (Dropout)          (None, 180568, 10)        0         
=================================================================
Total params: 4,540
Trainable params: 4,540
Non-trainable params: 0
________________________
history = model.fit(features_train,
          labels_train,
          epochs=10,
          batch_size=128)

features_train应该包含从 0 到 9 的索引(这是您的 model 所期望的。但features_train[120, 2]等于 -1。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM