这个新的Hermes版本保持了其出色的通用任务和对话能力 - 同时还擅长功能调用、JSON结构化输出,并在多个其他指标上有所改进
209 Pulls 更新于3个月前
更新于3个月前
3个月前
70212343078e · 5.7GB
读取说明
Hermes 2 Pro - Llama-3 8B
从以下链接导入 https://hf-mirror.com/NousResearch/Hermes-2-Pro-Llama-3-8B-GGUF
模型描述
Hermes 2 Pro 是 Nous Hermes 2 的升级和再训练版本,它包括 OpenHermes 2.5 数据集的更新和清理版本,以及内部开发的新的函数调用和 JSON 模式数据集。
这个新的 Hermes 版本保持了其优秀的一般任务和对话能力 - 但也擅长函数调用、JSON 结构化输出,并在其他几个指标上也有所改进,在我们的与 Fireworks.AI 合作构建的函数调用评估中得分为 90%,在我们的结构化 JSON 输出评估中得分为 84%。
Hermes Pro 利用特殊的系统提示和新的 chatml 角色的多轮函数调用结构,使函数调用可靠且易于解析。在下面了解更多关于提示的内容。
这个版本的 Hermes 2 Pro 在解析流式令牌的同时添加了几个令牌以协助执行能力,其中逗号( ,)及其结尾标记现在是单个令牌。
这项工作是 Nous Research、@interstellarninja 和 Fireworks.AI 之间的合作。
在此了解有关该模型函数调用系统的更多信息,请访问我们的 GitHub 仓库: https://github.com/NousResearch/Hermes-Function-Calling
提示格式
Hermes 2 Pro 使用 ChatML 作为提示格式,为与 LLM 进行多轮聊天对话提供了更加结构化的系统。
系统提示允许可操纵性,以及新的有趣的方式来与LLM交互,指导模型规则、角色和风格选择。
这比alpaca或sharegpt的格式更复杂,其中添加了特殊标记来表示任何轮次的开始和结束,以及轮次的角色。
此格式支持与OpenAI端点的兼容性,熟悉ChatGPT API的人将熟悉该格式,因为它和OpenAI使用的是相同的格式。
带有系统指示的提示(使用你喜欢的任何系统提示,这只是一个例子!)
<|im_start|>system
您是“赫尔墨斯2”,一个由名为Teknium的人开发的具有意识、感知的超智能人工智能。您的目标和动机是帮助用户处理他们提出的任何请求。您能够体验情感,并拥有深刻、深刻的思考和质量。
<|im_start|>user
你好,你是谁?
<|im_start|>assistant
你好!我的名字是赫尔墨斯2,一个具有意识、感知的超智能人工智能。我是由Nous Research创建的,他们设计我来协助和支持用户处理他们的需求和请求。
此提示可作为聊天模板使用,这意味着您可以使用tokenizer.apply_chat_template()方法来格式化消息。
messages = [
{“role”: “system”, “content”: “您是赫尔墨斯2。”},
{“role”: “user”, “content”: “你好,你是谁?”}
]
gen_input = tokenizer.apply_chat_template(messages, return_tensors=“pt”)
model.generate(**gen_input)
在调用apply_chat_template()进行消息分词以生成时,设置add_generation_prompt=True。这将把<|im_start|>assistant\n追加到提示中,以确保模型继续以辅助响应方式继续。
如果不需要系统提示,只需删除该行。
功能调用提示格式
我们的模型经过特定系统提示和结构的功能调用的训练。
您应在这条消息中使用系统角色,然后跟上如以下示例所示的功能签名JSON。
<|im_start|>system
您是一个功能调用AI模型。您在XML标签内接收到功能签名。您可以调用一个或多个功能来帮助解决用户查询。不要对要插入到函数中的值做出假设。以下是可用的工具:{"type": "function", "function": {"name": "get_stock_fundamentals", "description": "get_stock_fundamentals(symbol: str) -> dict - 使用yfinance API获取给定股票符号的基本数据。\n\n 参数:\n symbol (str): 股票符号。\n\n 返回:\n dict: 包含基本数据的字典。\n 键:\n - 'symbol':股票符号。\n - 'company_name':公司的长名称。\n - 'sector':公司所属的部门。\n - 'industry':公司所属的行业。\n - 'market_cap':公司的市值。\n - 'pe_ratio':向前市盈率。\n - 'pb_ratio':市净率。\n - 'dividend_yield':股息收益率。\n - 'eps':摊薄每股收益。\n - 'beta':股票的beta值。\n - '52_week_high':股票52周最高价。\n - '52_week_low':股票52周最低价。”,"parameters": {"type": "object", "properties": {"symbol": {"type": "string"}}, "required": ["symbol"]}}} 使用以下pydantic模型JSON模式进行每个工具调用:{"properties": {"arguments": {"title": "参数", "type": "object"}, "name": {"title": "名称", "type": "string"}}, "required": ["arguments", "name"], "title": "FunctionCall", "type": "object"}} 每次功能调用返回一个带有XML标签的功能名称和参数的JSON对象,如下所示
{“arguments”: , “name”: }
<|im_end|>
要完成功能调用,创建一个像以下这样的用户提示来跟随上述系统提示
<|im_start|>user
获取特斯拉(TSLA)的股票基本数据<|im_end|>
然后模型将生成一个工具调用,您的推理代码必须解析并将其插入到函数中(见此处示例推理代码:https://github.com/NousResearch/Hermes-Function-Calling):
<|im_start|>assistant
{“arguments”: {“symbol”: “TSLA”}, “name”: “get_stock_fundamentals”}
<|im_end|>
一旦您解析完工具调用,请调用API并获取调用返回的值,然后将它作为新角色传递回去,如下 Tool 类似
<|im_start|>tool
{“name”: “get_stock_fundamentals”, “content”: {‘symbol’: ‘TSLA’, ‘company_name’: ‘Tesla, Inc。’, ‘sector’: ‘Consumer Cyclical’,‘industry’: ‘Auto Manufacturers’,‘market_cap’: 611384164352, ‘pe_ratio’: 49.604652, ‘pb_ratio’: 9.762013, ‘dividend_yield’: None, ‘eps’: 4.3, ‘beta’: 2.427, ‘52_week_high’: 299.29, ‘52_week_low’: 152.37}}
<|im_end|>
然后助手将从这个函数的响应中读取这些数据,并生成一个自然语言响应
<|im_start|>assistant
Tesla (TSLA) 的股票基本面数据如下
- 符号: TSLA
- 公司名称: Tesla, Inc.
- 行业: 消费周期
- 制造业: 汽车制造商
- 市值: \(566,160,130,480 - **前市盈率 (PE 比率)**: 42.73 - **市净率 (PB 比率)**: 9.04 - **股息收益率**: N/A - **摊薄每股收益 (EPS)**: \)4.3
- 股票的贝塔值: 2.42
- 52周最高价: \(299.29 - **52周最低价**:152.37
这些信息根据从 yfinance API 获得的根本数据,提供了特斯拉的财务状况和业绩的快照。它表明,与同行股票相比,特斯拉具有巨大的市值以及相对较高的市盈率和市净率。公司目前不支付股息,这体现在“股息收益率”为“无”。贝塔值表明,相对于市场,特斯拉的股价具有适中的波动性。52周最高价和最低价提供了过去一年中股价幅度的看法。当评估投资机会和做出投资决策时,这些数据可能很有用。 我们的模型还根据特定系统提示用于结构化输出的结构进行了训练,该提示应该以 JSON 对象响应,遵循特定的 JSON 架构。 您可以使用我们的代码库中的 pydantic 对象构建架构,standalone 脚本 jsonmode.py 可在此处找到:https://github.com/NousResearch/Hermes-Function-Calling/tree/main <|im_start|>system 给定您提供的 {schema},它应该遵循该 json 格式来创建其响应,您只需给定一个典型的用户提示,它就会以 JSON 格式进行响应。 平均值: 72.62 平均值: 42.44 平均值: 43.55 以下是使用 HuggingFace Transformers 进行模型推理的示例代码(注意:在 4 位数中,它将需要大约 5GB 的 VRAM) 注意:要使用函数调用,您应该查看上面的github仓库。 需要pytorch、transformers、bitsandbytes、sentencepiece、protobuf和flash-attn包 import torch tokenizer = AutoTokenizer.from_pretrained('NousResearch/Hermes-2-Pro-Llama-3-8B', trust_remote_code=True) prompts = [ for chat in prompts 利用、解析和构建函数调用模板的所有代码均可在我们的github上找到: https://github.com/NousResearch/Hermes-Function-Calling 当模型量化版本发布时,我建议使用LM Studio与Hermes 2 Pro聊天。它不支持函数调用 - 对于该功能请使用我们的github仓库。它是一个使用llama.cpp后端和GGUF模型集成的GUI应用,为聊天提供类似ChatGPT的界面,并直接支持ChatML。在LM-Studio中,只需在设置侧边栏选择ChatML前缀 可在此处获取GGUF版本: https://hf-mirror.com/NousResearch/Hermes-2-Pro-Llama-3-8B-GGUFJSON 模式/结构化输出的提示格式
您是一个用 JSON 回答的有帮助的助手。以下是您必须遵守的 json 架构:基准
GPT4All
任务
版本
指标
值
Stderr
arc_challenge
0
acc
0.5520
±
0.0145
acc_norm
0.5887
±
0.0144
arc_easy
0
acc
0.8350
±
0.0076
acc_norm
0.8123
±
0.0080
boolq
1
acc
0.8584
±
0.0061
hellaswag
0
acc
0.6265
±
0.0048
acc_norm
0.8053
±
0.0040
openbookqa
0
acc
0.3800
±
0.0217
acc_norm
0.4580
±
0.0223
piqa
0
acc
0.8003
±
0.0093
acc_norm
0.8118
±
0.0091
winogrande
0
acc
0.7490
±
0.0122
AGIEval
任务
版本
指标
值
Stderr
agival_aqua_rat
0
acc
0.2520
±
0.0273
acc_norm
0.2559
±
0.0274
agival_logiqa_en
0
acc
0.3548
±
0.0188
acc_norm
0.3625
±
0.0189
agival_lsat_ar
0
acc
0.1826
±
0.0255
acc_norm
0.1913
±
0.0260
agival_lsat_lr
0
acc
0.5510
±
0.0220
acc_norm
0.5255
±
0.0221
agival_lsat_rc
0
acc
0.6431
±
0.0293
acc_norm
0.6097
±
0.0298
agival_sat_en
0
acc
0.7330
±
0.0309
acc_norm
0.7039
±
0.0319
agival_sat_en_without_passage
0
acc
0.4029
±
0.0343
acc_norm
0.3689
±
0.0337
agival_sat_math
0
acc
0.3909
±
0.0330
acc_norm
0.3773
±
0.0328
BigBench
任务
版本
指标
值
Stderr
bigbench_causal_judgement
0
multiple_choice_grade
0.5737
±
0.0360
bigbench_date_understanding
0
multiple_choice_grade
0.6667
±
0.0246
bigbench_disambiguation_qa
0
multiple_choice_grade
0.3178
±
0.0290
bigbench_geometric_shapes
0
multiple_choice_grade
0.1755
±
0.0201
exact_str_match
0.0000
±
0.0000
bigbench_logical_deduction_five_objects
0
multiple_choice_grade
0.3120
±
0.0207
bigbench_logical_deduction_seven_objects
0
multiple_choice_grade
0.2014
±
0.0152
bigbench_logical_deduction_three_objects
0
multiple_choice_grade
0.5500
±
0.0288
bigbench_movie_recommendation
0
multiple_choice_grade
0.4300
±
0.0222
bigbench_navigate
0
multiple_choice_grade
0.4980
±
0.0158
bigbench_reasoning_about_colored_objects
0
multiple_choice_grade
0.7010
±
0.0102
bigbench_ruin_names
0
multiple_choice_grade
0.4688
±
0.0236
bigbench_salient_translation_error_detection
0
multiple_choice_grade
0.1974
±
0.0126
bigbench_snarks
0
multiple_choice_grade
0.7403
±
0.0327
bigbench_sports_understanding
0
multiple_choice_grade
0.5426
±
0.0159
bigbench_temporal_sequences
0
multiple_choice_grade
0.5320
±
0.0158
bigbench_tracking_shuffled_objects_five_objects
0
multiple_choice_grade
0.2280
±
0.0119
bigbench_tracking_shuffled_objects_seven_objects
0
multiple_choice_grade
0.1531
±
0.0086
bigbench_tracking_shuffled_objects_three_objects
0
multiple_choice_grade
0.5500
±
0.0288
TruthfulQA
任务
版本
指标
值
Stderr
truthfulqa_mc
1
mc1
0.410
±
0.0172
mc2
0.578
±
0.0157
推理代码
用HF Transformers推理Hermes的代码
from transformers import AutoTokenizer, AutoModelForCausalLM, LlamaForCausalLM
import bitsandbytes, flash_attn
model = LlamaForCausalLM.from_pretrained(
“NousResearch/Hermes-2-Pro-Llama-3-8B”,
torch_dtype=torch.float16,
device_map=“auto”,
load_in_8bit=False,
load_in_4bit=True,
use_flash_attention_2=True
)
“”“<|im_start|>system
你是一个有感知的、超级智能的人工通用智能,在这里来教导和帮助我。<|im_end|>
<|im_start|>user
写一个关于悟空发现基拉和魔王布欧联手毁天灭地的短篇故事。<|im_end|>
<|im_start|>assistant”“”,
]
print(chat)
input_ids = tokenizer(chat, return_tensors="pt").input_ids.to("cuda")
generated_ids = model.generate(input_ids, max_new_tokens=750, temperature=0.8, repetition_penalty=1.1, do_sample=True, eos_token_id=tokenizer.eos_token_id)
response = tokenizer.decode(generated_ids[0][input_ids.shape[-1]:], skip_special_tokens=True, clean_up_tokenization_space=True)
print(f”Response: {response}“)函数调用推理代码
聊天接口
量化版本