MLCrack

    LLMS & TRANSFORMERS · INTERVIEW QUESTION

    What is chain-of-thought prompting? Why does it improve reasoning?

    🟢 beginner · Prompt Engineering

    Hint: Think about breaking complex problems into intermediate steps.

    Answer

    Chain-of-thought (CoT) prompting encourages the model to show intermediate reasoning steps before giving the final answer.

    Example

    Without CoT: "Q: 23 × 17 = ? A: 391"

    With CoT: "Let me break this down: 23 × 17 = 23 × 10 + 23 × 7 = 230 + 161 = 391"

    Why It Works

    • Decomposes complex problems into simpler subproblems
    • Allocates more computation per problem (more tokens = more thinking)
    • Provides an inspectable explanation — useful for debugging, but a plausible trace need not faithfully describe the computation causing the answer

    Variants

    VariantDescription
    Zero-shot CoTJust add "Let's think step by step"
    Few-shot CoTProvide examples with reasoning
    Self-consistencySample multiple CoTs, majority vote
    Tree-of-thoughtExplore multiple reasoning branches
    python
    # Zero-shot CoT prompt = """Q: If a store has 23 items and 8 are sold, then 15 arrive, how many now? A: Let's think step by step. """ response = model.generate(prompt)

    Benefits depend on model training, task and prompting; there is no universal parameter-count threshold for useful reasoning. Validate accuracy and cost on the target task.