Sentence Similarity
sentence-transformers
Safetensors
Transformers
English
bert
feature-extraction
text-embeddings-inference
Instructions to use NeuML/celeberty-small-embeddings with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use NeuML/celeberty-small-embeddings with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("NeuML/celeberty-small-embeddings") sentences = [ "That is a happy person", "That is a happy dog", "That is a very happy person", "Today is a sunny day" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4] - Transformers
How to use NeuML/celeberty-small-embeddings with Transformers:
# Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("NeuML/celeberty-small-embeddings") model = AutoModel.from_pretrained("NeuML/celeberty-small-embeddings", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Commit ·
d79745f
1
Parent(s): 236acd4
Add model
Browse files- 1_Pooling/config.json +5 -0
- README.md +116 -0
- config.json +28 -0
- config_sentence_transformers.json +14 -0
- model.safetensors +3 -0
- modules.json +14 -0
- sentence_bert_config.json +10 -0
- tokenizer.json +0 -0
- tokenizer_config.json +15 -0
1_Pooling/config.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"embedding_dimension": 384,
|
| 3 |
+
"pooling_mode": "mean",
|
| 4 |
+
"include_prompt": true
|
| 5 |
+
}
|
README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
pipeline_tag: sentence-similarity
|
| 3 |
+
tags:
|
| 4 |
+
- sentence-transformers
|
| 5 |
+
- feature-extraction
|
| 6 |
+
- sentence-similarity
|
| 7 |
+
- transformers
|
| 8 |
+
base_model: NeuML/celeberty-small
|
| 9 |
+
language: en
|
| 10 |
+
license: apache-2.0
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# CeleBERTy Small Embeddings
|
| 14 |
+
|
| 15 |
+
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.
|
| 16 |
+
|
| 17 |
+
The training dataset was generated using a random sample of [Wikipedia articles](https://huggingface.co/datasets/NeuML/wikipedia-celebrity-similarity) labeled as `celebrity`.
|
| 18 |
+
|
| 19 |
+
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.
|
| 20 |
+
|
| 21 |
+
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.
|
| 22 |
+
|
| 23 |
+
## Usage (txtai)
|
| 24 |
+
|
| 25 |
+
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).
|
| 26 |
+
|
| 27 |
+
```python
|
| 28 |
+
import txtai
|
| 29 |
+
|
| 30 |
+
embeddings = txtai.Embeddings(path="neuml/celeberty-small-embeddings", content=True)
|
| 31 |
+
embeddings.index(documents())
|
| 32 |
+
|
| 33 |
+
# Run a query
|
| 34 |
+
embeddings.search("query to run")
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
## Usage (Sentence-Transformers)
|
| 38 |
+
|
| 39 |
+
Alternatively, the model can be loaded with [sentence-transformers](https://www.SBERT.net).
|
| 40 |
+
|
| 41 |
+
```python
|
| 42 |
+
from sentence_transformers import SentenceTransformer
|
| 43 |
+
sentences = ["This is an example sentence", "Each sentence is converted"]
|
| 44 |
+
|
| 45 |
+
model = SentenceTransformer("neuml/celeberty-small-embeddings")
|
| 46 |
+
embeddings = model.encode(sentences)
|
| 47 |
+
print(embeddings)
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
## Usage (Hugging Face Transformers)
|
| 51 |
+
|
| 52 |
+
The model can also be used directly with Transformers.
|
| 53 |
+
|
| 54 |
+
```python
|
| 55 |
+
from transformers import AutoTokenizer, AutoModel
|
| 56 |
+
import torch
|
| 57 |
+
|
| 58 |
+
# Mean Pooling - Take attention mask into account for correct averaging
|
| 59 |
+
def meanpooling(output, mask):
|
| 60 |
+
embeddings = output[0] # First element of model_output contains all token embeddings
|
| 61 |
+
mask = mask.unsqueeze(-1).expand(embeddings.size()).float()
|
| 62 |
+
return torch.sum(embeddings * mask, 1) / torch.clamp(mask.sum(1), min=1e-9)
|
| 63 |
+
|
| 64 |
+
# Sentences we want sentence embeddings for
|
| 65 |
+
sentences = ['This is an example sentence', 'Each sentence is converted']
|
| 66 |
+
|
| 67 |
+
# Load model from HuggingFace Hub
|
| 68 |
+
tokenizer = AutoTokenizer.from_pretrained("neuml/celeberty-small-embeddings")
|
| 69 |
+
model = AutoModel.from_pretrained("neuml/celeberty-small-embeddings")
|
| 70 |
+
|
| 71 |
+
# Tokenize sentences
|
| 72 |
+
inputs = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
| 73 |
+
|
| 74 |
+
# Compute token embeddings
|
| 75 |
+
with torch.no_grad():
|
| 76 |
+
output = model(**inputs)
|
| 77 |
+
|
| 78 |
+
# Perform pooling. In this case, mean pooling.
|
| 79 |
+
embeddings = meanpooling(output, inputs['attention_mask'])
|
| 80 |
+
|
| 81 |
+
print("Sentence embeddings:")
|
| 82 |
+
print(embeddings)
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
## Evaluation Results
|
| 86 |
+
|
| 87 |
+
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.
|
| 88 |
+
|
| 89 |
+
Evaluation results are shown below. [NDCG](https://en.wikipedia.org/wiki/Discounted_cumulative_gain) is used as the evaluation metric.
|
| 90 |
+
|
| 91 |
+
| Model | Parameters | NDCG | Index Time | Search Time | Disk |
|
| 92 |
+
| ----------------------------------------------------------------------------------- | ---------- | --------- | ----------- | ----------- | --------- |
|
| 93 |
+
| [**CeleBERTy Small Embeddings**](https://hf.co/neuml/celeberty-small-embeddings) | **22.7M** | **55.24** | **3.71s** | **0.37s** | **16 MB** |
|
| 94 |
+
| [all-MiniLM-L6-v2](https://hf.co/sentence-transformers/all-MiniLM-L6-v2) | 22.7M | 48.12 | 4.03s | 0.41s | 16 MB |
|
| 95 |
+
| [DenseOn](https://hf.co/lightonai/DenseOn) | 149M | 57.26 | 21.19s | 0.76s | 31 MB |
|
| 96 |
+
| [EmbeddingGemma](https://hf.co/google/embeddinggemma-300m) | 300M | 58.61 | 27.37s | 1.39s | 31 MB |
|
| 97 |
+
| [Qwen3-Embedding-0.6B](https://huggingface.co/Qwen/Qwen3-Embedding-0.6B) | 600M | 54.02 | 34.02s | 2.01s | 41 MB |
|
| 98 |
+
| [Qwen3-Embedding-4B](https://huggingface.co/Qwen/Qwen3-Embedding-4B) | 4000M | 60.72 | 167.01s | 9.34s | 103 MB |
|
| 99 |
+
| [Qwen3-Embedding-8B](https://huggingface.co/Qwen/Qwen3-Embedding-8B) | 8000M | 61.04 | 283.28s | 16.05s | 164 MB |
|
| 100 |
+
|
| 101 |
+
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`).
|
| 102 |
+
|
| 103 |
+
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.
|
| 104 |
+
|
| 105 |
+
## Full Model Architecture
|
| 106 |
+
|
| 107 |
+
```
|
| 108 |
+
SentenceTransformer(
|
| 109 |
+
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False, 'architecture': 'BertModel'})
|
| 110 |
+
(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})
|
| 111 |
+
)
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
## More Information
|
| 115 |
+
|
| 116 |
+
Read more about the model in [this article](https://huggingface.co/blog/NeuML/celeberty-small).
|
config.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_cross_attention": false,
|
| 3 |
+
"architectures": [
|
| 4 |
+
"BertModel"
|
| 5 |
+
],
|
| 6 |
+
"attention_probs_dropout_prob": 0.1,
|
| 7 |
+
"bos_token_id": null,
|
| 8 |
+
"classifier_dropout": null,
|
| 9 |
+
"dtype": "float32",
|
| 10 |
+
"eos_token_id": null,
|
| 11 |
+
"hidden_act": "gelu",
|
| 12 |
+
"hidden_dropout_prob": 0.1,
|
| 13 |
+
"hidden_size": 384,
|
| 14 |
+
"initializer_range": 0.02,
|
| 15 |
+
"intermediate_size": 1536,
|
| 16 |
+
"is_decoder": false,
|
| 17 |
+
"layer_norm_eps": 1e-12,
|
| 18 |
+
"max_position_embeddings": 512,
|
| 19 |
+
"model_type": "bert",
|
| 20 |
+
"num_attention_heads": 6,
|
| 21 |
+
"num_hidden_layers": 6,
|
| 22 |
+
"pad_token_id": 0,
|
| 23 |
+
"tie_word_embeddings": true,
|
| 24 |
+
"transformers_version": "5.11.0",
|
| 25 |
+
"type_vocab_size": 2,
|
| 26 |
+
"use_cache": false,
|
| 27 |
+
"vocab_size": 30522
|
| 28 |
+
}
|
config_sentence_transformers.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"__version__": {
|
| 3 |
+
"pytorch": "2.12.0+cu130",
|
| 4 |
+
"sentence_transformers": "5.5.0",
|
| 5 |
+
"transformers": "5.11.0"
|
| 6 |
+
},
|
| 7 |
+
"default_prompt_name": null,
|
| 8 |
+
"model_type": "SentenceTransformer",
|
| 9 |
+
"prompts": {
|
| 10 |
+
"document": "document: ",
|
| 11 |
+
"query": "query: "
|
| 12 |
+
},
|
| 13 |
+
"similarity_fn_name": "cosine"
|
| 14 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5c585beb23b400ab6e9c586d10a2bc6ad26d64f3ad20b33671e49cc417fd04e8
|
| 3 |
+
size 90864192
|
modules.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"idx": 0,
|
| 4 |
+
"name": "0",
|
| 5 |
+
"path": "",
|
| 6 |
+
"type": "sentence_transformers.base.modules.transformer.Transformer"
|
| 7 |
+
},
|
| 8 |
+
{
|
| 9 |
+
"idx": 1,
|
| 10 |
+
"name": "1",
|
| 11 |
+
"path": "1_Pooling",
|
| 12 |
+
"type": "sentence_transformers.sentence_transformer.modules.pooling.Pooling"
|
| 13 |
+
}
|
| 14 |
+
]
|
sentence_bert_config.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"transformer_task": "feature-extraction",
|
| 3 |
+
"modality_config": {
|
| 4 |
+
"text": {
|
| 5 |
+
"method": "forward",
|
| 6 |
+
"method_output_name": "last_hidden_state"
|
| 7 |
+
}
|
| 8 |
+
},
|
| 9 |
+
"module_output_name": "token_embeddings"
|
| 10 |
+
}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"cls_token": "[CLS]",
|
| 4 |
+
"do_lower_case": true,
|
| 5 |
+
"is_local": true,
|
| 6 |
+
"local_files_only": false,
|
| 7 |
+
"mask_token": "[MASK]",
|
| 8 |
+
"model_max_length": 512,
|
| 9 |
+
"pad_token": "[PAD]",
|
| 10 |
+
"sep_token": "[SEP]",
|
| 11 |
+
"strip_accents": null,
|
| 12 |
+
"tokenize_chinese_chars": true,
|
| 13 |
+
"tokenizer_class": "BertTokenizer",
|
| 14 |
+
"unk_token": "[UNK]"
|
| 15 |
+
}
|