Я изучаю глубокое обучение с помощью tensorflow. Я сделал простой код НЛП, предсказывающий следующее слово в заданном предложении
model = tf.keras.Sequential()
model.add(Embedding(num,64,input_length = max_len-1)) # we subtract 1 coz we cropped the laste word from X in out data
model.add(Bidirectional(LSTM(32)))
model.add(Dense(num,activation = 'softmax'))
model.compile(optimizer = 'adam',loss = 'categorical_crossentropy',metrics = ['accuracy'])
history = model.fit(X,Y,epochs = 500)
, однако использование category_crossentropy дает мне следующую ошибку:
ValueError: You are passing a target array of shape (453, 1) while using as loss `categorical_crossentropy`. `categorical_crossentropy` expects targets to be binary matrices (1s and 0s) of shape (samples, classes). If your targets are integer classes, you can convert them to the expected format via:
```
from keras.utils import to_categorical
y_binary = to_categorical(y_int)
```
Alternatively, you can use the loss function `sparse_categorical_crossentropy` instead, which does expect integer targets.
Может кто-нибудь объяснить мне, что это означает и почему Я не могу использовать категориальную функцию потерь кроссэнтропии? Спасибо вам большое! Любая помощь будет оценена!