{"record":{"id":"3c0a7c6cdab6c867","repo":"keras-team/keras","slug":"weight-dimension-dim-did-not-have-a-match-in-e","errorCode":null,"errorMessage":"Weight dimension '{dim}' did not have a match in either the input spec '{input_spec}' or the output spec '{output_spec}'. For this layer, the weight must be fully specified.","messagePattern":"Weight dimension '(.+?)' did not have a match in either the input spec '(.+?)' or the output spec '(.+?)'\\. For this layer, the weight must be fully specified\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/core/einsum_dense.py","lineNumber":1862,"sourceCode":"    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 \"\n                f\"spec '{output_spec}'. For this layer, the weight must \"\n                \"be fully specified.\"\n            )\n\n    if bias_axes is not None:\n        num_left_elided = elided if left_elided else 0\n        idx_map = {\n            char: output_shape[i + num_left_elided]\n            for i, char in enumerate(output_spec)\n        }\n\n        for char in bias_axes:\n            if char not in output_spec:\n                raise ValueError(\n                    f\"Bias dimension '{char}' was requested, but is not part \"\n                    f\"of the output spec '{output_spec}'\"","sourceCodeStart":1844,"sourceCodeEnd":1880,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/core/einsum_dense.py#L1844-L1880","documentation":"In split equations each weight (second-operand) letter must match a letter in the input spec or the output spec so Keras can size the kernel. A weight letter found on neither side leaves a kernel dimension of unknown size, so _analyze_split_string raises this error.","triggerScenarios":"A split equation like 'aab,bxy->acd' where a weight letter (e.g. 'x' or 'y') appears in neither the first operand nor the output spec; constructing the layer triggers _analyze_einsum_string during build or compute_output_shape.","commonSituations":"Leftover letters from refactoring the equation; misunderstanding that every kernel axis must be bound to an input or output axis in this layer, unlike general einsum contractions.","solutions":["Remove the unbound letter from the weight spec, or bind it by adding it to the input or output spec","Rewrite the equation so every second-operand letter appears on one of the sides","Verify the intended contraction with numpy.einsum first, then port it keeping only bound letters"],"exampleFix":"# before: 'x' unbound\nlayer = EinsumDense('aab,bcx->acd', output_shape=(4, 5, 6))\n# after\nlayer = EinsumDense('aab,bcd->acd', output_shape=(4, 5, 6))","handlingStrategy":"validation","validationCode":"def weight_letters_bound(eq):\n    lhs, out = eq.split('->')\n    in_spec, w_spec = lhs.split(',')\n    out_letters = set(out) - {'.'}\n    return set(w_spec).issubset(set(in_spec) | out_letters)","typeGuard":"def weight_spec_fully_bound(eq):\n    eq = eq.replace(' ', '')\n    return '->' in eq and eq.count(',') == 1 and weight_letters_bound(eq)","tryCatchPattern":null,"preventionTips":["Remember EinsumDense kernels must be fully specified - no free weight letters","Port equations from numpy.einsum only after binding every kernel axis"],"tags":["keras","einsum-dense","einsum-equation","kernel-shape"],"backgroundTag":"einsum-equation-syntax","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}