🚀 Llama 3 8B Instruct (金融領域檢索增強生成)
本模型是原始 Llama 3 8B Instruct 模型的微調版本,基於 virattt/financial-qa-10K 數據集中的 4000 個示例進行微調。
該模型使用 LoRA 適配器針對檢索增強生成(RAG)用例進行微調,經過優化後可基於給定上下文回答問題:
回答問題:
{問題}
使用以下信息:
{上下文}
🚀 快速開始
加載模型
MODEL_NAME = "curiousily/Llama-3-8B-Instruct-Finance-RAG"
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, use_fast=True)
model = AutoModelForCausalLM.from_pretrained(
MODEL_NAME,
device_map="auto"
)
pipe = pipeline(
task="text-generation",
model=model,
tokenizer=tokenizer,
max_new_tokens=128,
return_full_text=False,
)
格式化提示詞(使用原始指令提示詞格式)
prompt = """
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
Use only the information to answer the question<|eot_id|><|start_header_id|>user<|end_header_id|>
How much did the company's net earnings amount to in fiscal 2022?
Information:
Net earnings were $17.1 billion in fiscal 2022.
"""
進行預測
print(outputs[0]["generated_text"])
$17.1 billion
構建提示詞的輔助函數
def create_test_prompt(data_row):
prompt = dedent(f"""
{data_row["question"]}
Information:
```
{data_row["context"]}
```
""")
messages = [
{"role": "system", "content": "Use only the information to answer the question"},
{"role": "user", "content": prompt},
]
return tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
其中,data_row
必須是一個字典:
data_row = {
"question": "...",
"context": "..."
}
💻 使用示例
基礎用法
MODEL_NAME = "curiousily/Llama-3-8B-Instruct-Finance-RAG"
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, use_fast=True)
model = AutoModelForCausalLM.from_pretrained(
MODEL_NAME,
device_map="auto"
)
pipe = pipeline(
task="text-generation",
model=model,
tokenizer=tokenizer,
max_new_tokens=128,
return_full_text=False,
)
prompt = """
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
Use only the information to answer the question<|eot_id|><|start_header_id|>user<|end_header_id|>
How much did the company's net earnings amount to in fiscal 2022?
Information:
Net earnings were $17.1 billion in fiscal 2022.
"""
# 進行預測
outputs = pipe(prompt)
print(outputs[0]["generated_text"])
高級用法
def create_test_prompt(data_row):
prompt = dedent(f"""
{data_row["question"]}
Information:
```
{data_row["context"]}
```
""")
messages = [
{"role": "system", "content": "Use only the information to answer the question"},
{"role": "user", "content": prompt},
]
return tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
data_row = {
"question": "How much did the company's net earnings amount to in fiscal 2022?",
"context": "Net earnings were $17.1 billion in fiscal 2022."
}
prompt = create_test_prompt(data_row)
outputs = pipe(prompt)
print(outputs[0]["generated_text"])
📚 詳細文檔
示例預測
以下是經過訓練和未經過訓練的模型的預測示例:
示例 1
答案:達美航空公司與其地區航空公司的協議通常至少為期十年,並有延期選項。達美航空控制著航班調度和定價等運營方面。
訓練後模型:達美連接協議通常至少為期十年,並有延期選項。
未訓練模型:根據信息,達美航空公司通過達美連接與其地區航空公司簽訂的協議條款如下:
1. 協議通常至少為期十年。
2. 有延期選項。
3. 達美航空控制著航班調度和定價等主要運營方面。
4. 地區航空公司提供服務。
示例 2
答案:公司通過將資產的賬面價值與該資產預期的未來未折現淨現金流進行比較,來評估與收購相關的無形資產是否減值。如果賬面價值超過資產的可收回金額,則確認減值損失。
訓練後模型:公司會在發生特定事件或情況變化表明賬面價值可能無法收回時,評估與收購相關的無形資產和其他長期資產是否減值。這涉及通過將資產的賬面價值與該資產組預期產生的未來未折現淨現金流進行比較,來衡量資產的可收回性。
未訓練模型:根據信息,公司使用以下標準來確定是否應確認與收購相關的無形資產的減值損失:
* 表明資產賬面價值可能無法收回的事件或情況變化。
* 將資產的賬面價值與該資產組預期產生的未來未折現淨現金流進行比較。
換句話說,公司通過將資產的賬面價值與預期未來現金流進行比較來評估其是否可收回,這涉及對未來前景的假設和估計未來現金流的計算。
示例 3
答案:在美國,生物類似藥的審批流程受《公共衛生服務法》(PHSA)以及實施這些法規的條例管轄,具體包括 2010 年 3 月頒佈的聯邦醫療改革立法中的相關條款。
訓練後模型:《聯邦食品、藥品和化妝品法案》(FFDCA)和《公共衛生服務法》(PHSA)
未訓練模型:美國生物類似藥審批流程的法律框架是《聯邦食品、藥品和化妝品法案》(FFDCA)和《公共衛生服務法》(PHSA),以及實施這些法規的條例。
示例 4
答案:蒂莫西·S·泰特擁有加州大學戴維斯分校的機械工程理學學士學位和斯坦福法學院的法學博士學位。
訓練後模型:加州大學戴維斯分校機械工程理學學士和斯坦福法學院法學博士
未訓練模型:根據信息,蒂莫西·S·泰特擁有:
1. 加州大學戴維斯分校的機械工程理學學士學位。
2. 斯坦福法學院的法學博士學位。
示例 5
答案:從 2024 財年開始,公司計劃將暫停的互聯健身訂閱從其新的“期末付費互聯健身訂閱”指標中排除,並將暫停操作視為“平均每月付費互聯健身訂閱淨流失率”指標中的流失事件。
訓練後模型:從 2024 財年開始,公司將不再將暫停的互聯健身訂閱納入其期末付費互聯健身訂閱指標,並將暫停操作視為平均每月付費互聯健身訂閱淨流失率指標中的流失事件。
未訓練模型:從 2024 財年開始,公司將:
* 不再將暫停的互聯健身訂閱納入期末付費互聯健身訂閱指標。
* 將暫停操作視為平均每月付費互聯健身訂閱淨流失率指標中的流失事件。
📄 許可證
本模型使用原始的 Llama 3 許可證。可在以下鏈接獲取定製商業許可證:https://llama.meta.com/llama3/license
📦 模型信息
屬性 |
詳情 |
模型類型 |
Llama 3 8B Instruct(金融領域檢索增強生成) |
基礎模型 |
meta-llama/Meta-Llama-3-8B-Instruct |
訓練數據集 |
virattt/financial-qa-10K |
許可證 |
llama3 |
任務類型 |
文本生成 |