Safetensors
qwen2
qypeng commited on
Commit
fd8b545
1 Parent(s): 37c1c7e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +12 -3
README.md CHANGED
@@ -6,18 +6,18 @@ datasets:
6
  base_model:
7
  - Qwen/Qwen2.5-3B-Instruct
8
  ---
9
-
10
  ## Introduction
11
  We're excited to release lightweight Hammer 2.0 models ([0.5B](https://huggingface.co/MadeAgents/Hammer2.0-0.5b) , [1.5B](https://huggingface.co/MadeAgents/Hammer2.0-1.5b) , [3B](https://huggingface.co/MadeAgents/Hammer2.0-3b) , and [7B](https://huggingface.co/MadeAgents/Hammer2.0-7b)) with strong function calling capability, which empower developers to build personalized, on-device agentic applications.
12
 
13
  ## Model Details
14
- Hammer2.0 finetuned based on [Qwen 2.5 series](https://huggingface.co/collections/Qwen/qwen25-66e81a666513e518adb90d9e) and [Qwen 2.5 coder series](https://huggingface.co/collections/Qwen/qwen25-coder-66eaa22e6f99801bf65b0c2f) using function masking techniques. It's trained using the [APIGen Function Calling Datasets](https://huggingface.co/datasets/Salesforce/xlam-function-calling-60k) containing 60,000 samples, supplemented by [xlam-irrelevance-7.5k](https://huggingface.co/datasets/MadeAgents/xlam-irrelevance-7.5k) we generated. Hammer2.0 has achieved exceptional performances across numerous function calling benchmarks. For detailed data construction, training methods, and evaluation strategies, please refer to our paper [Hammer: Robust Function-Calling for On-Device Language Models via Function Masking](https://arxiv.org/abs/2410.04587) and the [Hammer GitHub repository](https://github.com/MadeAgents/Hammer) .
15
 
16
  ## Evaluation
17
  The evaluation results of Hammer 2.0 models on the Berkeley Function-Calling Leaderboard (BFCL-v3) are presented in the following table:
18
  <div style="text-align: center;">
19
  <img src="v2_figures/bfcl.PNG" alt="overview" width="1000" style="margin: auto;">
20
  </div>
 
21
  Our Hammer 2.0 series consistently achieves corresponding best performance at comparable scales. The 7B model outperforms most function calling enchanced models, and the 1.5B model also achieves unexpected performance.
22
 
23
  In addition, we evaluated the Hammer 2.0 models on other academic benchmarks to further demonstrate the generalization ability of our models.
@@ -25,7 +25,8 @@ In addition, we evaluated the Hammer 2.0 models on other academic benchmarks to
25
  <div style="text-align: center;">
26
  <img src="v2_figures/others.PNG" alt="overview" width="1000" style="margin: auto;">
27
  </div>
28
- Hammer 2.0 models showcase highly stable performance, suggesting the robustness of Hammer 2.0 series. In contrast, the baseline approaches display varying levels of effectiveness on these other benchmarks.
 
29
 
30
  ## Requiements
31
  The code of Hammer 2.0 models have been in the latest Hugging face transformers and we advise you to install `transformers>=4.37.0`.
@@ -36,15 +37,18 @@ This is a simple example of how to use our model.
36
  import json
37
  import torch
38
  from transformers import AutoModelForCausalLM, AutoTokenizer
 
39
  model_name = "MadeAgents/Hammer2.0-3b"
40
  model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", torch_dtype="auto", trust_remote_code=True)
41
  tokenizer = AutoTokenizer.from_pretrained(model_name)
 
42
  # Please use our provided instruction prompt for best performance
43
  TASK_INSTRUCTION = """You are a tool calling assistant. In order to complete the user's request, you need to select one or more appropriate tools from the following tools and fill in the correct values for the tool parameters. Your specific tasks are:
44
  1. Make one or more function/tool calls to meet the request based on the question.
45
  2. If none of the function can be used, point it out and refuse to answer.
46
  3. If the given question lacks the parameters required by the function, also point it out.
47
  """
 
48
  FORMAT_INSTRUCTION = """
49
  The output MUST strictly adhere to the following JSON format, and NO other text MUST be included.
50
  The example format is as follows. Please make sure the parameter type is correct. If no function call is needed, please directly output an empty list '[]'
@@ -55,8 +59,10 @@ The example format is as follows. Please make sure the parameter type is correct
55
  ]
56
  ```
57
  """
 
58
  # Define the input query and available tools
59
  query = "Where can I find live giveaways for beta access and games? And what's the weather like in New York, US?"
 
60
  live_giveaways_by_type = {
61
  "name": "live_giveaways_by_type",
62
  "description": "Retrieve live giveaways from the GamerPower API based on the specified type.",
@@ -100,6 +106,7 @@ get_stock_price={
100
  "required": ["ticker"]
101
  }
102
  }
 
103
  def convert_to_format_tool(tools):
104
  ''''''
105
  if isinstance(tools, dict):
@@ -132,10 +139,12 @@ def build_prompt(task_instruction: str, format_instruction: str, tools: list, qu
132
  openai_format_tools = [live_giveaways_by_type, get_current_weather,get_stock_price]
133
  format_tools = convert_to_format_tool(openai_format_tools)
134
  content = build_prompt(TASK_INSTRUCTION, FORMAT_INSTRUCTION, format_tools, query)
 
135
  messages=[
136
  { 'role': 'user', 'content': content}
137
  ]
138
  inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
 
139
  # tokenizer.eos_token_id is the id of <|EOT|> token
140
  outputs = model.generate(inputs, max_new_tokens=512, do_sample=False, num_return_sequences=1, eos_token_id=tokenizer.eos_token_id)
141
  print(tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True))
 
6
  base_model:
7
  - Qwen/Qwen2.5-3B-Instruct
8
  ---
 
9
  ## Introduction
10
  We're excited to release lightweight Hammer 2.0 models ([0.5B](https://huggingface.co/MadeAgents/Hammer2.0-0.5b) , [1.5B](https://huggingface.co/MadeAgents/Hammer2.0-1.5b) , [3B](https://huggingface.co/MadeAgents/Hammer2.0-3b) , and [7B](https://huggingface.co/MadeAgents/Hammer2.0-7b)) with strong function calling capability, which empower developers to build personalized, on-device agentic applications.
11
 
12
  ## Model Details
13
+ Hammer2.0 finetuned based on [Qwen 2.5 series](https://huggingface.co/collections/Qwen/qwen25-66e81a666513e518adb90d9e) and [Qwen 2.5 coder series](https://huggingface.co/collections/Qwen/qwen25-coder-66eaa22e6f99801bf65b0c2f) using function masking techniques. It's trained using the [APIGen Function Calling Datasets](https://huggingface.co/datasets/Salesforce/xlam-function-calling-60k) containing 60,000 samples, supplemented by [xlam-irrelevance-7.5k](https://huggingface.co/datasets/MadeAgents/xlam-irrelevance-7.5k) we generated. Hammer2.0 has achieved exceptional performances across numerous function calling benchmarks. For more details, please refer to [Hammer: Robust Function-Calling for On-Device Language Models via Function Masking](https://arxiv.org/abs/2410.04587) and [Hammer GitHub repository](https://github.com/MadeAgents/Hammer) .
14
 
15
  ## Evaluation
16
  The evaluation results of Hammer 2.0 models on the Berkeley Function-Calling Leaderboard (BFCL-v3) are presented in the following table:
17
  <div style="text-align: center;">
18
  <img src="v2_figures/bfcl.PNG" alt="overview" width="1000" style="margin: auto;">
19
  </div>
20
+
21
  Our Hammer 2.0 series consistently achieves corresponding best performance at comparable scales. The 7B model outperforms most function calling enchanced models, and the 1.5B model also achieves unexpected performance.
22
 
23
  In addition, we evaluated the Hammer 2.0 models on other academic benchmarks to further demonstrate the generalization ability of our models.
 
25
  <div style="text-align: center;">
26
  <img src="v2_figures/others.PNG" alt="overview" width="1000" style="margin: auto;">
27
  </div>
28
+
29
+ Hammer 2.0 models showcase highly stable performance, suggesting the robustness of Hammer 2.0 series. In contrast, the baseline approaches display varying levels of effectiveness.
30
 
31
  ## Requiements
32
  The code of Hammer 2.0 models have been in the latest Hugging face transformers and we advise you to install `transformers>=4.37.0`.
 
37
  import json
38
  import torch
39
  from transformers import AutoModelForCausalLM, AutoTokenizer
40
+
41
  model_name = "MadeAgents/Hammer2.0-3b"
42
  model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", torch_dtype="auto", trust_remote_code=True)
43
  tokenizer = AutoTokenizer.from_pretrained(model_name)
44
+
45
  # Please use our provided instruction prompt for best performance
46
  TASK_INSTRUCTION = """You are a tool calling assistant. In order to complete the user's request, you need to select one or more appropriate tools from the following tools and fill in the correct values for the tool parameters. Your specific tasks are:
47
  1. Make one or more function/tool calls to meet the request based on the question.
48
  2. If none of the function can be used, point it out and refuse to answer.
49
  3. If the given question lacks the parameters required by the function, also point it out.
50
  """
51
+
52
  FORMAT_INSTRUCTION = """
53
  The output MUST strictly adhere to the following JSON format, and NO other text MUST be included.
54
  The example format is as follows. Please make sure the parameter type is correct. If no function call is needed, please directly output an empty list '[]'
 
59
  ]
60
  ```
61
  """
62
+
63
  # Define the input query and available tools
64
  query = "Where can I find live giveaways for beta access and games? And what's the weather like in New York, US?"
65
+
66
  live_giveaways_by_type = {
67
  "name": "live_giveaways_by_type",
68
  "description": "Retrieve live giveaways from the GamerPower API based on the specified type.",
 
106
  "required": ["ticker"]
107
  }
108
  }
109
+
110
  def convert_to_format_tool(tools):
111
  ''''''
112
  if isinstance(tools, dict):
 
139
  openai_format_tools = [live_giveaways_by_type, get_current_weather,get_stock_price]
140
  format_tools = convert_to_format_tool(openai_format_tools)
141
  content = build_prompt(TASK_INSTRUCTION, FORMAT_INSTRUCTION, format_tools, query)
142
+
143
  messages=[
144
  { 'role': 'user', 'content': content}
145
  ]
146
  inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
147
+
148
  # tokenizer.eos_token_id is the id of <|EOT|> token
149
  outputs = model.generate(inputs, max_new_tokens=512, do_sample=False, num_return_sequences=1, eos_token_id=tokenizer.eos_token_id)
150
  print(tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True))