KishoreK commited on
Commit
3a96d48
1 Parent(s): 34047de

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +130 -4
README.md CHANGED
@@ -1,16 +1,25 @@
1
  ---
2
  library_name: transformers
3
- tags: []
 
 
 
 
 
 
4
  ---
5
 
6
  # Model Card for Model ID
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
9
-
10
 
11
 
12
  ## Model Details
13
 
 
 
 
14
  ### Model Description
15
 
16
  <!-- Provide a longer summary of what this model is. -->
@@ -40,7 +49,124 @@ This is the model card of a 🤗 transformers model that has been pushed on the
40
  ### Direct Use
41
 
42
  <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  [More Information Needed]
45
 
46
  ### Downstream Use [optional]
 
1
  ---
2
  library_name: transformers
3
+ tags:
4
+ - LAM
5
+ - tooluse
6
+ - function calling
7
+ license: mit
8
+ datasets:
9
+ - Salesforce/xlam-function-calling-60k
10
  ---
11
 
12
  # Model Card for Model ID
13
 
14
+ ActionGemma is a LargeActionModel inspired from Salesforce/xLAM and trained on it's dataset. this is a combination of multi-lingual capabilities of Gemma with Function calling capabilites from xLAM dataset
15
+ Now you have a Action /function calling Model for all the languages supported by gemma2
16
 
17
 
18
  ## Model Details
19
 
20
+ Base Model : Gemma2-9B-it
21
+ Fine-Tuned on : xLAM dataset
22
+
23
  ### Model Description
24
 
25
  <!-- Provide a longer summary of what this model is. -->
 
49
  ### Direct Use
50
 
51
  <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
52
+ tokenizer in built have a chat template as follows
53
+ ```
54
+ tokenizer = AutoTokenizer.from_pretrained("KishoreK/ActionGemma-9B")
55
+ tokenizer.chat_template = """{{ bos_token }}
56
+ {% for message in messages %}
57
+ {% if message['role'] == 'tools' %}
58
+ {{ '<unused0>\n' + message['content'] + '<unused1>\n'}}
59
+ {% else %}
60
+ {{ '<start_of_turn>' + message['role'] + '\n' + message['content'] | trim + '<end_of_turn>\n' }}
61
+ {% endif %}
62
+ {% endfor %}
63
+
64
+ {% if add_generation_prompt %}
65
+ {{ '<start_of_turn>assistant\n' }}
66
+ {% endif %}
67
+ """
68
+ ```
69
+ you can utilise this or modify based on this syntax.
70
+
71
+ ```
72
+ task_instruction = """
73
+ You are an expert in composing functions. You are given a question and a set of possible functions.
74
+ Based on the question, you will need to make one or more function/tool calls to achieve the purpose.
75
+ If none of the functions can be used, point it out and refuse to answer.
76
+ If the given question lacks the parameters required by the function, also point it out.
77
+ """.strip()
78
+
79
+ get_weather_api = {
80
+ "name": "get_weather",
81
+ "description": "Get the current weather for a location",
82
+ "parameters": {
83
+ "type": "object",
84
+ "properties": {
85
+ "location": {
86
+ "type": "string",
87
+ "description": "The city and state, e.g. San Francisco, New York"
88
+ },
89
+ "unit": {
90
+ "type": "string",
91
+ "enum": ["celsius", "fahrenheit"],
92
+ "description": "The unit of temperature to return"
93
+ }
94
+ },
95
+ "required": ["location"]
96
+ }
97
+ }
98
+
99
+ search_api = {
100
+ "name": "search",
101
+ "description": "Search for information on the internet",
102
+ "parameters": {
103
+ "type": "object",
104
+ "properties": {
105
+ "query": {
106
+ "type": "string",
107
+ "description": "The search query, e.g. 'latest news on AI'"
108
+ }
109
+ },
110
+ "required": ["query"]
111
+ }
112
+ }
113
+
114
+ openai_format_tools = [get_weather_api, search_api]
115
+
116
+ def convert_to_xlam_tool(tools):
117
+ ''''''
118
+ if isinstance(tools, dict):
119
+ return {
120
+ "name": tools["name"],
121
+ "description": tools["description"],
122
+ "parameters": {k: v for k, v in tools["parameters"].get("properties", {}).items()}
123
+ }
124
+ elif isinstance(tools, list):
125
+ return [convert_to_xlam_tool(tool) for tool in tools]
126
+ else:
127
+ return tools
128
+
129
+ user_query = "अमेरिका के राष्ट्रपति कौन है?"
130
+ tools = openai_format_tools
131
+ messages = [{
132
+ "role" : "system",
133
+ "content" : task_instruction
134
+ },{
135
+ "role" : "user",
136
+ "content" : user_query
137
+ },{
138
+ "role": "tools",
139
+ "content": json.dumps(convert_to_xlam_tool(tools))
140
+ }]
141
+
142
+ print(tokenizer.decode(tokenizer.apply_chat_template(messages, add_generation_prompt=True)))
143
+ ```
144
+
145
+ sample response from applied chat template
146
+ ```
147
+ <bos>
148
+ <start_of_turn>system
149
+ You are an expert in composing functions. You are given a question and a set of possible functions.
150
+ Based on the question, you will need to make one or more function/tool calls to achieve the purpose.
151
+ If none of the functions can be used, point it out and refuse to answer.
152
+ If the given question lacks the parameters required by the function, also point it out.<end_of_turn>
153
+
154
+ <start_of_turn>user
155
+ अमेरिका के राष्ट्रपति कौन है?<end_of_turn>
156
+
157
+ <unused0>
158
+ [{"name": "get_weather", "description": "Get the current weather for a location", "parameters": {"location": {"type": "string", "description": "The city and state, e.g. San Francisco, New York"}, "unit": {"type": "string", "enum": ["celsius", "fahrenheit"], "description": "The unit of temperature to return"}}}, {"name": "search", "description": "Search for information on the internet", "parameters": {"query": {"type": "string", "description": "The search query, e.g. 'latest news on AI'"}}}]<unused1>
159
+
160
+
161
+ <start_of_turn>assistant
162
+ ```
163
+ invoking model with this prompt
164
+ ```
165
+ model = AutoModelForCausalLM.from_pretrained("KishoreK/ActionGemma-9B", use_cache=True)
166
+ outputs = model.generate(inputs, max_new_tokens=512, do_sample=False, num_return_sequences=1, eos_token_id=tokenizer.eos_token_id)
167
+ print(tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True))
168
+ ```
169
+ chat template, inference are referenced from xLAM documentation.
170
  [More Information Needed]
171
 
172
  ### Downstream Use [optional]