Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- executorch
|
| 5 |
+
- xnnpack
|
| 6 |
+
- pte
|
| 7 |
+
- on-device
|
| 8 |
+
- text-ranking
|
| 9 |
+
- text-classification
|
| 10 |
+
base_model:
|
| 11 |
+
- BAAI/bge-reranker-base
|
| 12 |
+
---
|
| 13 |
+
# bge-reranker-base — ExecuTorch
|
| 14 |
+
|
| 15 |
+
A cross-encoder reranker: a query and one document in, one relevance score out. The second
|
| 16 |
+
stage of on-device retrieval — an embedding model fetches candidates cheaply, this reads
|
| 17 |
+
each candidate together with the query and scores it properly.
|
| 18 |
+
|
| 19 |
+
- **Source**: BAAI/bge-reranker-base — 278M parameters, 12 XLM-RoBERTa layers, hidden 768, 250k vocabulary
|
| 20 |
+
- **License**: MIT
|
| 21 |
+
- **Input**: `input_ids` and `attention_mask`, both `[1, 512]` int64
|
| 22 |
+
- **Output**: `[1, 1]` fp32 — the raw logit. `sigmoid(x)` maps it to 0..1 and does not
|
| 23 |
+
change the ordering.
|
| 24 |
+
|
| 25 |
+
## Variants
|
| 26 |
+
|
| 27 |
+
| build | file | size (MB) | worst score error vs eager | Mac median (ms)* |
|
| 28 |
+
|---|---|---|---|---|
|
| 29 |
+
| fp32 | `rerank_bge_reranker_base_xnnpack_fp32.pte` | 1112.4 | 0.0000 logits | 76.9 |
|
| 30 |
+
| fp16 | `rerank_bge_reranker_base_xnnpack_fp16.pte` | 556.4 | 0.0185 logits | 169.4 |
|
| 31 |
+
| Core ML (fp16, iOS) | `rerank_bge_reranker_base_coreml_all.pte` | 556.6 | 0.0458 logits | 19.7 |
|
| 32 |
+
|
| 33 |
+
\*Mac arm64, single process, median of 10, one query-document pair at 512 tokens — a
|
| 34 |
+
reference point for relative cost, not a device number. PyTorch eager fp32 on the same
|
| 35 |
+
machine: 54.7 ms.
|
| 36 |
+
|
| 37 |
+
Correlation is not reported because it cannot be: the output is a single number, and the
|
| 38 |
+
correlation of a one-element vector is undefined. The column above is the error in the
|
| 39 |
+
units the model is used in — logits — over 6 real query-document pairs, and every build
|
| 40 |
+
listed reproduces eager's ranking order exactly.
|
| 41 |
+
|
| 42 |
+
## What it does, on the shipped fp32 build
|
| 43 |
+
|
| 44 |
+
Query: *"How many people live in Berlin?"*
|
| 45 |
+
|
| 46 |
+
| rank | score | document |
|
| 47 |
+
|---|---|---|
|
| 48 |
+
| 1 | +10.308 | ベルリンの人口はおよそ350万人です。 |
|
| 49 |
+
| 2 | +10.302 | In 2019 the city recorded 3.7 million residents within its metropolitan area. |
|
| 50 |
+
| 3 | +9.940 | Berlin has a population of 3,520,031 registered inhabitants in an area of 891.82 km². |
|
| 51 |
+
| 4 | -2.708 | The capital of France is Paris, a city of about 2.1 million people. |
|
| 52 |
+
| 5 | -6.198 | Berlin is well known for its museums, its nightlife and its history. |
|
| 53 |
+
| 6 | -10.194 | Water boils at 100 degrees Celsius at sea level. |
|
| 54 |
+
|
| 55 |
+
The narrowest gap between adjacent ranks here is 0.0057 logits — the top two both answer the question, so their order is a coin toss and a build that swapped them would not be wrong.
|
| 56 |
+
|
| 57 |
+
## It ranks across languages
|
| 58 |
+
|
| 59 |
+
The candidate list above includes a Japanese passage that answers the English query. This
|
| 60 |
+
model puts it **first**; ms-marco-MiniLM-L6, the English-only reranker on this shelf, scores
|
| 61 |
+
the same passage -10.96 and puts it fifth of six. That is what the 250k-token
|
| 62 |
+
vocabulary buys, and it is also why this file is 12 times larger.
|
| 63 |
+
|
| 64 |
+
## Not shipped
|
| 65 |
+
|
| 66 |
+
- **int8 (dynamic) is not shipped**: at 856.1 MB it is larger than the fp16 build's 556.4 MB, and its score error is 0.5776 logits. Dynamic int8 quantizes the linear weights and leaves the token embedding table in fp32; fp16 halves that table too.
|
| 67 |
+
|
| 68 |
+
## Verification
|
| 69 |
+
|
| 70 |
+
```bash
|
| 71 |
+
python convert/export_rerank.py bge_reranker_base
|
| 72 |
+
python convert/check_rerank.py bge_reranker_base fp32
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
The check has two halves. One is agreement with the model run in eager, in logits and in
|
| 76 |
+
ranking order. The other is that the ranking is useful at all: the passage that answers the
|
| 77 |
+
question has to outscore a passage about the same subject that does not — agreement alone
|
| 78 |
+
would pass a build that ranked by document length in both arms.
|
| 79 |
+
|
| 80 |
+
(conversion scripts: [executorch-models](https://github.com/john-rocky/executorch-models))
|