keras-team/keras · error · ValueError

Unrecognized keyword argument(s): {kwargs}

Error message

Unrecognized keyword argument(s): {kwargs}

What it means

IndexLookup.__init__ pops a few legacy kwargs (has_input_vocabulary, trainable, dtype) and rejects anything else left over. This surfaces typos and arguments that were renamed or removed across Keras versions.

Source

Thrown at keras/src/layers/preprocessing/index_lookup.py:251

        # Remember original `vocabulary` as `input_vocabulary` for serialization
        # via `get_config`. However, if `vocabulary` is a file path or a URL, we
        # serialize the vocabulary as an asset and clear the original path/URL.
        self.input_vocabulary = (
            vocabulary if not isinstance(vocabulary, str) else None
        )
        self.input_idf_weights = idf_weights

        # We set this hidden attr to
        # persist the fact that we have have a non-adaptable layer with a
        # manually set vocab.
        self._has_input_vocabulary = kwargs.pop(
            "has_input_vocabulary", (vocabulary is not None)
        )
        kwargs.pop("trainable", None)
        kwargs.pop("dtype", None)
        if kwargs:
            raise ValueError(f"Unrecognized keyword argument(s): {kwargs}")

        if invert:
            self._key_dtype = "int64"
            self._value_dtype = self.vocabulary_dtype
            mask_key = 0
            mask_value = mask_token
            self._default_value = self.oov_token
        else:
            self._key_dtype = self.vocabulary_dtype
            self._value_dtype = "int64"
            mask_key = mask_token
            # Masks should map to 0 for int output and be dropped otherwise. Max
            # ints will be dropped from the bincount op.
            mask_value = (
                0
                if self.output_mode == "int"
                else tf.as_dtype(self._value_dtype).max
            )

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Remove or correct the unknown keyword; current args include max_tokens, num_oov_indices, oov_token, mask_token, vocabulary_dtype, idf_weights, invert, output_mode, sparse, pad_to_max_tokens, vocabulary, name.
  2. Check the real signature for your version: `inspect.signature(IndexLookup.__init__)`.
  3. Validate config dicts against the signature before forwarding them with `**cfg`.

Example fix

# before
layer = IndexLookup(max_token=20000)

# after
layer = IndexLookup(max_tokens=20000)
Defensive patterns

Strategy: type-guard

Validate before calling

import inspect
sig = inspect.signature(IndexLookup.__init__)
known = set(sig.parameters) - {'self', 'kwargs'}
unknown = set(cfg) - known
if unknown:
    raise ValueError('Unknown IndexLookup args: %s' % unknown)
layer = IndexLookup(**cfg)

Type guard

def valid_lookup_kwargs(cfg) -> bool:
    import inspect
    params = set(inspect.signature(IndexLookup.__init__).parameters)
    return not (set(cfg) - params - {'self'})

Try / catch

try:
    layer = IndexLookup(**cfg)
except ValueError as e:
    if 'Unrecognized keyword' in str(e):
        cfg = {k: v for k, v in cfg.items() if k in KNOWN_ARGS}
        layer = IndexLookup(**cfg)
    else:
        raise

Prevention

When it happens

Trigger: Passing a kwarg not in the signature, e.g. `IndexLookup(vocabulary_size=5000)` or a misspelled `max_token`; forwarding a config dict with `**cfg` built for a different layer version.

Common situations: Migrating configs from tf.keras TextVectorization or older Keras releases whose signatures differed; generic kwargs-forwarding from experiment frameworks.

Related errors


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/e80199c95352522d. Report an issue: GitHub.