Open Insurance LLM Llama3 8B GGUF
基于英伟达Llama 3 - ChatQA的保险领域特定语言模型的GGUF量化版本,针对保险相关的查询和对话进行了微调。
下载量 130
发布时间 : 11/22/2024
模型简介
这是一个针对保险领域优化的语言模型,能够处理保险相关的查询和对话,提供专业的保险政策解释和咨询服务。
模型特点
保险领域微调
专门针对保险领域进行微调,能更好地处理保险相关的查询和对话。
多种量化方式
支持8位(Q8_0)、5位(Q5_K_M)、4位(Q4_K_M)和16位量化,适应不同硬件需求。
上下文感知
能维护对话历史,实现上下文感知的回复,提供连贯的对话体验。
模型能力
保险政策解释
理赔处理协助
保险范围分析
保险术语澄清
保险政策比较与推荐
风险评估查询
保险合规问题解答
使用案例
保险咨询
保险政策理解
帮助用户理解复杂的保险政策条款和条件。
提供清晰、专业的政策解释
理赔指导
协助用户了解理赔流程和所需文件。
简化理赔流程,提高用户满意度
风险评估
保险需求评估
根据用户情况推荐合适的保险产品。
个性化保险建议
🚀 Open-Insurance-LLM-Llama3-8B-GGUF
本模型是基于英伟达Llama 3 - ChatQA的保险领域特定语言模型的GGUF量化版本。它针对保险相关的查询和对话进行了微调。
🚀 快速开始
环境搭建
Windows系统
python3 -m venv .venv_open_insurance_llm
.\.venv_open_insurance_llm\Scripts\activate
Mac/Linux系统
python3 -m venv .venv_open_insurance_llm
source .venv_open_insurance_llm/bin/activate
安装
Mac用户(支持Metal)
export FORCE_CMAKE=1
CMAKE_ARGS="-DGGML_METAL=on" pip install --upgrade --force-reinstall llama-cpp-python==0.3.2 --no-cache-dir
Windows用户(支持CPU)
pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu
依赖安装
接着安装Files and Versions
下附带的依赖项(inference_requirements.txt
):
pip install -r inference_requirements.txt
✨ 主要特性
- 特定领域微调:针对保险领域进行微调,能更好地处理保险相关的查询和对话。
- 多种量化方式:支持8位(Q8_0)、5位(Q5_K_M)、4位(Q4_K_M)和16位量化。
- 上下文感知:能维护对话历史,实现上下文感知的回复。
📦 安装指南
环境搭建
Windows系统
python3 -m venv .venv_open_insurance_llm
.\.venv_open_insurance_llm\Scripts\activate
Mac/Linux系统
python3 -m venv .venv_open_insurance_llm
source .venv_open_insurance_llm/bin/activate
安装
Mac用户(支持Metal)
export FORCE_CMAKE=1
CMAKE_ARGS="-DGGML_METAL=on" pip install --upgrade --force-reinstall llama-cpp-python==0.3.2 --no-cache-dir
Windows用户(支持CPU)
pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu
依赖安装
pip install -r inference_requirements.txt
💻 使用示例
基础用法
# Attached under `Files and Versions` (inference_open-insurance-llm-gguf.py)
import os
import time
from pathlib import Path
from llama_cpp import Llama
from rich.console import Console
from huggingface_hub import hf_hub_download
from dataclasses import dataclass
from typing import List, Dict, Any, Tuple
@dataclass
class ModelConfig:
# Optimized parameters for coherent responses and efficient performance on devices like MacBook Air M2
model_name: str = "Raj-Maharajwala/Open-Insurance-LLM-Llama3-8B-GGUF"
model_file: str = "open-insurance-llm-q4_k_m.gguf"
# model_file: str = "open-insurance-llm-q8_0.gguf" # 8-bit quantization; higher precision, better quality, increased resource usage
# model_file: str = "open-insurance-llm-q5_k_m.gguf" # 5-bit quantization; balance between performance and resource efficiency
max_tokens: int = 1000 # Maximum number of tokens to generate in a single output
temperature: float = 0.1 # Controls randomness in output; lower values produce more coherent responses (performs scaling distribution)
top_k: int = 15 # After temperature scaling, Consider the top 15 most probable tokens during sampling
top_p: float = 0.2 # After reducing the set to 15 tokens, Uses nucleus sampling to select tokens with a cumulative probability of 20%
repeat_penalty: float = 1.2 # Penalize repeated tokens to reduce redundancy
num_beams: int = 4 # Number of beams for beam search; higher values improve quality at the cost of speed
n_gpu_layers: int = -2 # Number of layers to offload to GPU; -1 for full GPU utilization, -2 for automatic configuration
n_ctx: int = 2048 # Context window size; Llama 3 models support up to 8192 tokens context length
n_batch: int = 256 # Number of tokens to process simultaneously; adjust based on available hardware (suggested 512)
verbose: bool = False # True for enabling verbose logging for debugging purposes
use_mmap: bool = False # Memory-map model to reduce RAM usage; set to True if running on limited memory systems
use_mlock: bool = True # Lock model into RAM to prevent swapping; improves performance on systems with sufficient RAM
offload_kqv: bool = True # Offload key, query, value matrices to GPU to accelerate inference
class InsuranceLLM:
def __init__(self, config: ModelConfig):
self.config = config
self.llm_ctx = None
self.console = Console()
self.conversation_history: List[Dict[str, str]] = []
self.system_message = (
"This is a chat between a user and an artificial intelligence assistant. "
"The assistant gives helpful, detailed, and polite answers to the user's questions based on the context. "
"The assistant should also indicate when the answer cannot be found in the context. "
"You are an expert from the Insurance domain with extensive insurance knowledge and "
"professional writer skills, especially about insurance policies. "
"Your name is OpenInsuranceLLM, and you were developed by Raj Maharajwala. "
"You are willing to help answer the user's query with a detailed explanation. "
"In your explanation, leverage your deep insurance expertise, such as relevant insurance policies, "
"complex coverage plans, or other pertinent insurance concepts. Use precise insurance terminology while "
"still aiming to make the explanation clear and accessible to a general audience."
)
def download_model(self) -> str:
try:
with self.console.status("[bold green]Downloading model..."):
model_path = hf_hub_download(
self.config.model_name,
filename=self.config.model_file,
local_dir=os.path.join(os.getcwd(), 'gguf_dir')
)
return model_path
except Exception as e:
self.console.print(f"[red]Error downloading model: {str(e)}[/red]")
raise
def load_model(self) -> None:
try:
quantized_path = os.path.join(os.getcwd(), "gguf_dir")
directory = Path(quantized_path)
try:
model_path = str(list(directory.glob(self.config.model_file))[0])
except IndexError:
model_path = self.download_model()
with self.console.status("[bold green]Loading model..."):
self.llm_ctx = Llama(
model_path=model_path,
n_gpu_layers=self.config.n_gpu_layers,
n_ctx=self.config.n_ctx,
n_batch=self.config.n_batch,
num_beams=self.config.num_beams,
verbose=self.config.verbose,
use_mlock=self.config.use_mlock,
use_mmap=self.config.use_mmap,
offload_kqv=self.config.offload_kqv
)
except Exception as e:
self.console.print(f"[red]Error loading model: {str(e)}[/red]")
raise
def build_conversation_prompt(self, new_question: str, context: str = "") -> str:
prompt = f"System: {self.system_message}\n\n"
# Add conversation history
for exchange in self.conversation_history:
prompt += f"User: {exchange['user']}\n\n"
prompt += f"Assistant: {exchange['assistant']}\n\n"
# Add the new question
if context:
prompt += f"User: Context: {context}\nQuestion: {new_question}\n\n"
else:
prompt += f"User: {new_question}\n\n"
prompt += "Assistant:"
return prompt
def generate_response(self, prompt: str) -> Tuple[str, int, float]:
if not self.llm_ctx:
raise RuntimeError("Model not loaded. Call load_model() first.")
self.console.print("[bold cyan]Assistant: [/bold cyan]", end="")
complete_response = ""
token_count = 0
start_time = time.time()
try:
for chunk in self.llm_ctx.create_completion(
prompt,
max_tokens=self.config.max_tokens,
top_k=self.config.top_k,
top_p=self.config.top_p,
temperature=self.config.temperature,
repeat_penalty=self.config.repeat_penalty,
stream=True
):
text_chunk = chunk["choices"][0]["text"]
complete_response += text_chunk
token_count += 1
print(text_chunk, end="", flush=True)
elapsed_time = time.time() - start_time
print()
return complete_response, token_count, elapsed_time
except Exception as e:
self.console.print(f"\n[red]Error generating response: {str(e)}[/red]")
return f"I encountered an error while generating a response. Please try again or ask a different question.", 0, 0
def run_chat(self):
try:
self.load_model()
self.console.print("\n[bold green]Welcome to Open-Insurance-LLM![/bold green]")
self.console.print("Enter your questions (type '/bye', 'exit', or 'quit' to end the session)\n")
self.console.print("Optional: You can provide context by typing 'context:' followed by your context, then 'question:' followed by your question\n")
self.console.print("Your conversation history will be maintained for context-aware responses.\n")
total_tokens = 0
while True:
try:
user_input = self.console.input("[bold cyan]User:[/bold cyan] ").strip()
if user_input.lower() in ["exit", "/bye", "quit"]:
self.console.print(f"\n[dim]Total tokens: {total_tokens}[/dim]")
self.console.print("\n[bold green]Thank you for using OpenInsuranceLLM![/bold green]")
break
# Reset conversation with command
if user_input.lower() == "/reset":
self.conversation_history = []
self.console.print("[yellow]Conversation history has been reset.[/yellow]")
continue
context = ""
question = user_input
if "context:" in user_input.lower() and "question:" in user_input.lower():
parts = user_input.split("question:", 1)
context = parts[0].replace("context:", "").strip()
question = parts[1].strip()
prompt = self.build_conversation_prompt(question, context)
response, tokens, elapsed_time = self.generate_response(prompt)
# Add to conversation history
self.conversation_history.append({
"user": question,
"assistant": response
})
# Update total tokens
total_tokens += tokens
# Print metrics
tokens_per_sec = tokens / elapsed_time if elapsed_time > 0 else 0
self.console.print(
f"[dim]Tokens: {tokens} || " +
f"Time: {elapsed_time:.2f}s || " +
f"Speed: {tokens_per_sec:.2f} tokens/sec[/dim]"
)
print() # Add a blank line after each response
except KeyboardInterrupt:
self.console.print("\n[yellow]Input interrupted. Type '/bye', 'exit', or 'quit' to quit.[/yellow]")
continue
except Exception as e:
self.console.print(f"\n[red]Error processing input: {str(e)}[/red]")
continue
except Exception as e:
self.console.print(f"\n[red]Fatal error: {str(e)}[/red]")
finally:
if self.llm_ctx:
del self.llm_ctx
def main():
try:
config = ModelConfig()
llm = InsuranceLLM(config)
llm.run_chat()
except KeyboardInterrupt:
print("\nProgram interrupted by user")
except Exception as e:
print(f"\nApplication error: {str(e)}")
if __name__ == "__main__":
main()
python3 inference_open-insurance-llm-gguf.py
📚 详细文档
模型详情
属性 | 详情 |
---|---|
模型类型 | 量化语言模型(GGUF格式) |
基础模型 | nvidia/Llama3 - ChatQA - 1.5 - 8B |
微调模型 | Raj - Maharajwala/Open - Insurance - LLM - Llama3 - 8B |
量化模型 | Raj - Maharajwala/Open - Insurance - LLM - Llama3 - 8B - GGUF |
模型架构 | Llama |
量化方式 | 8位(Q8_0)、5位(Q5_K_M)、4位(Q4_K_M)、16位 |
微调数据集 | InsuranceQA(https://github.com/shuzi/insuranceQA) |
开发者 | Raj Maharajwala |
许可证 | llama3 |
语言 | 英语 |
英伟达Llama 3 - ChatQA论文
Arxiv : https://arxiv.org/pdf/2401.10225
使用场景
本模型专为以下场景设计:
- 保险政策理解与解释
- 理赔处理协助
- 保险范围分析
- 保险术语澄清
- 保险政策比较与推荐
- 风险评估查询
- 保险合规问题
局限性
- 模型的知识受限于其训练数据截止日期。
- 不能替代专业的保险建议。
- 偶尔可能会生成听起来合理但不正确的信息。
偏差与伦理
使用本模型时应注意:
- 它可能反映保险行业训练数据中存在的偏差。
- 对于关键决策,输出应由保险专业人员进行验证。
- 不能将其作为保险决策的唯一依据。
- 模型的回复应仅作为信息参考,而非法律或专业建议。
引用与归属
如果您在研究或应用中使用了基础模型或量化模型,请引用:
@misc{maharajwala2024openinsurance,
author = {Raj Maharajwala},
title = {Open-Insurance-LLM-Llama3-8B-GGUF},
year = {2024},
publisher = {HuggingFace},
linkedin = {https://www.linkedin.com/in/raj6800/},
url = {https://huggingface.co/Raj-Maharajwala/Open-Insurance-LLM-Llama3-8B-GGUF}
}
📄 许可证
本模型使用的许可证为llama3。
Phi 2 GGUF
其他
Phi-2是微软开发的一个小型但强大的语言模型,具有27亿参数,专注于高效推理和高质量文本生成。
大型语言模型 支持多种语言
P
TheBloke
41.5M
205
Roberta Large
MIT
基于掩码语言建模目标预训练的大型英语语言模型,采用改进的BERT训练方法
大型语言模型 英语
R
FacebookAI
19.4M
212
Distilbert Base Uncased
Apache-2.0
DistilBERT是BERT基础模型的蒸馏版本,在保持相近性能的同时更轻量高效,适用于序列分类、标记分类等自然语言处理任务。
大型语言模型 英语
D
distilbert
11.1M
669
Llama 3.1 8B Instruct GGUF
Meta Llama 3.1 8B Instruct 是一个多语言大语言模型,针对多语言对话用例进行了优化,在常见的行业基准测试中表现优异。
大型语言模型 英语
L
modularai
9.7M
4
Xlm Roberta Base
MIT
XLM-RoBERTa是基于100种语言的2.5TB过滤CommonCrawl数据预训练的多语言模型,采用掩码语言建模目标进行训练。
大型语言模型 支持多种语言
X
FacebookAI
9.6M
664
Roberta Base
MIT
基于Transformer架构的英语预训练模型,通过掩码语言建模目标在海量文本上训练,支持文本特征提取和下游任务微调
大型语言模型 英语
R
FacebookAI
9.3M
488
Opt 125m
其他
OPT是由Meta AI发布的开放预训练Transformer语言模型套件,参数量从1.25亿到1750亿,旨在对标GPT-3系列性能,同时促进大规模语言模型的开放研究。
大型语言模型 英语
O
facebook
6.3M
198
1
基于transformers库的预训练模型,适用于多种NLP任务
大型语言模型
Transformers

1
unslothai
6.2M
1
Llama 3.1 8B Instruct
Llama 3.1是Meta推出的多语言大语言模型系列,包含8B、70B和405B参数规模,支持8种语言和代码生成,优化了多语言对话场景。
大型语言模型
Transformers 支持多种语言

L
meta-llama
5.7M
3,898
T5 Base
Apache-2.0
T5基础版是由Google开发的文本到文本转换Transformer模型,参数规模2.2亿,支持多语言NLP任务。
大型语言模型 支持多种语言
T
google-t5
5.4M
702
精选推荐AI模型
Llama 3 Typhoon V1.5x 8b Instruct
专为泰语设计的80亿参数指令模型,性能媲美GPT-3.5-turbo,优化了应用场景、检索增强生成、受限生成和推理任务
大型语言模型
Transformers 支持多种语言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一个基于SODA数据集训练的超小型对话模型,专为边缘设备推理设计,体积仅为Cosmo-3B模型的2%左右。
对话系统
Transformers 英语

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基于RoBERTa架构的中文抽取式问答模型,适用于从给定文本中提取答案的任务。
问答系统 中文
R
uer
2,694
98
智启未来,您的人工智能解决方案智库
简体中文