Gemma4-E4B-Function-Calling-xLAM
Fine-Tuning a Language Model for External Tool Use
2 min readupdated
This model is a fine-tuned version of google/gemma-4-E4B-it, trained to efficiently handle function calling (invoking functions and APIs based on text prompts). It is built on the Salesforce/xlam-function-calling-60k dataset using the QLoRA approach (an efficient fine-tuning method with quantization) within the Transformers library. The model takes a text prompt and JSON descriptions of available tools as input, then outputs a structured response invoking the required functions. This development will be useful for developers of bots, agents, and applications that require reliable integration of language models with external services.
Key features
- Specialized in function calling for integration with third-party APIs and databases.
- Trained on the 60,000-example Salesforce xlam-function-calling-60k dataset.
- The base language model was fine-tuned while preserving the original visual and audio encoders.
- Uses the QLoRA method with saving in bfloat16 format.
What you can do
- Integrate the model into a Telegram bot or web service to process user requests via external APIs.
- Automate data searches in catalogs, on websites, or through third-party interfaces using text instructions.
- Build a task management system where the AI independently selects the necessary function to execute a command.
Example
import json
from transformers import AutoModelForCausalLM, AutoTokenizer
repo = 'ermiaazarkhalili/Gemma4-E4B-Function-Calling-xLAM'
tokenizer = AutoTokenizer.from_pretrained(repo)
model = AutoModelForCausalLM.from_pretrained(repo, dtype="auto", device_map="auto")
query = 'What information can be obtained about the Maine Coon cat breed?'
prompt = '' + query + '...'
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
out = model.generate(**inputs, max_new_tokens=995, do_sample=False)
text = tokenizer.decode(out[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True)
print(text)
Read more
DetailsBase model: google/gemma-4-E4B-it
Training parameters: 1 epoch, batch size 4, lr 0.0001
Evaluation results: eval_loss 0.0152, eval_mean_token_accuracy 0.9957
Trainable parameters: 38.8 million (via LoRA)










Comments