Gemma-1.1-2B-IT is the result of post-training on the base model google/gemma-1.1-2b-it. This model is designed for high performance in various instruction-following tasks and complex interactions, including multi-turn function calling and detailed conversations.
Training Data
The model underwent additional training on a proprietary dataset encompassing diverse instruction-following, chat, and function calling data. This post-training process enhances the model's ability to integrate tools and manage complex interaction scenarios effectively.
How to Use
To use the model with the Hugging Face transformers and the rubra library rubra-tools, follow these steps:
Here we use 4 functions for a simple math chaining question:
python
1functions =[2{3'type':'function',4'function':{5'name':'addition',6'description':"Adds two numbers together",7'parameters':{8'type':'object',9'properties':{10'a':{11'description':'First number to add',12'type':'string'13},14'b':{15'description':'Second number to add',16'type':'string'17}18},19'required':[]20}21}22},23{24'type':'function',25'function':{26'name':'subtraction',27'description':"Subtracts two numbers",28'parameters':{29'type':'object',30'properties':{31'a':{32'description':'First number to be subtracted from',33'type':'string'34},35'b':{36'description':'Number to subtract',37'type':'string'38}39},40'required':[]41}42}43},44{45'type':'function',46'function':{47'name':'multiplication',48'description':"Multiply two numbers together",49'parameters':{50'type':'object',51'properties':{52'a':{53'description':'First number to multiply',54'type':'string'55},56'b':{57'description':'Second number to multiply',58'type':'string'59}60},61'required':[]62}63}64},65{66'type':'function',67'function':{68'name':'division',69'description':"Divide two numbers",70'parameters':{71'type':'object',72'properties':{73'a':{74'description':'First number to use as the dividend',75'type':'string'76},77'b':{78'description':'Second number to use as the divisor',79'type':'string'80}81},82'required':[]83}84}85},86]
3. Start the conversation
python
1messages =[2{"role":"system","content":"You are a helpful assistant."},3{"role":"user","content":"What is the result of four plus six? Take the result and add 2? Then multiply by 5 and then divide by two"},4]56defrun_model(messages, functions):7## Format messages in Rubra's format8 formatted_msgs = preprocess_input(msgs=messages, tools=functions)910 input_ids = tokenizer.apply_chat_template(11 formatted_msgs,12 add_generation_prompt=True,13 return_tensors="pt"14).to(model.device)1516 terminators =[17 tokenizer.eos_token_id,18 tokenizer.convert_tokens_to_ids("")19]2021 outputs = model.generate(22 input_ids,23 max_new_tokens=1000,24 eos_token_id=terminators,25 do_sample=True,26 temperature=0.1,27 top_p=0.9,28)29 response = outputs[0][input_ids.shape[-1]:]30 raw_output = tokenizer.decode(response, skip_special_tokens=True)31return raw_output
3233raw_output = run_model(messages, functions)34# Check if there's a function call35function_call = postprocess_output(raw_output)36if function_call:37print(function_call)38else:39print(raw_output)
You should see this output, which is a function call made by the AI assistant:
4. Add Executed Tool Result to Message History & Continue the Conversation
python
1if function_call:2# append the assistant tool call msg3 messages.append({"role":"assistant","tool_calls": function_call})4# append the result of the tool call in openai format, in this case, the value of add 6 to 4 is 10.5 messages.append({'role':'tool','tool_call_id': function_call[0]["id"],'name': function_call[0]["function"]["name"],'content':'10'})6 raw_output = run_model(messages, functions)7# Check if there's a function call8 function_call = postprocess_output(raw_output)9if function_call:10print(function_call)11else:12print(raw_output)
While the model performs well on a wide range of tasks, it may still produce biased or incorrect outputs. Users should exercise caution and critical judgment when using the model in sensitive or high-stakes applications. The model's outputs are influenced by the data it was trained on, which may contain inherent biases.
Ethical Considerations
Users should ensure that the deployment of this model adheres to ethical guidelines and consider the potential societal impact of the generated text. Misuse of the model for generating harmful or misleading content is strongly discouraged.
Acknowledgements
We would like to thank Google for the model.
Contact Information
For questions or comments about the model, please reach out to the rubra team.
Citation
If you use this work, please cite it as:
@misc {rubra_ai_2024,
author = { Sanjay Nadhavajhala and Yingbei Tong },
title = { Rubra-Gemma-1.1-2B-IT },
year = 2024,
url = { https://huggingface.co/rubra-ai/gemma-1.1-2b-it },
doi = { 10.57967/hf/2681 },
publisher = { Hugging Face }
}