Chain-of-thought और self-consistency प्रॉम्प्टिंग

OpenAI API के साथ Prompt Engineering

Fouad Trad

Machine Learning Engineer

Chain-of-thought प्रॉम्प्टिंग

  • उत्तर से पहले LLMs से तर्क के चरण (विचार) माँगती है
  • जटिल रीज़निंग टास्क के लिए उपयोगी
  • मॉडल की त्रुटियाँ घटाने में मदद करती है

एक इमेज जो दिखाती है कि chain-of-thought प्रॉम्प्ट मॉडल से समस्या को चरण-दर-चरण हल करने को कहता है, और आउटपुट में हर चरण की तर्क-श्रृंखला होती है।

OpenAI API के साथ Prompt Engineering

Chain-of-thought प्रॉम्प्टिंग

किसी रीज़निंग टास्क के लिए स्टैंडर्ड प्रॉम्प्टिंग
prompt = """Q: You start with 15 books in your collection. At the bookstore, you 
purchase 8 new books. Then, you lend 3 to your friend and 2 to your cousin. Later, 
you visit another bookstore and buy 5 more books. How many books do you have now? 
A: The answer is"""

print(get_response(prompt))
25 books
OpenAI API के साथ Prompt Engineering

Chain-of-thought प्रॉम्प्टिंग

किसी रीज़निंग टास्क के लिए Chain-of-thought प्रॉम्प्टिंग
prompt = """Q: You start with 15 books in your collection. At the bookstore, you 
purchase 8 new books. Then, you lend 3 to your friend and 2 to your cousin. Later, 
you visit another bookstore and buy 5 more books. How many books do you have now? 
A: Let's think step by step""" 
print(get_response(prompt))
Step 1: Start with the number of books in your collection: 15 books
Step 2: Purchase 8 new books at the bookstore: 15 + 8 = 23 books
Step 3: Lend 3 books to your friend: 23 - 3 = 20 books
Step 4: Lend 2 books to your cousin: 20 - 2 = 18 books
Step 5: Visit another bookstore and buy 5 more books: 18 + 5 = 23 books
Therefore, you have 23 books now.
OpenAI API के साथ Prompt Engineering

Few-shots के साथ Chain-of-thought प्रॉम्प्टिंग

example = """
Q: The odd numbers in this group add up to an even number:  9, 10, 13, 4, 2.
A: Adding all the odd numbers (9, 13) gives 22. The answer is True.
"""

question = """ Q: The odd numbers in this group add up to an even number: 15, 13, 82, 7. A: """
prompt = example + question print(get_response(prompt))
Adding all the odd numbers (15, 13, 7) gives 35. The answer is False.
OpenAI API के साथ Prompt Engineering

Chain-of-thought बनाम multi-step प्रॉम्प्टिंग

Multi-step प्रॉम्प्ट्स

  • चरणों को प्रॉम्प्ट के भीतर शामिल करें

डायग्राम जो दिखाता है कि multi-step प्रॉम्प्ट मॉडल को क्रमबद्ध चरणों की श्रृंखला देता है।

OpenAI API के साथ Prompt Engineering

Chain-of-thought बनाम multi-step प्रॉम्प्टिंग

Multi-step प्रॉम्प्ट्स

  • चरणों को प्रॉम्प्ट के भीतर शामिल करें

डायग्राम जो दिखाता है कि multi-step प्रॉम्प्ट मॉडल को क्रमबद्ध चरणों की श्रृंखला देता है।

Chain-of-thought प्रॉम्प्ट्स

  • मॉडल से बीच के चरण जनरेट करने को कहें

इमेज जो दिखाती है कि chain-of-thought प्रॉम्प्ट्स में, आउटपुट बनाते समय चरण मॉडल ही जनरेट करता है।

OpenAI API के साथ Prompt Engineering

Chain-of-thought की सीमा

  • एक गलत विचार --> गलत नतीजा
  • Self-consistency प्रॉम्प्ट्स पेश किए गए

एक डायग्राम जो दिखाता है कि chain-of-thought प्रॉम्प्ट में यदि किसी विचार की तर्क-श्रृंखला त्रुटिपूर्ण हो, तो नतीजा असफल हो सकता है।

OpenAI API के साथ Prompt Engineering

Self-consistency प्रॉम्प्टिंग

  • मॉडल को कई बार प्रॉम्प्ट कर कई chain-of-thoughts जनरेट करें
  • अंतिम आउटपुट के लिए मेजॉरिटी वोट लें

इमेज जो दिखाती है कि self-consistency प्रॉम्प्ट में कई chain-of-thoughts बनते हैं, हर एक का आउटपुट होता है, और अंतिम नतीजा मेजॉरिटी वोट से तय होता है।

OpenAI API के साथ Prompt Engineering

Self-consistency प्रॉम्प्टिंग

इसे multiple प्रॉम्प्ट्स बनाकर या एक प्रॉम्प्ट से multiple responses लेकर किया जा सकता है।

self_consistency_instruction = "Imagine three completely independent experts who 
reason differently are answering this question. The final answer is obtained by 
majority vote. The question is: "

problem_to_solve = "If there are 10 cars in the parking lot and 3 more cars arrive. Half the original number of cars leave. Then, half of the current number of cars arrive. How many cars are there in the parking?"
prompt = self_consistency_instruction + problem_to_solve print(get_response(prompt))
OpenAI API के साथ Prompt Engineering

Self-consistency प्रॉम्प्ट

Expert 1: Let's go step by step [...] Therefore, the total number of cars in the 
parking lot is 8 + 4 = 12.

Expert 2: First, let's calculate [...] Therefore, the total number of cars in the 
parking lot is now 5 + 2 = 7 cars.

Expert 3: Initially, there are 10 cars [...] Thus, the final answer is 8 + 4 = 12 
cars in the parking lot.

Based on the majority vote, the final answer is that there are 12 cars in the 
parking lot.
OpenAI API के साथ Prompt Engineering

अभ्यास करते हैं!

OpenAI API के साथ Prompt Engineering

Preparing Video For Download...