Llama (Bidirectional) for Embedding
Llama (Bidirectional) for Embedding
NeMo AutoModel provides a bidirectional variant of Meta’s Llama for embedding and dense retrieval tasks. Unlike the standard causal (left-to-right) Llama used for text generation, this variant uses bidirectional attention, so each token can attend to both past and future tokens in the sequence, producing richer representations for semantic similarity and dense retrieval.
For the cross-encoder variant, see Llama (Bidirectional) for Reranking.
Available Models
Any Llama checkpoint can be loaded as a bidirectional backbone. The following configurations are tested:
- Llama 3.2 1B — fast iteration, fits on a single GPU
- Llama 3.1 8B — higher-quality embeddings for production use
Embedding Models
The bidirectional bi-encoder path is used for embedding generation and dense retrieval.
Pooling Strategies
The bi-encoder supports multiple pooling strategies to aggregate token representations into a single embedding vector:
Example HF Models
Example Recipes
Try with NeMo AutoModel
1. Install NeMo AutoModel. Refer to the (Installation Guide) for information:
2. Clone the repo to get the example recipes:
3. Run the recipe from inside the repo:
Run with Docker
1. Pull the container and mount a checkpoint directory:
2. Navigate to the AutoModel directory (where the recipes are):
3. Run the recipe:
See the Installation Guide.
Hugging Face Model Card
NVIDIA trained and released the Llama Nemotron Embedding 1B model, which leverages a bidirectional attention mechanism for multilingual and cross-lingual question–answer retrieval. The model supports long documents (up to 8,192 tokens) and dynamic embedding sizes via Matryoshka embeddings. For more details, see the model card on Hugging Face.