What is AnglE?
AnglE (angle_emb) es una librería de Python para entrenar y ejecutar modelos de embeddings de frases. It sits in the Embedding Models & Inference category of the Retrieval & Knowledge (RAG) tools and is open-source, written in Python. To get started: instalar angle-emb.
Resumen
AnglE (angle_emb) es una librería de Python para entrenar y ejecutar modelos de embeddings de frases. Viene del artículo «AnglE: Angle-optimized Text Embeddings» y te permite entrenar modelos de embeddings basados en BERT o LLM, y luego usar la misma librería para hacer inferencia con varios backbones de transformers.
Está pensada para ingenieros de machine learning y desarrolladores de PLN que necesitan embeddings de texto para tareas como similitud semántica, recuperación y clustering. Puedes cargar modelos ya listos desde Hugging Face (como WhereIsAI/UAE-Large-V1) o ajustar los tuyos con las funciones de pérdida incluidas.
Como herramienta de modelos de embeddings, AnglE cubre ambos extremos: un framework de entrenamiento con varios objetivos contrastivos (las pérdidas AnglE, CoSENT, contrastiva y Espresso/2DMSE) y un framework de inferencia que admite modelos de la familia BERT, modelos basados en LLM mediante LoRA y LLM bidireccionales.
Qué hace
- Pérdida optimizada por ángulo (AnglE), además de las opciones de pérdida CoSENT, contrastiva y Espresso/2DMSE para entrenar embeddings
- Funciona con backbones de la familia BERT (BERT, RoBERTa, ModernBERT) y backbones LLM (LLaMA, Mistral, Qwen)
- Embeddings de LLM bidireccionales mediante BiLLM (apply_billm=True)
- Carga modelos preentrenados desde Hugging Face, incluidos UAE-Large-V1 y los modelos pubmed-angle
- Compatible con entrenamiento en una o varias GPU
- Estrategias de pooling configurables (cls, último token) y prompts opcionales para tareas de recuperación
Primeros pasos
Instala el paquete angle-emb, luego carga un modelo preentrenado y convierte el texto en vectores. Para las llamadas a .cuda() de abajo se necesita una GPU compatible con CUDA.
Instalar angle-emb
Instálalo desde PyPI con uv o pip.
pip install -U angle-embGenerar embeddings de texto con un modelo basado en BERT
Carga un modelo preentrenado, convierte los documentos en vectores y compáralos con la similitud del coseno.
from angle_emb import AnglE
from angle_emb.utils import cosine_similarity
angle = AnglE.from_pretrained('WhereIsAI/UAE-Large-V1', pooling_strategy='cls').cuda()
doc_vecs = angle.encode([
'The weather is great!',
'The weather is very good!',
'i am going to bed'
])
for i, dv1 in enumerate(doc_vecs):
for dv2 in doc_vecs[i+1:]:
print(cosine_similarity(dv1, dv2))Usar prompts para la recuperación
Para tareas de recuperación, codifica la consulta con un prompt y los documentos sin ninguno. Lista los prompts disponibles con Prompts.list_prompts().
from angle_emb import AnglE, Prompts
from angle_emb.utils import cosine_similarity
angle = AnglE.from_pretrained('WhereIsAI/UAE-Large-V1', pooling_strategy='cls').cuda()
qv = angle.encode(['what is the weather?'], to_numpy=True, prompt=Prompts.C)
doc_vecs = angle.encode([
'The weather is great!',
'it is rainy today.',
'i am going to bed'
], to_numpy=True)
for dv in doc_vecs:
print(cosine_similarity(qv[0], dv))Commands and code are distilled from the project's own documentation — always check the repositorio oficial para lo último.
Cuándo usarlo
- Crear búsqueda semántica o recuperación incrustando consultas y documentos y ordenándolos por similitud del coseno
- Medir la similitud textual semántica entre pares de frases
- Ajustar un modelo de embeddings propio con tus datos usando la pérdida AnglE, CoSENT o contrastiva
- Generar embeddings para clustering, deduplicación o pipelines de RAG usando un modelo preentrenado como UAE-Large-V1
How AnglE compares
AnglE alongside other open-source embedding models & inference tools AI/TLDR tracks, ranked by GitHub stars.
| Herramienta | Estrellas | Qué hace |
|---|---|---|
| Sentence Transformers | ★ 19.3k | The standard Python framework for loading, training, and computing embeddings with sentence and reranking models. |
| OpenCLIP | ★ 14.3k | An open implementation of CLIP for training and running image-text embedding models, with a large catalogue of pretrained checkpoints for zero-shot classification and retrieval. |
| PyTorch Metric Learning | ★ 6.3k | PyTorch library of losses, miners, distances, samplers, trainers and accuracy testers for training embedding models with deep metric and self-supervised learning. |
| EmbeddingGemma (Gemma) | ★ 5.9k | Google DeepMind's Gemma repo, home to EmbeddingGemma, a 308M multilingual embedding model small enough to run on-device for RAG and semantic search. |
| Text Embeddings Inference (TEI) | ★ 5.1k | Hugging Face's Rust-based server for deploying embedding, reranking, and sequence-classification models with high throughput on GPU or CPU. |
| text2vec | ★ 5k | Python library for sentence embeddings and text similarity, implementing Word2Vec, BM25, Sentence-BERT, CoSENT and BGE with Chinese and multilingual models. |
| Infinity (Embeddings) | ★ 3k | A high-throughput serving engine for text embeddings, rerankers, CLIP, and ColPali models, exposing an OpenAI-compatible API. |
| AnglE | ★ 576 | Entrena y ejecuta embeddings de frases basados en BERT y LLM con objetivos optimizados por ángulo |

