Giter VIP home page Giter VIP logo

toolalpaca's Introduction

ToolAlpaca: Generalized Tool Learning for Language Models with 3000 Simulated Cases

arXiv

ToolAlpaca is a framework designed for learning generalized tool-use abilities in compact language models with minimal human supervision. It addresses the challenge of tool learning by generating a tool-use corpus via a multi-agent simulation environment, providing 3.9k tool-use instances from more than 400 tools.

Data

Dataset list:

  • train_data.json: training data with 400+ APIs
  • eval_simulated.json: evaluation data with 10 simulated APIs
  • eval_real.json: evaluation data with 11 real APIs, some APIs require authentication.

Data format:

{
  "Name": "name, from public-apis",
  "Description": "description, from public-apis",
  "Category": "category, from public-apis",
  "Introduction": "introduction, generated by LLM",
  "Functions": "NLDocumentation in paper v1, generated by LLM",
  "Documentation": "str(json), OpenAPI Specification documentation, generated by LLM",
  "NLDocumentation": "natural language documentation, similar to Functions, converted from Documentation",
  "Function_Description": "each functions description in NLDocumentation",
  "Function_Projection": "function to HTTP request method",
  "Instructions": "instructions, generated by LLM",
  "Instances": [
    {
      "input": "use's init instruction, from use agent",
      "output": "final output, from assistant agent",
      "Final Thought": "the final thought before output, from assistant agent",
      "intermediate_steps": [
        [
          [
            "action, from assistant agent",
            "action input, str(json), from assistant agent",
            "thought + action + action input, assistant agent's output"
          ]
          "bbservation, from [user agent, type check python code, tool executor agent]"
        ]
      ]
    }
  ]
}

Dataset Generation

  • download public-api data
python tool_maker/preprocess_public_apis.py -api data/public_apis.json
  • toolset construction
export PYTHONPATH=$PYTHONPAT:$(pwd)
export OPENAI_API_KEY=""

python tool_maker/get_elements.py -api data/public_apis.json -out ./data

python tool_maker/natural_language_documentation.py -api ./data/api_data.json
  • tool-use instances generation
python instance_generation/instruction.py -api ./data/api_data.json -out ./data

python instance_generation/simulator.py -api ./data/api_data.json

python instance_generation/generation.py -api ./data/api_data.json -out ./data --use_cache

Train

To train Toolapaca, we need to create a prompt to organize the dataset in a format that the standard SFT training code can read, similar to what is done in build_dataset.py. Afterward, we can proceed with training using the standard SFT method, only optimizing the loss on thought, action, and action input.

You can Find our models on huggingface hub: ToolAlpaca-7B, ToolAlpaca-13B.

Evaluation

  • for simulated APIs:
# start the api simulator
python instance_generation/simulator.py -api ./data/eval_simulated.json

# get LLM outputs
python instance_generation/generation.py \
  -api ./data/eval_simulated.json \
  -out ./eval \
  -llm TangQiaoYu/ToolAlpaca-13B \
  --agent_prompt test_v2 \
  --use_cache

# evaluation with LLM like GPT-4
python evaluation.py -api ${api_data_path} -out ./eval
  • for real APIs: You should register the websites and get the API_KEYs.
python instance_generation/generation.py \
  -api ./data/eval_real.json \
  -out ./data \
  -llm TangQiaoYu/ToolAlpaca-13B \
  --agent_prompt test_v2 \
  --real

python evaluation.py -api ${api_data_path} -out ./eval

Citation

If you find our work helpful, please cite as

@misc{tang2023toolalpaca,
      title={ToolAlpaca: Generalized Tool Learning for Language Models with 3000 Simulated Cases}, 
      author={Qiaoyu Tang and Ziliang Deng and Hongyu Lin and Xianpei Han and Qiao Liang and Le Sun},
      year={2023},
      eprint={2306.05301},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}

toolalpaca's People

Contributors

tangqiaoyu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.