News:
Granite Embedding R2 models with 8192 context length released.
granite-embedding-english-r2 (149M parameters): with an output embedding size of 768, replacing granite-embedding-125m-english.
granite-embedding-small-english-r2 (47M parameters): A first-of-its-kind reduced-size model, with fewer layers and a smaller output embedding size (384), replacing granite-embedding-30m-english.
Model Summary:
Granite-Embedding-125m-English is a 125M parameter dense biencoder embedding model from the Granite Embeddings suite that can be used to generate high quality text embeddings. This model produces embedding vectors of size 768. Compared to most other open-source models, this model was only trained using open-source relevance-pair datasets with permissive, enterprise-friendly license, plus IBM collected and generated datasets. While maintaining competitive scores on academic benchmarks such as BEIR, this model also performs well on many enterprise use cases. This model is developed using retrieval oriented pretraining, contrastive finetuning and knowledge distillation.
Intended use:
The model is designed to produce fixed length vector representations for a given text, which can be used for text similarity, retrieval, and search applications.
Usage with Sentence Transformers:
The model is compatible with SentenceTransformer library and is very easy to use:
First, install the sentence transformers library
pip install sentence_transformers
The model can then be used to encode pairs of text and find the similarity between their representations
python
1from sentence_transformers import SentenceTransformer, util
23model_path ="ibm-granite/granite-embedding-125m-english"4# Load the Sentence Transformer model5model = SentenceTransformer(model_path)67input_queries =[8' Who made the song My achy breaky heart? ',9'summit define'10]1112input_passages =[13"Achy Breaky Heart is a country song written by Don Von Tress. Originally titled Don't Tell My Heart and performed by The Marcy Brothers in 1991. ",14"Definition of summit for English Language Learners. : 1 the highest point of a mountain : the top of a mountain. : 2 the highest level. : 3 a meeting or series of meetings between the leaders of two or more governments."15]1617# encode queries and passages18query_embeddings = model.encode(input_queries)19passage_embeddings = model.encode(input_passages)2021# calculate cosine similarity22print(util.cos_sim(query_embeddings, passage_embeddings))
Usage with Huggingface Transformers:
This is a simple example of how to use the Granite-Embedding-125m-English model with the Transformers library and PyTorch.
First, install the required libraries
pip install transformers torch
The model can then be used to encode pairs of text
python
1import torch
2from transformers import AutoModel, AutoTokenizer
34model_path ="ibm-granite/granite-embedding-125m-english"56# Load the model and tokenizer7model = AutoModel.from_pretrained(model_path)8tokenizer = AutoTokenizer.from_pretrained(model_path)9model.eval()1011input_queries =[12' Who made the song My achy breaky heart? ',13'summit define'14]1516# tokenize inputs17tokenized_queries = tokenizer(input_queries, padding=True, truncation=True, return_tensors='pt')1819# encode queries20with torch.no_grad():21# Queries22 model_output = model(**tokenized_queries)23# Perform pooling. granite-embedding-125m-english uses CLS Pooling24 query_embeddings = model_output[0][:,0]2526# normalize the embeddings27query_embeddings = torch.nn.functional.normalize(query_embeddings, dim=1)28
Evaluation:
The performance of the Granite-Embedding-125M-English model on MTEB Retrieval (i.e., BEIR) and code retrieval (CoIR) benchmarks is reported below.
Model
Paramters (M)
Embedding Dimension
MTEB Retrieval (15)
CoIR (10)
granite-embedding-125m-english
125
768
52.3
50.3
Model Architecture:
Granite-Embedding-125m-English is based on an encoder-only RoBERTa like transformer architecture, trained internally at IBM Research.
Model
granite-embedding-30m-english
granite-embedding-125m-english
granite-embedding-107m-multilingual
granite-embedding-278m-multilingual
Embedding size
384
768
384
768
Number of layers
6
12
6
12
Number of attention heads
12
12
12
12
Intermediate size
1536
3072
1536
3072
Activation Function
GeLU
GeLU
GeLU
GeLU
Vocabulary Size
50265
50265
250002
250002
Max. Sequence Length
512
512
512
512
# Parameters
30M
125M
107M
278M
Training Data:
Overall, the training data consists of four key sources: (1) unsupervised title-body paired data scraped from the web, (2) publicly available paired with permissive, enterprise-friendly license, (3) IBM-internal paired data targetting specific technical domains, and (4) IBM-generated synthetic data. The data is listed below:
Notably, we do not use the popular MS-MARCO retrieval dataset in our training corpus due to its non-commercial license, while other open-source models train on this dataset due to its high quality.
Infrastructure:
We train Granite Embedding Models using IBM's computing cluster, Cognitive Compute Cluster, which is outfitted with NVIDIA A100 80gb GPUs. This cluster provides a scalable and efficient infrastructure for training our models over multiple GPUs.
Ethical Considerations and Limitations:
The data used to train the base language model was filtered to remove text containing hate, abuse, and profanity. Granite-Embedding-125m-English is trained only for English texts, and has a context length of 512 tokens (longer texts will be truncated to this size).