A partire dal 29 aprile 2025, i modelli Gemini 1.5 Pro e Gemini 1.5 Flash non sono disponibili nei progetti che non li hanno mai utilizzati, inclusi i nuovi progetti. Per maggiori dettagli, vedi Versioni e ciclo di vita dei modelli.
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Puoi includere esempi nel prompt che mostrino al modello come dovrebbe essere una buona risposta. Il modello
tenta di identificare pattern e relazioni dagli esempi e li applica quando
genera una risposta. I prompt che contengono esempi sono chiamati prompt few-shot, mentre
i prompt che non forniscono esempi sono chiamati prompt zero-shot. I prompt few-shot vengono spesso utilizzati per regolare la formattazione, la formulazione, l'ambito o il pattern generale delle risposte del modello. Utilizza esempi specifici e vari per aiutare il modello a restringere il campo e generare risultati piรน accurati.
L'inclusione di esempi few-shot nei prompt contribuisce a renderli piรน affidabili ed efficaci.
Tuttavia, dovresti sempre accompagnare gli esempi few-shot con istruzioni chiare. Senza istruzioni chiare, i modelli potrebbero rilevare uno schema o una relazione non intenzionale dagli esempi, il che puรฒ portare a risultati scadenti.
I punti chiave di questa strategia sono i seguenti:
L'inclusione di esempi di prompt-risposta nel prompt aiuta il modello a imparare a rispondere.
Utilizza un markup simile a XML per contrassegnare gli esempi.
Sperimenta con il numero di prompt da includere. A seconda del modello, un numero troppo basso di esempi
non รจ efficace per modificare il comportamento del modello. Troppi esempi possono causare l'overfitting del modello.
Utilizzare una formattazione coerente in tutti gli esempi
Prompt zero-shot e few-shot
Il seguente prompt zero-shot chiede al modello di estrarre le specifiche tecniche dal testo e di generare l'output in formato JSON:
Extract the technical specifications from the text below in JSON format.
Google Pixel 7, 5G network, 8GB RAM, Tensor G2 processor, 128GB of storage, Lemongrass
Supponiamo che il tuo caso d'uso richieda una formattazione specifica, ad esempio l'utilizzo di nomi di chiavi in minuscolo. Puoi includere
esempi nel prompt che mostrano al modello come formattare il JSON. Il seguente prompt few-shot
mostra un formato di output in cui le chiavi JSON sono in minuscolo:
Extract the technical specifications from the text below in a JSON format.
<EXAMPLE>
INPUT: Google Nest Wifi, network speed up to 1200Mpbs, 2.4GHz and 5GHz frequencies, WP3 protocol
OUTPUT:
{
"product":"Google Nest Wifi",
"speed":"1200Mpbs",
"frequencies": ["2.4GHz", "5GHz"],
"protocol":"WP3"
}
</EXAMPLE>
Google Pixel 7, 5G network, 8GB RAM, Tensor G2 processor, 128GB of storage, Lemongrass
Tieni presente che l'esempio utilizza una formattazione simile a XML per separare i componenti del prompt. Per
scoprire di piรน su come formattare in modo ottimale i prompt few-shot utilizzando una formattazione simile a XML, consulta
Prompt strutturati.
Trovare il numero ottimale di esempi
Puoi sperimentare con il numero di esempi da fornire nel prompt per ottenere i risultati piรน desiderati. Modelli come Gemini spesso riescono a individuare i pattern utilizzando pochi esempi, anche se
potresti dover sperimentare con il numero di esempi che porta ai risultati desiderati. Allo stesso tempo,
se includi troppi esempi, il modello potrebbe iniziare a
fare overfitting
della risposta agli esempi.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema รจ stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-02 UTC."],[],[],null,["# Include few-shot examples\n\nYou can include examples in the prompt that show the model what a good response looks like. The\nmodel attempts to identify patterns and relationships from the examples and applies them when\ngenerating a response. Prompts that contain examples are called *few-shot* prompts, while\nprompts that provide no examples are called *zero-shot prompts*. Few-shot prompts are\noften used to regulate the output formatting, phrasing, scoping, or general patterning of model\nresponses. Use specific and varied examples to help the model narrow its focus and generate more\naccurate results.\n\nIncluding few-shot examples in your prompts helps make them more reliable and effective.\nHowever, you should always accompany few-shot examples with clear instructions. Without clear\ninstructions, models might pick up one unintended patterns or relationships from the examples, which\ncan lead to poor results.\n\nThe key points to this strategy are as follows:\n\n- Including prompt-response examples in the prompt helps the model learn how to respond.\n- Use XML-like markup to markup the examples.\n- Experiment with the number of prompts to include. Depending on the model, too few examples are ineffective at changing model behavior. Too many examples can cause the model to overfit.\n- Use consistent formatting across examples\n\nZero-shot versus few-shot prompts\n---------------------------------\n\nThe following zero-shot prompt asks the model to extract the technical specifications from\ntext and output it in JSON format:\n\nSuppose that your use case requires specific formatting, such as using lowercase key names. You can include\nexamples in the prompt that shows the model how to format the JSON. The following few-shot prompt\ndemonstrates an output format where the JSON keys are lowercase:\n\nNote that the example uses XML-like formatting to separate the components of the prompt. To\nlearn more about how to optimally format few-shot prompts using XML-like formatting, see\n[Structure prompts](/vertex-ai/generative-ai/docs/learn/prompts/structure-prompts).\n\nFind the optimal number of examples\n-----------------------------------\n\nYou can experiment with the number of examples to provide in the prompt for the most desired\nresults. Models like Gemini can often pick up on patterns using a few examples, though you\nmay need to experiment with what number of examples leads to the desired results. At the same time,\nif you include too many examples, the model might start to\n[overfit](https://developers.google.com/machine-learning/glossary#overfitting)\nthe response to the examples.\n\nWhat's next\n-----------\n\n- Explore more examples of prompts in the [Prompt gallery](/vertex-ai/generative-ai/docs/prompt-gallery)."]]