@meburka

ValueError: Shapes (None, 0, 6) and (None, 6) are incompatible?

Здравсвуйте, нашёл какую-то нейросеть, решил запустить, создал чуть данных, но при запуске пишет ValueError: Shapes (None, 0, 6) and (None, 6) are incompatible. Код:
import tensorflow as tf
from tensorflow import *
from tensorflow.keras.layers import Dense, LSTM, Embedding
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
filename = "in.txt"
with open(filename, 'r', encoding='utf-8') as f:
    lines = f.read().split('\n')
    print(lines)
input_texts = []
target_texts = []
for line in lines:
    if line:
        print(line)
        input_text, target_text = line.split('|')
        input_texts.append(input_text)
        target_texts.append(target_text)
tokenizer = Tokenizer()
tokenizer.fit_on_texts(input_texts)
input_sequences = tokenizer.texts_to_sequences(input_texts)
max_len = max(len(seq) for seq in input_sequences)
input_data = pad_sequences(input_sequences, maxlen=max_len, padding='post')
model = tf.keras.Sequential([
    Embedding(input_dim=len(tokenizer.word_index)+1, output_dim=64, input_length=max_len),
    LSTM(64),
    Dense(len(tokenizer.word_index)+1, activation='softmax')
])
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(input_data, tf.keras.utils.to_categorical(tokenizer.texts_to_sequences(target_texts), num_classes=len(tokenizer.word_index)+1), batch_size=32, epochs=100)
def generate_response(input_text):
    input_seq = tokenizer.texts_to_sequences([input_text])[0]
    padded_input_seq = pad_sequences([input_seq], maxlen=max_len, padding='post')
    output_seq = model.predict(padded_input_seq)[0]
    return tokenizer.sequences_to_texts([output_seq.argmax(axis=-1)])[0]
while True:
    input_text = input("Введите текст: ")
    if input_text == "exit":
        break
    response = generate_response(input_text)
    print(response)

Ошибка на 44 строке:
model.fit(input_data, tf.keras.utils.to_categorical(tokenizer.texts_to_sequences(target_texts), num_classes=len(tokenizer.word_index)+1), batch_size=32, epochs=100)
  • Вопрос задан
  • 96 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы