🚀 doc2query/msmarco-t5-base-v1
這是一個基於T5的doc2query模型(也稱為docT5query)。該模型可用於解決文檔搜索中的詞彙差距問題,以及生成特定領域的訓練數據,助力訓練強大的密集嵌入模型。
🚀 快速開始
本模型可用於以下兩個主要場景:
- 文檔擴展:為段落生成20 - 40個查詢,並將段落和生成的查詢索引到標準的BM25索引(如Elasticsearch、OpenSearch或Lucene)中。生成的查詢有助於縮小詞彙搜索的詞彙差距,因為生成的查詢包含同義詞。此外,它會重新加權單詞,即使重要單詞在段落中很少出現,也會賦予更高的權重。在我們的BEIR論文中,我們證明了BM25 + docT5query是一個強大的搜索引擎。在BEIR倉庫中,我們有一個如何使用docT5query與Pyserini的示例。
- 特定領域訓練數據生成:可用於生成訓練數據以學習嵌入模型。在SBERT.net上,我們有一個如何使用該模型為給定的未標記文本集合生成(查詢,文本)對的示例。這些對可用於訓練強大的密集嵌入模型。
💻 使用示例
基礎用法
from transformers import T5Tokenizer, T5ForConditionalGeneration
model_name = 'doc2query/msmarco-t5-base-v1'
tokenizer = T5Tokenizer.from_pretrained(model_name)
model = T5ForConditionalGeneration.from_pretrained(model_name)
text = "Python is an interpreted, high-level and general-purpose programming language. Python's design philosophy emphasizes code readability with its notable use of significant whitespace. Its language constructs and object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects."
input_ids = tokenizer.encode(text, max_length=320, truncation=True, return_tensors='pt')
outputs = model.generate(
input_ids=input_ids,
max_length=64,
do_sample=True,
top_p=0.95,
num_return_sequences=5)
print("Text:")
print(text)
print("\nGenerated Queries:")
for i in range(len(outputs)):
query = tokenizer.decode(outputs[i], skip_special_tokens=True)
print(f'{i + 1}: {query}')
⚠️ 重要提示
model.generate()
是非確定性的,每次運行時會產生不同的查詢。
🔧 技術細節
本模型在 google/t5-v1_1-base 的基礎上進行了微調,訓練了31000個步驟(在來自MS MARCO的500000個訓練對數據上約4個輪次)。訓練腳本可在本倉庫的 train_script.py
中查看。
輸入文本被截斷為320個詞塊,輸出文本最多生成64個詞塊。該模型使用了來自 MS MARCO Passage-Ranking數據集 的(查詢,段落)對進行訓練。
📄 許可證
本項目採用Apache 2.0許可證。