[Paper Review] Octopus: On-device language model for function calling of software APIs
This paper introduces Octopus, a family of on-device 2B, 3B, and 7B parameter language models fine-tuned on 30,000+ software APIs to improve accuracy in function calling. By leveraging curriculum learning, dataset curation, and a novel conditional masking technique during inference, Octopus achieves higher accuracy than GPT-4 in API function calling while maintaining low latency and format correctness.
In the rapidly evolving domain of artificial intelligence, Large Language Models (LLMs) play a crucial role due to their advanced text processing and generation abilities. This study introduces a new strategy aimed at harnessing on-device LLMs in invoking software APIs. We meticulously compile a dataset derived from software API documentation and apply fine-tuning to LLMs with capacities of 2B, 3B and 7B parameters, specifically to enhance their proficiency in software API interactions. Our approach concentrates on refining the models' grasp of API structures and syntax, significantly enhancing the accuracy of API function calls. Additionally, we propose extit{conditional masking} techniques to ensure outputs in the desired formats and reduce error rates while maintaining inference speeds. We also propose a novel benchmark designed to evaluate the effectiveness of LLMs in API interactions, establishing a foundation for subsequent research. Octopus, the fine-tuned model, is proved to have better performance than GPT-4 for the software APIs calling. This research aims to advance automated software development and API integration, representing substantial progress in aligning LLM capabilities with the demands of practical software engineering applications.
Motivation & Objective
- To develop a lightweight, on-device LLM capable of accurately invoking software APIs without relying on large, costly models like GPT-4.
- To address the challenge of format errors and hallucinations in LLM-generated API calls, especially in parameter selection and function name matching.
- To improve inference efficiency and output reliability through conditional masking, ensuring correct JSON-like output structure.
- To establish a new benchmark for evaluating LLMs in real-world API interaction tasks.
- To enable practical deployment of LLMs on mobile and edge devices by training compact models with high API calling accuracy.
Proposed method
- Fine-tuned 2B, 3B, and 7B parameter models (e.g., CodeLlama, Gemma, Stable Code) on a curated dataset of 30,000+ software APIs from RapidAPI Hub.
- Employed curriculum learning and negative sampling to improve model generalization and reduce confusion between similar API functions.
- Designed a conditional masking technique during inference to constrain output formats, especially for enum-type parameters, ensuring syntactic correctness.
- Used a prompt template with few-shot demonstrations and structured input to guide function and parameter selection.
- Applied greedy decoding during inference to maximize precision in function and argument prediction.
- Constructed a new benchmark with balanced solvable/unsolvable queries and human-annotated ground truth for evaluation.
Experimental results
Research questions
- RQ1Can a small, on-device LLM outperform GPT-4 in real-world software API function calling tasks?
- RQ2How effective is conditional masking in reducing format errors and hallucinations in LLM-generated API calls?
- RQ3To what extent can curriculum learning and dataset curation improve model performance on complex API selection and parameter generation?
- RQ4Can compact LLMs achieve high accuracy in API interaction while maintaining low inference latency and deployment feasibility on mobile devices?
- RQ5What is the impact of model size (2B, 3B, 7B) on API calling accuracy when fine-tuned on a diverse, real-world API dataset?
Key findings
- The Octopus 7B model outperformed GPT-4 in function calling accuracy on the proposed benchmark, achieving higher precision in both function name and parameter prediction.
- Conditional masking significantly improved output format correctness, especially for enum-type parameters, reducing validation loss without increasing inference time.
- All Octopus models demonstrated near-perfect function name accuracy, but parameter hallucinations were the primary source of errors in baseline GPT-4 outputs.
- The conditional masking technique was mathematically proven to increase accuracy by constraining output space to valid formats.
- The 7B models in the Octopus series achieved higher accuracy than GPT-4, demonstrating that smaller, task-specific models can surpass larger, general-purpose models in specialized API tasks.
- The dataset and benchmark are open-sourced, providing a foundation for future research in on-device LLMs for API interaction.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.