CoolFace
Modelpublic

badmadrad/granite-embedding-125m-english-mlx

sourceHugging Faceapache-2.0updated 8mo agoView on Hugging Face
0likes19downloads
Model Card

Granite-Embedding-125m-English

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.

Supported Languages: English.

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

shell
pip install sentence_transformers

The model can then be used to encode pairs of text and find the similarity between their representations

python
from sentence_transformers import SentenceTransformer, util

model_path = "ibm-granite/granite-embedding-125m-english"
# Load the Sentence Transformer model
model = SentenceTransformer(model_path)

input_queries = [
    ' Who made the song My achy breaky heart? ',
    'summit define'
    ]

input_passages = [
    "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. ",
    "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."
    ]

# encode queries and passages
query_embeddings = model.encode(input_queries)
passage_embeddings = model.encode(input_passages)

# calculate cosine similarity
print(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

shell
pip install transformers torch

The model can then be used to encode pairs of text

python
import torch
from transformers import AutoModel, AutoTokenizer

model_path = "ibm-granite/granite-embedding-125m-english"

# Load the model and tokenizer
model = AutoModel.from_pretrained(model_path)
tokenizer = AutoTokenizer.from_pretrained(model_path)
model.eval()

input_queries = [
    ' Who made the song My achy breaky heart? ',
    'summit define'
    ]

# tokenize inputs
tokenized_queries = tokenizer(input_queries, padding=True, truncation=True, return_tensors='pt')

# encode queries
with torch.no_grad():
    # Queries
    model_output = model(**tokenized_queries)
    # Perform pooling. granite-embedding-125m-english uses CLS Pooling
    query_embeddings = model_output[0][:, 0]

# normalize the embeddings
query_embeddings = torch.nn.functional.normalize(query_embeddings, dim=1)

Evaluation:

The performance of the Granite-Embedding-125M-English model on MTEB Retrieval (i.e., BEIR) and code retrieval (CoIR) benchmarks is reported below.

ModelParamters (M)Embedding DimensionMTEB Retrieval (15)CoIR (10)
granite-embedding-125m-english12576852.350.3

Model Architecture: Granite-Embedding-125m-English is based on an encoder-only RoBERTa like transformer architecture, trained internally at IBM Research.

Modelgranite-embedding-30m-englishgranite-embedding-125m-englishgranite-embedding-107m-multilingualgranite-embedding-278m-multilingual
Embedding size384768384768
Number of layers612612
Number of attention heads12121212
Intermediate size1536307215363072
Activation FunctionGeLUGeLUGeLUGeLU
Vocabulary Size5026550265250002250002
Max. Sequence Length512512512512
# Parameters30M125M107M278M

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:

**Dataset****Num. Pairs**
SPECTER citation triplets684,100
Stack Exchange Duplicate questions (titles)304,525
Stack Exchange Duplicate questions (bodies)250,519
Stack Exchange Duplicate questions (titles+bodies)250,460
Natural Questions (NQ)100,231
SQuAD2.087,599
PAQ (Question, Answer) pairs64,371,441
Stack Exchange (Title, Answer) pairs4,067,139
Stack Exchange (Title, Body) pairs23,978,013
Stack Exchange (Title+Body, Answer) pairs187,195
S2ORC Citation pairs (Titles)52,603,982
S2ORC (Title, Abstract)41,769,185
S2ORC (Citations, abstracts)52,603,982
WikiAnswers Duplicate question pairs77,427,422
SearchQA582,261
HotpotQA85,000
Fever109,810
Arxiv2,358,545
Wikipedia20,745,403
PubMed20,000,000
Miracl En Pairs9,016
DBPedia Title-Body Pairs4,635,922
Synthetic: Query-Wikipedia Passage1,879,093
Synthetic: Fact Verification9,888
IBM Internal Triples40,290
IBM Internal Title-Body Pairs1,524,586

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).

Resources

  • —⭐️ Learn about the latest updates with Granite: https://www.ibm.com/granite
  • —📄 Get started with tutorials, best practices, and prompt engineering advice: https://www.ibm.com/granite/docs/
  • —💡 Learn about the latest Granite learning resources: https://ibm.biz/granite-learning-resources

<!-- ## Citation

@misc{granite-embedding-models,
  author = {author 1, author2, ...},
  title = {},
  journal = {},
  volume = {},
  year = {2024},
  url = {https://arxiv.org/abs/0000.00000},
}