Instructions to use keras/multilingual_e5_small with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- KerasHub
How to use keras/multilingual_e5_small with KerasHub:
import keras_hub # Load TextClassifier model text_classifier = keras_hub.models.TextClassifier.from_preset( "hf://keras/multilingual_e5_small", 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/multilingual_e5_small")import keras_hub # Create a TextEmbedder model task = keras_hub.models.TextEmbedder.from_preset("hf://keras/multilingual_e5_small")import keras_hub # Create a Backbone model unspecialized for any task backbone = keras_hub.models.Backbone.from_preset("hf://keras/multilingual_e5_small") - Keras
How to use keras/multilingual_e5_small with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://keras/multilingual_e5_small") - Notebooks
- Google Colab
- Kaggle
Model Overview
Model Summary
Multilingual E5 is a family of multilingual text embedding models from intfloat , based on the XLM-RoBERTa architecture. These models generate fixed-size sentence embeddings suitable for semantic search, retrieval, clustering, and text classification across 100+ languages.
The E5 models were introduced in "Multilingual E5 Text Embeddings: A Technical Report" by Wang et al. The models are trained in two stages: (1) contrastive pre-training on ~1 billion multilingual text pairs, and (2) fine-tuning on labeled datasets. Input text should be prefixed with "query: " or "passage: " for optimal performance.
Key Features:
- Supports 100+ languages via XLM-RoBERTa backbone
- Trained on ~1 billion multilingual text pairs
- MIT licensed
- Works out of the box for semantic search, retrieval, clustering, and classification
- Model Family: Multilingual E5
- Architecture: XLM-RoBERTa (bidirectional Transformer encoder)
- Languages: 100+
- Task Type: Text Embedding / Sentence Similarity / Retrieval
- Max Sequence Length: 512 tokens
Model Details
- [Multilingual E5 Quickstart Notebook](coming soon..)
- Multilingual E5 API Documentation
- Multilingual E5 Model Card
- Multilingual E5 Technical Paper
- KerasHub Beginner Guide
- KerasHub Model Publishing Guide
Installation
Keras and KerasHub can be installed with:
pip install -U -q keras-hub
pip install -U -q keras
Jax, TensorFlow, and Torch come preinstalled in Kaggle Notebooks. For instructions on installing them in another environment see the Keras Getting Started page.
Presets
Preset Table
| Preset | Architecture | Pooling | Normalize | Languages | Description |
|---|---|---|---|---|---|
multilingual_e5_small |
XLM-RoBERTa | Mean | L2 | 100+ | 12-layer Multilingual E5 small model. Produces 384-dim embeddings. |
multilingual_e5_base |
XLM-RoBERTa | Mean | L2 | 100+ | 12-layer Multilingual E5 base model. Produces 768-dim embeddings. |
multilingual_e5_large |
XLM-RoBERTa | Mean | L2 | 100+ | 24-layer Multilingual E5 large model. Produces 1024-dim embeddings. |
Example Usage
import keras_hub
# Load the text embedder with preprocessing.
embedder = keras_hub.models.TextEmbedder.from_preset(
"multilingual_e5_small"
)
# Encode queries
query = "query: Which planet is known as the Red Planet?"
q_emb = embedder.encode_text(query)
# Encode documents/passages
documents = [
"passage: Mars is often referred to as the Red Planet.",
"passage: Venus is often called Earth's twin.",
]
d_embs = embedder.encode_text(documents)
# Load just the backbone for custom architectures.
backbone = keras_hub.models.XLMRobertaBackbone.from_preset(
"multilingual_e5_small",
)
Example Usage with Hugging Face URI
import keras_hub
# Load the text embedder with preprocessing.
embedder = keras_hub.models.TextEmbedder.from_preset(
"hf://keras/multilingual_e5_small"
)
# Encode queries
query = "query: Which planet is known as the Red Planet?"
q_emb = embedder.encode_text(query)
# Encode documents/passages
documents = [
"passage: Mars is often referred to as the Red Planet.",
"passage: Venus is often called Earth's twin.",
]
d_embs = embedder.encode_text(documents)
# Load just the backbone for custom architectures.
backbone = keras_hub.models.XLMRobertaBackbone.from_preset(
"hf://keras/multilingual_e5_small",
)
- Downloads last month
- -