{"record":{"id":"8721e942b831dbf8","repo":"keras-team/keras","slug":"dimension-dim-was-specified-in-the-output-ou","errorCode":null,"errorMessage":"Dimension '{dim}' was specified in the output '{output_spec}' but has no corresponding dim in the input spec '{input_spec}' or weight spec '{output_spec}'","messagePattern":"Dimension '(.+?)' was specified in the output '(.+?)' but has no corresponding dim in the input spec '(.+?)' or weight spec '(.+?)'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/core/einsum_dense.py","lineNumber":1846,"sourceCode":"\n    for dim in input_spec:\n        input_shape_at_dim = input_shape[input_dim_map[dim]]\n        if dim in output_dim_map:\n            output_shape_at_dim = output_shape[output_dim_map[dim]]\n            if (\n                output_shape_at_dim is not None\n                and output_shape_at_dim != input_shape_at_dim\n            ):\n                raise ValueError(\n                    \"Input shape and output shape do not match at shared \"\n                    f\"dimension '{dim}'. Input shape is {input_shape_at_dim}, \"\n                    \"and output shape \"\n                    f\"is {output_shape[output_dim_map[dim]]}.\"\n                )\n\n    for dim in output_spec:\n        if dim not in input_spec and dim not in weight_spec:\n            raise ValueError(\n                f\"Dimension '{dim}' was specified in the output \"\n                f\"'{output_spec}' but has no corresponding dim in the input \"\n                f\"spec '{input_spec}' or weight spec '{output_spec}'\"\n            )\n\n    weight_shape = []\n    input_axes, output_axes = [], []\n    for i, dim in enumerate(weight_spec):\n        if dim in output_dim_map:\n            weight_shape.append(output_shape[output_dim_map[dim]])\n            output_axes.append(i)\n        elif dim in input_dim_map:\n            weight_shape.append(input_shape[input_dim_map[dim]])\n            input_axes.append(i)\n        else:\n            raise ValueError(\n                f\"Weight dimension '{dim}' did not have a match in either \"\n                f\"the input spec '{input_spec}' or the output \"","sourceCodeStart":1828,"sourceCodeEnd":1864,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/core/einsum_dense.py#L1828-L1864","documentation":"For split equations, every letter in the output spec must appear in either the input spec or the weight spec; Keras cannot infer the size of an output dimension that appears nowhere on the left-hand side. _analyze_split_string raises this error for each such orphan letter.","triggerScenarios":"Writing a split equation like 'aab,bc->acd' where 'd' (or any output letter) is absent from both the first operand's letters and the weight spec letters, then building the layer.","commonSituations":"Assuming Keras infers free output dims like numpy.einsum does (it does not); typos in one letter between left and right sides; refactoring equations and dropping a letter from the left side only.","solutions":["Add the missing letter to the input spec or the weight spec so its size is derivable","Fix the typo so the output letter matches one on the left-hand side","Remember Keras needs every output dim sized, unlike raw numpy.einsum"],"exampleFix":"# before: 'd' has no left-side match\nlayer = EinsumDense('aab,bc->acd', output_shape=(4, 5, 6))\n# after: 'd' now appears in the weight operand\nlayer = EinsumDense('aab,bcd->acd', output_shape=(4, 5, 6))","handlingStrategy":"validation","validationCode":"def output_letters_bound(eq):\n    lhs, out = eq.split('->')\n    in_spec, w_spec = lhs.split(',')\n    out_letters = set(out) - {'.'}\n    return out_letters.issubset(set(in_spec) | set(w_spec))","typeGuard":"def einsum_specs_consistent(eq):\n    eq = eq.replace(' ', '')\n    return '->' in eq and eq.count(',') == 1 and output_letters_bound(eq)","tryCatchPattern":null,"preventionTips":["Check every output letter appears on the left-hand side before constructing","Write a small equation linter in test fixtures for einsum-heavy codebases"],"tags":["keras","einsum-dense","einsum-equation","split-equation"],"backgroundTag":"einsum-equation-syntax","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}