🚀 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 |
任务类型 |
文本生成 |