nehcgs commited on
Commit
23cb52c
·
verified ·
1 Parent(s): 03d128c

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +326 -0
README.md ADDED
@@ -0,0 +1,326 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ license_name: katanemo-research
4
+ license_link: >-
5
+ https://huggingface.co/katanemolabs/Arch-Function-Calling-1.5B/blob/main/LICENSE
6
+ base_model:
7
+ - Qwen/Qwen2.5-1.5B-Instruct
8
+ ---
9
+
10
+ # Katanemo/Arch-Function-Calling-1.5B
11
+
12
+ ## Overview
13
+ The Katanemo Arch-Function-Calling collection of large language models (LLMs) is a collection state-of-the-art (SOTA) LLMs specifically designed for **function calling** tasks. The models are designed to understand complex function signatures, identify required parameters, and produce accurate function call outputs based on natural language prompts. Achieving performance on par with GPT-4, these models set a new benchmark in the domain of function-oriented tasks, making them suitable for scenarios where automated API interaction and function execution is crucial.
14
+
15
+ In summary, the Katanemo Arch-Function-Calling collection demonstrates:
16
+ - **State-of-the-art performance** in function calling
17
+ - **Accurate parameter identification and suggestion**, even in ambiguous or incomplete inputs
18
+ - **High generalization** across multiple function calling use cases, from API interactions to automated backend tasks.
19
+ - Optimized **low-latency, high-throughput** performance, making it suitable for real-time, production environments.
20
+
21
+
22
+ ## Key Features
23
+ <table>
24
+ <tr style="text-align: left; vertical-align: middle; font-weight: bold;">
25
+ <td>Functionality</td>
26
+ <td>Definition</td>
27
+ </tr>
28
+ <tr style="text-left: left; vertical-align: middle;">
29
+ <td>Single Function Calling</td>
30
+ <td>Call only one function per user query </td>
31
+ </tr>
32
+ <tr style="text-left: left; vertical-align: middle;">
33
+ <td>Parallel Function Calling</td>
34
+ <td>Call the same function multiple times but with different set of parameter values</td>
35
+ </tr>
36
+ <tr style="text-left: left; vertical-align: middle;">
37
+ <td>Multiple Function Calling</td>
38
+ <td>Call different functions per user query</td>
39
+ </tr>
40
+ <tr style="text-left: left; vertical-align: middle;">
41
+ <td>Parallel & Multiple</td>
42
+ <td>Perform both parallel and multiple function calling</td>
43
+ </tr>
44
+ </table>
45
+
46
+
47
+ ## Training Details
48
+ Katanemo Arch-Function-Calling collection is built on top of the [Qwen 2.5](https://huggingface.co/collections/Qwen/qwen25-66e81a666513e518adb90d9e). A blog with technical details leading to our models will be published soon.
49
+
50
+
51
+ ## Performance Benchmarks
52
+ We evaluate Katanemo Arch-Function-Calling series on the [Berkeley Function-Calling Leaderboard (BFCL)](https://gorilla.cs.berkeley.edu/leaderboard.html#leaderboard). For each model family, we select the one with the highest rank. The results are shwon below:
53
+
54
+ <table>
55
+ <tr style="text-align: center; vertical-align: middle; font-weight: bold;">
56
+ <td rowspan=2>Rank</td>
57
+ <td rowspan=2>Model</td>
58
+ <td rowspan=2>Overall</td>
59
+ <td colspan=3>Single Turn</td>
60
+ <td rowspan=1>Multi Turn</td>
61
+ <td colspan=2>Hallucination</td>
62
+ </tr>
63
+ <tr style="text-align: center; vertical-align: middle; font-weight: bold;">
64
+ <td>Non-live (AST)</td>
65
+ <td>Non-live (Exec)</td>
66
+ <td>Live (AST)</td>
67
+ <td>Overall</td>
68
+ <td>Relevance</td>
69
+ <td>Irrelevance</td>
70
+ </tr>
71
+ <tr style="text-align: center; vertical-align: middle;">
72
+ <td>1</td>
73
+ <td>GPT-4-turbo-2024-04-09</td>
74
+ <td>59.49%</td>
75
+ <td>82.65%</td>
76
+ <td>83.80%</td>
77
+ <td>73.39%</td>
78
+ <td>21.62%</td>
79
+ <td>70.73%</td>
80
+ <td>79.79%</td>
81
+ </tr>
82
+ <tr style="text-align: center; vertical-align: middle;">
83
+ <td>3</td>
84
+ <td>xLAM-8x22b-r</td>
85
+ <td>59.13%</td>
86
+ <td>89.75%</td>
87
+ <td>89.32%</td>
88
+ <td>72.81%</td>
89
+ <td>15.62%</td>
90
+ <td>97.56%</td>
91
+ <td>75.23%</td>
92
+ </tr>
93
+ <tr style="text-align: center; vertical-align: middle; font-weight: bold;">
94
+ <td> </td>
95
+ <td>Arch-Function-Calling-7B</td>
96
+ <td>57.48%</td>
97
+ <td>87.50%</td>
98
+ <td>86.80%</td>
99
+ <td>72.19%</td>
100
+ <td>13.75%</td>
101
+ <td>82.93%</td>
102
+ <td>79.54%</td>
103
+ </tr>
104
+ <tr style="text-align: center; vertical-align: middle; font-weight: bold;">
105
+ <td> </td>
106
+ <td>Arch-Function-Calling-3B</td>
107
+ <td>56.23%</td>
108
+ <td>85.10%</td>
109
+ <td>89.16%</td>
110
+ <td>70.72%</td>
111
+ <td>12.28%</td>
112
+ <td>90.24%</td>
113
+ <td>73.98%</td>
114
+ </tr>
115
+ <tr style="text-align: center; vertical-align: middle;">
116
+ <td>7</td>
117
+ <td>mistral-large-2407</td>
118
+ <td>55.82%</td>
119
+ <td>84.12%</td>
120
+ <td>83.09%</td>
121
+ <td>67.17%</td>
122
+ <td>20.50%</td>
123
+ <td>78.05%</td>
124
+ <td>48.93%</td>
125
+ </tr>
126
+ <tr style="text-align: center; vertical-align: middle;">
127
+ <td>9</td>
128
+ <td>Claude-3.5-Sonnet-20240620</td>
129
+ <td>54.83%</td>
130
+ <td>70.35%</td>
131
+ <td>66.34%</td>
132
+ <td>71.39%</td>
133
+ <td>23.5%</td>
134
+ <td>63.41%</td>
135
+ <td>75.91%</td>
136
+ </tr>
137
+ </tr>
138
+ <tr style="text-align: center; vertical-align: middle; font-weight: bold;">
139
+ <td> </td>
140
+ <td>Arch-Function-Calling-1.5B</td>
141
+ <td>53.61%</td>
142
+ <td>82.60%</td>
143
+ <td>87.36%</td>
144
+ <td>68.19%</td>
145
+ <td>8.62%</td>
146
+ <td>87.80%</td>
147
+ <td>75.90%</td>
148
+ </tr>
149
+ <tr style="text-align: center; vertical-align: middle;">
150
+ <td>11</td>
151
+ <td>o1-mini-2024-09-12</td>
152
+ <td>53.43%</td>
153
+ <td>75.48%</td>
154
+ <td>76.86%</td>
155
+ <td>71.17%</td>
156
+ <td>11.00%</td>
157
+ <td>46.34%</td>
158
+ <td>88.07%</td>
159
+ </tr>
160
+ <tr style="text-align: center; vertical-align: middle;">
161
+ <td>12</td>
162
+ <td>Gemini-1.5-Flash-Preview-0514</td>
163
+ <td>53.01%</td>
164
+ <td>77.10%</td>
165
+ <td>71.23%</td>
166
+ <td>71.17%</td>
167
+ <td>13.12%</td>
168
+ <td>60.98%</td>
169
+ <td>76.15%</td>
170
+ </tr>
171
+ </table>
172
+
173
+
174
+ # Requirements
175
+ The code of Arch-Function-Calling-1.5B has been in the latest Hugging face transformers and we advise you to install install the `transformers` library:
176
+ ```bash
177
+ pip install transformers>=4.37.0
178
+ ```
179
+
180
+
181
+ # How to use
182
+ We use the following example to illustrate how to use our model to perform function calling tasks. Please note that, our model works best with our provided prompt format. It allows us to extract JSON output that is similar to the [function-calling mode of ChatGPT](https://platform.openai.com/docs/guides/function-calling).
183
+
184
+
185
+ ### Single Turn Example
186
+ ````python
187
+ import json
188
+ from typing import Any, Dict, List
189
+ from transformers import AutoModelForCausalLM, AutoTokenizer
190
+
191
+ model_name = "katanemolabs/Arch-Function-Calling-1.5B"
192
+ model = AutoModelForCausalLM.from_pretrained(
193
+ model_name, device_map="auto", torch_dtype="auto", trust_remote_code=True
194
+ )
195
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
196
+
197
+ # Please use our provided prompt for best performance
198
+ TASK_PROMPT = """
199
+ You are a helpful assistant.
200
+ """.strip()
201
+
202
+ TOOL_PROMPT = """
203
+ # Tools
204
+
205
+ You may call one or more functions to assist with the user query.
206
+
207
+ You are provided with function signatures within <tools></tools> XML tags:
208
+ <tools>
209
+ {tool_text}
210
+ </tools>
211
+ """.strip()
212
+
213
+ FORMAT_PROMPT = """
214
+ For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
215
+ <tool_call>
216
+ {"name": <function-name>, "arguments": <args-json-object>}
217
+ </tool_call>
218
+ """.strip()
219
+
220
+ # Define available tools
221
+ get_weather_api = {
222
+ "type": "function",
223
+ "function": {
224
+ "name": "get_weather",
225
+ "description": "Get the current weather for a location",
226
+ "parameters": {
227
+ "type": "object",
228
+ "properties": {
229
+ "location": {
230
+ "type": "str",
231
+ "description": "The city and state, e.g. San Francisco, New York",
232
+ },
233
+ "unit": {
234
+ "type": "str",
235
+ "enum": ["celsius", "fahrenheit"],
236
+ "description": "The unit of temperature to return",
237
+ },
238
+ },
239
+ "required": ["location"],
240
+ },
241
+ },
242
+ }
243
+
244
+ openai_format_tools = [get_weather_api]
245
+
246
+
247
+ def convert_tools(tools: List[Dict[str, Any]]):
248
+ return "\n".join([json.dumps(tool) for tool in tools])
249
+
250
+ # Helper function to create the system prompt for our model
251
+ def format_prompt(tools: List[Dict[str, Any]]):
252
+ tool_text = convert_tools(tools)
253
+
254
+ return (
255
+ TASK_PROMPT
256
+ + "\n\n"
257
+ + TOOL_PROMPT.format(tool_text=tool_text)
258
+ + "\n\n"
259
+ + FORMAT_PROMPT
260
+ + "\n"
261
+ )
262
+
263
+
264
+ system_prompt = format_prompt(openai_format_tools)
265
+
266
+ messages = [
267
+ {"role": "system", "content": system_prompt},
268
+ {"role": "user", "content": "What is the weather in Seattle?"},
269
+ ]
270
+
271
+ inputs = tokenizer.apply_chat_template(
272
+ messages, add_generation_prompt=True, return_tensors="pt"
273
+ ).to(model.device)
274
+
275
+ # tokenizer.eos_token_id is the id of <|EOT|> token
276
+ outputs = model.generate(
277
+ inputs,
278
+ max_new_tokens=512,
279
+ do_sample=False,
280
+ num_return_sequences=1,
281
+ eos_token_id=tokenizer.eos_token_id,
282
+ )
283
+
284
+ response = tokenizer.decode(outputs[0][len(inputs[0]) :], skip_special_tokens=True)
285
+ print(response)
286
+ ````
287
+
288
+ Then you should be able to see the following output string in JSON format:
289
+ ````python
290
+ <tool_call>
291
+ {"name": "get_weather", "arguments": {"location": "Seattle"}}
292
+ </tool_call>
293
+ ````
294
+
295
+ ### Multi Turn Example
296
+ Upon getting results from functions, you can add it to the `messages` list as a `user` message and pass it to the model to get responses for users.
297
+
298
+ ````python
299
+ # Suppose we receive the following result from the function:
300
+ get_weather_api_result = {'name': 'get_weather', 'results': {'temperature': '62°', 'unit': 'fahrenheit'}}
301
+ execution_results = [get_weather_api_result]
302
+
303
+ def add_execution_results(messages: List[Dict[str, Any]], execution_results: List[Dict[str, Any]]):
304
+ content = "\n".join([f"<tool_response>\n{json.dumps(result)}</tool_response>" for result in execution_results])
305
+ messages.append({"role": "user", "content": content})
306
+ return messages
307
+
308
+ messages = add_execution_results(messages, execution_results)
309
+
310
+ inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
311
+
312
+ outputs = model.generate(
313
+ inputs,
314
+ max_new_tokens=512,
315
+ do_sample=False,
316
+ num_return_sequences=1,
317
+ eos_token_id=tokenizer.eos_token_id,
318
+ )
319
+
320
+ response = tokenizer.decode(outputs[0][len(inputs[0]) :], skip_special_tokens=True)
321
+ print(response)
322
+ ````
323
+
324
+
325
+ # License
326
+ Katanemo Arch-Function-Calling collection is distributed under the [Katanemo license](https://huggingface.co/katanemolabs/Arch-Function-Calling-1.5B/blob/main/LICENSE).