🚀 Self-RAG 13B模型
本模型是一個13B的 Self-RAG 模型,它能夠針對用戶的各種查詢生成輸出,還能生成 反思標記(reflection tokens),以自適應地調用檢索系統,並對自身的輸出和檢索到的段落進行評估。
Self-RAG 在我們的指令跟隨語料庫上進行訓練,這些語料庫包含交錯的段落和反思標記,採用標準的下一個標記預測目標,從而能夠通過細粒度的反饋實現高效且穩定的學習。在推理階段,我們利用涵蓋生成各個方面的反思標記,來採樣出最符合用戶偏好的輸出。更多詳細描述請參閱 我們的論文。
🚀 快速開始
✨ 主要特性
- 能夠針對用戶的多樣化查詢生成輸出。
- 生成反思標記,自適應調用檢索系統並評估自身輸出和檢索段落。
- 在包含交錯段落和反思標記的指令跟隨語料庫上訓練,實現高效穩定學習。
- 推理時利用反思標記採樣最符合用戶偏好的輸出。
📦 安裝指南
請確保安裝 self-rag/requirements.txt 中列出的依賴項。
💻 使用示例
基礎用法
from transformers import AutoTokenizer, AutoModelForCausalLM
from vllm import LLM, SamplingParams
model = LLM("selfrag/selfrag_llama2_13b", download_dir="/gscratch/h2lab/akari/model_cache", dtype="half")
sampling_params = SamplingParams(temperature=0.0, top_p=1.0, max_tokens=100, skip_special_tokens=False)
def format_prompt(input, paragraph=None):
prompt = "### Instruction:\n{0}\n\n### Response:\n".format(input)
if paragraph is not None:
prompt += "[Retrieval]<paragraph>{0}</paragraph>".format(paragraph)
return prompt
query_1 = "Leave odd one out: twitter, instagram, whatsapp."
query_2 = "Can you tell me the difference between llamas and alpacas?"
queries = [query_1, query_2]
preds = model.generate([format_prompt(query) for query in queries], sampling_params)
for pred in preds:
print("Model prediction: {0}".format(pred.outputs[0].text))
prompt = format_prompt("Can you tell me the difference between llamas and alpacas?", paragraph="The alpaca (Lama pacos) is a species of South American camelid mammal. It is similar to, and often confused with, the llama. Alpacas are considerably smaller than llamas, and unlike llamas, they were not bred to be working animals, but were bred specifically for their fiber.")
preds = model.generate([prompt], sampling_params)
print([pred.outputs[0].text for pred in preds])
📚 詳細文檔
輸入格式
如 format_prompt
函數中所述,輸入應按照以下格式:
### Instruction:\n{instruction}\n\n### Response:\n".format(instruction)
或者,如果有額外輸入:
### Instruction:\n{instruction}\n\n### Input:\n{input}\n\n### Response:\n"
你可以在 ### Response:\n"
之後的任何位置插入段落,但要確保將段落標記為段落標記(即 <paragraph>{0}</paragraph>
)。
🔧 技術細節
- 訓練數據:我們的訓練數據可在HuggingFace數據集 selfrag_train_data 中獲取。
- 訓練環境:我們在Stability HPC服務器上使用8個A100 40GB進行訓練。
📄 許可證
本項目採用MIT許可證。
引用說明
如果您使用此模型,請引用我們的工作:
@article{asai2023selfrag,
author = {Asai, Akari and Wu, Zeqiu and Wang, Yizhong and Sil, Avirup and Hajishirzi, Hannaneh},
title = {{Self-RAG}: Learning to Retrieve, Generate, and Critique through Self-Reflection},
year = {2023},
journal = { arXiv preprint arXiv:2310.11511 },
URL = {https://arxiv.org/abs/2310.11511}
}