datadabllp

few-shot learning

Aug 26th, 2024
631
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. def few_shot_learning(llm_agent, task, examples, new_input):
  2.     prompt = f"Task: {task}\n\nExamples:\n"
  3.     for example in examples:
  4.         prompt += f"Input: {example['input']}\nOutput: {example['output']}\n\n"
  5.     prompt += f"Now, given this new input: {new_input}\nOutput:"
  6.    
  7.     return llm_agent.generate(prompt)
  8.  
  9. # Usage
  10. task = "Translate English to French"
  11. examples = [
  12.     {"input": "Hello", "output": "Bonjour"},
  13.     {"input": "How are you?", "output": "Comment allez-vous?"}
  14. ]
  15. new_input = "Good morning"
  16.  
  17. result = few_shot_learning(my_llm_agent, task, examples, new_input)
  18. print(result)  # Expected output: "Bonjour"
  19.  
Advertisement
Add Comment
Please, Sign In to add comment