Downloads · 30 days
76
24% of all-time downloads
xtr-replicability/modernbert_colbert_kd
modernbert_colbert_kd is a sentence similarity model from xtr-replicability. Use it when you need a score for how close two texts are. It is set up for PyLate.
This is a PyLate model trained on the train dataset. It maps sentences & paragraphs to sequences of 128-dimensional dense vectors and can be used for semantic textual similarity using the MaxSim operator.
Downloads · 30 days
76
24% of all-time downloads
All-time downloads
315
Public
Parameters
149M
596 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors596 MB · 99%
From the Hugging Face model README
This is a PyLate model trained on the train dataset. It maps sentences & paragraphs to sequences of 128-dimensional dense vectors and can be used for semantic textual similarity using the MaxSim operator.
ColBERT(
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False, 'architecture': 'ModernBertModel'})
(1): Dense({'in_features': 768, 'out_features': 128, 'bias': False, 'activation_function': 'torch.nn.modules.linear.Identity', 'use_residual': False})
)
First install the PyLate library:
pip install -U pylate
Use this model with PyLate to index and retrieve documents. The index uses FastPLAID for efficient similarity search.
Load the ColBERT model and initialize the PLAID index, then encode and index your documents:
from pylate import indexes, models, retrieve
# Step 1: Load the ColBERT model
model = models.ColBERT(
model_name_or_path="pylate_model_id",
)
# Step 2: Initialize the PLAID index
index = indexes.PLAID(
index_folder="pylate-index",
index_name="index",
override=True, # This overwrites the existing index if any
)
# Step 3: Encode the documents
documents_ids = ["1", "2", "3"]
documents = ["document 1 text", "document 2 text", "document 3 text"]
documents_embeddings = model.encode(
documents,
batch_size=32,
is_query=False, # Ensure that it is set to False to indicate that these are documents, not queries
show_progress_bar=True,
)
# Step 4: Add document embeddings to the index by providing embeddings and corresponding ids
index.add_documents(
documents_ids=documents_ids,
documents_embeddings=documents_embeddings,
)
Note that you do not have to recreate the index and encode the documents every time. Once you have created an index and added the documents, you can re-use the index later by loading it:
# To load an index, simply instantiate it with the correct folder/name and without overriding it
index = indexes.PLAID(
index_folder="pylate-index",
index_name="index",
)
Once the documents are indexed, you can retrieve the top-k most relevant documents for a given set of queries. To do so, initialize the ColBERT retriever with the index you want to search in, encode the queries and then retrieve the top-k documents to get the top matches ids and relevance scores:
# Step 1: Initialize the ColBERT retriever
retriever = retrieve.ColBERT(index=index)
# Step 2: Encode the queries
queries_embeddings = model.encode(
["query for document 3", "query for document 1"],
batch_size=32,
is_query=True, # # Ensure that it is set to False to indicate that these are queries
show_progress_bar=True,
)
# Step 3: Retrieve top-k documents
scores = retriever.retrieve(
queries_embeddings=queries_embeddings,
k=10, # Retrieve the top 10 matches for each query
)
If you only want to use the ColBERT model to perform reranking on top of your first-stage retrieval pipeline without building an index, you can simply use rank function and pass the queries and documents to rerank:
from pylate import rank, models
queries = [
"query A",
"query B",
]
documents = [
["document A", "document B"],
["document 1", "document C", "document B"],
]
documents_ids = [
[1, 2],
[1, 3, 2],
]
model = models.ColBERT(
model_name_or_path="pylate_model_id",
)
queries_embeddings = model.encode(
queries,
is_query=True,
)
documents_embeddings = model.encode(
documents,
is_query=False,
)
reranked_documents = rank.rerank(
documents_ids=documents_ids,
queries_embeddings=queries_embeddings,
documents_embeddings=documents_embeddings,
)
<!--
### Direct Usage (Transformers)
<details><summary>Click to see the direct usage in Transformers</summary>
</details>
-->
<!--
### Downstream Usage (Sentence Transformers)
You can finetune this model on your own dataset.
<details><summary>Click to expand</summary>
</details>
-->
<!--
### Out-of-Scope Use
*List how the model may foreseeably be misused and address what users ought not to do with the model.*
-->
['NanoClimateFEVER', 'NanoDBPedia', 'NanoFEVER', 'NanoFiQA2018', 'NanoHotpotQA', 'NanoMSMARCO', 'NanoNFCorpus', 'NanoNQ', 'NanoQuoraRetrieval', 'NanoSCIDOCS', 'NanoArguAna', 'NanoSciFact', 'NanoTouche2020']| Metric | NanoClimateFEVER | NanoDBPedia | NanoFEVER | NanoFiQA2018 | NanoHotpotQA | NanoMSMARCO | NanoNFCorpus | NanoNQ | NanoQuoraRetrieval | NanoSCIDOCS | NanoArguAna | NanoSciFact | NanoTouche2020 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| MaxSim_accuracy@1 | 0.24 | 0.76 | 0.9 | 0.58 | 0.92 | 0.52 | 0.48 | 0.52 | 0.9 | 0.48 | 0.26 | 0.74 | 0.7755 |
| MaxSim_accuracy@3 | 0.42 | 0.92 | 0.96 | 0.68 | 1.0 | 0.72 | 0.62 | 0.84 | 0.96 | 0.68 | 0.56 | 0.82 | 0.9592 |
| MaxSim_accuracy@5 | 0.56 | 0.92 | 1.0 | 0.72 | 1.0 | 0.78 | 0.68 | 0.86 | 0.98 | 0.7 | 0.66 | 0.88 | 0.9796 |
| MaxSim_accuracy@10 | 0.76 | 0.94 | 1.0 | 0.78 | 1.0 | 0.92 | 0.74 | 0.88 | 1.0 | 0.84 | 0.8 | 0.88 | 1.0 |
| MaxSim_precision@1 | 0.24 | 0.76 | 0.9 | 0.58 | 0.92 | 0.52 | 0.48 | 0.52 | 0.9 | 0.48 | 0.26 | 0.74 | 0.7755 |
| MaxSim_precision@3 | 0.1467 | 0.72 | 0.34 | 0.32 | 0.5533 | 0.24 | 0.4267 | 0.2867 | 0.3867 | 0.3267 | 0.1867 | 0.2933 | 0.7211 |
| MaxSim_precision@5 | 0.132 | 0.64 | 0.216 | 0.244 | 0.352 | 0.156 | 0.372 | 0.18 | 0.252 | 0.256 | 0.132 | 0.196 | 0.6327 |
| MaxSim_precision@10 | 0.1 | 0.536 | 0.11 | 0.138 | 0.182 | 0.092 | 0.288 | 0.094 | 0.138 | 0.186 | 0.08 | 0.098 | 0.5306 |
| MaxSim_recall@1 | 0.115 | 0.1033 | 0.8367 | 0.3661 | 0.46 | 0.52 | 0.0445 | 0.49 | 0.7873 | 0.1017 | 0.26 | 0.715 | 0.0525 |
| MaxSim_recall@3 | 0.205 | 0.2069 | 0.9233 | 0.4851 | 0.83 | 0.72 | 0.0833 | 0.79 | 0.9147 | 0.2027 | 0.56 | 0.805 | 0.146 |
| MaxSim_recall@5 | 0.2733 | 0.2663 | 0.97 | 0.5518 | 0.88 | 0.78 | 0.1239 | 0.82 | 0.956 | 0.2627 | 0.66 | 0.87 | 0.2086 |
| MaxSim_recall@10 | 0.3907 | 0.3798 | 0.98 | 0.6032 | 0.91 | 0.92 | 0.1562 | 0.84 | 0.9967 | 0.3797 | 0.8 | 0.87 | 0.3417 |
| MaxSim_ndcg@10 | 0.2951 | 0.6745 | 0.9295 | 0.5639 | 0.8736 | 0.7115 | 0.3662 | 0.7064 | 0.9423 | 0.3745 | 0.5177 | 0.8104 | 0.6057 |
| MaxSim_mrr@10 | 0.3688 | 0.842 | 0.9367 | 0.6376 | 0.9533 | 0.6469 | 0.5659 | 0.6779 | 0.9383 | 0.6007 | 0.4285 | 0.7907 | 0.8646 |
| MaxSim_map@100 | 0.2245 | 0.5354 | 0.9026 | 0.5137 | 0.8197 | 0.6513 | 0.1629 | 0.657 | 0.9162 | 0.2818 | 0.435 | 0.7927 | 0.4446 |
NanoBEIR_mean| Metric | Value |
|---|---|
| MaxSim_accuracy@1 | 0.6212 |
| MaxSim_accuracy@3 | 0.7799 |
| MaxSim_accuracy@5 | 0.8246 |
| MaxSim_accuracy@10 | 0.8877 |
| MaxSim_precision@1 | 0.6212 |
| MaxSim_precision@3 | 0.3806 |
| MaxSim_precision@5 | 0.2893 |
| MaxSim_precision@10 | 0.1979 |
| MaxSim_recall@1 | 0.3732 |
| MaxSim_recall@3 | 0.5286 |
| MaxSim_recall@5 | 0.5864 |
| MaxSim_recall@10 | 0.6591 |
| MaxSim_ndcg@10 | 0.6439 |
| MaxSim_mrr@10 | 0.7117 |
| MaxSim_map@100 | 0.5644 |
| query_id | document_ids | scores | |
|---|---|---|---|
| type | int | list | list |
The model card is truncated. Read the rest on Hugging Face.