TL-CodeLLaMA-2 / README.md
nielsr's picture
nielsr HF Staff
Add pipeline tag, library name, and GitHub link
2c9ac07 verified
|
raw
history blame
5.58 kB
metadata
base_model:
  - codellama/CodeLlama-7b-hf
language:
  - en
license: apache-2.0
library_name: transformers
pipeline_tag: text-generation

TL-CodeLLaMA-2

TL-CodeLLaMA-2 is a model designed for tool use, built upon CodeLLaMA-7b. It is trained on 1,217 data samples using the TL-Training framework and demonstrates effective performance across a variety of tool use tasks. More information can be found in the paper "TL-Training: A Task-Feature-Based Framework for Training Large Language Models in Tool Use".

Code: https://github.com/Junjie-Ye/TL-Training

Model Use

Requirements

To use this model, please make sure to install transformers:

pip install transformers

Data Orgnization

The data needs to be organized in the following format:

[
    {
        "role": "System",
        "content": "Function:
def random_advice():
    \"\"\"
    Returns a random advice slip as a slip object.
    \"\"\"

Function:
def advice_by_id(slip_id:str):
    \"\"\"
    If an advice slip is found with the corresponding {slip_id}, a slip object is returned.

    Args:
        slip_id (string): The unique ID of this advice slip.
    \"\"\"

Function:
def search_advice(query:str):
    \"\"\"
    If an advice slip is found, containing the corresponding search term in {query}, an array of slip objects is returned inside a search object.

    Args:
        query (string): The search query provided.
    \"\"\"

Function:
def ask_to_user(question:str):
    \"\"\"
    You can ask user for guidance when you think you need more information to handle the task, but you should use this tool as less as you can.

    Args:
        question (string): The question you want to ask to user.
    \"\"\"

Function:
def finish(answer:str):
    \"\"\"
    Finish the task and give your answer.

    Args:
        answer (string): Your answer for the task.
    \"\"\"

"
    },
    {
        "role": "User",
        "content": "Could you give me some advice about 'love'?"
    },
    {
        "role": "Assistant",
        "content": "search_advice(query = 'love') "
    },
    {
        "role": "Output",
        "content": "..."
    }
]

Chat Template

The chat template is:

{% for message in messages %}{{message['role'] + ': ' + message['content']}}{% if loop.last %}{% if add_generation_prompt %}{{ '
Assistant:' }}{% else %}{{ '</s>'}}{% endif %}{% else %}{{ '
' }}{% endif %}{% endfor %}

Inference

from transformers import AutoModelForCausalLM, AutoTokenizer

model_path = "Junjie-Ye/TL-CodeLLaMA-2"

data = [
    {
        "role": "System",
        "content": "Function:
def random_advice():
    \"\"\"
    Returns a random advice slip as a slip object.
    \"\"\"

Function:
def advice_by_id(slip_id:str):
    \"\"\"
    If an advice slip is found with the corresponding {slip_id}, a slip object is returned.

    Args:
        slip_id (string): The unique ID of this advice slip.
    \"\"\"

Function:
def search_advice(query:str):
    \"\"\"
    If an advice slip is found, containing the corresponding search term in {query}, an array of slip objects is returned inside a search object.

    Args:
        query (string): The search query provided.
    \"\"\"

Function:
def ask_to_user(question:str):
    \"\"\"
    You can ask user for guidance when you think you need more information to handle the task, but you should use this tool as less as you can.

    Args:
        question (string): The question you want to ask to user.
    \"\"\"

Function:
def finish(answer:str):
    \"\"\"
    Finish the task and give your answer.

    Args:
        answer (string): Your answer for the task.
    \"\"\"

"
    },
    {
        "role": "User",
        "content": "Could you give me some advice about 'love'?"
    }
]

chat_template = "{% for message in messages %}{{message['role'] + ': ' + message['content']}}{% if loop.last %}{% if add_generation_prompt %}{{ '
Assistant:' }}{% else %}{{ '</s>'}}{% endif %}{% else %}{{ '
' }}{% endif %}{% endfor %}"

model = AutoModelForCausalLM.from_pretrained(
    model_path,
    torch_dtype="auto",
    device_map="auto",
    trust_remote_code=True
).eval()

tokenizer = AutoTokenizer.from_pretrained(model_path,
                                            padding_side="left",
                                            trust_remote_code=True)
if tokenizer.pad_token_id is None:
    tokenizer.pad_token_id = tokenizer.eos_token_id

text = tokenizer.apply_chat_template(
        data,
        tokenize=False,
        chat_template=chat_template,
        add_generation_prompt=add_generation_prompt
    )
model_inputs = tokenizer(
    [text], return_tensors="pt", padding=True).to("cuda")

generated_ids = model.generate(
    max_new_tokens=1024,
    **model_inputs,
)
generated_ids = [
    output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)

print(response)

Citation

If you find this model useful in your research, please cite:

@misc{TL-Training,
      title={TL-Training: A Task-Feature-Based Framework for Training Large Language Models in Tool Use}, 
      author={Junjie Ye and Yilong Wu and Sixian Li and Yuming Yang and Tao Gui and Qi Zhang and Xuanjing Huang and Peng Wang and Zhongchao Shi and Jianping Fan and Zhengyin Du},
      year={2024},
      eprint={2412.15495},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2412.15495}, 
}