Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keras_nlp.models.GemmaPreprocessor No Longer Exists #2013

Closed
rlcauvin opened this issue Dec 7, 2024 · 4 comments
Closed

keras_nlp.models.GemmaPreprocessor No Longer Exists #2013

rlcauvin opened this issue Dec 7, 2024 · 4 comments
Assignees
Labels
Gemma Gemma model specific issues

Comments

@rlcauvin
Copy link

rlcauvin commented Dec 7, 2024

Describe the bug
The keras_nlp.models.GemmaPreprocessor class described here no longer exists.

To Reproduce

!pip install -U keras-nlp
!pip install -U tensorflow

import keras_nlp
import tensorflow as tf

gemma_backbone = keras_nlp.models.GemmaBackbone.from_preset("gemma_2b_en", trainable = True)
gemma_preprocessor = keras_nlp.models.GemmaPreprocessor(gemma_backbone.vocabulary)

inputs = tf.keras.layers.Input(shape=(None,), dtype=tf.string)
x = gemma_preprocessor(inputs)
x = gemma_backbone(x)
sentence_embeddings = x['sequence_output'][:, 0, :]
x = tf.keras.layers.Dense(64, activation='relu')(sentence_embeddings)
x = tf.keras.layers.Dropout(0.2)(x)
outputs = tf.keras.layers.Dense(1, activation='sigmoid')(x)
model = tensorflow.keras.models.Model(inputs=inputs, outputs=outputs)

Output of the line that attempts to create the preprocessor:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[75], line 1
----> 1 gemma_preprocessor = keras_nlp.models.GemmaPreprocessor(gemma_backbone.vocabulary)

AttributeError: module 'keras_nlp.api.models' has no attribute 'GemmaPreprocessor'

I get the same results if I replace keras_nlp with keras_hub.

Expected behavior

As described here, this class used to exist.

Additional context

I am trying to use Gemma as a sentence encoding layer in a binary classifier. How should I do so if not with keras_nlp.models.GemmaPreprocessor and the code above?

@github-actions github-actions bot added the Gemma Gemma model specific issues label Dec 7, 2024
@jeffcarp
Copy link
Member

jeffcarp commented Dec 7, 2024

That was removed in dd0651e. We'll update the docs. The new one is here:
https://keras.io/keras_hub/api/models/gemma/gemma_causal_lm_preprocessor/#gemmacausallmpreprocessor-class

@jeffcarp jeffcarp self-assigned this Dec 7, 2024
@Gopi-Uppari
Copy link

Hi @rlcauvin,

I have reproduced the issue, please refer to this gist file. To avoid it could you please use keras_hub.models.GemmaCausalLMPreprocessor class as mentioned by @jeffcarp and also please refer this keras documentation.

Thank you.

@rlcauvin
Copy link
Author

rlcauvin commented Dec 9, 2024

Thank you. For reference, here is what @jeffcarp suggested for accessing token embeddings directly in KerasHub models.

@jeffcarp
Copy link
Member

The original link points to the keras_nlp docs. In the updated keras_hub docs the GemmaPreprocessor class (correctly) no longer exists:
https://keras.io/keras_hub/api/models/gemma/

Closing this as the keras_nlp docs should remain (unlinked in the navigation) for legacy reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gemma Gemma model specific issues
Projects
None yet
Development

No branches or pull requests

4 participants