[अनुवाद] Claude-3 से बेहतर परिणाम पाने के लिए प्रॉम्प्ट इंजीनियरिंग रणनीतियाँ (feat. Anthropic)
(discuss.pytorch.kr)शुरुआत
पिछले साल के मध्य के आसपास मैंने OpenAI में ChatGPT मॉडल का उपयोग करते हुए बेहतर उत्तर पाने के लिए 6 prompt-writing strategies का अनुवाद और संक्षेप किया था। हाल ही में Claude-3 का भी गंभीरता से उपयोग शुरू करने के बाद देखा कि उदाहरण prompts की बारीकियों और उनके एहसास में कुछ सूक्ष्म अंतर हैं.
क्या कुछ अलग है, यह देखने के लिए संदर्भ सामग्री खोजते-खोजते मुझे Anthropic द्वारा प्रकाशित prompt engineering दस्तावेज़ मिला, जिसे मैंने मोटे तौर पर पढ़ा। इसमें OpenAI द्वारा व्यवस्थित 6 prompt-writing strategies से काफ़ी ओवरलैप दिखा, इसलिए पूरे लेख को विस्तार से समेटने के बजाय मैंने प्रतिस्पर्धी मॉडल (...) ChatGPT से इसका संक्षिप्त सार माँग लिया.
एक बार इसे देखिए, और अगर कुछ कम लगे तो OpenAI की GPT best practices: overview. बेहतर उत्तर पाने के लिए 6 prompt-writing strategies (Six strategies for getting better results) श्रृंखला के साथ Anthropic के मूल लेख को भी ज़रूर पढ़ें. :D
परिचय
यह दस्तावेज़ Claude-3 की prompt engineering strategies पर चर्चा करता है। इन strategies का उपयोग करके Claude-3 के प्रदर्शन को बेहतर बनाया जा सकता है और responses को किसी विशेष use case के अनुसार fine-tune किया जा सकता है। ये तकनीकें अनिवार्य नहीं हैं, लेकिन Claude के input और output को बेहतर बनाने में मदद कर सकती हैं.
Prompt engineering एक प्रयोगात्मक विज्ञान है, जिसमें prompts को बार-बार सुधारना और test करना शामिल है ताकि प्रदर्शन को optimize किया जा सके। यानी, prompt engineering entity extraction, question answering, text summarization जैसे कार्यों से शुरू होकर अधिक जटिल कार्यों तक पहुँचने वाली एक पुनरावृत्त विकास और मूल्यांकन प्रक्रिया है। इस प्रक्रिया में अलग-अलग test cases बनाना, शुरुआती prompt विकसित करना, मॉडल की प्रतिक्रिया का मूल्यांकन करना और फिर उसमें संशोधन करना शामिल होता है.
Claude और अन्य AI मॉडलों की तुलना में, Claude-3 इस बात से अलग नज़र आता है कि इसे किसी विशेष role में रखना या XML tags का उपयोग करना जैसी विभिन्न prompt engineering तकनीकों से इसका प्रदर्शन बेहतर किया जा सकता है। ये तकनीकें Claude को अधिक सटीक और सुसंगत output देने में मदद करती हैं.
मुख्य तकनीकें
नीचे दस्तावेज़ में बताई गई प्रमुख तकनीकें दी गई हैं:
स्पष्ट और सीधे पूछें (Be clear & direct
Claude को यह बताने के लिए कि आप किस तरह का response चाहते हैं, स्पष्ट निर्देश और context दें:
- विस्तृत context और निर्देश दें: कार्य को सही ढंग से पूरा करने के लिए Claude को जितना संभव हो उतना context और विस्तृत निर्देश देने चाहिए। उदाहरण के लिए, यदि आप उससे personal information हटाने को कह रहे हैं, तो यह स्पष्ट बताना चाहिए कि कौन-सी जानकारी किस तरह हटाई जानी है.
| Role | Prompt |
|---|---|
| User | We want to anonymize some text by removing all personally identifiable information (PII). |
Please follow these steps:
- Replace all instances of names, phone numbers, and home and email addresses with 'XXX'.
- If the text contains no PII, copy it word-for-word without replacing anything.
- Output only the processed text, without any additional commentary.
Here is the text to process: {{TEXT}}|
- संख्या वाली सूची या bullet points का उपयोग करें: जटिल कार्य-निर्देश देते समय संख्या वाली सूची या bullet points का उपयोग करके निर्देशों को अलग-अलग करना Claude को उन्हें बेहतर समझने और पालन करने में मदद करता है। उदाहरण के लिए, किसी textbook chapter को lesson plan में बदलने के निर्देश में हर चरण को स्पष्ट रूप से अलग करके लिखा जा सकता है.
| Role | Prompt |
|---|---|
| User | Your task is turn the given textbook chapter into a comprehensive lesson plan. To do this task, you should: |
- Extract and summarize key concepts by section
- Convert each extracted concept into a 30 minute lesson plan, including a list of questions to check comprehension.
- Design an accompanying homework assignment that reinforces learnings from this chapter.
Here is the chapter:
{{CHAPTER}}|
- जो चाहिए उसे ठोस रूप से लिखें: जब आप Claude से कोई स्पष्ट उत्तर या एक विशिष्ट रुख चाहते हैं, तो उसे साफ़-साफ़ लिखना चाहिए। उदाहरण के लिए, “अब तक का सबसे महान basketball player कौन है?” जैसे सवाल में आप उसे विशेष रूप से केवल एक खिलाड़ी चुनने के लिए कह सकते हैं.
| Role | Prompt |
|---|---|
| User | (खराब उदाहरण) Who is the best basketball player of all time? |
| (अच्छा उदाहरण) Who is the best basketball player of all time? Yes, there are differing opinions, but if you absolutely had to pick one player, who would it be? | |
| Assistant (Claude's response) | There is no definitive answer to who is the best basketball player of all time, as reasonable people can disagree on this. However, if forced to choose just one player, I would say Michael Jordan is most commonly considered the GOAT (Greatest Of All Time) based on his exceptional talent, championships, awards, and cultural impact on the game of basketball. But others like LeBron James, Kareem Abdul-Jabbar, Wilt Chamberlain and Bill Russell are also frequently mentioned in the debate. It's a subjective call without a clear consensus. |
- स्पष्ट prompting का स्वर्ण नियम: prompt को किसी दूसरे व्यक्ति को दिखाकर देखें कि क्या वह उसके निर्देशों के अनुसार कार्य कर सकता है। यही बात Claude पर भी लागू होती है, और इससे यह जाँचने में मदद मिलती है कि निर्देश पर्याप्त रूप से स्पष्ट हैं या नहीं.
उदाहरण दें (Use examples
जिस output format या style की आप अपेक्षा करते हैं, उसे समझाने के लिए prompt में examples शामिल करें.
-
उदाहरण क्यों उपयोग करें?: examples का उपयोग करने से Claude दिए गए निर्देशों को बेहतर समझ सकता है और वांछित output format को अधिक स्पष्ट रूप से पकड़ सकता है। इससे मॉडल अधिक सटीक और सुसंगत परिणाम उत्पन्न करने में सक्षम होता है.
-
प्रभावी examples कैसे बनाएँ: प्रभावी examples में input और अपेक्षित output स्पष्ट रूप से दिखने चाहिए। examples वास्तविक use case को दर्शाने वाले होने चाहिए और उनमें इतनी जानकारी होनी चाहिए कि Claude उनसे सीख सके.
| Role | Content |
|---|---|
| User | मैं आपको कुछ quotes दूँगा। कृपया quote block से author निकालें. |
यहाँ एक उदाहरण है:
Quote: "When the reasoning mind is forced to confront the impossible again and again, it has no choice but to adapt." ― N.K. Jemisin, The Fifth Season Author: N.K. Jemisin
Quote: "Some humans theorize that intelligent species go extinct before they can expand into outer space. If they're correct, then the hush of the night sky is the silence of the graveyard." ― Ted Chiang, Exhalation Author:| |Assistant (Claude's response)|Ted Chiang|
- आउटपुट फ़ॉर्मैटिंग: उदाहरणों का उपयोग करके वांछित आउटपुट फ़ॉर्मैट निर्दिष्ट करने से Claude परिणामों को अनुमानित और सुसंगत तरीके से दे सकता है। यह विशेष रूप से data extraction या report generation जैसे कार्यों में उपयोगी है.
| Role | Content |
|---|---|
| User | `` |
| Text: Sarah Martinez, a dedicated nurse, was known for her compassionate care at the local hospital. David Thompson, an innovative software engineer, worked tirelessly on groundbreaking projects. | |
| Output: |
- Sarah Martinez [NURSE]
- David Thompson [SOFTWARE ENGINEER] ``
`` Text: Chef Oliver Hamilton has transformed the culinary scene with his farm-to-table restaurant. Just down the street, you'll find the library, where head librarian Elizabeth Chen has worked diligently to create a welcoming space for all. Output:
- Oliver Hamilton [CHEF]
- Elizabeth Chen [LIBRARIAN] ``
Text: At the town's bustling farmer's market, you'll find Laura Simmons, a passionate organic farmer known for her delicious produce. In the community center, Kevin Alvarez, a skilled dance instructor, has brought the joy of movement to people of all ages. Output:| |Assistant (Claude's response)|1. Laura Simmons [ORGANIC FARMER] 2. Kevin Alvarez [DANCE INSTRUCTOR]|
-
ध्यान देने योग्य बातें: उदाहरणों का उपयोग करते समय यह ध्यान रखें कि बहुत सीमित data पर निर्भर न रहें, और Claude को केवल किसी खास pattern पर अत्यधिक निर्भर होने से बचाएँ.
-
पुनरावृत्ति और संशोधन: यदि शुरू में दिए गए उदाहरणों से मनचाहा परिणाम नहीं मिलता, तो उदाहरणों में बदलाव करें या नए उदाहरण जोड़कर धीरे-धीरे सुधार करें। इस प्रक्रिया से मॉडल के आउटपुट को लगातार बेहतर बनाया जा सकता है.
-
परिणाम विश्लेषण: Claude के उत्तरों में उन patterns को देखें जो आपकी अपेक्षा से अलग हैं। इससे यह पहचानने में मदद मिल सकती है कि उदाहरण कहाँ अस्पष्ट हैं, कहाँ गलतफ़हमी की गुंजाइश है, या कहाँ अधिक उदाहरण मददगार हो सकते हैं.
-
उदाहरण जोड़ें: यदि Claude किसी विशेष प्रकार के input में कठिनाई महसूस करता है, तो उस scenario को विशेष रूप से कवर करने वाले अतिरिक्त उदाहरण दें.
-
मौजूदा उदाहरणों में संशोधन: कभी-कभी उदाहरण में छोटा-सा बदलाव भी बड़ा फ़र्क ला सकता है। अलग-अलग phrasing, format या structure के साथ प्रयोग करके देखें कि क्या सबसे प्रभावी है.
-
Claude की मदद लें: अच्छे उदाहरण लिखना आसान नहीं है! Claude से कहें कि वह दिए गए कार्य के लिए उदाहरणों की विविधता या प्रासंगिकता का मूल्यांकन करे, या संदर्भ के लिए मौजूदा example set के आधार पर नए उदाहरण बनाने में मदद करे.
-
Claude को एक भूमिका देना (Give Claude a role)
हर use case में प्रदर्शन बेहतर करने के लिए Claude को किसी expert जैसी विशिष्ट भूमिका दें:
-
role prompting कैसे काम करता है: Claude को एक विशिष्ट भूमिका देने से वह किसी खास स्थिति या समस्या को अधिक सटीक रूप से समझ और संबोधित कर सकता है। उदाहरण के लिए, यदि Claude को गणित के सवाल हल करने के लिए 'math expert' की भूमिका दी जाए, तो वह बेहतर प्रदर्शन कर सकता है.
-
role prompting का उपयोग कब करें: खास तौर पर तब, जब आप technical या complex tasks करवा रहे हों, या जब किसी विशेष communication style की ज़रूरत हो। यह तरीका Claude की baseline performance को बेहतर बनाने में भी मदद करता है.
उदाहरण के लिए, जब There are two ducks in front of a duck, two ducks behind a duck and a duck in the middle. How many ducks are there? जैसी समस्या हल करनी हो, तो आप निम्नलिखित तरीका आज़मा सकते हैं:
| Role | Content |
|---|---|
| User | You are a master logic bot designed to answer complex logic problems. Solve this logic puzzle. There are two ducks in front of a duck, two ducks behind a duck and a duck in the middle. How many ducks are there? |
| Assistant (Claude's response) | [Automatically outputting thinking step by step as part of its training...] Without additional clarification or assumptions, the logic puzzle does not provide enough information to determine the exact number of ducks. The answer could range from a minimum of 3 ducks to a maximum of 5 ducks, depending on the interpretation of the given information. |
- role prompting के उदाहरण: ऐसे उदाहरण हैं जिनमें Claude को अलग-अलग भूमिकाएँ दी जाती हैं ताकि वह 'आसमान नीला क्यों है' को विभिन्न audiences के लिए समझाए, जैसे kindergarten teacher या university professor। प्रत्येक भूमिका के अनुसार Claude की explanation style बदल जाती है.
| Role | Content |
|---|---|
| User | आप एक kindergarten teacher हैं। अपने छात्रों को संक्षेप में समझाइए कि आकाश नीला क्यों होता है। |
| Assistant (Claude's response) | क्या आपने कभी सोचा है कि आकाश इतना सुंदर और नीला क्यों दिखता है? इसकी वजह सूरज की रोशनी है! जब सूरज की किरणें पृथ्वी के वायुमंडल से होकर नीचे आती हैं, तो वे हवा में मौजूद बहुत-से छोटे gas molecules से टकराती हैं। सूरज की रोशनी में मौजूद नीले रंग इन molecules से टकराकर चारों ओर बिखर जाते हैं। और इसी वजह से हमारी आँखों को आकाश नीला दिखाई देता है! है न कमाल? चमकीला नीला आकाश मानो प्रकृति की हमारे लिए बनाई गई एक बड़ी रंगीन पेंटिंग है। |
| Role | Content |
|---|---|
| User | आप graduate physics professor हैं। अपने छात्रों को संक्षेप में समझाइए कि आकाश नीला क्यों होता है। |
| Assistant (Claude's response) | आकाश नीला दिखाई देता है क्योंकि पृथ्वी के वायुमंडल में मौजूद molecules सूर्य के प्रकाश का Rayleigh scattering करते हैं। सूर्य का प्रकाश, जो विभिन्न wavelengths के spectrum से मिलकर बना होता है, वायुमंडल के gaseous molecules के साथ अंतःक्रिया करता है। दृश्य प्रकाश की छोटी wavelengths, जो नीले और बैंगनी रंगों से संबंधित होती हैं, इन molecules द्वारा लंबी wavelengths की तुलना में अधिक प्रभावी ढंग से बिखेरी जाती हैं. |
वायुमंडलीय molecules द्वारा इन छोटी नीली wavelengths का सभी दिशाओं में चयनात्मक scattering ही पृथ्वी की सतह से देखने पर आकाश को नीला दिखाता है। लाल और नारंगी जैसी लंबी wavelengths कम बिखरती हैं, इसलिए वे वायुमंडल से अधिक सीधे गुजरती हैं। इसी कारण सूर्योदय और सूर्यास्त के समय, जब सूर्य के प्रकाश को वायुमंडल की अधिक गहराई से होकर गुजरना पड़ता है, हमें लालिमा लिए हुए रंग दिखाई देते हैं।|
- प्रभावी role prompting tips: Claude को कोई भूमिका देते समय उसे विशिष्ट संदर्भ और भूमिका संबंधी जानकारी देना महत्वपूर्ण है। अलग-अलग भूमिकाओं और prompts के साथ प्रयोग करके सबसे उपयुक्त तरीका ढूँढना चाहिए.
XML tags का उपयोग (Use XML tags)
XML tags का साथ में उपयोग करके prompt और response को संरचित किया जा सकता है, जिससे स्पष्टता बढ़ती है:
-
XML tags क्या हैं?: XML tags का उपयोग
कॉन्टेंट सामग्रीजैसे angle-bracket tags के भीतर सामग्री को घेरने के लिए किया जाता है। ये tags instructions, examples या input data को अलग करते हैं, ताकि Claude संदर्भ को बेहतर समझ सके और अधिक सटीक output तैयार कर सके। tag names के मामले में, ऐसे कोई standard XML tags नहीं हैं जिन पर Claude विशेष रूप से बेहतर काम करता हो। उदाहरण के लिए,भीकी तरह ही अच्छी तरह काम करता है। लेकिन function calling feature का उपयोग करते समय आपको विशिष्ट tag names का उपयोग करना होगा। -
XML tags का उपयोग क्यों करें: XML tags का उपयोग करने से prompt के अलग-अलग हिस्सों को स्पष्ट रूप से अलग किया जा सकता है, जिससे अधिक सटीक responses मिलते हैं। यह विशेष रूप से जटिल prompts या विविध inputs को संभालते समय उपयोगी होता है।
-
XML tags का उपयोग कैसे करें: XML tags का उपयोग करके instructions, content और examples को अलग किया जा सकता है। variable input वाले prompt templates को प्रोसेस करते समय भी XML tags का उपयोग करके यह बताया जा सकता है कि content कहाँ insert किया जाए:
| Role | Content |
|---|---|
| User | कृपया इस document का विश्लेषण करें और नीचे दिए गए instructions के अनुसार, example में दिए गए format का पालन करते हुए एक विस्तृत summary memo लिखें: |
| `` | |
| {{DOCUMENT}} | |
| `` |
{{DETAILED_INSTRUCTIONS}}
{{EXAMPLE}}|
नीचे किसी विशिष्ट variable input का एक उदाहरण दिया गया है:
| Role | Content |
|---|---|
| User | मैं आपको किसी जानवर का नाम बताऊँगा। कृपया उस जानवर की आवाज़ के साथ जवाब दें. |
{{ANIMAL}} |
इसे structured output के लिए अनुरोध करते समय भी उपयोग किया जाता है:
| Role | Content |
|---|---|
| User | कृपया निम्न email से मुख्य विवरण निकालें और उन्हें XML tags में लौटाएँ: |
- sender name को `` tags में
- main topic को `` tags में
- उल्लेखित किसी भी deadline या dates को `` tags में
`` From: John Smith To: Jane Doe Subject: Project X Update
Hi Jane,
I wanted to give you a quick update on Project X. We've made good progress this week and are on track to meet the initial milestones. However, we may need some additional resources to complete the final phase by the August 15th deadline.
Can we schedule a meeting next week to discuss the budget and timeline in more detail?
Thanks, John ``|
आपको इस तरह का उत्तर मिल सकता है:
| Role | Content |
|---|---|
| Assistant (Claude's response) | John Smith |
Project X Update |
|
| ``August 15th | |
| ` |
- XML उपयोग के सर्वोत्तम तरीके: XML टैग का अधिकतम लाभ उठाने के लिए, इन सुझावों को ध्यान में रखें:
-
,, `` आदि जैसे वर्णनात्मक टैग नामों का उपयोग करें, जो टैग के भीतर मौजूद सामग्री को दर्शाते हों. -
पूरे प्रॉम्प्ट में टैग नामों में एकरूपता बनाए रखें, और टैग हमेशा opening tag
और closing tagकी जोड़ी में इस्तेमाल होने चाहिए. -
ज़रूरत पड़ने पर टैग को nested किया जा सकता है, लेकिन जटिलता के आधार पर 5 से अधिक nesting layers होने पर performance में गिरावट आ सकती है.
-
प्रॉम्प्ट जोड़ना (Chain prompts)
जटिल कार्यों को छोटे और अधिक आसानी से संभाले जा सकने वाले चरणों में बाँटकर बेहतर परिणाम प्राप्त करें:
-
चेन प्रॉम्प्ट क्या है? (What is prompt chaining?): चेन प्रॉम्प्ट एक तरीका है जिसमें जटिल लक्ष्य हासिल करने के लिए एक output को अगले input के रूप में इस्तेमाल करते हुए कार्यों को क्रमिक रूप से संसाधित किया जाता है. यह तरीका accuracy और consistency बेहतर बनाने में मदद करता है.
-
चेन प्रॉम्प्ट कब उपयोग करें (When to use prompt chaining): जब किसी कार्य में कई चरणों की आवश्यकता हो या उसमें जटिल निर्देश शामिल हों, तब चेन प्रॉम्प्ट का उपयोग करके हर चरण के performance को बेहतर किया जा सकता है.
-
चेन प्रॉम्प्ट को प्रभावी ढंग से उपयोग करने के सुझाव (Tips for effective prompt chaining): यह महत्वपूर्ण है कि हर subtask को सरल और स्पष्ट रखा जाए, और डेटा को संरचित करने के लिए XML टैग का उपयोग किया जाए.
-
उदाहरण (Examples): यह दिखाता है कि दस्तावेज़ और प्रश्न का उपयोग कर उत्तर बनाना, या व्याकरण संबंधी त्रुटियों की पहचान कर उनका सत्यापन करना जैसे कार्य चेन प्रॉम्प्ट के साथ कैसे किए जा सकते हैं:
उदाहरण: दस्तावेज़ और quotes का उपयोग करके प्रश्न का उत्तर देना
- Claude को प्रश्न के साथ दिए गए दस्तावेज़ से दस्तावेज़ के भीतर मौजूद quotes का उपयोग करके उत्तर तैयार करने के लिए कहा जाता है.
प्रॉम्प्ट 1. quotes निकालना
| Role | Content |
|---|---|
| User | Here is a document, in `` XML tags: |
{{DOCUMENT}}
Please extract, word-for-word, any quotes relevant to the question {{QUESTION}}. Please enclose the full list of quotes in `` XML tags. If there are no quotes in this document that seem relevant to this question, please say "I can't find any relevant quotes".|
प्रॉम्प्ट 2. (प्रॉम्प्ट 1 के {{QUOTES}} output का उपयोग करके) उत्तर देना
| Role | Content |
|---|---|
| User | I want you to use a document and relevant quotes from the document to answer a question. |
| Here is the document: | |
| `` | |
| {{DOCUMENT}} | |
| `` |
Here are direct quotes from the document that are most relevant to the question:
{{QUOTES}}
Please use these to construct an answer to the question " {{QUESTION}}"
Ensure that your answer is accurate and doesn't contain any information not directly supported by the quotes.|
Claude को सोचने दें (Let Claude think)
step-by-step सोच को प्रोत्साहित करके Claude के output की गुणवत्ता बेहतर की जा सकती है:
- जटिल प्रश्नों से निपटना: जब Claude किसी जटिल समस्या का सामना करता है, तो समस्या को चरण-दर-चरण विभाजित करके उससे निपटने पर वह अधिक सूक्ष्म और सटीक उत्तर दे सकता है. यह विशेष रूप से उन समस्याओं में उपयोगी है जिनमें logical या analytical सोच की आवश्यकता होती है.
| Role | Content |
|---|---|
| User | Use the following clues to answer the multiple-choice question below, using this procedure: |
- Go through the clues one by one and consider whether each is potentially relevant
- Combine the relevant clues to reason out the answer to the question
- Map the answer to one of the multiple choice options: (a), (b), or (c)
Clues:
- Miss Scarlett was the only person in the lounge.
- The person with the pipe was in the kitchen.
- Colonel Mustard was the only person in the observatory.
- Professor Plum was not in the library nor the billiard room.
- The person with the candlestick was in the observatory.
Question: Was Colonel Mustard in the observatory with the candlestick? (a) Yes; Colonel Mustard was in the observatory with the candlestick (b) No; Colonel Mustard was not in the observatory with the candlestick (c) Unknown; there is not enough information to determine whether Colonel Mustard was in the observatory with the candlestick |
-
उसे step-by-step सोचने के लिए कैसे कहें: उपयोगकर्ता प्रॉम्प्ट में "step-by-step सोचो" जैसा निर्देश शामिल करके Claude को समस्या के प्रति विश्लेषणात्मक तरीके से आगे बढ़ने के लिए कह सकता है. ऐसा करने पर Claude हर चरण की व्याख्या करते हुए अंतिम निष्कर्ष तक पहुँचता है.
-
सोचने की प्रक्रिया को कैप्चर करना: सोचने की प्रक्रिया को दृश्य रूप से अलग दिखाने के लिए XML टैग का उपयोग करके Claude की thought process और final answer को स्पष्ट रूप से अलग किया जा सकता है. इससे उपयोगकर्ता को Claude की reasoning process को अधिक स्पष्ट रूप से समझने में मदद मिलती है.
| Role | Content |
|---|---|
| User | [Rest of prompt] Before answering the question, please think about it step-by-step within tags. Then, provide your final answer within tags. |
| Assistant (prefill) | `` |
(यह नीचे देखी जाने वाली response prefill तकनीक का उपयोग करता है.)
| Role | Content |
|---|---|
| Assistant (Claude's response) | [समस्या पर step-by-step reasoning] |
| `` |
[अंतिम उत्तर]|
- ध्यान देने योग्य बातें: इस तकनीक का उपयोग करते समय Claude का output लंबा हो सकता है, इसलिए response time बढ़ सकता है। इसलिए इस्तेमाल से पहले इन विशेषताओं को ध्यान में रखकर इसे उपयुक्त परिस्थितियों में इस्तेमाल करना चाहिए।
Claude के response को पहले से भरना (Prefill Claude's response)
चाहे गए दिशा में output को guide करने के लिए, Claude के response के शुरुआती हिस्से को पहले से भरकर शुरू करें:
- Claude के response को prefill क्यों करें: यह तकनीक तब उपयोगी है जब उपयोगकर्ता चाहता है कि response किसी खास format या content में हो। उदाहरण के लिए, जानकारी को पहले से तय format में व्यवस्थित करना, या response को किसी विशेष शब्द या वाक्यांश से शुरू करवाकर उसकी consistency बनाए रखना। नीचे के मामले में, response की शुरुआत
{से prefill करके Claude को JSON format में उत्तर देने के लिए guide किया जा सकता है.
| ole | Good Prompt |
|---|---|
| User | Please extract the name, size, price, and color from this product description and output it within a JSON object. |
The SmartHome Mini is a compact smart home assistant available in black or white for only $49.99. At just 5 inches wide, it lets you control lights, thermostats, and other connected devices via voice or app—no matter where you place it in your home. This affordable little hub brings convenient hands-free control to your smart devices.|
|Assistant (prefill)|{|
Claude का response इस प्रकार है.
| Role | Response |
|---|---|
| Assistant (Claude's response) | "name": "SmartHome Mini", |
| "size": "5 inches wide", | |
| "price": "$49.99", | |
| "colors": [ | |
| "black", | |
| "white" | |
| ] | |
| } |
- Claude के response को कैसे prefill करें?: उपयोगकर्ता Claude को शुरुआती text देकर response की दिशा सेट कर सकता है। यह तरीका खासकर API के जरिए automated systems में उपयोगी है, और structured data format में Claude से आवश्यक जानकारी को सटीक रूप से दिला सकता है.
output format को नियंत्रित करना (Control output format)
consistency और readability सुनिश्चित करने के लिए, आप इच्छित output format निर्दिष्ट कर सकते हैं:
- इच्छित format निर्दिष्ट करना: उपयोगकर्ता अगर Claude को specific output format बताए, तो परिणाम की consistency और accuracy बढ़ाई जा सकती है। यह खासकर data processing या report writing के समय एक आवश्यक तत्व है, जहाँ स्पष्ट format निर्देश महत्वपूर्ण होते हैं। उदाहरण के लिए, response को JSON, XML, HTML, Markdown आदि कई formats में सेट किया जा सकता है। इस तरह Claude को स्पष्ट format निर्देश देकर consistent output format सुनिश्चित किया जाता है.
| Role | Content |
|---|---|
| User | Please write a haiku about a cat. Use JSON format with the keys "first_line", "second_line", and "third_line". |
| Assistant (Claude's response) | { |
| "first_line": "Soft furry feline", | |
| "second_line": "Napping in the warm sunlight", | |
| "third_line": "Purring contentedly" | |
| } |
- response को prefill करना: response की शुरुआत को पहले से भरकर Claude को निर्दिष्ट format के अनुसार content generate करने के लिए guide किया जा सकता है। यह तरीका structured data formats का उपयोग करते समय विशेष रूप से उपयोगी है.
| Role | Content |
|---|---|
| User | कृपया chocolate chip cookies की एक recipe JSON format में generate करें. |
| Assistant (prefill) | { |
| Assistant (Claude's response) | "title": "Chocolate Chip Cookies", |
| "ingredients": [ | |
| "2 1/4 cups all-purpose flour", | |
| "1 tsp baking soda", | |
| "1 tsp salt", | |
| "1 cup unsalted butter, softened", | |
| "3/4 cup granulated sugar", | |
| "3/4 cup brown sugar", | |
| "1 tsp vanilla extract", | |
| "2 large eggs", | |
| "2 cups semisweet chocolate chips" | |
| ], | |
| "instructions": [ | |
| "Preheat the oven to 375°F (190°C) and line baking sheets with parchment paper.", | |
| "In a medium bowl, whisk together the flour, baking soda, and salt. Set aside.", | |
| "In a large bowl, beat the butter and sugars with an electric mixer until light and fluffy, about 2-3 minutes.", | |
| "Beat in the vanilla and eggs one at a time until well combined.", | |
| "Gradually stir the flour mixture into the butter mixture until just combined.", | |
| "Fold in the chocolate chips.", | |
| "Drop rounded tablespoons of the dough onto the prepared baking sheets, about 2 inches apart.", | |
| "Bake for 9-11 minutes, until the edges are golden brown.", | |
| "Allow the cookies to cool on the baking sheets for 5 minutes before transferring to a wire rack to cool completely." | |
| ], | |
| "yield": "About 3 dozen cookies" | |
| } |
- उदाहरण देना: उपयुक्त output format को और स्पष्ट रूप से बताने के लिए उदाहरण दिए जा सकते हैं। इससे Claude को आवश्यकताओं को बेहतर समझने और सही format में response generate करने में मदद मिलती है, और यह खासकर उन tasks में उपयोगी है जिनमें complex format की जरूरत होती है.
| Role | Content |
|---|---|
| User | आपका task एक poem लिखना है। poem के ideal formatting के कुछ उदाहरण यहां दिए गए हैं: |
`` Title: "Autumn Leaves" Verse 1: Crisp autumn leaves dance In the gentle, chilly breeze A colorful sight
Verse 2: Red, orange, and gold Painting the world with beauty Before winter comes ``
`` Title: "Moonlit Night" Verse 1: Moonlight casts shadows Across the tranquil garden A peaceful retreat
Verse 2: Stars twinkle above As crickets sing their nightsong Nature's lullaby ``
अब, कृपया ऊपर दिए गए उदाहरणों की formatting का पालन करते हुए sunset पर एक poem लिखें.| |Assistant (prefill)|``| |Assistant (Claude's response)|Title: "Sunset Symphony" Verse 1: Fiery sun descends Painting the sky with wonder A masterpiece forms
Verse 2: Pinks, purples, and reds Blending in pure harmony Day bids night hello ``|
- output control के लिए टिप्स: प्रभावी output control के लिए विभिन्न उदाहरण और स्पष्ट निर्देश देने चाहिए। जहां संभव हो, कई तरह के उदाहरण दें, वांछित format पर जोर दें, और प्रयोग करके सबसे अच्छा तरीका खोजें। इस प्रक्रिया में विभिन्न techniques को मिलाकर आज़माना और सर्वोत्तम परिणाम निकालना महत्वपूर्ण है, ताकि Claude की performance को लगातार बेहतर बनाया जा सके.
Claude से rewrite के लिए कहना (Ask Claude for rewrites)
संशोधन के लिए rubric बताकर Claude को output को दोहराने और सुधारने दें:
-
rewrite request का कारण: जब Claude का शुरुआती response सटीक न हो या उम्मीदों पर खरा न उतरे, तो rewrite का अनुरोध करके output को बेहतर बनाया जा सकता है। उपयोगकर्ता specific format, style, या content से जुड़ी details को स्पष्ट करके Claude को अधिक सटीक response देने के लिए मार्गदर्शन कर सकता है.
-
rewrite request कैसे करें: API के माध्यम से पहले से generate किए गए text को शामिल करें और rewrite के लिए specific instructions जोड़ें। उदाहरण के लिए, आप किसी paragraph को फिर से लिखने के लिए कह सकते हैं, लेकिन इस बार किसी खास विषय पर ध्यान केंद्रित करने को कहें.
| Role | Prompt |
|---|---|
| User | यह एक paragraph है: |
| `` | |
| {{PARAGRAPH}} | |
| `` |
मैं चाहता/चाहती हूं कि आप इसे निम्नलिखित निर्देशों के अनुसार rewrite करें:
{{INSTRUCTIONS}}
कृपया अपना rewrite tags के भीतर रखें.| |Assistant (prefill)||
- प्रभावी rewrite instructions लिखना: rewrite के लिए निर्देश स्पष्ट और specific होने चाहिए। इनमें वांछित format, tone, style, और अतिरिक्त जानकारी शामिल होनी चाहिए, ताकि Claude ठीक-ठीक समझ सके कि उससे क्या अपेक्षा की जा रही है.
| Role | Prompt |
|---|---|
| User | Tell me about all the ways I can get fitter. |
| Assistant (Claude's response) | यहाँ कुछ तरीके हैं जिनसे आप ज़्यादा फिट हो सकते हैं: [list-style response] |
| User | इसे टेक्स्ट के एक ही पैराग्राफ में फिर से लिखें, और सबसे प्रभावी रणनीतियों पर फोकस करें. |
| Assistant (Claude's response) | अगर आप ज़्यादा फिट होना चाहते हैं, तो सबसे प्रभावी रणनीतियों में शामिल हैं: [brief paragraph-style response] |
- पुनरावृत्त री-राइटिंग प्रक्रिया: कभी-कभी सिर्फ एक बार री-राइट करने से बिल्कुल सही परिणाम नहीं मिलता। ऐसे में कई बार री-राइट करके परिणाम को धीरे-धीरे बेहतर बनाया जा सकता है, और हर चरण में फ़ीडबैक देकर Claude को उपयोगकर्ता की प्राथमिकताएँ सीखने में मदद की जा सकती है.
लॉन्ग कॉन्टेक्स्ट विंडो टिप्स(Long context window tips)
आप Claude की लॉन्ग कॉन्टेक्स्ट विंडो का लाभ उठाने के लिए प्रॉम्प्ट को ऑप्टिमाइज़ कर सकते हैं:
नीचे "लॉन्ग कॉन्टेक्स्ट विंडो टिप्स (Long Context Window Tips)" दस्तावेज़ के हर सेक्शन का विस्तृत विवरण दिया गया है:
- लंबे दस्तावेज़ संभालना (Handling Long Documents): लंबे दस्तावेज़ों के साथ काम करते समय महत्वपूर्ण जानकारी को दस्तावेज़ के शुरुआती हिस्से में रखना चाहिए, और प्रश्न को दस्तावेज़ के अंत में रखना चाहिए। इससे Claude पूरे दस्तावेज़ में मौजूद आवश्यक जानकारी को प्रभावी ढंग से प्रोसेस कर पाता है और उपयुक्त उत्तर दे सकता है.
Here are some documents for you to reference for your task:
(a unique identifying source for this item - could be a URL, file name, hash, etc)
(the text content of the document - could be a passage, web page, article, etc)
(a unique identifying source for this item - could be a URL, file name, hash, etc)
(the text content of the document - could be a passage, web page, article, etc)
...
[Rest of prompt]
-
दस्तावेज़-प्रश्न प्लेसमेंट (Document-query Placement): दस्तावेज़ से संबंधित प्रश्न को दस्तावेज़ डेटा दिए जाने के बाद रखना चाहिए। यह संरचना Claude को पूरे दस्तावेज़ का संदर्भ लेकर अधिक सटीक उत्तर देने में सक्षम बनाती है.
-
दस्तावेज़ Q&A लिखने के टिप्स (Tips for Document Q&A): दस्तावेज़-आधारित प्रश्नोत्तर कार्य करते समय प्रश्न को दस्तावेज़ के अंत में रखें, और संबंधित उद्धरण ढूँढकर उन्हें उत्तर में शामिल करने के लिए कहें। इससे परिणाम की सटीकता बढ़ाने में मदद मिलती है.
| Role | Content |
|---|---|
| User | I'm going to give you a document. Read the document carefully, because I'm going to ask you a question about it. Here is the document: {{TEXT}} |
First, find the quotes from the document that are most relevant to answering the question, and then print them in numbered order in `` tags. Quotes should be relatively short. If there are no relevant quotes, write "No relevant quotes" instead.
Then, answer the question in `` tags. Do not include or reference quoted content verbatim in the answer. Don't say "According to Quote [1]" when answering. Instead make references to quotes relevant to each section of the answer solely by adding their bracketed numbers at the end of relevant sentences.
Thus, the format of your overall response should look like what's shown between the `` tags. Make sure to follow the formatting and spacing exactly.
[Examples of question + answer pairs, with answers written exactly like how Claude's output should be structured]
If the question cannot be answered by the document, say so.
Here is the first question: {{QUESTION}}|
- मल्टिपल चॉइस प्रश्न बनाना (Multiple Choice Question Generation): दस्तावेज़ के आधार पर मल्टिपल चॉइस प्रश्न बनाते समय दस्तावेज़ की सामग्री पर आधारित उदाहरण प्रश्न और उत्तर दें। इससे Claude को प्रश्न बनाते समय एकसमान फ़ॉर्मैट और सामग्री बनाए रखने में मदद मिलती है.
| भूमिका | सामग्री |
|---|---|
| User | आपका कार्य निम्नलिखित दस्तावेज़ की सामग्री के आधार पर multiple choice questions बनाना है: |
| `` | |
| {{DOCUMENT}} | |
| `` |
यहाँ टेक्स्ट के अन्य हिस्सों के आधार पर multiple choice questions और answers के कुछ उदाहरण दिए गए हैं: `` Q1: [दस्तावेज़ के भीतर की जानकारी से बनाया गया उदाहरण प्रश्न 1] A. [उत्तर विकल्प A] B. [उत्तर विकल्प B] C. [उत्तर विकल्प C] D. [उत्तर विकल्प D] Answer: [सही उत्तर का अक्षर]
Q2: [दस्तावेज़ के भीतर की जानकारी से बनाया गया उदाहरण प्रश्न 2] A. [उत्तर विकल्प A] B. [उत्तर विकल्प B] C. [उत्तर विकल्प C] D. [उत्तर विकल्प D] Answer: [सही उत्तर का अक्षर] ``
निर्देश:
- दिए गए टेक्स्ट के आधार पर 5 multiple choice questions बनाइए।
- प्रत्येक प्रश्न में 4 उत्तर विकल्प (A, B, C, D) होने चाहिए।
- प्रत्येक प्रश्न के लिए सही उत्तर बताइए।
- सुनिश्चित करें कि प्रश्न टेक्स्ट से प्रासंगिक हों और सभी उत्तर विकल्प विश्वसनीय लगें।|
आगे पढ़ें
https://docs.anthropic.com/claude/docs/prompt-engineering
यह लेख GPT model से तैयार किए गए सारांश पर आधारित है, इसलिए संभव है कि इसमें मूल लेख की सामग्री या आशय से अलग तरह से संक्षेपित की गई बातें हों। यदि विषय में आपकी रुचि है, तो कृपया मूल लेख भी साथ में देखें! पढ़ते समय यदि आपको कोई अटपटा या गलत हिस्सा मिले, तो कृपया comment में बताएं। 🤗
⚠️विज्ञापन⚠️: 🔥PyTorch Korean Users Group🇰🇷 द्वारा संकलित यह लेख क्या आपके लिए उपयोगी रहा? सदस्य के रूप में जुड़ें, तो हम प्रमुख लेख आपको ईमेल💌 से भेजेंगे! (डिफ़ॉल्ट रूप से Weekly, लेकिन Daily में बदलना भी संभव है।)
अभी कोई टिप्पणी नहीं है.