{"record":{"id":"368d155cd5991caf","repo":"keras-team/keras","slug":"when-creating-a-variable-from-an-initializer-the","errorCode":null,"errorMessage":"When creating a Variable from an initializer, the `shape` argument should be specified. Received: initializer={initializer} and shape={shape}","messagePattern":"When creating a Variable from an initializer, the `shape` argument should be specified\\. Received: initializer=(.+?) and shape=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/common/variables.py","lineNumber":170,"sourceCode":"        self._regularizer = None\n        self._constraint = None\n        self._trainable = bool(trainable)\n        self._autocast = bool(autocast)\n        self._aggregation = aggregation\n        self._synchronization = synchronization\n        self._layout = layout\n\n        # `self._overwrite_with_gradient` is an internal property to determine\n        # whether this variable should be overwritten by the computed gradient.\n        # Ref: https://github.com/google/flax/blob/main/flax/linen/fp8_ops.py\n        self._overwrite_with_gradient = False\n        if isinstance(initializer, str):\n            from keras.src import initializers\n\n            initializer = initializers.get(initializer)\n        if callable(initializer):\n            if shape is None:\n                raise ValueError(\n                    \"When creating a Variable from an initializer, \"\n                    \"the `shape` argument should be specified. \"\n                    f\"Received: initializer={initializer} \"\n                    f\"and shape={shape}\"\n                )\n        else:\n            initializer = self._convert_to_tensor(initializer, dtype=dtype)\n            # If dtype is None and `initializer` is an array, use its dtype.\n            if dtype is None:\n                dtype = initializer.dtype\n        self._dtype = standardize_dtype(dtype)\n\n        if in_stateless_scope():\n            if callable(initializer):\n                self._value = None\n                self._initializer = initializer\n                self._shape = self._validate_shape(shape)\n                register_uninitialized_variable(self)","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/common/variables.py#L152-L188","documentation":"Error \"When creating a Variable from an initializer, the `shape` argument should be specified. Received: initializer={initializer} and shape={shape}\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/backend/common/variables.py:170 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"}