{"record":{"id":"37719f292f4aca07","repo":"keras-team/keras","slug":"please-initialize-bidirectional-layer-with-a-ke","errorCode":null,"errorMessage":"Please initialize `Bidirectional` layer with a `keras.layers.Layer` instance. Received: {layer}","messagePattern":"Please initialize `Bidirectional` layer with a `keras\\.layers\\.Layer` instance\\. Received: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/rnn/bidirectional.py","lineNumber":95,"sourceCode":"    model = Sequential([\n        Input(shape=(5, 10)),\n        Bidirectional(forward_layer, backward_layer=backward_layer),\n        Dense(5, activation=\"softmax\"),\n    ])\n    model.compile(loss='categorical_crossentropy', optimizer='rmsprop')\n    ```\n    \"\"\"\n\n    def __init__(\n        self,\n        layer,\n        merge_mode=\"concat\",\n        weights=None,\n        backward_layer=None,\n        **kwargs,\n    ):\n        if not isinstance(layer, Layer):\n            raise ValueError(\n                \"Please initialize `Bidirectional` layer with a \"\n                f\"`keras.layers.Layer` instance. Received: {layer}\"\n            )\n        if backward_layer is not None and not isinstance(backward_layer, Layer):\n            raise ValueError(\n                \"`backward_layer` need to be a `keras.layers.Layer` \"\n                f\"instance. Received: {backward_layer}\"\n            )\n        if merge_mode not in [\"sum\", \"mul\", \"ave\", \"concat\", None]:\n            raise ValueError(\n                f\"Invalid merge mode. Received: {merge_mode}. \"\n                \"Merge mode should be one of \"\n                '{\"sum\", \"mul\", \"ave\", \"concat\", None}'\n            )\n        super().__init__(**kwargs)\n\n        # Recreate the forward layer from the original layer config, so that it\n        # will not carry over any state from the layer.","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/rnn/bidirectional.py#L77-L113","documentation":"Error \"Please initialize `Bidirectional` layer with a `keras.layers.Layer` instance. Received: {layer}\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/layers/rnn/bidirectional.py:95 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}