Instructions to use baseten/gemma-4-e2b-it-sequence-classification with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use baseten/gemma-4-e2b-it-sequence-classification with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="baseten/gemma-4-e2b-it-sequence-classification", trust_remote_code=True)# Load model directly from transformers import AutoProcessor, AutoModelForSequenceClassification processor = AutoProcessor.from_pretrained("baseten/gemma-4-e2b-it-sequence-classification", trust_remote_code=True) model = AutoModelForSequenceClassification.from_pretrained("baseten/gemma-4-e2b-it-sequence-classification", trust_remote_code=True) - Notebooks
- Google Colab
- Kaggle
Update modeling_gemma4_sequence.py
Browse files
modeling_gemma4_sequence.py
CHANGED
|
@@ -15,7 +15,7 @@ from transformers.models.gemma4.configuration_gemma4 import Gemma4Config
|
|
| 15 |
from transformers.models.gemma4.modeling_gemma4 import Gemma4Model, Gemma4PreTrainedModel
|
| 16 |
|
| 17 |
|
| 18 |
-
class
|
| 19 |
"""Pool the last text position and score it with selected Gemma 4 token rows."""
|
| 20 |
|
| 21 |
config_class = Gemma4Config
|
|
@@ -49,7 +49,7 @@ class Gemma4ForTokenSequenceClassification(Gemma4PreTrainedModel):
|
|
| 49 |
model_lm: nn.Module,
|
| 50 |
selected_token_ids: Sequence[int],
|
| 51 |
labels: Sequence[str],
|
| 52 |
-
) -> "
|
| 53 |
token_ids = torch.tensor(selected_token_ids, device=model_lm.lm_head.weight.device)
|
| 54 |
classifier_weight = model_lm.lm_head.weight.index_select(0, token_ids).detach().clone()
|
| 55 |
cls.configure_classification_config(model_lm.config, selected_token_ids, labels)
|
|
|
|
| 15 |
from transformers.models.gemma4.modeling_gemma4 import Gemma4Model, Gemma4PreTrainedModel
|
| 16 |
|
| 17 |
|
| 18 |
+
class Gemma4ForSequenceClassification(Gemma4PreTrainedModel):
|
| 19 |
"""Pool the last text position and score it with selected Gemma 4 token rows."""
|
| 20 |
|
| 21 |
config_class = Gemma4Config
|
|
|
|
| 49 |
model_lm: nn.Module,
|
| 50 |
selected_token_ids: Sequence[int],
|
| 51 |
labels: Sequence[str],
|
| 52 |
+
) -> "Gemma4ForSequenceClassification":
|
| 53 |
token_ids = torch.tensor(selected_token_ids, device=model_lm.lm_head.weight.device)
|
| 54 |
classifier_weight = model_lm.lm_head.weight.index_select(0, token_ids).detach().clone()
|
| 55 |
cls.configure_classification_config(model_lm.config, selected_token_ids, labels)
|