Modernbert Base ColBERT
這是一個從answerdotai/ModernBERT-base在MS-MARCO數據集上微調的PyLate模型,用於句子相似度計算和文檔檢索。
下載量 88
發布時間 : 1/3/2025
模型概述
該模型將句子和段落映射為128維密集向量序列,使用MaxSim算子進行語義文本相似度計算,適用於信息檢索和重排序任務。
模型特點
高效檢索
利用Voyager HNSW索引實現快速文檔檢索
多向量表示
生成128維密集向量序列而非單一向量,保留更多語義信息
蒸餾訓練
使用蒸餾損失函數進行訓練,提升模型性能
模型能力
語義相似度計算
文檔檢索
查詢重排序
特徵提取
使用案例
信息檢索
文檔搜索
在文檔集合中檢索與查詢最相關的文檔
在MS-MARCO等標準檢索數據集上表現良好
搜索結果重排序
對初步檢索結果進行精細化排序
可提升檢索系統的準確率和相關性
🚀 基於answerdotai/ModernBERT-base的PyLate模型
本模型基於answerdotai/ModernBERT-base,在訓練數據集上進行微調。它能將句子和段落映射為128維的密集向量序列,可通過MaxSim算子用於語義文本相似度計算。
🚀 快速開始
本模型是基於answerdotai/ModernBERT-base
微調的PyLate
模型,可用於語義文本相似度任務。以下是使用該模型的基本步驟:
- 安裝
PyLate
庫。 - 加載模型並進行文檔索引和檢索。
- 可根據需求進行重排序操作。
✨ 主要特性
- 高效映射:能夠將句子和段落映射為128維的密集向量,便於進行語義文本相似度計算。
- 多場景應用:支持文檔索引、檢索和重排序等多種應用場景。
- 集成Voyager索引:在檢索過程中,利用Voyager HNSW索引高效處理文檔嵌入,實現快速檢索。
📦 安裝指南
首先,安裝PyLate
庫:
pip install -U pylate
💻 使用示例
基礎用法
文檔索引
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 Voyager index
index = indexes.Voyager(
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,
)
注意,無需每次都重新創建索引和編碼文檔。創建索引並添加文檔後,可通過以下方式加載並重復使用索引:
# To load an index, simply instantiate it with the correct folder/name and without overriding it
index = indexes.Voyager(
index_folder="pylate-index",
index_name="index",
)
檢索前k個相關文檔
# 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
)
高級用法
重排序
如果僅想使用ColBERT
模型在一級檢索管道的基礎上進行重排序,而不構建索引,可以使用rank
函數:
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,
)
📚 詳細文檔
模型詳情
模型描述
屬性 | 詳情 |
---|---|
模型類型 | PyLate模型 |
基礎模型 | answerdotai/ModernBERT-base |
文檔長度 | 180個詞元 |
查詢長度 | 32個詞元 |
輸出維度 | 128個詞元 |
相似度函數 | MaxSim |
訓練數據集 | train |
語言 | 英語 |
模型來源
- 文檔:PyLate文檔
- 倉庫:GitHub上的PyLate
- Hugging Face:Hugging Face上的PyLate模型
完整模型架構
ColBERT(
(0): Transformer({'max_seq_length': 179, 'do_lower_case': False}) with Transformer model: ModernBertModel
(1): Dense({'in_features': 768, 'out_features': 128, 'bias': False, 'activation_function': 'torch.nn.modules.linear.Identity'})
)
訓練詳情
訓練數據集
訓練集
- 數據集:train,版本為11e6ffa
- 大小:808,728個訓練樣本
- 列:
query_id
、document_ids
和scores
- 基於前1000個樣本的近似統計信息:
query_id document_ids scores 類型 字符串 列表 列表 詳情 - 最小:5個詞元
- 平均:5.59個詞元
- 最大:6個詞元
- 大小:32個元素
- 大小:32個元素
- 樣本:
query_id document_ids scores 121352
['2259784', '4923159', '40211', '1545154', '8527175', ...]
[0.2343463897705078, 0.639204204082489, 0.3806908428668976, 0.5623092651367188, 0.8051995635032654, ...]
634306
['7723525', '1874779', '379307', '2738583', '7599583', ...]
[0.7124203443527222, 0.7379189729690552, 0.5786551237106323, 0.6142299175262451, 0.6755089163780212, ...]
920825
['5976297', '2866112', '3560294', '3285659', '4706740', ...]
[0.6462352871894836, 0.7880821228027344, 0.791019856929779, 0.7709633111953735, 0.8284491300582886, ...]
- 損失函數:
pylate.losses.distillation.Distillation
評估結果
多向量檢索模型的nDCG@10分數:
模型 | SciFact | NFCorpus | FiQA | TREC-Covid |
---|---|---|---|---|
BERT | 71.5 | 34.2 | 35.0 | 69.9 |
ModernBERT-Base (論文中) | 73.0 | 35.2 | 38.0 | 80.5 |
ModernBERT-Base (本倉庫) | 73.88 | 34.96 | 39.47 | 79.36 |
訓練超參數
非默認超參數
per_device_train_batch_size
:16learning_rate
:8e-05num_train_epochs
:1warmup_ratio
:0.05bf16
:True
所有超參數
點擊展開
overwrite_output_dir
:Falsedo_predict
:Falseeval_strategy
:noprediction_loss_only
:Trueper_device_train_batch_size
:16per_device_eval_batch_size
:8per_gpu_train_batch_size
:Noneper_gpu_eval_batch_size
:Nonegradient_accumulation_steps
:1eval_accumulation_steps
:Nonetorch_empty_cache_steps
:Nonelearning_rate
:8e-05weight_decay
:0.0adam_beta1
:0.9adam_beta2
:0.999adam_epsilon
:1e-08max_grad_norm
:1.0num_train_epochs
:1max_steps
:-1lr_scheduler_type
:linearlr_scheduler_kwargs
:{}warmup_ratio
:0.05warmup_steps
:0log_level
:passivelog_level_replica
:warninglog_on_each_node
:Truelogging_nan_inf_filter
:Truesave_safetensors
:Truesave_on_each_node
:Falsesave_only_model
:Falserestore_callback_states_from_checkpoint
:Falseno_cuda
:Falseuse_cpu
:Falseuse_mps_device
:Falseseed
:42data_seed
:Nonejit_mode_eval
:Falseuse_ipex
:Falsebf16
:Truefp16
:Falsefp16_opt_level
:O1half_precision_backend
:autobf16_full_eval
:Falsefp16_full_eval
:Falsetf32
:Nonelocal_rank
:0ddp_backend
:Nonetpu_num_cores
:Nonetpu_metrics_debug
:Falsedebug
:[]dataloader_drop_last
:Truedataloader_num_workers
:0dataloader_prefetch_factor
:Nonepast_index
:-1disable_tqdm
:Falseremove_unused_columns
:Truelabel_names
:Noneload_best_model_at_end
:Falseignore_data_skip
:Falsefsdp
:[]fsdp_min_num_params
:0fsdp_config
:{'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}fsdp_transformer_layer_cls_to_wrap
:Noneaccelerator_config
:{'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}deepspeed
:Nonelabel_smoothing_factor
:0.0optim
:adamw_torchoptim_args
:Noneadafactor
:Falsegroup_by_length
:Falselength_column_name
:lengthddp_find_unused_parameters
:Noneddp_bucket_cap_mb
:Noneddp_broadcast_buffers
:Falsedataloader_pin_memory
:Truedataloader_persistent_workers
:Falseskip_memory_metrics
:Trueuse_legacy_prediction_loop
:Falsepush_to_hub
:Falseresume_from_checkpoint
:Nonehub_model_id
:Nonehub_strategy
:every_savehub_private_repo
:Nonehub_always_push
:Falsegradient_checkpointing
:Falsegradient_checkpointing_kwargs
:Noneinclude_inputs_for_metrics
:Falseinclude_for_metrics
:[]eval_do_concat_batches
:Truefp16_backend
:autopush_to_hub_model_id
:Nonepush_to_hub_organization
:Nonemp_parameters
:auto_find_batch_size
:Falsefull_determinism
:Falsetorchdynamo
:Noneray_scope
:lastddp_timeout
:1800torch_compile
:Falsetorch_compile_backend
:Nonetorch_compile_mode
:Nonedispatch_batches
:Nonesplit_batches
:Noneinclude_tokens_per_second
:Falseinclude_num_input_tokens_seen
:Falseneftune_noise_alpha
:Noneoptim_target_modules
:Nonebatch_eval_metrics
:Falseeval_on_start
:Falseuse_liger_kernel
:Falseeval_use_gather_object
:Falseaverage_tokens_across_devices
:Falseprompts
:Nonebatch_sampler
:batch_samplermulti_dataset_batch_sampler
:proportional
框架版本
- Python:3.11.9
- Sentence Transformers:3.3.0
- PyLate:1.1.4
- Transformers:4.48.0.dev0
- PyTorch:2.4.0
- Accelerate:1.2.1
- Datasets:2.21.0
- Tokenizers:0.21.0
📄 許可證
文檔未提及相關信息。
🔧 技術細節
本模型基於answerdotai/ModernBERT-base
進行微調,使用ColBERT
架構。在訓練過程中,利用Voyager HNSW
索引對文檔嵌入進行高效處理,以實現快速檢索。模型將句子和段落映射為128維的密集向量,通過MaxSim
算子計算語義文本相似度。訓練數據集為lightonai/ms-marco-en-bge
,包含808,728個樣本。訓練過程中使用了Distillation
損失函數,並設置了一系列超參數,如per_device_train_batch_size
為16,learning_rate
為8e-05等。
📄 引用
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"
}
PyLate
@misc{PyLate,
title={PyLate: Flexible Training and Retrieval for Late Interaction Models},
author={Chaffin, Antoine and Sourty, Raphaël},
url={https://github.com/lightonai/pylate},
year={2024}
}
Jina Embeddings V3
Jina Embeddings V3 是一個多語言句子嵌入模型,支持超過100種語言,專注於句子相似度和特徵提取任務。
文本嵌入
Transformers 支持多種語言

J
jinaai
3.7M
911
Ms Marco MiniLM L6 V2
Apache-2.0
基於MS Marco段落排序任務訓練的交叉編碼器模型,用於信息檢索中的查詢-段落相關性評分
文本嵌入 英語
M
cross-encoder
2.5M
86
Opensearch Neural Sparse Encoding Doc V2 Distill
Apache-2.0
基於蒸餾技術的稀疏檢索模型,專為OpenSearch優化,支持免推理文檔編碼,在搜索相關性和效率上優於V1版本
文本嵌入
Transformers 英語

O
opensearch-project
1.8M
7
Sapbert From PubMedBERT Fulltext
Apache-2.0
基於PubMedBERT的生物醫學實體表徵模型,通過自對齊預訓練優化語義關係捕捉
文本嵌入 英語
S
cambridgeltl
1.7M
49
Gte Large
MIT
GTE-Large 是一個強大的句子轉換器模型,專注於句子相似度和文本嵌入任務,在多個基準測試中表現出色。
文本嵌入 英語
G
thenlper
1.5M
278
Gte Base En V1.5
Apache-2.0
GTE-base-en-v1.5 是一個英文句子轉換器模型,專注於句子相似度任務,在多個文本嵌入基準測試中表現優異。
文本嵌入
Transformers 支持多種語言

G
Alibaba-NLP
1.5M
63
Gte Multilingual Base
Apache-2.0
GTE Multilingual Base 是一個多語言的句子嵌入模型,支持超過50種語言,適用於句子相似度計算等任務。
文本嵌入
Transformers 支持多種語言

G
Alibaba-NLP
1.2M
246
Polybert
polyBERT是一個化學語言模型,旨在實現完全由機器驅動的超快聚合物信息學。它將PSMILES字符串映射為600維密集指紋,以數值形式表示聚合物化學結構。
文本嵌入
Transformers

P
kuelumbus
1.0M
5
Bert Base Turkish Cased Mean Nli Stsb Tr
Apache-2.0
基於土耳其語BERT的句子嵌入模型,專為語義相似度任務優化
文本嵌入
Transformers 其他

B
emrecan
1.0M
40
GIST Small Embedding V0
MIT
基於BAAI/bge-small-en-v1.5模型微調的文本嵌入模型,通過MEDI數據集與MTEB分類任務數據集訓練,優化了檢索任務的查詢編碼能力。
文本嵌入
Safetensors 英語
G
avsolatorio
945.68k
29
精選推薦AI模型
Llama 3 Typhoon V1.5x 8b Instruct
專為泰語設計的80億參數指令模型,性能媲美GPT-3.5-turbo,優化了應用場景、檢索增強生成、受限生成和推理任務
大型語言模型
Transformers 支持多種語言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一個基於SODA數據集訓練的超小型對話模型,專為邊緣設備推理設計,體積僅為Cosmo-3B模型的2%左右。
對話系統
Transformers 英語

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基於RoBERTa架構的中文抽取式問答模型,適用於從給定文本中提取答案的任務。
問答系統 中文
R
uer
2,694
98