Sentence Similarity
sentence-transformers
ONNX
Safetensors
bert
embeddings
indic
romanized
transliteration
code-mixing
hinglish
tanglish
text-embeddings-inference
Instructions to use cidcodes/indic-e5-small with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use cidcodes/indic-e5-small with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("cidcodes/indic-e5-small") sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Notebooks
- Google Colab
- Kaggle
indic-e5-small v1: trimmed + distilled multilingual-e5-small for Indic and romanized text
Browse files- 1_Pooling/config.json +7 -0
- README.md +85 -0
- config.json +30 -0
- config_sentence_transformers.json +13 -0
- model.safetensors +3 -0
- modules.json +20 -0
- onnx/model.onnx +3 -0
- onnx/model_quantized.onnx +3 -0
- sentence_bert_config.json +4 -0
- tokenizer.json +0 -0
- tokenizer_config.json +17 -0
1_Pooling/config.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"word_embedding_dimension": 384,
|
| 3 |
+
"pooling_mode_cls_token": false,
|
| 4 |
+
"pooling_mode_mean_tokens": true,
|
| 5 |
+
"pooling_mode_max_tokens": false,
|
| 6 |
+
"pooling_mode_mean_sqrt_len_tokens": false
|
| 7 |
+
}
|
README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
base_model: intfloat/multilingual-e5-small
|
| 4 |
+
library_name: sentence-transformers
|
| 5 |
+
pipeline_tag: sentence-similarity
|
| 6 |
+
language: [hi, bn, ta, te, ml, mr, gu, kn, pa, or, as, ur, ne, en]
|
| 7 |
+
tags: [sentence-transformers, embeddings, indic, romanized, transliteration, code-mixing, hinglish, tanglish]
|
| 8 |
+
datasets: [ai4bharat/sangraha]
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# indic-e5-small
|
| 12 |
+
|
| 13 |
+
A 47M-parameter sentence-embedding model for 13 Indian languages and English that understands Indic text **in its
|
| 14 |
+
native script and typed in the Latin alphabet** ("mujhe kal office jaana hai", "naan nalaikku varuven").
|
| 15 |
+
It is [multilingual-e5-small](https://huggingface.co/intfloat/multilingual-e5-small) with the vocabulary trimmed
|
| 16 |
+
to the scripts that matter here (250K → 64K tokens, 118M → 47M parameters), then distilled so that romanized,
|
| 17 |
+
casually spelled and code-mixed text lands where the original model puts the native-script text.
|
| 18 |
+
|
| 19 |
+
| model | params | MTEB(Indic) | Dakshina roman→native R@1 | native→roman R@1 | TanglishSTS |
|
| 20 |
+
|---|---|---|---|---|---|
|
| 21 |
+
| **indic-e5-small** | **47M** | 0.648 | **0.827** | **0.905** | 0.699 |
|
| 22 |
+
| multilingual-e5-small | 118M | 0.648 | 0.396 | 0.498 | 0.729 |
|
| 23 |
+
| L3Cube indic-sentence-similarity-sbert | 238M | 0.592 | 0.772 | 0.819 | 0.692 |
|
| 24 |
+
| bge-m3 | 568M | 0.686 | 0.534 | 0.586 | 0.758 |
|
| 25 |
+
| LaBSE | 471M | 0.617 | 0.478 | 0.436 | 0.750 |
|
| 26 |
+
|
| 27 |
+
MTEB(Indic, v1): mean over its 20 tasks. Dakshina: 2,000 human-romanized sentences per language, 10 languages,
|
| 28 |
+
retrieval of the native sentence among 2,000. TanglishSTS: Spearman on 325 Tamil–English code-mixed pairs.
|
| 29 |
+
Neither Dakshina nor TanglishSTS was used for training or for choosing checkpoints. TanglishSTS is small: the
|
| 30 |
+
difference to multilingual-e5-small is -0.032, 95% paired-bootstrap CI [-0.081, +0.017], i.e. not significant.
|
| 31 |
+
English is unchanged (STSB 0.837 vs 0.841, SICK-R 0.773 vs 0.775).
|
| 32 |
+
|
| 33 |
+
## Usage
|
| 34 |
+
|
| 35 |
+
Same prefixes as e5: `query: ` for queries and symmetric tasks, `passage: ` for documents.
|
| 36 |
+
`encode_query` / `encode_document` add them for you (sentence-transformers 5+); with older versions, or with
|
| 37 |
+
plain `encode`, add them yourself.
|
| 38 |
+
|
| 39 |
+
```python
|
| 40 |
+
from sentence_transformers import SentenceTransformer
|
| 41 |
+
|
| 42 |
+
model = SentenceTransformer("cidcodes/indic-e5-small")
|
| 43 |
+
q = model.encode_query(["mujhe kal office jana hai"])
|
| 44 |
+
d = model.encode_document(["मुझे कल ऑफिस जाना है", "আজ খুব বৃষ্টি হচ্ছে", "I have to go to the office tomorrow"])
|
| 45 |
+
print(model.similarity(q, d))
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
In the browser or Node with [transformers.js](https://github.com/huggingface/transformers.js) (`onnx/model_quantized.onnx`,
|
| 49 |
+
47 MB, per-channel int8; cosine ≥ 0.99 to the full model). Try it in the
|
| 50 |
+
[demo Space](https://huggingface.co/spaces/cidcodes/indic-e5-small-demo).
|
| 51 |
+
|
| 52 |
+
```js
|
| 53 |
+
import { pipeline } from "@huggingface/transformers";
|
| 54 |
+
|
| 55 |
+
const embed = await pipeline("feature-extraction", "cidcodes/indic-e5-small", { dtype: "q8" });
|
| 56 |
+
const out = await embed(["query: mujhe kal office jana hai", "passage: मुझे कल ऑफिस जाना है"],
|
| 57 |
+
{ pooling: "mean", normalize: true });
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
## How it was made
|
| 61 |
+
|
| 62 |
+
1. **Vocabulary trimming.** Token frequencies from Wikipedia and Sangraha in 13 languages plus romanized text,
|
| 63 |
+
balanced per language; the 64K most useful pieces (and every single character of the target scripts) are kept
|
| 64 |
+
and the embedding rows gathered. MTEB(Indic) 0.6471 vs 0.6484 for the full model.
|
| 65 |
+
2. **Distillation** ([Reimers & Gurevych, 2020](https://arxiv.org/abs/2004.09813)). Teacher: the original
|
| 66 |
+
multilingual-e5-small, frozen. On 256K aligned native/romanized paragraphs from Sangraha's synthetic split, the
|
| 67 |
+
student is trained so that S(native), S(romanized), S(casually spelled romanized) and S(code-mixed romanized)
|
| 68 |
+
all match T(native), and S(English) matches T(English). Code-mixing swaps words for English using a lexicon
|
| 69 |
+
induced from the teacher's own embeddings (margin-based mutual nearest neighbours). Short, query-like inputs
|
| 70 |
+
come from the same 2-8 word window of each word-aligned pair, with the teacher run on the fly. One epoch on a
|
| 71 |
+
4 GB laptop GPU (RTX 3050), about 75 minutes.
|
| 72 |
+
|
| 73 |
+
## Limitations
|
| 74 |
+
|
| 75 |
+
- Romanization in the training data is synthetic; very informal spellings and heavy code-mixing are only
|
| 76 |
+
approximated by rules and an induced lexicon.
|
| 77 |
+
- Tamil is the weakest language for romanized input (Dakshina R@1 0.668; Hindi 0.921).
|
| 78 |
+
- Training text is Wikipedia-style written language. Very colloquial spoken forms (e.g. spoken Tamil
|
| 79 |
+
"enakku pasikkudhu" for written "enakku pasikkiradhu") and short chat messages are weaker.
|
| 80 |
+
- Max sequence length 512 as in e5-small, but training used 128 tokens.
|
| 81 |
+
|
| 82 |
+
## Data and licenses
|
| 83 |
+
|
| 84 |
+
Base model: multilingual-e5-small (MIT). Training text: [Sangraha](https://huggingface.co/datasets/ai4bharat/sangraha)
|
| 85 |
+
(AI4Bharat, CC BY 4.0). Evaluation only: Dakshina (CC BY-SA 4.0), TanglishSTS (CC BY 4.0), MTEB.
|
config.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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": 12,
|
| 21 |
+
"num_hidden_layers": 12,
|
| 22 |
+
"pad_token_id": 0,
|
| 23 |
+
"position_embedding_type": "absolute",
|
| 24 |
+
"tie_word_embeddings": true,
|
| 25 |
+
"tokenizer_class": "XLMRobertaTokenizer",
|
| 26 |
+
"transformers_version": "5.24.1",
|
| 27 |
+
"type_vocab_size": 2,
|
| 28 |
+
"use_cache": false,
|
| 29 |
+
"vocab_size": 65536
|
| 30 |
+
}
|
config_sentence_transformers.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"__version__": {
|
| 3 |
+
"sentence_transformers": "6.3.0",
|
| 4 |
+
"transformers": "5.24.1",
|
| 5 |
+
"pytorch": "2.14.1+cu126"
|
| 6 |
+
},
|
| 7 |
+
"prompts": {
|
| 8 |
+
"query": "query: ",
|
| 9 |
+
"document": "passage: "
|
| 10 |
+
},
|
| 11 |
+
"default_prompt_name": null,
|
| 12 |
+
"similarity_fn_name": "cosine"
|
| 13 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:921e9b05087adc0c66f50b3d7b14e932e275acedd1ba334ab5b6d8cb7f077fb4
|
| 3 |
+
size 187243880
|
modules.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"idx": 0,
|
| 4 |
+
"name": "0",
|
| 5 |
+
"path": "",
|
| 6 |
+
"type": "sentence_transformers.models.Transformer"
|
| 7 |
+
},
|
| 8 |
+
{
|
| 9 |
+
"idx": 1,
|
| 10 |
+
"name": "1",
|
| 11 |
+
"path": "1_Pooling",
|
| 12 |
+
"type": "sentence_transformers.models.Pooling"
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"idx": 2,
|
| 16 |
+
"name": "2",
|
| 17 |
+
"path": "2_Normalize",
|
| 18 |
+
"type": "sentence_transformers.models.Normalize"
|
| 19 |
+
}
|
| 20 |
+
]
|
onnx/model.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:48534687d8761ecfc7b7e24441e9a7220c5981f75d48a33acbfe77c5c35cbba0
|
| 3 |
+
size 186823449
|
onnx/model_quantized.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:645b1fd4e77838095b744d2fbce07248571a8b91dfdcc501d3764c4b9cf6d5ef
|
| 3 |
+
size 47408655
|
sentence_bert_config.json
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"max_seq_length": 512,
|
| 3 |
+
"do_lower_case": false
|
| 4 |
+
}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": true,
|
| 3 |
+
"backend": "tokenizers",
|
| 4 |
+
"bos_token": "<s>",
|
| 5 |
+
"clean_up_tokenization_spaces": true,
|
| 6 |
+
"cls_token": "<s>",
|
| 7 |
+
"eos_token": "</s>",
|
| 8 |
+
"is_local": true,
|
| 9 |
+
"local_files_only": false,
|
| 10 |
+
"mask_token": "<mask>",
|
| 11 |
+
"model_max_length": 128,
|
| 12 |
+
"pad_token": "<pad>",
|
| 13 |
+
"sep_token": "</s>",
|
| 14 |
+
"sp_model_kwargs": {},
|
| 15 |
+
"tokenizer_class": "XLMRobertaTokenizer",
|
| 16 |
+
"unk_token": "<unk>"
|
| 17 |
+
}
|