我正在尝试使用 Keras 作为使用 LSTM 网络的机器翻译中的注意机制。
但是,我在代码中遇到 TypeError 异常。
TypeError: Exception encountered when calling layer "tf.keras.backend.rnn_1" (type TFOpLambda).
You are passing KerasTensor(type_spec=TensorSpec(shape=(None, 35), dtype=tf.float32, name=None), name='tf.compat.v1.nn.softmax_3/Softmax:0', description="created by layer 'tf.compat.v1.nn.softmax_3'"), an intermediate Keras symbolic input/output, to a TF API that does not allow registering custom dispatchers, such as `tf.cond`, `tf.function`, gradient tapes, or `tf.map_fn`. Keras Functional model construction only supports TF API calls that *do* support dispatching, such as `tf.math.add` or `tf.reshape`. Other APIs cannot be called directly on symbolic Kerasinputs/outputs. …Run Code Online (Sandbox Code Playgroud)