Day 1a: Prompting

Module Overview

Session 1: Prompting

Session 2: Evaluation and Structured Output

  • Structured output and schemas
  • Pointwise and pairwise evaluation
  • Evaluation methods and best practices

Session 1: Prompting

How LLMs Work

Prediction engines, not databases

Large language model as a prediction engine showing sequential token prediction process

Prompt Engineering Defined

Designing high-quality prompts

  • Tinkering to find the best prompt
  • Optimizing prompt length
  • Evaluating writing style and structure
  • Matching prompts to tasks

LLM Output Configuration

Controlling how the model generates

  • Output length
  • Temperature
  • Top-K
  • Top-P

Output Length

Controlling response size

Tokens and cost

Sampling Controls

How tokens are selected

Temperature, top-K, and top-P

  • Temperature: Control the randomness of the output
  • Top-K: Consider only the K most likely tokens
  • Top-P (nucleus sampling): Consider tokens whose cumulative probability exceeds P

Temperature

Controlling randomness

  • Low temperature (0): Deterministic, highest probability token always selected
  • High temperature: More diverse or unexpected results
  • Very high temperature: All tokens become equally likely

Temperature scale showing deterministic to random output behavior

General Prompting / Zero-Shot

Direct instruction without examples

Zero-shot prompting

One-Shot & Few-Shot Prompting

Instruction + examples

One-Shot & Few-Shot Prompting

System Prompting

Persistent context and behavior

System Prompting

Role Prompting

Defining expertise and perspective

You are a Python programming tutor with 10 years 
of experience. Explain concepts clearly and 
provide code examples.

Use cases:

  • Domain expertise
  • Perspective setting
  • Style consistency

Contextual Prompting

Providing relevant background

Context: The user is working on a machine learning 
project using scikit-learn. They have a dataset 
with 10,000 samples and 50 features.

Question: What preprocessing steps should I take?

Step-Back Prompting

Evoking reasoning via abstraction

Instead of asking directly, first ask the model to step back and think about the broader principles or concepts.

Step-back prompting showing abstraction before specific reasoning

Chain of Thought (CoT)

Adding reasoning steps

Chain of thought prompting showing step-by-step reasoning process

Self-Consistency

Multiple reasoning paths

Generate multiple chain-of-thought reasoning paths, then select the most consistent answer.

Self-consistency showing multiple reasoning paths converging on answer

Tree of Thoughts (ToT)

Exploring multiple reasoning branches

Instead of linear reasoning, explore multiple reasoning branches and select the best path.

Tree of thoughts showing branching reasoning exploration

ReAct (Reason & Act)

Synergizing reasoning and acting

The model alternates between reasoning (thinking) and acting (taking actions like tool use).

ReAct pattern showing alternating reasoning and action steps

Automatic Prompt Engineering

Using LLMs to improve prompts

LLMs can be used to automatically generate, refine, and optimize prompts.

Automatic prompt engineering showing LLM improving its own prompts

Keytakeaways

Your complete toolkit

  • Zero-shot: Simple, well-known tasks
  • Few-shot: Specific formats and styles
  • System/Role/Contextual: Setting behavior and context
  • Chain-of-thought: Complex reasoning
  • Self-consistency: Validating results
  • Tree of Thoughts: Exploring good thought trajectories
  • ReAct: Reasoning with actions