keras-team/keras · error · ValueError
Invalid merge mode. Received
Error message
Invalid merge mode. Received: {merge_mode}. Merge mode should be one of {"sum", "mul", "ave", "concat", None} What it means
Raised by Bidirectional.__init__ when `merge_mode` is not one of the allowed values {'sum', 'mul', 'ave', 'concat', None}. The merge mode determines how forward and backward outputs are combined, so any other string or object is rejected at construction time.
Solutions
- Use one of 'sum', 'mul', 'ave', 'concat', or None (None returns both outputs as a list)
- Check for typos such as 'avg' (use 'ave') or 'mean' (use 'ave')
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/layers/rnn/bidirectional.py:105 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/7d7a222be629f9ab.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/rnn/bidirectional.py:105
self,
layer,
merge_mode="concat",
weights=None,
backward_layer=None,
**kwargs,
):
if not isinstance(layer, Layer):
raise ValueError(
"Please initialize `Bidirectional` layer with a "
f"`keras.layers.Layer` instance. Received: {layer}"
)
if backward_layer is not None and not isinstance(backward_layer, Layer):
raise ValueError(
"`backward_layer` need to be a `keras.layers.Layer` "
f"instance. Received: {backward_layer}"
)
if merge_mode not in ["sum", "mul", "ave", "concat", None]:
raise ValueError(
f"Invalid merge mode. Received: {merge_mode}. "
"Merge mode should be one of "
'{"sum", "mul", "ave", "concat", None}'
)
super().__init__(**kwargs)
# Recreate the forward layer from the original layer config, so that it
# will not carry over any state from the layer.
config = serialization_lib.serialize_keras_object(layer)
config["config"]["name"] = (
f"forward_{utils.removeprefix(layer.name, 'forward_')}"
)
self.forward_layer = serialization_lib.deserialize_keras_object(config)
if backward_layer is None:
config = serialization_lib.serialize_keras_object(layer)
config["config"]["go_backwards"] = True
config["config"]["name"] = (View on GitHub (pinned to 7a34a03db6)