2

Here is my script:

from transformers import AutoTokenizer, AutoModelForCausalLM   

tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-chat-hf")
model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-2-7b-chat-hf")

prompt = """
A message can be classified as one of the following categories: book, cancel, change.

Based on these categories, classify this message:
I would like to cancel my booking and ask for a refund.
"""

input_ids = tokenizer(prompt, return_tensors="pt").input_ids
outputs = model.generate(input_ids, max_new_tokens=200)
print(tokenizer.decode(outputs[0]))

Here is the output:

<s> 
A message can be classified as one of the following categories: book, cancel, change.

Based on these categories, classify this message:
I would like to cancel my booking and ask for a refund.

Please select one of the following options:

book
cancel
change</s>

I would like to know how to design a prompt so that Llama-2 can give me "cancel" as the answer.

1 Answer 1

2

you can just add category examples, the more the merrier. 'tis like so:

prompt = """
A message can be classified as one of the following categories: book, cancel, change.

Examples:
- Book: "I would like to book a room for two nights."
- Cancel: "Please cancel my reservation and refund the payment."
- Change: "I need to change the dates of my booking to next week."

Based on these categories, classify this message:
"I would like to cancel my booking and ask for a refund."
"""

make the examples fine-tuned to your business or w/e.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.