{"record":{"id":"87019b5c311a7e29","repo":"keras-team/keras","slug":"cannot-unroll-a-rnn-if-the-time-dimension-is-undef","errorCode":null,"errorMessage":"Cannot unroll a RNN if the time dimension is undefined. \n- If using a Sequential model, specify the time dimension by passing an `Input()` as your first layer.\n- If using the functional API, specify the time dimension by passing a `shape` or `batch_shape` argument to your `Input()`.","messagePattern":"Cannot unroll a RNN if the time dimension is undefined\\. \n- If using a Sequential model, specify the time dimension by passing an `Input\\(\\)` as your first layer\\.\n- If using the functional API, specify the time dimension by passing a `shape` or `batch_shape` argument to your `Input\\(\\)`\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/rnn/rnn.py","lineNumber":371,"sourceCode":"            initial_state,\n            go_backwards=self.go_backwards,\n            mask=mask,\n            unroll=self.unroll,\n            input_length=sequences.shape[1],\n            zero_output_for_mask=self.zero_output_for_mask,\n            return_all_outputs=self.return_sequences,\n        )\n\n    def call(\n        self,\n        sequences,\n        initial_state=None,\n        mask=None,\n        training=False,\n    ):\n        timesteps = sequences.shape[1]\n        if self.unroll and timesteps is None:\n            raise ValueError(\n                \"Cannot unroll a RNN if the \"\n                \"time dimension is undefined. \\n\"\n                \"- If using a Sequential model, \"\n                \"specify the time dimension by passing \"\n                \"an `Input()` as your first layer.\\n\"\n                \"- If using the functional API, specify \"\n                \"the time dimension by passing a `shape` \"\n                \"or `batch_shape` argument to your `Input()`.\"\n            )\n\n        if initial_state is None:\n            if self.stateful:\n                initial_state = self.states\n            else:\n                initial_state = self.get_initial_state(\n                    batch_size=ops.shape(sequences)[0]\n                )\n        if self.stateful:","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/rnn/rnn.py#L353-L389","documentation":"Error \"Cannot unroll a RNN if the time dimension is undefined. \n- If using a Sequential model, specify the time dimension by passing an `Input()` as your first layer.\n- If using the functional API, specify the time dimension by passing a `shape` or `batch_shape` argument to your `Input()`.\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/layers/rnn/rnn.py:371 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"}