我正在使用嵌入的Glove单词对文本数据进行NUM_Labels(= 29)个不同目标变量的多类分类问题。为此,我在下面构造了一个简单的模型。
MAX_SEQUENCE_LENGTH = 12
EMBEDDING_DIM = 100
VALIDATION_SPLIT = 0.2
BATCH_SIZE = 64
EPOCHS = 10
NUM_LABELS = len(set(dataset['Label']))
model = Sequential()
model.add(Embedding(num_words, EMBEDDING_DIM, input_length=MAX_SEQUENCE_LENGTH))
model.add(GRU(units=32))
model.add(Dense(NUM_LABELS, activation = 'softmax'))
model.compile(optimizer='adam',
loss='categorical_crossentropy',
metrics=['accuracy'])
r = model.fit(x = sentences,
y=targets,
batch_size=BATCH_SIZE,
epochs=EPOCHS,
validation_split=VALIDATION_SPLIT
)
但是,我仍然收到错误消息:
ValueError: Error when checking input: expected embedding_5_input to have shape (12,) but got array with shape (1,)
我看过several similar pages,但这些仍然不能告诉我我在做什么错。谁可以在这里帮助我?
谢谢!