Sentence Similarity
sentence-transformers
baa-embedding-reranker
retrieval
embeddings
reranker
cross-encoder
rag
Instructions to use baa-ai/Merino-Pro-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use baa-ai/Merino-Pro-4bit with sentence-transformers:
from sentence_transformers import CrossEncoder model = CrossEncoder("baa-ai/Merino-Pro-4bit") 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) - Notebooks
- Google Colab
- Kaggle
Upload baa-ai-Embedding-Reranker-v1
Browse files- .gitattributes +2 -0
- LICENSE +24 -0
- LICENSE-xlm-roberta-large.txt +23 -0
- MODEL_CARD.md +42 -0
- NOTICE +5 -0
- README.md +85 -0
- config.json +20 -0
- embedder/config.json +33 -0
- embedder/config_sentence_transformers.json +14 -0
- embedder/modules.json +20 -0
- embedder/sentence_bert_config.json +10 -0
- embedder/tokenizer.json +3 -0
- embedder/tokenizer_config.json +23 -0
- modeling_baa.py +68 -0
- quant_config.json +303 -0
- requirements.txt +4 -0
- reranker/config.json +36 -0
- reranker/config_sentence_transformers.json +11 -0
- reranker/modules.json +8 -0
- reranker/sentence_bert_config.json +10 -0
- reranker/tokenizer.json +3 -0
- reranker/tokenizer_config.json +17 -0
- weights_q4.safetensors +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
embedder/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
reranker/tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
baa-ai-Embedding-Reranker-v1 — Proprietary License
|
| 2 |
+
Copyright (c) 2026 BAA AI (Black Sheep AI). All rights reserved.
|
| 3 |
+
|
| 4 |
+
1. SCOPE. This license governs the "BAA Contributions" in this package: the
|
| 5 |
+
shared word-embedding architecture and configuration, the router / loader
|
| 6 |
+
code (modeling_baa.py), the model packaging, BAA AI's weight contributions,
|
| 7 |
+
the model card, and associated documentation.
|
| 8 |
+
|
| 9 |
+
2. GRANT. No right to use, reproduce, modify, distribute, sublicense, or create
|
| 10 |
+
derivative works of the BAA Contributions is granted except under a separate
|
| 11 |
+
written agreement with BAA AI (Black Sheep AI).
|
| 12 |
+
|
| 13 |
+
3. THIRD-PARTY COMPONENT. This package incorporates the xlm-roberta-large
|
| 14 |
+
backbone, provided under the MIT License — see LICENSE-xlm-roberta-large.txt.
|
| 15 |
+
The MIT terms govern that backbone component only; nothing in this license
|
| 16 |
+
limits any rights you have under the MIT License with respect to it.
|
| 17 |
+
|
| 18 |
+
4. NO WARRANTY. THE PACKAGE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 19 |
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO MERCHANTABILITY, FITNESS FOR
|
| 20 |
+
A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL BAA AI BE LIABLE
|
| 21 |
+
FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY ARISING FROM OR IN CONNECTION WITH
|
| 22 |
+
THE PACKAGE OR ITS USE.
|
| 23 |
+
|
| 24 |
+
Contact: BAA AI (Black Sheep AI) — baa.ai
|
LICENSE-xlm-roberta-large.txt
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Backbone component: xlm-roberta-large — MIT License
|
| 2 |
+
|
| 3 |
+
MIT License
|
| 4 |
+
|
| 5 |
+
Copyright (c) Facebook, Inc. and its affiliates.
|
| 6 |
+
|
| 7 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 8 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 9 |
+
in the Software without restriction, including without limitation the rights
|
| 10 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 11 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 12 |
+
furnished to do so, subject to the following conditions:
|
| 13 |
+
|
| 14 |
+
The above copyright notice and this permission notice shall be included in all
|
| 15 |
+
copies or substantial portions of the Software.
|
| 16 |
+
|
| 17 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 18 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 19 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 20 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 21 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 22 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 23 |
+
SOFTWARE.
|
MODEL_CARD.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# baa-ai-Embedding-Reranker-v1
|
| 2 |
+
|
| 3 |
+
Unified **embedder + reranker** in one package, sharing a single XLM-RoBERTa-large word-embedding table.
|
| 4 |
+
By BAA AI (Black Sheep AI).
|
| 5 |
+
|
| 6 |
+
## What it is
|
| 7 |
+
A two-role retrieval model over a **shared input word-embedding matrix** (250002x1024 ~ 256M params, stored
|
| 8 |
+
once). Validated finding: the word-embedding table is fully shareable between a bi-encoder embedder and a
|
| 9 |
+
cross-encoder reranker (both built on `xlm-roberta-large`) at **zero quality loss**, while the transformer
|
| 10 |
+
*layers* are NOT mergeable. So we keep each role's native layers + head and dedupe only the embedding table.
|
| 11 |
+
|
| 12 |
+
- **Embed role:** bi-encoder. 1024-d, CLS-pool, L2-normalized. Use `"query: "` prefix on queries.
|
| 13 |
+
- **Rerank role:** cross-encoder. Single relevance logit per (query, doc) pair.
|
| 14 |
+
- **Router:** trivial — call `.embed(...)` or `.rerank(...)`.
|
| 15 |
+
|
| 16 |
+
## Footprint
|
| 17 |
+
~**0.77x** the two separate models (the 256M word-embedding table is stored once and tied at load), with
|
| 18 |
+
**no quality loss** and **no retraining**. Disk: the reranker's word-embedding copy is stripped and injected
|
| 19 |
+
from the embedder at load.
|
| 20 |
+
|
| 21 |
+
## Eval (450-query ML-PDF holdout)
|
| 22 |
+
| Role | hit@3 | note |
|
| 23 |
+
|---|---|---|
|
| 24 |
+
| Embed (dense retrieval) | 0.9511 | == standalone bi-encoder baseline |
|
| 25 |
+
| Rerank (full pipeline) | 0.9511 | == standalone cross-encoder baseline |
|
| 26 |
+
Both identical to the two-model baseline; sharing the word-embedding table is a no-op on quality.
|
| 27 |
+
|
| 28 |
+
## Usage
|
| 29 |
+
```python
|
| 30 |
+
from modeling_baa import BaaEmbeddingReranker
|
| 31 |
+
m = BaaEmbeddingReranker() # loads embedder + reranker (shared word-emb)
|
| 32 |
+
qv = m.embed(["my query"], is_query=True) # 1024-d normalized
|
| 33 |
+
dv = m.embed(["doc a", "doc b"]) # doc embeddings
|
| 34 |
+
ranked = m.rerank("my query", ["doc a","doc b"], top_k=10) # [(doc, score), ...]
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
## License
|
| 38 |
+
- **BAA Contributions** (shared-embedding architecture, router/loader code, packaging, weights, docs) are
|
| 39 |
+
**proprietary to BAA AI (Black Sheep AI)** — see `LICENSE`.
|
| 40 |
+
- Incorporates the `xlm-roberta-large` backbone under the **MIT License** — see `LICENSE-xlm-roberta-large.txt`.
|
| 41 |
+
|
| 42 |
+
Build: shared-embedding MoE (Experiment A, 2026-06-22).
|
NOTICE
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
baa-ai-Embedding-Reranker-v1
|
| 2 |
+
Copyright (c) 2026 BAA AI (Black Sheep AI). All rights reserved.
|
| 3 |
+
|
| 4 |
+
BAA Contributions: proprietary — see LICENSE.
|
| 5 |
+
Backbone: xlm-roberta-large — MIT License — see LICENSE-xlm-roberta-large.txt.
|
README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
license_name: baa-proprietary
|
| 4 |
+
library_name: baa-embedding-reranker
|
| 5 |
+
tags: [embeddings, reranker, retrieval, rag, cross-encoder, bi-encoder]
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
# baa-ai-Embedding-Reranker-v1-4bit
|
| 9 |
+
|
| 10 |
+
A **single package that does both embedding (retrieval) and reranking** for RAG / search pipelines,
|
| 11 |
+
by **BAA AI (Black Sheep AI)**. The bi-encoder embedder and cross-encoder reranker share one
|
| 12 |
+
XLM-RoBERTa-large word-embedding table (stored once). This is the **4-bit** build (group-64 int4 Linear weights; ~2x smaller download, same hit@3).
|
| 13 |
+
|
| 14 |
+
- **Embed (bi-encoder):** 1024-d, L2-normalized. Prefix queries with `"query: "`.
|
| 15 |
+
- **Rerank (cross-encoder):** relevance score per (query, document) pair.
|
| 16 |
+
- One class, two methods: `.embed(...)` and `.rerank(...)`.
|
| 17 |
+
|
| 18 |
+
## Install
|
| 19 |
+
```bash
|
| 20 |
+
pip install -r requirements.txt
|
| 21 |
+
```
|
| 22 |
+
The package is self-contained — the loader lives in `modeling_baa.py` and reconstructs the model from the
|
| 23 |
+
files in this folder. Works on CPU, Apple Silicon (MPS), and CUDA.
|
| 24 |
+
|
| 25 |
+
## Load into memory
|
| 26 |
+
```python
|
| 27 |
+
from modeling_baa import BaaEmbeddingReranker
|
| 28 |
+
|
| 29 |
+
# point at the downloaded folder (or "." if you cd into it). Auto-selects mps/cuda/cpu.
|
| 30 |
+
model = BaaEmbeddingReranker("path/to/baa-ai-Embedding-Reranker-v1-4bit")
|
| 31 |
+
# force a device if you want: BaaEmbeddingReranker("...", device="cpu")
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
## Embed — dense retrieval
|
| 35 |
+
```python
|
| 36 |
+
import numpy as np
|
| 37 |
+
|
| 38 |
+
docs = ["Paris is the capital of France.", "The mitochondria is the powerhouse of the cell."]
|
| 39 |
+
doc_vecs = model.embed(docs) # (2, 1024) float32, L2-normalized
|
| 40 |
+
q_vec = model.embed(["What is the capital of France?"], is_query=True)[0] # note is_query=True
|
| 41 |
+
|
| 42 |
+
scores = doc_vecs @ q_vec # cosine (vectors are normalized)
|
| 43 |
+
top = int(np.argmax(scores))
|
| 44 |
+
print("best doc:", docs[top], "score:", float(scores[top]))
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
## Rerank — order candidates for a query
|
| 48 |
+
```python
|
| 49 |
+
query = "What is the capital of France?"
|
| 50 |
+
candidates = ["Paris is the capital of France.",
|
| 51 |
+
"Berlin is the capital of Germany.",
|
| 52 |
+
"France is in western Europe."]
|
| 53 |
+
|
| 54 |
+
ranked = model.rerank(query, candidates, top_k=3) # [(doc, score), ...] best-first
|
| 55 |
+
for doc, score in ranked:
|
| 56 |
+
print(round(score, 2), doc)
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
## End-to-end RAG retrieval (embed -> shortlist -> rerank)
|
| 60 |
+
```python
|
| 61 |
+
import numpy as np
|
| 62 |
+
|
| 63 |
+
# 1) index your corpus once
|
| 64 |
+
corpus = ["...doc 1...", "...doc 2...", "...", "...doc N..."]
|
| 65 |
+
corpus_vecs = model.embed(corpus) # (N, 1024)
|
| 66 |
+
|
| 67 |
+
def search(query, k_dense=50, k_final=5):
|
| 68 |
+
qv = model.embed([query], is_query=True)[0]
|
| 69 |
+
# 2) dense shortlist
|
| 70 |
+
sims = corpus_vecs @ qv
|
| 71 |
+
shortlist = np.argsort(-sims)[:k_dense]
|
| 72 |
+
# 3) rerank the shortlist
|
| 73 |
+
cand = [corpus[i] for i in shortlist]
|
| 74 |
+
return model.rerank(query, cand, top_k=k_final)
|
| 75 |
+
|
| 76 |
+
print(search("your question here"))
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
## Performance
|
| 80 |
+
Validated on a 450-query holdout: hit@3 = **0.9511** (fp16) / **0.9556** (4-bit) — quantization is free here
|
| 81 |
+
because the cross-encoder absorbs it. This is the **4-bit** build (group-64 int4 Linear weights; ~2x smaller download, same hit@3).
|
| 82 |
+
|
| 83 |
+
## License
|
| 84 |
+
- **BAA Contributions** (architecture, loader, packaging, weights, docs): **proprietary** — see `LICENSE`.
|
| 85 |
+
- Backbone `xlm-roberta-large`: **MIT** — see `LICENSE-xlm-roberta-large.txt`.
|
config.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model_type": "baa-embedding-reranker",
|
| 3 |
+
"name": "baa-ai-Embedding-Reranker-v1-4bit",
|
| 4 |
+
"version": "1",
|
| 5 |
+
"license": "Proprietary \u2014 BAA AI (Black Sheep AI); xlm-roberta-large backbone under MIT",
|
| 6 |
+
"architecture": "shared-word-embedding MoE (one XLM-R-large word-embedding table shared across the embedder and reranker stacks)",
|
| 7 |
+
"roles": {
|
| 8 |
+
"embed": "1024-d bi-encoder, CLS-pool, normalized, 'query: ' prefix for queries",
|
| 9 |
+
"rerank": "cross-encoder, single relevance logit"
|
| 10 |
+
},
|
| 11 |
+
"backbone": "xlm-roberta-large (MIT)",
|
| 12 |
+
"eval": {
|
| 13 |
+
"holdout": "450-q ML-PDF",
|
| 14 |
+
"embed_hit@3": 0.9511,
|
| 15 |
+
"rerank_pipeline_hit@3": 0.9511,
|
| 16 |
+
"footprint_vs_two_models": "~0.77x (shared word-embeddings, ~256M params stored once)"
|
| 17 |
+
},
|
| 18 |
+
"loader": "modeling_baa.py :: BaaEmbeddingReranker",
|
| 19 |
+
"quantization": "group-64 int4 (RTN), fp16 compute"
|
| 20 |
+
}
|
embedder/config.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_cross_attention": false,
|
| 3 |
+
"architectures": [
|
| 4 |
+
"XLMRobertaModel"
|
| 5 |
+
],
|
| 6 |
+
"attention_probs_dropout_prob": 0.1,
|
| 7 |
+
"bos_token_id": 0,
|
| 8 |
+
"classifier_dropout": null,
|
| 9 |
+
"dtype": "float16",
|
| 10 |
+
"eos_token_id": 2,
|
| 11 |
+
"hidden_act": "gelu",
|
| 12 |
+
"hidden_dropout_prob": 0.1,
|
| 13 |
+
"hidden_size": 1024,
|
| 14 |
+
"initializer_range": 0.02,
|
| 15 |
+
"intermediate_size": 4096,
|
| 16 |
+
"is_decoder": false,
|
| 17 |
+
"layer_norm_eps": 1e-05,
|
| 18 |
+
"matryoshka_dimensions": [
|
| 19 |
+
256
|
| 20 |
+
],
|
| 21 |
+
"max_position_embeddings": 8194,
|
| 22 |
+
"model_type": "xlm-roberta",
|
| 23 |
+
"num_attention_heads": 16,
|
| 24 |
+
"num_hidden_layers": 24,
|
| 25 |
+
"output_past": true,
|
| 26 |
+
"pad_token_id": 1,
|
| 27 |
+
"position_embedding_type": "absolute",
|
| 28 |
+
"tie_word_embeddings": true,
|
| 29 |
+
"transformers_version": "5.12.1",
|
| 30 |
+
"type_vocab_size": 1,
|
| 31 |
+
"use_cache": true,
|
| 32 |
+
"vocab_size": 250002
|
| 33 |
+
}
|
embedder/config_sentence_transformers.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"__version__": {
|
| 3 |
+
"pytorch": "2.12.1",
|
| 4 |
+
"sentence_transformers": "5.6.0",
|
| 5 |
+
"transformers": "5.12.1"
|
| 6 |
+
},
|
| 7 |
+
"default_prompt_name": null,
|
| 8 |
+
"model_type": "SentenceTransformer",
|
| 9 |
+
"prompts": {
|
| 10 |
+
"document": "",
|
| 11 |
+
"query": "query: "
|
| 12 |
+
},
|
| 13 |
+
"similarity_fn_name": "cosine"
|
| 14 |
+
}
|
embedder/modules.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
{
|
| 15 |
+
"idx": 2,
|
| 16 |
+
"name": "2",
|
| 17 |
+
"path": "2_Normalize",
|
| 18 |
+
"type": "sentence_transformers.sentence_transformer.modules.normalize.Normalize"
|
| 19 |
+
}
|
| 20 |
+
]
|
embedder/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 |
+
}
|
embedder/tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:883b037111086fd4dfebbbc9b7cee11e1517b5e0c0514879478661440f137085
|
| 3 |
+
size 17082987
|
embedder/tokenizer_config.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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": false,
|
| 9 |
+
"local_files_only": false,
|
| 10 |
+
"mask_token": "<mask>",
|
| 11 |
+
"max_length": 512,
|
| 12 |
+
"model_max_length": 8192,
|
| 13 |
+
"pad_to_multiple_of": null,
|
| 14 |
+
"pad_token": "<pad>",
|
| 15 |
+
"pad_token_type_id": 0,
|
| 16 |
+
"padding_side": "right",
|
| 17 |
+
"sep_token": "</s>",
|
| 18 |
+
"stride": 0,
|
| 19 |
+
"tokenizer_class": "XLMRobertaTokenizer",
|
| 20 |
+
"truncation_side": "right",
|
| 21 |
+
"truncation_strategy": "longest_first",
|
| 22 |
+
"unk_token": "<unk>"
|
| 23 |
+
}
|
modeling_baa.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""baa-ai-Embedding-Reranker-v1 (4-bit) — standalone embedder+reranker.
|
| 2 |
+
Group-64 int4-packed Linear weights (fp16 for embeddings/LayerNorm/classifier/pooler), dequantized to fp16 at
|
| 3 |
+
load. Pure torch + transformers + safetensors; runs on CPU / Apple MPS / CUDA. API: BaaEmbeddingReranker."""
|
| 4 |
+
import os, json, numpy as np, torch, torch.nn.functional as F
|
| 5 |
+
from safetensors.torch import load_file
|
| 6 |
+
from transformers import AutoConfig, AutoModel, AutoModelForSequenceClassification, AutoTokenizer
|
| 7 |
+
GROUP = 64
|
| 8 |
+
|
| 9 |
+
def _dequant(st, fk):
|
| 10 |
+
p = st[fk + "::q"].numpy().astype(np.uint8)
|
| 11 |
+
L = int(st[fk + "::len"][0]); out_, in_ = int(st[fk + "::shape"][0]), int(st[fk + "::shape"][1])
|
| 12 |
+
q = np.empty(L, dtype=np.uint8); q[0::2] = p >> 4; q[1::2] = p & 0xF
|
| 13 |
+
s = st[fk + "::s"].float().numpy().reshape(-1, 1); m = st[fk + "::m"].float().numpy().reshape(-1, 1)
|
| 14 |
+
w = (q.reshape(-1, GROUP).astype(np.float32) * s + m).reshape(out_, in_)
|
| 15 |
+
return torch.from_numpy(w)
|
| 16 |
+
|
| 17 |
+
class BaaEmbeddingReranker:
|
| 18 |
+
def __init__(self, path=None, device=None):
|
| 19 |
+
path = path or os.path.dirname(os.path.abspath(__file__))
|
| 20 |
+
self.device = device or ("mps" if torch.backends.mps.is_available()
|
| 21 |
+
else "cuda" if torch.cuda.is_available() else "cpu")
|
| 22 |
+
qc = json.load(open(os.path.join(path, "quant_config.json")))
|
| 23 |
+
st = load_file(os.path.join(path, "weights_q4.safetensors"))
|
| 24 |
+
shared = st["shared::word_embeddings"]
|
| 25 |
+
self.emb = AutoModel.from_config(AutoConfig.from_pretrained(os.path.join(path, "embedder")))
|
| 26 |
+
self.rr = AutoModelForSequenceClassification.from_config(
|
| 27 |
+
AutoConfig.from_pretrained(os.path.join(path, "reranker")))
|
| 28 |
+
self._fill(self.emb, st, "emb", "embeddings.word_embeddings.weight", shared, set(qc["emb_q4"]))
|
| 29 |
+
self._fill(self.rr, st, "rr", "roberta.embeddings.word_embeddings.weight", shared, set(qc["rr_q4"]))
|
| 30 |
+
self.emb = self.emb.half().to(self.device).eval()
|
| 31 |
+
self.rr = self.rr.half().to(self.device).eval()
|
| 32 |
+
self.emb_tok = AutoTokenizer.from_pretrained(os.path.join(path, "embedder"))
|
| 33 |
+
self.rr_tok = AutoTokenizer.from_pretrained(os.path.join(path, "reranker"))
|
| 34 |
+
|
| 35 |
+
def _fill(self, model, st, ns, wemb_key, shared, q4):
|
| 36 |
+
sd = dict(model.state_dict())
|
| 37 |
+
for k in list(sd.keys()):
|
| 38 |
+
if k == wemb_key:
|
| 39 |
+
sd[k] = shared.to(sd[k].dtype); continue
|
| 40 |
+
fk = f"{ns}::{k}"
|
| 41 |
+
if k in q4:
|
| 42 |
+
sd[k] = _dequant(st, fk).to(sd[k].dtype)
|
| 43 |
+
elif fk in st:
|
| 44 |
+
sd[k] = st[fk].to(sd[k].dtype)
|
| 45 |
+
model.load_state_dict(sd)
|
| 46 |
+
|
| 47 |
+
@torch.no_grad()
|
| 48 |
+
def embed(self, texts, is_query=False, batch_size=32):
|
| 49 |
+
pref = "query: " if is_query else ""
|
| 50 |
+
out = []
|
| 51 |
+
for i in range(0, len(texts), batch_size):
|
| 52 |
+
enc = self.emb_tok([pref + t for t in texts[i:i+batch_size]], padding=True, truncation=True,
|
| 53 |
+
max_length=512, return_tensors="pt").to(self.device)
|
| 54 |
+
h = self.emb(**enc).last_hidden_state[:, 0] # CLS
|
| 55 |
+
out.append(F.normalize(h, dim=-1).float().cpu().numpy())
|
| 56 |
+
return np.vstack(out)
|
| 57 |
+
|
| 58 |
+
@torch.no_grad()
|
| 59 |
+
def rerank(self, query, docs, top_k=None, batch_size=32):
|
| 60 |
+
scores = []
|
| 61 |
+
for i in range(0, len(docs), batch_size):
|
| 62 |
+
enc = self.rr_tok([(query, d[:2000]) for d in docs[i:i+batch_size]], padding=True,
|
| 63 |
+
truncation=True, max_length=512, return_tensors="pt").to(self.device)
|
| 64 |
+
scores.extend(self.rr(**enc).logits[:, 0].float().cpu().tolist())
|
| 65 |
+
order = sorted(range(len(docs)), key=lambda j: -scores[j])
|
| 66 |
+
if top_k:
|
| 67 |
+
order = order[:top_k]
|
| 68 |
+
return [(docs[j], scores[j]) for j in order]
|
quant_config.json
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"quant": "q4",
|
| 3 |
+
"group": 64,
|
| 4 |
+
"scheme": "group-wise affine RTN (4-bit), fp16 compute",
|
| 5 |
+
"protected_fp16": [
|
| 6 |
+
"classifier",
|
| 7 |
+
"pooler",
|
| 8 |
+
"embeddings",
|
| 9 |
+
"LayerNorm"
|
| 10 |
+
],
|
| 11 |
+
"emb_q4": [
|
| 12 |
+
"encoder.layer.0.attention.output.dense.weight",
|
| 13 |
+
"encoder.layer.0.attention.self.key.weight",
|
| 14 |
+
"encoder.layer.0.attention.self.query.weight",
|
| 15 |
+
"encoder.layer.0.attention.self.value.weight",
|
| 16 |
+
"encoder.layer.0.intermediate.dense.weight",
|
| 17 |
+
"encoder.layer.0.output.dense.weight",
|
| 18 |
+
"encoder.layer.1.attention.output.dense.weight",
|
| 19 |
+
"encoder.layer.1.attention.self.key.weight",
|
| 20 |
+
"encoder.layer.1.attention.self.query.weight",
|
| 21 |
+
"encoder.layer.1.attention.self.value.weight",
|
| 22 |
+
"encoder.layer.1.intermediate.dense.weight",
|
| 23 |
+
"encoder.layer.1.output.dense.weight",
|
| 24 |
+
"encoder.layer.10.attention.output.dense.weight",
|
| 25 |
+
"encoder.layer.10.attention.self.key.weight",
|
| 26 |
+
"encoder.layer.10.attention.self.query.weight",
|
| 27 |
+
"encoder.layer.10.attention.self.value.weight",
|
| 28 |
+
"encoder.layer.10.intermediate.dense.weight",
|
| 29 |
+
"encoder.layer.10.output.dense.weight",
|
| 30 |
+
"encoder.layer.11.attention.output.dense.weight",
|
| 31 |
+
"encoder.layer.11.attention.self.key.weight",
|
| 32 |
+
"encoder.layer.11.attention.self.query.weight",
|
| 33 |
+
"encoder.layer.11.attention.self.value.weight",
|
| 34 |
+
"encoder.layer.11.intermediate.dense.weight",
|
| 35 |
+
"encoder.layer.11.output.dense.weight",
|
| 36 |
+
"encoder.layer.12.attention.output.dense.weight",
|
| 37 |
+
"encoder.layer.12.attention.self.key.weight",
|
| 38 |
+
"encoder.layer.12.attention.self.query.weight",
|
| 39 |
+
"encoder.layer.12.attention.self.value.weight",
|
| 40 |
+
"encoder.layer.12.intermediate.dense.weight",
|
| 41 |
+
"encoder.layer.12.output.dense.weight",
|
| 42 |
+
"encoder.layer.13.attention.output.dense.weight",
|
| 43 |
+
"encoder.layer.13.attention.self.key.weight",
|
| 44 |
+
"encoder.layer.13.attention.self.query.weight",
|
| 45 |
+
"encoder.layer.13.attention.self.value.weight",
|
| 46 |
+
"encoder.layer.13.intermediate.dense.weight",
|
| 47 |
+
"encoder.layer.13.output.dense.weight",
|
| 48 |
+
"encoder.layer.14.attention.output.dense.weight",
|
| 49 |
+
"encoder.layer.14.attention.self.key.weight",
|
| 50 |
+
"encoder.layer.14.attention.self.query.weight",
|
| 51 |
+
"encoder.layer.14.attention.self.value.weight",
|
| 52 |
+
"encoder.layer.14.intermediate.dense.weight",
|
| 53 |
+
"encoder.layer.14.output.dense.weight",
|
| 54 |
+
"encoder.layer.15.attention.output.dense.weight",
|
| 55 |
+
"encoder.layer.15.attention.self.key.weight",
|
| 56 |
+
"encoder.layer.15.attention.self.query.weight",
|
| 57 |
+
"encoder.layer.15.attention.self.value.weight",
|
| 58 |
+
"encoder.layer.15.intermediate.dense.weight",
|
| 59 |
+
"encoder.layer.15.output.dense.weight",
|
| 60 |
+
"encoder.layer.16.attention.output.dense.weight",
|
| 61 |
+
"encoder.layer.16.attention.self.key.weight",
|
| 62 |
+
"encoder.layer.16.attention.self.query.weight",
|
| 63 |
+
"encoder.layer.16.attention.self.value.weight",
|
| 64 |
+
"encoder.layer.16.intermediate.dense.weight",
|
| 65 |
+
"encoder.layer.16.output.dense.weight",
|
| 66 |
+
"encoder.layer.17.attention.output.dense.weight",
|
| 67 |
+
"encoder.layer.17.attention.self.key.weight",
|
| 68 |
+
"encoder.layer.17.attention.self.query.weight",
|
| 69 |
+
"encoder.layer.17.attention.self.value.weight",
|
| 70 |
+
"encoder.layer.17.intermediate.dense.weight",
|
| 71 |
+
"encoder.layer.17.output.dense.weight",
|
| 72 |
+
"encoder.layer.18.attention.output.dense.weight",
|
| 73 |
+
"encoder.layer.18.attention.self.key.weight",
|
| 74 |
+
"encoder.layer.18.attention.self.query.weight",
|
| 75 |
+
"encoder.layer.18.attention.self.value.weight",
|
| 76 |
+
"encoder.layer.18.intermediate.dense.weight",
|
| 77 |
+
"encoder.layer.18.output.dense.weight",
|
| 78 |
+
"encoder.layer.19.attention.output.dense.weight",
|
| 79 |
+
"encoder.layer.19.attention.self.key.weight",
|
| 80 |
+
"encoder.layer.19.attention.self.query.weight",
|
| 81 |
+
"encoder.layer.19.attention.self.value.weight",
|
| 82 |
+
"encoder.layer.19.intermediate.dense.weight",
|
| 83 |
+
"encoder.layer.19.output.dense.weight",
|
| 84 |
+
"encoder.layer.2.attention.output.dense.weight",
|
| 85 |
+
"encoder.layer.2.attention.self.key.weight",
|
| 86 |
+
"encoder.layer.2.attention.self.query.weight",
|
| 87 |
+
"encoder.layer.2.attention.self.value.weight",
|
| 88 |
+
"encoder.layer.2.intermediate.dense.weight",
|
| 89 |
+
"encoder.layer.2.output.dense.weight",
|
| 90 |
+
"encoder.layer.20.attention.output.dense.weight",
|
| 91 |
+
"encoder.layer.20.attention.self.key.weight",
|
| 92 |
+
"encoder.layer.20.attention.self.query.weight",
|
| 93 |
+
"encoder.layer.20.attention.self.value.weight",
|
| 94 |
+
"encoder.layer.20.intermediate.dense.weight",
|
| 95 |
+
"encoder.layer.20.output.dense.weight",
|
| 96 |
+
"encoder.layer.21.attention.output.dense.weight",
|
| 97 |
+
"encoder.layer.21.attention.self.key.weight",
|
| 98 |
+
"encoder.layer.21.attention.self.query.weight",
|
| 99 |
+
"encoder.layer.21.attention.self.value.weight",
|
| 100 |
+
"encoder.layer.21.intermediate.dense.weight",
|
| 101 |
+
"encoder.layer.21.output.dense.weight",
|
| 102 |
+
"encoder.layer.22.attention.output.dense.weight",
|
| 103 |
+
"encoder.layer.22.attention.self.key.weight",
|
| 104 |
+
"encoder.layer.22.attention.self.query.weight",
|
| 105 |
+
"encoder.layer.22.attention.self.value.weight",
|
| 106 |
+
"encoder.layer.22.intermediate.dense.weight",
|
| 107 |
+
"encoder.layer.22.output.dense.weight",
|
| 108 |
+
"encoder.layer.23.attention.output.dense.weight",
|
| 109 |
+
"encoder.layer.23.attention.self.key.weight",
|
| 110 |
+
"encoder.layer.23.attention.self.query.weight",
|
| 111 |
+
"encoder.layer.23.attention.self.value.weight",
|
| 112 |
+
"encoder.layer.23.intermediate.dense.weight",
|
| 113 |
+
"encoder.layer.23.output.dense.weight",
|
| 114 |
+
"encoder.layer.3.attention.output.dense.weight",
|
| 115 |
+
"encoder.layer.3.attention.self.key.weight",
|
| 116 |
+
"encoder.layer.3.attention.self.query.weight",
|
| 117 |
+
"encoder.layer.3.attention.self.value.weight",
|
| 118 |
+
"encoder.layer.3.intermediate.dense.weight",
|
| 119 |
+
"encoder.layer.3.output.dense.weight",
|
| 120 |
+
"encoder.layer.4.attention.output.dense.weight",
|
| 121 |
+
"encoder.layer.4.attention.self.key.weight",
|
| 122 |
+
"encoder.layer.4.attention.self.query.weight",
|
| 123 |
+
"encoder.layer.4.attention.self.value.weight",
|
| 124 |
+
"encoder.layer.4.intermediate.dense.weight",
|
| 125 |
+
"encoder.layer.4.output.dense.weight",
|
| 126 |
+
"encoder.layer.5.attention.output.dense.weight",
|
| 127 |
+
"encoder.layer.5.attention.self.key.weight",
|
| 128 |
+
"encoder.layer.5.attention.self.query.weight",
|
| 129 |
+
"encoder.layer.5.attention.self.value.weight",
|
| 130 |
+
"encoder.layer.5.intermediate.dense.weight",
|
| 131 |
+
"encoder.layer.5.output.dense.weight",
|
| 132 |
+
"encoder.layer.6.attention.output.dense.weight",
|
| 133 |
+
"encoder.layer.6.attention.self.key.weight",
|
| 134 |
+
"encoder.layer.6.attention.self.query.weight",
|
| 135 |
+
"encoder.layer.6.attention.self.value.weight",
|
| 136 |
+
"encoder.layer.6.intermediate.dense.weight",
|
| 137 |
+
"encoder.layer.6.output.dense.weight",
|
| 138 |
+
"encoder.layer.7.attention.output.dense.weight",
|
| 139 |
+
"encoder.layer.7.attention.self.key.weight",
|
| 140 |
+
"encoder.layer.7.attention.self.query.weight",
|
| 141 |
+
"encoder.layer.7.attention.self.value.weight",
|
| 142 |
+
"encoder.layer.7.intermediate.dense.weight",
|
| 143 |
+
"encoder.layer.7.output.dense.weight",
|
| 144 |
+
"encoder.layer.8.attention.output.dense.weight",
|
| 145 |
+
"encoder.layer.8.attention.self.key.weight",
|
| 146 |
+
"encoder.layer.8.attention.self.query.weight",
|
| 147 |
+
"encoder.layer.8.attention.self.value.weight",
|
| 148 |
+
"encoder.layer.8.intermediate.dense.weight",
|
| 149 |
+
"encoder.layer.8.output.dense.weight",
|
| 150 |
+
"encoder.layer.9.attention.output.dense.weight",
|
| 151 |
+
"encoder.layer.9.attention.self.key.weight",
|
| 152 |
+
"encoder.layer.9.attention.self.query.weight",
|
| 153 |
+
"encoder.layer.9.attention.self.value.weight",
|
| 154 |
+
"encoder.layer.9.intermediate.dense.weight",
|
| 155 |
+
"encoder.layer.9.output.dense.weight"
|
| 156 |
+
],
|
| 157 |
+
"rr_q4": [
|
| 158 |
+
"roberta.encoder.layer.0.attention.output.dense.weight",
|
| 159 |
+
"roberta.encoder.layer.0.attention.self.key.weight",
|
| 160 |
+
"roberta.encoder.layer.0.attention.self.query.weight",
|
| 161 |
+
"roberta.encoder.layer.0.attention.self.value.weight",
|
| 162 |
+
"roberta.encoder.layer.0.intermediate.dense.weight",
|
| 163 |
+
"roberta.encoder.layer.0.output.dense.weight",
|
| 164 |
+
"roberta.encoder.layer.1.attention.output.dense.weight",
|
| 165 |
+
"roberta.encoder.layer.1.attention.self.key.weight",
|
| 166 |
+
"roberta.encoder.layer.1.attention.self.query.weight",
|
| 167 |
+
"roberta.encoder.layer.1.attention.self.value.weight",
|
| 168 |
+
"roberta.encoder.layer.1.intermediate.dense.weight",
|
| 169 |
+
"roberta.encoder.layer.1.output.dense.weight",
|
| 170 |
+
"roberta.encoder.layer.10.attention.output.dense.weight",
|
| 171 |
+
"roberta.encoder.layer.10.attention.self.key.weight",
|
| 172 |
+
"roberta.encoder.layer.10.attention.self.query.weight",
|
| 173 |
+
"roberta.encoder.layer.10.attention.self.value.weight",
|
| 174 |
+
"roberta.encoder.layer.10.intermediate.dense.weight",
|
| 175 |
+
"roberta.encoder.layer.10.output.dense.weight",
|
| 176 |
+
"roberta.encoder.layer.11.attention.output.dense.weight",
|
| 177 |
+
"roberta.encoder.layer.11.attention.self.key.weight",
|
| 178 |
+
"roberta.encoder.layer.11.attention.self.query.weight",
|
| 179 |
+
"roberta.encoder.layer.11.attention.self.value.weight",
|
| 180 |
+
"roberta.encoder.layer.11.intermediate.dense.weight",
|
| 181 |
+
"roberta.encoder.layer.11.output.dense.weight",
|
| 182 |
+
"roberta.encoder.layer.12.attention.output.dense.weight",
|
| 183 |
+
"roberta.encoder.layer.12.attention.self.key.weight",
|
| 184 |
+
"roberta.encoder.layer.12.attention.self.query.weight",
|
| 185 |
+
"roberta.encoder.layer.12.attention.self.value.weight",
|
| 186 |
+
"roberta.encoder.layer.12.intermediate.dense.weight",
|
| 187 |
+
"roberta.encoder.layer.12.output.dense.weight",
|
| 188 |
+
"roberta.encoder.layer.13.attention.output.dense.weight",
|
| 189 |
+
"roberta.encoder.layer.13.attention.self.key.weight",
|
| 190 |
+
"roberta.encoder.layer.13.attention.self.query.weight",
|
| 191 |
+
"roberta.encoder.layer.13.attention.self.value.weight",
|
| 192 |
+
"roberta.encoder.layer.13.intermediate.dense.weight",
|
| 193 |
+
"roberta.encoder.layer.13.output.dense.weight",
|
| 194 |
+
"roberta.encoder.layer.14.attention.output.dense.weight",
|
| 195 |
+
"roberta.encoder.layer.14.attention.self.key.weight",
|
| 196 |
+
"roberta.encoder.layer.14.attention.self.query.weight",
|
| 197 |
+
"roberta.encoder.layer.14.attention.self.value.weight",
|
| 198 |
+
"roberta.encoder.layer.14.intermediate.dense.weight",
|
| 199 |
+
"roberta.encoder.layer.14.output.dense.weight",
|
| 200 |
+
"roberta.encoder.layer.15.attention.output.dense.weight",
|
| 201 |
+
"roberta.encoder.layer.15.attention.self.key.weight",
|
| 202 |
+
"roberta.encoder.layer.15.attention.self.query.weight",
|
| 203 |
+
"roberta.encoder.layer.15.attention.self.value.weight",
|
| 204 |
+
"roberta.encoder.layer.15.intermediate.dense.weight",
|
| 205 |
+
"roberta.encoder.layer.15.output.dense.weight",
|
| 206 |
+
"roberta.encoder.layer.16.attention.output.dense.weight",
|
| 207 |
+
"roberta.encoder.layer.16.attention.self.key.weight",
|
| 208 |
+
"roberta.encoder.layer.16.attention.self.query.weight",
|
| 209 |
+
"roberta.encoder.layer.16.attention.self.value.weight",
|
| 210 |
+
"roberta.encoder.layer.16.intermediate.dense.weight",
|
| 211 |
+
"roberta.encoder.layer.16.output.dense.weight",
|
| 212 |
+
"roberta.encoder.layer.17.attention.output.dense.weight",
|
| 213 |
+
"roberta.encoder.layer.17.attention.self.key.weight",
|
| 214 |
+
"roberta.encoder.layer.17.attention.self.query.weight",
|
| 215 |
+
"roberta.encoder.layer.17.attention.self.value.weight",
|
| 216 |
+
"roberta.encoder.layer.17.intermediate.dense.weight",
|
| 217 |
+
"roberta.encoder.layer.17.output.dense.weight",
|
| 218 |
+
"roberta.encoder.layer.18.attention.output.dense.weight",
|
| 219 |
+
"roberta.encoder.layer.18.attention.self.key.weight",
|
| 220 |
+
"roberta.encoder.layer.18.attention.self.query.weight",
|
| 221 |
+
"roberta.encoder.layer.18.attention.self.value.weight",
|
| 222 |
+
"roberta.encoder.layer.18.intermediate.dense.weight",
|
| 223 |
+
"roberta.encoder.layer.18.output.dense.weight",
|
| 224 |
+
"roberta.encoder.layer.19.attention.output.dense.weight",
|
| 225 |
+
"roberta.encoder.layer.19.attention.self.key.weight",
|
| 226 |
+
"roberta.encoder.layer.19.attention.self.query.weight",
|
| 227 |
+
"roberta.encoder.layer.19.attention.self.value.weight",
|
| 228 |
+
"roberta.encoder.layer.19.intermediate.dense.weight",
|
| 229 |
+
"roberta.encoder.layer.19.output.dense.weight",
|
| 230 |
+
"roberta.encoder.layer.2.attention.output.dense.weight",
|
| 231 |
+
"roberta.encoder.layer.2.attention.self.key.weight",
|
| 232 |
+
"roberta.encoder.layer.2.attention.self.query.weight",
|
| 233 |
+
"roberta.encoder.layer.2.attention.self.value.weight",
|
| 234 |
+
"roberta.encoder.layer.2.intermediate.dense.weight",
|
| 235 |
+
"roberta.encoder.layer.2.output.dense.weight",
|
| 236 |
+
"roberta.encoder.layer.20.attention.output.dense.weight",
|
| 237 |
+
"roberta.encoder.layer.20.attention.self.key.weight",
|
| 238 |
+
"roberta.encoder.layer.20.attention.self.query.weight",
|
| 239 |
+
"roberta.encoder.layer.20.attention.self.value.weight",
|
| 240 |
+
"roberta.encoder.layer.20.intermediate.dense.weight",
|
| 241 |
+
"roberta.encoder.layer.20.output.dense.weight",
|
| 242 |
+
"roberta.encoder.layer.21.attention.output.dense.weight",
|
| 243 |
+
"roberta.encoder.layer.21.attention.self.key.weight",
|
| 244 |
+
"roberta.encoder.layer.21.attention.self.query.weight",
|
| 245 |
+
"roberta.encoder.layer.21.attention.self.value.weight",
|
| 246 |
+
"roberta.encoder.layer.21.intermediate.dense.weight",
|
| 247 |
+
"roberta.encoder.layer.21.output.dense.weight",
|
| 248 |
+
"roberta.encoder.layer.22.attention.output.dense.weight",
|
| 249 |
+
"roberta.encoder.layer.22.attention.self.key.weight",
|
| 250 |
+
"roberta.encoder.layer.22.attention.self.query.weight",
|
| 251 |
+
"roberta.encoder.layer.22.attention.self.value.weight",
|
| 252 |
+
"roberta.encoder.layer.22.intermediate.dense.weight",
|
| 253 |
+
"roberta.encoder.layer.22.output.dense.weight",
|
| 254 |
+
"roberta.encoder.layer.23.attention.output.dense.weight",
|
| 255 |
+
"roberta.encoder.layer.23.attention.self.key.weight",
|
| 256 |
+
"roberta.encoder.layer.23.attention.self.query.weight",
|
| 257 |
+
"roberta.encoder.layer.23.attention.self.value.weight",
|
| 258 |
+
"roberta.encoder.layer.23.intermediate.dense.weight",
|
| 259 |
+
"roberta.encoder.layer.23.output.dense.weight",
|
| 260 |
+
"roberta.encoder.layer.3.attention.output.dense.weight",
|
| 261 |
+
"roberta.encoder.layer.3.attention.self.key.weight",
|
| 262 |
+
"roberta.encoder.layer.3.attention.self.query.weight",
|
| 263 |
+
"roberta.encoder.layer.3.attention.self.value.weight",
|
| 264 |
+
"roberta.encoder.layer.3.intermediate.dense.weight",
|
| 265 |
+
"roberta.encoder.layer.3.output.dense.weight",
|
| 266 |
+
"roberta.encoder.layer.4.attention.output.dense.weight",
|
| 267 |
+
"roberta.encoder.layer.4.attention.self.key.weight",
|
| 268 |
+
"roberta.encoder.layer.4.attention.self.query.weight",
|
| 269 |
+
"roberta.encoder.layer.4.attention.self.value.weight",
|
| 270 |
+
"roberta.encoder.layer.4.intermediate.dense.weight",
|
| 271 |
+
"roberta.encoder.layer.4.output.dense.weight",
|
| 272 |
+
"roberta.encoder.layer.5.attention.output.dense.weight",
|
| 273 |
+
"roberta.encoder.layer.5.attention.self.key.weight",
|
| 274 |
+
"roberta.encoder.layer.5.attention.self.query.weight",
|
| 275 |
+
"roberta.encoder.layer.5.attention.self.value.weight",
|
| 276 |
+
"roberta.encoder.layer.5.intermediate.dense.weight",
|
| 277 |
+
"roberta.encoder.layer.5.output.dense.weight",
|
| 278 |
+
"roberta.encoder.layer.6.attention.output.dense.weight",
|
| 279 |
+
"roberta.encoder.layer.6.attention.self.key.weight",
|
| 280 |
+
"roberta.encoder.layer.6.attention.self.query.weight",
|
| 281 |
+
"roberta.encoder.layer.6.attention.self.value.weight",
|
| 282 |
+
"roberta.encoder.layer.6.intermediate.dense.weight",
|
| 283 |
+
"roberta.encoder.layer.6.output.dense.weight",
|
| 284 |
+
"roberta.encoder.layer.7.attention.output.dense.weight",
|
| 285 |
+
"roberta.encoder.layer.7.attention.self.key.weight",
|
| 286 |
+
"roberta.encoder.layer.7.attention.self.query.weight",
|
| 287 |
+
"roberta.encoder.layer.7.attention.self.value.weight",
|
| 288 |
+
"roberta.encoder.layer.7.intermediate.dense.weight",
|
| 289 |
+
"roberta.encoder.layer.7.output.dense.weight",
|
| 290 |
+
"roberta.encoder.layer.8.attention.output.dense.weight",
|
| 291 |
+
"roberta.encoder.layer.8.attention.self.key.weight",
|
| 292 |
+
"roberta.encoder.layer.8.attention.self.query.weight",
|
| 293 |
+
"roberta.encoder.layer.8.attention.self.value.weight",
|
| 294 |
+
"roberta.encoder.layer.8.intermediate.dense.weight",
|
| 295 |
+
"roberta.encoder.layer.8.output.dense.weight",
|
| 296 |
+
"roberta.encoder.layer.9.attention.output.dense.weight",
|
| 297 |
+
"roberta.encoder.layer.9.attention.self.key.weight",
|
| 298 |
+
"roberta.encoder.layer.9.attention.self.query.weight",
|
| 299 |
+
"roberta.encoder.layer.9.attention.self.value.weight",
|
| 300 |
+
"roberta.encoder.layer.9.intermediate.dense.weight",
|
| 301 |
+
"roberta.encoder.layer.9.output.dense.weight"
|
| 302 |
+
]
|
| 303 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch>=2.2
|
| 2 |
+
transformers>=4.40
|
| 3 |
+
safetensors>=0.4
|
| 4 |
+
numpy>=1.24
|
reranker/config.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_cross_attention": false,
|
| 3 |
+
"architectures": [
|
| 4 |
+
"XLMRobertaForSequenceClassification"
|
| 5 |
+
],
|
| 6 |
+
"attention_probs_dropout_prob": 0.1,
|
| 7 |
+
"bos_token_id": 0,
|
| 8 |
+
"classifier_dropout": null,
|
| 9 |
+
"dtype": "float16",
|
| 10 |
+
"eos_token_id": 2,
|
| 11 |
+
"hidden_act": "gelu",
|
| 12 |
+
"hidden_dropout_prob": 0.1,
|
| 13 |
+
"hidden_size": 1024,
|
| 14 |
+
"id2label": {
|
| 15 |
+
"0": "LABEL_0"
|
| 16 |
+
},
|
| 17 |
+
"initializer_range": 0.02,
|
| 18 |
+
"intermediate_size": 4096,
|
| 19 |
+
"is_decoder": false,
|
| 20 |
+
"label2id": {
|
| 21 |
+
"LABEL_0": 0
|
| 22 |
+
},
|
| 23 |
+
"layer_norm_eps": 1e-05,
|
| 24 |
+
"max_position_embeddings": 514,
|
| 25 |
+
"model_type": "xlm-roberta",
|
| 26 |
+
"num_attention_heads": 16,
|
| 27 |
+
"num_hidden_layers": 24,
|
| 28 |
+
"output_past": true,
|
| 29 |
+
"pad_token_id": 1,
|
| 30 |
+
"position_embedding_type": "absolute",
|
| 31 |
+
"tie_word_embeddings": true,
|
| 32 |
+
"transformers_version": "5.12.1",
|
| 33 |
+
"type_vocab_size": 1,
|
| 34 |
+
"use_cache": true,
|
| 35 |
+
"vocab_size": 250002
|
| 36 |
+
}
|
reranker/config_sentence_transformers.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"__version__": {
|
| 3 |
+
"pytorch": "2.12.1",
|
| 4 |
+
"sentence_transformers": "5.6.0",
|
| 5 |
+
"transformers": "5.12.1"
|
| 6 |
+
},
|
| 7 |
+
"activation_fn": "torch.nn.modules.activation.Sigmoid",
|
| 8 |
+
"default_prompt_name": null,
|
| 9 |
+
"model_type": "CrossEncoder",
|
| 10 |
+
"prompts": {}
|
| 11 |
+
}
|
reranker/modules.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"idx": 0,
|
| 4 |
+
"name": "0",
|
| 5 |
+
"path": "",
|
| 6 |
+
"type": "sentence_transformers.base.modules.transformer.Transformer"
|
| 7 |
+
}
|
| 8 |
+
]
|
reranker/sentence_bert_config.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"transformer_task": "sequence-classification",
|
| 3 |
+
"modality_config": {
|
| 4 |
+
"text": {
|
| 5 |
+
"method": "forward",
|
| 6 |
+
"method_output_name": "logits"
|
| 7 |
+
}
|
| 8 |
+
},
|
| 9 |
+
"module_output_name": "scores"
|
| 10 |
+
}
|
reranker/tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:85e62d2d9c5fb57ba5cc374e1d0c0016945909d79bd60ad381d08dea3ca80d0e
|
| 3 |
+
size 17098084
|
reranker/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": false,
|
| 9 |
+
"local_files_only": false,
|
| 10 |
+
"mask_token": "<mask>",
|
| 11 |
+
"model_max_length": 512,
|
| 12 |
+
"pad_token": "<pad>",
|
| 13 |
+
"sep_token": "</s>",
|
| 14 |
+
"sp_model_kwargs": {},
|
| 15 |
+
"tokenizer_class": "XLMRobertaTokenizer",
|
| 16 |
+
"unk_token": "<unk>"
|
| 17 |
+
}
|
weights_q4.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7cef184a83e9189c2215d308bacf20b20c433a8defe76d66af507f2fcb199612
|
| 3 |
+
size 875305986
|