Instructions to use altslate/indic-rerank-small with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use altslate/indic-rerank-small with sentence-transformers:
from sentence_transformers import CrossEncoder model = CrossEncoder("altslate/indic-rerank-small") query = "Which planet is known as the Red Planet?" passages = [ "Venus is often called Earth's twin because of its similar size and proximity.", "Mars, known for its reddish appearance, is often referred to as the Red Planet.", "Jupiter, the largest planet in our solar system, has a prominent red spot.", "Saturn, famous for its rings, is sometimes mistaken for the Red Planet." ] scores = model.predict([(query, passage) for passage in passages]) print(scores) - Transformers.js
How to use altslate/indic-rerank-small with Transformers.js:
// npm i @huggingface/transformers import { AutoTokenizer, AutoModelForSequenceClassification } from '@huggingface/transformers'; const tokenizer = await AutoTokenizer.from_pretrained('altslate/indic-rerank-small'); const model = await AutoModelForSequenceClassification.from_pretrained('altslate/indic-rerank-small'); const query = 'Which planet is known as the Red Planet?'; const documents = [ 'Mars, known for its reddish appearance, is often referred to as the Red Planet.', 'Venus is often called the twin of Earth because of its similar size and proximity.', ]; const inputs = tokenizer(new Array(documents.length).fill(query), { text_pair: documents, padding: true, truncation: true }); const { logits } = await model(inputs); console.log(logits.sigmoid().tolist()); // one relevance score per document - Notebooks
- Google Colab
- Kaggle
indic-rerank-small
A 140M-parameter reranker (cross-encoder) for Indian-language search, which also works when the query is typed in the Latin alphabet ("bharat mein kitne rajya hain") and the passages are in native script. Give it a query and the candidate passages from a first-stage retriever (BM25, or an embedding model such as altslate/indic-embed-small); it returns a relevance score for each pair. Query and passages should be in the same language (see limitations).
Trained and tested on Hindi, Bengali and Telugu (the Indian languages in MIRACL). It is a distillation of BAAI/bge-reranker-v2-m3 (568M) into jhu-clsp/mmBERT-small. The teacher cannot handle romanized queries (on our test it reranks them no better than leaving the candidates in their original order), so this model was taught to give a romanized query the scores the teacher gives the native-script query.
Usage
sentence-transformers
from sentence_transformers import CrossEncoder
model = CrossEncoder("altslate/indic-rerank-small")
query = "bharat mein kitne rajya hain"
docs = ["เคญเคพเคฐเคค เคฎเฅเค 28 เคฐเคพเคเฅเคฏ เคเคฐ 8 เคเฅเคเคฆเฅเคฐ เคถเคพเคธเคฟเคค เคชเฅเคฐเคฆเฅเคถ เคนเฅเคเฅค", "เคเฅเคฐเคฟเคเฅเค เคเค เคฒเฅเคเคชเฅเคฐเคฟเคฏ เคเฅเคฒ เคนเฅเฅค"]
print(model.predict([(query, d) for d in docs])) # [0.96 0.004]
print(model.rank(query, docs)) # the first passage ranks first
Scores are passed through a sigmoid (0โ1). Tested with sentence-transformers 5.1.2 (transformers 4.57.6) and 6.3.0 (transformers
5.24.0); both give the same scores. With plain transformers, use AutoModelForSequenceClassification and read logits[:, 0]
(pairs encoded as tokenizer(queries, passages, truncation="only_second", max_length=384)).
transformers.js / ONNX
onnx/model.onnx (fp32, 563 MB) and onnx/model_fp16.onnx (282 MB) take input_ids and attention_mask for (query, passage)
pairs and return logits (apply a sigmoid for 0โ1 scores).
import { AutoTokenizer, AutoModelForSequenceClassification } from "@huggingface/transformers";
const tok = await AutoTokenizer.from_pretrained("altslate/indic-rerank-small");
const model = await AutoModelForSequenceClassification.from_pretrained("altslate/indic-rerank-small", { dtype: "fp16" }); // or "fp32"
const query = "bharat mein kitne rajya hain";
const docs = ["เคญเคพเคฐเคค เคฎเฅเค 28 เคฐเคพเคเฅเคฏ เคเคฐ 8 เคเฅเคเคฆเฅเคฐ เคถเคพเคธเคฟเคค เคชเฅเคฐเคฆเฅเคถ เคนเฅเคเฅค", "เคเฅเคฐเคฟเคเฅเค เคเค เคฒเฅเคเคชเฅเคฐเคฟเคฏ เคเฅเคฒ เคนเฅเฅค"];
const { logits } = await model(tok(docs.map(() => query), { text_pair: docs, padding: true, truncation: true, max_length: 384 }));
console.log(logits.tolist().map(r => r[0])); // ~[3.27, -5.57]: higher = more relevant
Tested with @huggingface/transformers 4.3.2 in Node 22: fp32 gives the PyTorch scores exactly; fp16 differs by at most 0.009 on
our check pairs. Through onnxruntime on 15 dev queries per language (100 candidates each), fp16 nDCG@10 is within ยฑ0.015 of PyTorch.
Dynamic int8 quantization lost too much (romanized Hindi 0.645 โ 0.563), so there is no int8 file.
Results
Test: mteb/MIRACLReranking, the MIRACL dev queries (350 per language), each with 100 candidate passages from Wikipedia and human relevance labels; nDCG@10. No dev query was used in training (one Hindi train query whose text matched a dev query was dropped), and the model was evaluated on it once, with no tuning. MIRACL's test labels are not public.
| Model | Params | Native-script queries (hi / bn / te) | Romanized queries (hi / bn / te) | English |
|---|---|---|---|---|
| altslate/indic-rerank-small | 140M | 0.806 (0.693 / 0.811 / 0.914) | 0.756 (0.614 / 0.763 / 0.892) | 0.645 |
| BAAI/bge-reranker-v2-m3 (teacher) | 568M | 0.857 (0.754 / 0.859 / 0.958) | 0.560 (0.483 / 0.503 / 0.695) | 0.746 |
| cross-encoder/mmarco-mMiniLMv2-L12-H384-v1 | 118M | 0.774 (0.676 / 0.754 / 0.892) | 0.264 (0.175 / 0.189 / 0.429) | 0.680 |
| no reranking (candidates in their given order) | โ | 0.565 | 0.565 | 0.420 |
- Romanized queries are the MIRACL queries romanized word by word by the dictionary + rule romanizer used to make the training data (a different random seed). This favours our model; we have no human-romanized test queries. Telugu romanized queries lose little (0.892 vs 0.914); Hindi loses most (0.614 vs 0.693).
- English: not trained on English; the teacher and mMiniLM are better. Use an English reranker for English-only search.
Known limitations
- Query and passage must be in the same language (a romanized query with a native-script passage of that language is fine). All training pairs were same-language, and cross-language pairs score near zero even when the passage is an exact translation (in a quick test, a romanized Hindi query scored 0.00 against the Bengali translation of its answer). For cross-language search, use the first-stage scores of a multilingual embedder such as indic-embed-small instead.
- Trained only on Hindi, Bengali and Telugu queries (the Indian languages in MIRACL). Other Indian languages are untested; the base model has seen them in pre-training, but expect lower quality.
- Below its teacher on native-script queries (0.806 vs 0.857); the teacher is 4ร larger.
- Training passages are Wikipedia paragraphs; chat-style or product-search text is untested.
- Queries were romanized by rules and dictionaries, not typed by people, so heavy abbreviation or unusual spellings are less covered.
- Inputs longer than 384 tokens (query + passage) are truncated.
Training
- Queries: MIRACL train topics for Hindi (1,168), Bengali (1,631) and Telugu (3,452); 189 of them held out for checks.
- Candidates per query: the passages MIRACL annotators judged (relevant and not relevant) plus the top 30 passages that altslate/indic-embed-small retrieves from that language's MIRACL Wikipedia corpus.
- Targets: bge-reranker-v2-m3 scores for each (native-script query, passage) pair.
- Inputs: each query is shown in native script (35%), fully romanized (50%) or half romanized (15%), always with the teacher's scores for the native-script query.
- Loss: listwise KL divergence between the softmax of the teacher's and the model's scores over each query's candidates (16 per query), plus 0.1 ร MSE on the raw scores. 6,000 steps of 16 queries, AdamW, lr 3e-5, about 3.7 hours on one NVIDIA DGX Spark (GB10). No text was generated by a language model.
| Data | Used for | License |
|---|---|---|
| miracl/miracl train topics and qrels, miracl/miracl-corpus (hi, bn, te) | queries, passages | Apache-2.0 (passages from Wikipedia, CC BY-SA) |
| mteb/MIRACLReranking (dev) | testing only | CC BY-SA 4.0 |
| Aksharantar word pairs, Dakshina romanization lexicons (train splits) | romanizing queries | CC0 / CC-BY 4.0; CC BY-SA 4.0 |
Code: github.com/AltSlate-Labs/indic-chat-toolkit (src/rerank/).
License
Apache-2.0. The base model (mmBERT-small) is MIT-licensed; the teacher (bge-reranker-v2-m3) is Apache-2.0.
Citation
Please cite MIRACL (Zhang et al., 2023), the teacher and the base model.
- Downloads last month
- -
Model tree for altslate/indic-rerank-small
Base model
jhu-clsp/mmBERT-small