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