Epoch 1/100 ————————————————————————— ValueError Traceback (most recent call last) Cell In[157], line 47 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) 49 # モデルの保存 50 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_6” is incompatible with the layer: expected shape=(None, 5), found shape=(None, 4)

このエラーは、モデルの入力の形状が期待されている形状と一致しないために発生しています。モデルの入力が期待される形状は (None, 5) ですが、実際の形状は (None, 4) です。

これは、answer_sequences[:, :-1] を使用してデコーダーの入力を作成する際に生じた可能性があります。answer_sequences[:, :-1] は、answer_sequences の最後の列を除いた部分であり、その結果、デコーダーの入力の長さが1つ減少しています。

この問題を解決するためには、answer_sequences をスライスする際に正しい形状を確認し、必要に応じて調整する必要があります。具体的には、answer_sequences の最後の列を削除しているため、デコーダーの入力の形状が一致するようにデータを変更する必要があります。

修正するには、answer_sequences[:, :-1] の代わりに answer_sequences[:, 1:] を使用してください。これにより、デコーダーの入力の形状が (None, 5) になり、エラーが解消されるはずです。

修正したコードは以下のようになります。

python
# モデルのトレーニング model.fit([question_sequences, answer_sequences[:, :-1]], answer_sequences[:, 1:], epochs=100)

これにより、エラーが解消されるはずです。

未分類

Posted by ぼっち