liveBook · Manning

Zero-shot prompting

As explained in Learn Generative AI with PyTorch

A prompting method that gives the model a task without any examples, relying only on instructions and prior knowledge.

Zero-shot prompting asks a language model to complete a task using instructions but no examples. The model relies on its preexisting knowledge to interpret the request and produce an answer. section 16.2.3

Compared with one-shot and few-shot prompting, zero-shot prompting supplies no demonstrations: one-shot supplies one example, while few-shot supplies several. Clear plain-English instructions replace the examples. section 16.2.3

Classifying sentiment without demonstrations

A prompt can ask, “Is the tone in the sentence ‘Today is a great day for me’ positive, negative, or neutral?” The model answers “Positive” without seeing labeled examples. section 16.2.3

prompt = """
Is the tone in the sentence "Today is a great day for me" positive, 
negative, or neutral?
"""
res=llm.invoke(prompt)
print(res)

Inspect the complete zero-shot classification prompt and its generated answer. section 16.2.3

Zero-shot prompting is useful for direct interactions with pretrained LLMs, including text-generation workflows accessed through Python and LangChain. Its simplicity avoids preparing task-specific examples, but model outputs can still contain logical errors, factual inaccuracies, or misunderstandings. section 16.0 section 16.5

How Learn Generative AI with PyTorch covers it

How deep it goes
Defines zero-shot prompting, contrasts it with one-shot and few-shot methods, and demonstrates classification without covering prompting internals.
Examples
Demonstrates zero-shot tone classification by labeling a sentence as positive, negative, or neutral.
What it assumes
Assumes familiarity with language models and prompts while teaching the distinction between zero-shot, one-shot, and few-shot instructions.
What you can do after
Apply it by writing a plain-English task prompt and evaluating the model’s response without providing examples.
How it connects
Connects zero-shot prompting with one-shot prompting, few-shot prompting, pretrained language models, sentiment analysis, and LangChain.

Also explained in

Compare how 9 books explain zero-shot prompting →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Generative AI with PyTorch. The section links point to the parts of the book it draws on.