davidmezzetti's picture
Add model
d79745f
|
Raw
History Blame Contribute Delete
5.99 kB
---
pipeline_tag: sentence-similarity
tags:
- sentence-transformers
- feature-extraction
- sentence-similarity
- transformers
base_model: NeuML/celeberty-small
language: en
license: apache-2.0
---
# CeleBERTy Small Embeddings
This is a [CeleBERTy Small](https://hf.co/neuml/sportsbert-small) model fined-tuned using [sentence-transformers](https://www.SBERT.net). It maps sentences & paragraphs to a 384 dimensional dense vector space and can be used for tasks like clustering or semantic search.
The training dataset was generated using a random sample of [Wikipedia articles](https://huggingface.co/datasets/NeuML/wikipedia-celebrity-similarity) labeled as `celebrity`.
The model was trained by distilling embeddings from the larger [DenseOn](https://huggingface.co/lightonai/DenseOn) model using [EmbedDistillLoss](https://sbert.net/docs/package_reference/sentence_transformer/losses.html#embeddistillloss) over the generated training dataset.
As noted in the paper [Well-Read Students Learn Better: On the Importance of Pre-training Compact Models](https://arxiv.org/abs/1908.08962), it's important that the base model is pretrained on a large corpus of relevant documents prior to distillation.
## Usage (txtai)
This model can be used to build embeddings databases with [txtai](https://github.com/neuml/txtai) for semantic search and/or as a knowledge source for retrieval augmented generation (RAG).
```python
import txtai
embeddings = txtai.Embeddings(path="neuml/celeberty-small-embeddings", content=True)
embeddings.index(documents())
# Run a query
embeddings.search("query to run")
```
## Usage (Sentence-Transformers)
Alternatively, the model can be loaded with [sentence-transformers](https://www.SBERT.net).
```python
from sentence_transformers import SentenceTransformer
sentences = ["This is an example sentence", "Each sentence is converted"]
model = SentenceTransformer("neuml/celeberty-small-embeddings")
embeddings = model.encode(sentences)
print(embeddings)
```
## Usage (Hugging Face Transformers)
The model can also be used directly with Transformers.
```python
from transformers import AutoTokenizer, AutoModel
import torch
# Mean Pooling - Take attention mask into account for correct averaging
def meanpooling(output, mask):
embeddings = output[0] # First element of model_output contains all token embeddings
mask = mask.unsqueeze(-1).expand(embeddings.size()).float()
return torch.sum(embeddings * mask, 1) / torch.clamp(mask.sum(1), min=1e-9)
# Sentences we want sentence embeddings for
sentences = ['This is an example sentence', 'Each sentence is converted']
# Load model from HuggingFace Hub
tokenizer = AutoTokenizer.from_pretrained("neuml/celeberty-small-embeddings")
model = AutoModel.from_pretrained("neuml/celeberty-small-embeddings")
# Tokenize sentences
inputs = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
# Compute token embeddings
with torch.no_grad():
output = model(**inputs)
# Perform pooling. In this case, mean pooling.
embeddings = meanpooling(output, inputs['attention_mask'])
print("Sentence embeddings:")
print(embeddings)
```
## Evaluation Results
A [BEIR-compatible dataset](https://huggingface.co/datasets/NeuML/wikipedia-celebrity-similarity/tree/main/beir) was generated to facilitate the evaluation process. This is a separate random sample of Wikipedia articles alongside generated user queries.
Evaluation results are shown below. [NDCG](https://en.wikipedia.org/wiki/Discounted_cumulative_gain) is used as the evaluation metric.
| Model | Parameters | NDCG | Index Time | Search Time | Disk |
| ----------------------------------------------------------------------------------- | ---------- | --------- | ----------- | ----------- | --------- |
| [**CeleBERTy Small Embeddings**](https://hf.co/neuml/celeberty-small-embeddings) | **22.7M** | **55.24** | **3.71s** | **0.37s** | **16 MB** |
| [all-MiniLM-L6-v2](https://hf.co/sentence-transformers/all-MiniLM-L6-v2) | 22.7M | 48.12 | 4.03s | 0.41s | 16 MB |
| [DenseOn](https://hf.co/lightonai/DenseOn) | 149M | 57.26 | 21.19s | 0.76s | 31 MB |
| [EmbeddingGemma](https://hf.co/google/embeddinggemma-300m) | 300M | 58.61 | 27.37s | 1.39s | 31 MB |
| [Qwen3-Embedding-0.6B](https://huggingface.co/Qwen/Qwen3-Embedding-0.6B) | 600M | 54.02 | 34.02s | 2.01s | 41 MB |
| [Qwen3-Embedding-4B](https://huggingface.co/Qwen/Qwen3-Embedding-4B) | 4000M | 60.72 | 167.01s | 9.34s | 103 MB |
| [Qwen3-Embedding-8B](https://huggingface.co/Qwen/Qwen3-Embedding-8B) | 8000M | 61.04 | 283.28s | 16.05s | 164 MB |
This model is a solid performer at a small size. It beats the same sized `all-MiniLM-L6-v2` model by a significant margin. It beats the 600M parameter Qwen3 Embeddings model which is over 25x larger. It scores slightly lower than the model it's distilled from (`DenseOn`).
This is a great model that can be used in CPU-only setups without trading off much on the accuracy front. It shows how small models can excel at specialized domains, requiring less compute and disk space.
## Full Model Architecture
```
SentenceTransformer(
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False, 'architecture': 'BertModel'})
(1): Pooling({'word_embedding_dimension': 384, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, 'include_prompt': True})
)
```
## More Information
Read more about the model in [this article](https://huggingface.co/blog/NeuML/celeberty-small).