Skip to content

compute_word_piece_vocabulary  #2034

@Raiden-Makoto

Description

@Raiden-Makoto

Describe the bug

if not isinstance(data, (list, tf.data.Dataset)): #from source code
AttributeError: 'NoneType' object has no attribute 'data'

because compute_word_piece_vocabulary function is not importing TensorFlow correctly (tf = None)(refer to source code lines 4-11 and 117)

To Reproduce

def train_word_piece(dataset, vocab_size, reserved_tokens):
    word_piece_ds = dataset.unbatch().map(lambda x, y: x)
    vocab = compute_word_piece_vocabulary(
        data = word_piece_ds.batch(1000).prefetch(2),
        vocabulary_size=vocab_size,
        reserved_tokens=reserved_tokens,
    )
    return vocab

train_word_piece(train_dataset, VOCAB_SIZE, reserved_tokens)

Code from https://keras.io/examples/nlp/fnet_classification_with_keras_hub/

Expected behavior
Function executes without error.

Additional context
Tensorflow version 2.17.1
KerasHub version 0.18.1

Maybe remove lines 4-11 in source?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions