🚀 基於answerdotai/ModernBERT-base的交叉編碼器
本模型是基於answerdotai/ModernBERT-base
的交叉編碼器,在msmarco
數據集上使用sentence-transformers
庫進行微調。它可以計算文本對的得分,可用於文本重排序和語義搜索。
🚀 快速開始
直接使用(Sentence Transformers)
首先安裝Sentence Transformers庫:
pip install -U sentence-transformers
然後你可以加載這個模型並進行推理。
from sentence_transformers import CrossEncoder
model = CrossEncoder("tomaarsen/reranker-msmarco-ModernBERT-base-lambdaloss")
pairs = [
['How many calories in an egg', 'There are on average between 55 and 80 calories in an egg depending on its size.'],
['How many calories in an egg', 'Egg whites are very low in calories, have no fat, no cholesterol, and are loaded with protein.'],
['How many calories in an egg', 'Most of the calories in an egg come from the yellow yolk in the center.'],
]
scores = model.predict(pairs)
print(scores.shape)
ranks = model.rank(
'How many calories in an egg',
[
'There are on average between 55 and 80 calories in an egg depending on its size.',
'Egg whites are very low in calories, have no fat, no cholesterol, and are loaded with protein.',
'Most of the calories in an egg come from the yellow yolk in the center.',
]
)
✨ 主要特性
- 基於
answerdotai/ModernBERT-base
模型進行微調,具有良好的文本處理能力。
- 能夠計算文本對的得分,可用於文本重排序和語義搜索。
- 支持最大長度為8192個標記的輸入序列。
📦 安裝指南
安裝Sentence Transformers庫:
pip install -U sentence-transformers
💻 使用示例
基礎用法
from sentence_transformers import CrossEncoder
model = CrossEncoder("tomaarsen/reranker-msmarco-ModernBERT-base-lambdaloss")
pairs = [
['How many calories in an egg', 'There are on average between 55 and 80 calories in an egg depending on its size.'],
['How many calories in an egg', 'Egg whites are very low in calories, have no fat, no cholesterol, and are loaded with protein.'],
['How many calories in an egg', 'Most of the calories in an egg come from the yellow yolk in the center.'],
]
scores = model.predict(pairs)
print(scores.shape)
高級用法
from sentence_transformers import CrossEncoder
model = CrossEncoder("tomaarsen/reranker-msmarco-ModernBERT-base-lambdaloss")
ranks = model.rank(
'How many calories in an egg',
[
'There are on average between 55 and 80 calories in an egg depending on its size.',
'Egg whites are very low in calories, have no fat, no cholesterol, and are loaded with protein.',
'Most of the calories in an egg come from the yellow yolk in the center.',
]
)
📚 詳細文檔
模型詳情
模型描述
模型來源
評估
指標
交叉編碼器重排序
指標 |
NanoMSMARCO_R100 |
NanoNFCorpus_R100 |
NanoNQ_R100 |
map |
0.6768 (+0.1872) |
0.3576 (+0.0966) |
0.7134 (+0.2938) |
mrr@10 |
0.6690 (+0.1915) |
0.5819 (+0.0820) |
0.7402 (+0.3135) |
ndcg@10 |
0.7251 (+0.1847) |
0.4143 (+0.0892) |
0.7594 (+0.2587) |
交叉編碼器Nano BEIR
- 數據集:
NanoBEIR_R100_mean
- 使用
CrossEncoderNanoBEIREvaluator
進行評估,參數如下:{
"dataset_names": [
"msmarco",
"nfcorpus",
"nq"
],
"rerank_k": 100,
"at_k": 10,
"always_rerank_positives": true
}
指標 |
值 |
map |
0.5826 (+0.1925) |
mrr@10 |
0.6637 (+0.1957) |
ndcg@10 |
0.6329 (+0.1776) |
訓練詳情
訓練數據集
評估數據集
訓練超參數
- 非默認超參數:
eval_strategy
: steps
num_train_epochs
: 1
warmup_ratio
: 0.1
seed
: 12
bf16
: True
load_best_model_at_end
: True
框架版本
- Python: 3.11.10
- Sentence Transformers: 3.5.0.dev0
- Transformers: 4.49.0
- PyTorch: 2.5.1+cu124
- Accelerate: 1.2.0
- Datasets: 2.21.0
- Tokenizers: 0.21.0
🔧 技術細節
損失函數
使用LambdaLoss
損失函數,參數如下:
{
"weighting_scheme": "sentence_transformers.cross_encoder.losses.LambdaLoss.NDCGLoss2PPScheme",
"k": null,
"sigma": 1.0,
"eps": 1e-10,
"reduction_log": "binary",
"activation_fct": "torch.nn.modules.linear.Identity",
"mini_batch_size": 8
}
訓練日誌
點擊展開
輪次 |
步數 |
訓練損失 |
驗證損失 |
NanoMSMARCO_R100_ndcg@10 |
NanoNFCorpus_R100_ndcg@10 |
NanoNQ_R100_ndcg@10 |
NanoBEIR_R100_mean_ndcg@10 |
-1 |
-1 |
- |
- |
0.0234 (-0.5170) |
0.3412 (+0.0161) |
0.0321 (-0.4686) |
0.1322 (-0.3231) |
0.0000 |
1 |
0.8349 |
- |
- |
- |
- |
- |
0.0040 |
200 |
0.8417 |
- |
- |
- |
- |
- |
... |
... |
... |
... |
... |
... |
... |
... |
0.8014 |
40000 |
0.1381 |
0.1289 |
0.7251 (+0.1847) |
0.4143 (+0.0892) |
0.7594 (+0.2587) |
0.6329 (+0.1776) |
... |
... |
... |
... |
... |
... |
... |
... |
📄 許可證
本模型使用apache-2.0
許可證。
引用
BibTeX
Sentence Transformers
@inproceedings{reimers-2019-sentence-bert,
title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
author = "Reimers, Nils and Gurevych, Iryna",
booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
month = "11",
year = "2019",
publisher = "Association for Computational Linguistics",
url = "https://arxiv.org/abs/1908.10084",
}
LambdaLoss
@inproceedings{wang2018lambdaloss,
title={The lambdaloss framework for ranking metric optimization},
author={Wang, Xuanhui and Li, Cheng and Golbandi, Nadav and Bendersky, Michael and Najork, Marc},
booktitle={Proceedings of the 27th ACM international conference on information and knowledge management},
pages={1313--1322},
year={2018}
}