🚀 土耳其长上下文基于ColBERT的重排器
这是一个基于 PyLate 库微调的模型,微调基础模型为 99eren99/ModernBERT-base-Turkish-uncased-mlm。该模型可将句子和段落映射为128维的密集向量序列,通过MaxSim算子进行语义文本相似度计算。
✨ 主要特性
- 基于 ColBERT 架构,适用于土耳其语长上下文重排任务。
- 可将文本映射为128维密集向量,用于语义相似度计算。
📦 安装指南
首先安装 PyLate 库:
pip install -U einops flash_attn
pip install -U pylate
然后对文本进行归一化处理:lambda x: x.replace("İ", "i").replace("I", "ı").lower()
💻 使用示例
基础用法
文档索引
from pylate import indexes, models, retrieve
document_length = 180
model = models.ColBERT(
model_name_or_path="99eren99/ColBERT-ModernBERT-base-Turkish-uncased", document_length=document_length
)
try:
model.tokenizer.model_input_names.remove("token_type_ids")
except:
pass
index = indexes.Voyager(
index_folder="pylate-index",
index_name="index",
override=True,
)
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,
show_progress_bar=True,
)
index.add_documents(
documents_ids=documents_ids,
documents_embeddings=documents_embeddings,
)
注意,无需每次都重新创建索引和编码文档。创建索引并添加文档后,可通过以下方式加载并复用索引:
index = indexes.Voyager(
index_folder="pylate-index",
index_name="index",
)
查询文档
retriever = retrieve.ColBERT(index=index)
queries_embeddings = model.encode(
["query for document 3", "query for document 1"],
batch_size=32,
is_query=True,
show_progress_bar=True,
)
scores = retriever.retrieve(
queries_embeddings=queries_embeddings,
k=10,
)
重排文档
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,
)
📚 详细文档
模型来源
评估结果
长上下文后期交互检索模型的 nDCG 和召回率得分,测试代码和详细指标见 "./assets"

📄 许可证
本项目采用 Apache-2.0 许可证。