Che cos'è un prompt? - Amazon Bedrock

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Che cos'è un prompt?

I prompt sono input specifici forniti dall'utente che guidano gli LLM su Amazon Bedrock nella generazione di una risposta o un output appropriato per una determinata attività o istruzione.

User Prompt: Who invented the airplane?

Quando viene interrogato da questo prompt, Titan fornisce un output:

Output: The Wright brothers, Orville and Wilbur Wright are widely credited with inventing and manufacturing the world's first successful airplane.

(Fonte del prompt: AWS, modello utilizzato: Amazon Titan Text)

Componenti di un prompt

Un singolo prompt include diversi componenti, come l'attività o l'istruzione che deve essere eseguita dagli LLM, il contesto dell'attività (ad esempio una descrizione del dominio pertinente), esempi dimostrativi e il testo di input che vuoi che gli LLM su Amazon Bedrock utilizzino nella risposta. A seconda del caso d'uso, della disponibilità dei dati e dell'attività, il prompt dovrebbe combinare uno o più di questi componenti.

Considera questo esempio di richiesta di riepilogo Titan di una recensione:

User Prompt: The following is text from a restaurant review: “I finally got to check out Alessandro’s Brilliant Pizza and it is now one of my favorite restaurants in Seattle. The dining room has a beautiful view over the Puget Sound but it was surprisingly not crowded. I ordered the fried castelvetrano olives, a spicy Neapolitan-style pizza and a gnocchi dish. The olives were absolutely decadent, and the pizza came with a smoked mozzarella, which was delicious. The gnocchi was fresh and wonderful. The waitstaff were attentive, and overall the experience was lovely. I hope to return soon." Summarize the above restaurant review in one sentence.

(Fonte del prompt:) AWS

In base a questa richiesta, Titan risponde con un breve riepilogo di una riga della recensione del ristorante. La recensione menziona i fatti fondamentali e illustra i punti principali, come desiderato.

Output: Alessandro's Brilliant Pizza is a fantastic restaurant in Seattle with a beautiful view over Puget Sound, decadent and delicious food, and excellent service.

(Modello utilizzato: Amazon Titan Text)

L'istruzione Summarize the above restaurant review in one sentence e il testo della recensione I finally got to check out ... erano entrambi necessari per questo tipo di output. Senza uno dei due, il modello non avrebbe informazioni sufficienti per produrre un riepilogo sensato. L'istruzione indica all'LLM cosa fare e il testo è l'input utilizzato dall'LLM. Il contesto (The following is text from a restaurant review) fornisce informazioni e parole chiave aggiuntive che indicano al modello come utilizzare l'input nella formulazione dell'output.

Nell'esempio seguente, il testo Context: Climate change threatens people with increased flooding ... è l'input che l'LLM può utilizzare per eseguire l'attività di rispondere alla domanda Question: What organization calls climate change the greatest threat to global health in the 21st century?”.

User prompt: Context: Climate change threatens people with increased flooding, extreme heat, increased food and water scarcity, more disease, and economic loss. Human migration and conflict can also be a result. The World Health Organization (WHO) calls climate change the greatest threat to global health in the 21st century. Adapting to climate change through efforts like flood control measures or drought-resistant crops partially reduces climate change risks, although some limits to adaptation have already been reached. Poorer communities are responsible for a small share of global emissions, yet have the least ability to adapt and are most vulnerable to climate change. The expense, time required, and limits of adaptation mean its success hinge on limiting global warming. Question: What organization calls climate change the greatest threat to global health in the 21st century?

(origine del prompt: https://en.wikipedia.org/wiki/Climate_change)

AI21 LabsRisposte Jurassic con il nome corretto dell'organizzazione in base al contesto fornito nel prompt.

Output: The World Health Organization (WHO) calls climate change the greatest threat to global health in the 21st century.

(Modello utilizzato: v1) AI21 Labs Jurassic-2 Ultra

Prompt few-shot e prompt zero-shot

A volte è utile fornire alcuni esempi per aiutare gli LLM a calibrare meglio i risultati in modo da soddisfare le aspettative. Per farlo, vengono impiegati i prompt few-shot o l'apprendimento contestuale, in cui uno shot corrisponde a un esempio di input abbinato e all'output desiderato. Per spiegare questo approccio, ecco anzitutto un esempio di prompt zero-shot per la classificazione del sentiment, il cui testo non contiene alcuna coppia di input-output di esempio:

User prompt: Tell me the sentiment of the following headline and categorize it as either positive, negative or neutral: New airline between Seattle and San Francisco offers a great opportunity for both passengers and investors.

(Fonte del prompt:) AWS

Output: Positive

(Modello utilizzato: Amazon Titan Text)

Ecco la versione few-shot di un prompt per la classificazione del sentiment:

User prompt: Tell me the sentiment of the following headline and categorize it as either positive, negative or neutral. Here are some examples: Research firm fends off allegations of impropriety over new technology. Answer: Negative Offshore windfarms continue to thrive as vocal minority in opposition dwindles. Answer: Positive Manufacturing plant is the latest target in investigation by state officials. Answer:

(Fonte del prompt: AWS)

Output: Negative

(Modello utilizzato: Amazon Titan Text)

L'esempio seguente utilizza Anthropic Claude modelli. Quando si utilizzano Anthropic Claude modelli, è buona norma utilizzare<example></example> tag per includere esempi dimostrativi. Consigliamo inoltre di utilizzare negli esempi delimitatori diversi, ad esempio H: e A:, per evitare confusione con i delimitatori Human: e Assistant: per l'intero prompt. Nota che per l'ultimo esempio con pochi esempi, la finale A: viene tralasciata a favore diAssistant:, e viene richiesto invece di Anthropic Claude generare la risposta.

User prompt: Human: Please classify the given email as "Personal" or "Commercial" related emails. Here are some examples. <example> H: Hi Tom, it's been long time since we met last time. We plan to have a party at my house this weekend. Will you be able to come over? A: Personal </example> <example> H: Hi Tom, we have a special offer for you. For a limited time, our customers can save up to 35% of their total expense when you make reservations within two days. Book now and save money! A: Commercial </example> H: Hi Tom, Have you heard that we have launched all-new set of products. Order now, you will save $100 for the new products. Please check our website. Assistant: Output: Commercial

(Fonte del prompt: AWS, modello utilizzato:) Anthropic Claude

Modello di prompt

Un modello di prompt specifica la formattazione del prompt con contenuti intercambiabili. I modelli di prompt sono "ricette" per utilizzare gli LLM in diversi casi d'uso come classificazione, riassunto, risposta a domande e altro ancora. Un modello di prompt può includere istruzioni ed esempi few-shot, nonché domande e contesti specifici appropriati per un determinato caso d'uso. L'esempio seguente è un modello che consente di eseguire la classificazione few-shot del sentiment utilizzando i modelli di testo di Amazon Bedrock:

Prompt template: """Tell me the sentiment of the following {{Text Type, e.g., “restaurant review”}} and categorize it as either {{Sentiment A}} or {{Sentiment B}}. Here are some examples: Text: {{Example Input 1}} Answer: {{Sentiment A}} Text: {{Example Input 2}} Answer: {{Sentiment B}} Text: {{Input}} Answer:"""

Gli utenti possono copiare e incollare questo modello inserendo il proprio testo ed esempi few-shot per completare i prompt quando utilizzano gli LLM su Amazon Bedrock. In questa sezione vengono forniti altri modelli.

Nota

Le doppie parentesi graffe {{ and }} indicano i punti in cui inserire informazioni specifiche sui dati nel modello. Non devono essere incluse nel testo del prompt.

Note importanti sull'uso degli LLM di Amazon Bedrock tramite chiamate API

Se accedi agli LLM su Amazon Bedrock tramite chiamate API, tieni presente che non richiamano i prompt e le richieste precedenti, a meno che l'interazione già avvenuta non sia inclusa nel prompt attuale. Ciò potrebbe essere necessario per interazioni di tipo colloquiale o richieste di follow-up.

Se accedi ai Anthropic Claude modelli utilizzando chiamate API anziché il campo di testo Amazon Bedrock, inserisci i prompt in uno stile colloquiale per ottenere la risposta desiderata (per la famiglia di modelli Titan Text and AI21 Labs Jurassic, non è necessario). Nell'esempio seguente viene mostrato un prompt di tipo colloquiale:

User prompt: Human: Describe where sea otters live in two sentences. Assistant: Output: Here is a two sentence description of where sea otters live: Sea otters live in the northern Pacific Ocean along the coasts of Russia, Alaska, Canada, and the continental United States. They prefer coastal habitats like rocky shores, kelp forests, and estuaries where they have access to shallow, nearshore waters.

(Fonte del prompt:, modello utilizzato:) AWSAnthropic Claude

Puoi notare che i contenuti principali del prompt sono racchiusi in questo modo: \n\nHuman: {{Main Content}}\n\nAssistant:. Per Anthropic Claude i modelli, i prompt inviati tramite l'API devono contenere\n\nHuman: and. \n\nAssistant:

Per attivare la modalità conversazionaleTitan, è possibile utilizzare il formato di quando si richiede il modello. User: {{}} \n Bot: