ModernBERT Embedding
Collection
2 items โข Updated
How to use keras/modern_bert_embed_base with KerasHub:
import keras_hub
# Load TextClassifier model
text_classifier = keras_hub.models.TextClassifier.from_preset(
"hf://keras/modern_bert_embed_base",
num_classes=2,
)
# Fine-tune
text_classifier.fit(x=["Thilling adventure!", "Total snoozefest."], y=[1, 0])
# Classify text
text_classifier.predict(["Not my cup of tea."])
import keras_hub
# Create a MaskedLM model
task = keras_hub.models.MaskedLM.from_preset("hf://keras/modern_bert_embed_base")
import keras_hub
# Create a TextEmbedder model
task = keras_hub.models.TextEmbedder.from_preset("hf://keras/modern_bert_embed_base")
import keras_hub
# Create a Backbone model unspecialized for any task
backbone = keras_hub.models.Backbone.from_preset("hf://keras/modern_bert_embed_base")
How to use keras/modern_bert_embed_base with Keras:
# !pip install -U keras tensorflow huggingface_hub
# Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here;
# "jax" and "torch" also work for computation once TensorFlow is installed.
import os
os.environ["KERAS_BACKEND"] = "tensorflow"
import keras
model = keras.saving.load_model("hf://keras/modern_bert_embed_base")