Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use few-shot? #1178

Open
xingchen0120 opened this issue Oct 9, 2024 · 1 comment
Open

how to use few-shot? #1178

xingchen0120 opened this issue Oct 9, 2024 · 1 comment

Comments

@xingchen0120
Copy link

Hello,I want to use the few-shot method to assist LLAMA in inference. May I ask how the input format should be set?

@adi-ydv-1
Copy link

from transformers import LLaMAForCausalLM, LLaMATokenizer

Initialize model and tokenizer

model = LLaMAForCausalLM.from_pretrained("llama-7b")
tokenizer = LLaMATokenizer.from_pretrained("llama-7b")

Define prompt, few-shot examples, and query

prompt = "Translate English to Spanish."
examples = [
"English: Hello, how are you? Spanish: Hola, ¿cómo estás?",
"English: What's your name? Spanish: ¿Cuál es tu nombre?",
]
query = "Hello, I'm John."

Format input and tokenize

input_text = f"{prompt}\n{'\n'.join(examples)}\n{query}"
inputs = tokenizer(input_text, return_tensors="pt")

Generate output

output = model.generate(**inputs)

Print output

print(tokenizer.decode(output[0], skip_special_tokens=True))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants