Epoch 1/100 ————————————————————————— ValueError Traceback (most recent call last) Cell In[158], line 48 44 model.compile(optimizer=’adam’, loss=’sparse_categorical_crossentropy’, metrics=[‘accuracy’]) 46 # モデルのトレーニング 47 # model.fit([question_sequences, answer_sequences[:, :-1]], answer_sequences[:, 1:], epochs=100) —> 48 model.fit([question_sequences, answer_sequences[:, :-1]], answer_sequences[:, 1:], epochs=100) 51 # モデルの保存 52 model.save(“qa_model”) File ~anaconda3libsite-packageskerasutilstraceback_utils.py:70, in filter_traceback.<locals>.error_handler(*args, **kwargs) 67 filtered_tb = _process_traceback_frames(e.__traceback__) 68 # To get the full stack trace, call: 69 # `tf.debugging.disable_traceback_filtering()` —> 70 raise e.with_traceback(filtered_tb) from None 71 finally: 72 del filtered_tb File ~AppDataLocalTemp__autograph_generated_file4r8nvhy_.py:15, in outer_factory.<locals>.inner_factory.<locals>.tf__train_function(iterator) 13 try: 14 do_return = True —> 15 retval_ = ag__.converted_call(ag__.ld(step_function), (ag__.ld(self), ag__.ld(iterator)), None, fscope) 16 except: 17 do_return = False ValueError: in user code: File “C:Usersdell25anaconda3libsite-packageskerasenginetraining.py”, line 1284, in train_function * return step_function(self, iterator) File “C:Usersdell25anaconda3libsite-packageskerasenginetraining.py”, line 1268, in step_function ** outputs = model.distribute_strategy.run(run_step, args=(data,)) File “C:Usersdell25anaconda3libsite-packageskerasenginetraining.py”, line 1249, in run_step ** outputs = model.train_step(data) File “C:Usersdell25anaconda3libsite-packageskerasenginetraining.py”, line 1050, in train_step y_pred = self(x, training=True) File “C:Usersdell25anaconda3libsite-packageskerasutilstraceback_utils.py”, line 70, in error_handler raise e.with_traceback(filtered_tb) from None File “C:Usersdell25anaconda3libsite-packageskerasengineinput_spec.py”, line 298, in assert_input_compatibility raise ValueError( ValueError: Input 1 of layer “model_7” is incompatible with the layer: expected shape=(None, 5), found shape=(None, 4)
先程のエラーが再度発生しましたね。このエラーは、モデルの入力形状が予期しない形状になっていることを示しています。モデルの入力が (None, 5) の形状を期待していますが、実際の形状は (None, 4) です。
この問題は、デコーダーの入力における誤ったデータのスライシングに起因しています。デコーダーの入力が正しい形状を持つようにデータを調整する必要があります。
修正の方法は、デコーダーの入力のスライスを変更し、適切な形状にすることです。具体的には、answer_sequences[:, :-1] の代わりに answer_sequences[:, 1:] を使用してください。
修正したコードは以下のようになります:
python
# モデルのトレーニング model.fit([question_sequences, answer_sequences[:, :-1]], answer_sequences[:, 1:], epochs=100)
この修正を行うことで、エラーが解消されるはずです。

ディスカッション
コメント一覧
まだ、コメントがありません