Skip to content

TextVectorization custom standardize callable receives EagerTensor instead of a Python string #22626

@alenowak

Description

@alenowak

Environment:

  • Keras version: 3.14.0
  • Backend: JAX
  • Python: 3.12

When using TextVectorization with a custom standardize callable and a non-TensorFlow backend (e.g. JAX), calling .adapt() raises an AttributeError because the callable receives a tf.EagerTensor instead of a plain Python string.

import os
os.environ["KERAS_BACKEND"] = "jax"

import re
import string
import keras

strip_chars = string.punctuation
def my_standardize(input_string):
    input_string = input_string.lower()          # AttributeError here
    return re.sub(f"[{re.escape(strip_chars)}]", "", input_string)

layer = keras.layers.TextVectorization(standardize=my_standardize)
layer.adapt(["Hello, world."])

AttributeError: 'tensorflow.python.framework.ops.EagerTensor' object has no attribute 'lower'

TextVectorization should be independent of TensorFlow.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions