Inside Model Reasoning

Fine-Tuning in Action


Barry S. Stahl

Solution Architect & Developer

@bsstahl@cognitiveinheritance.com

https://CognitiveInheritance.com

Transparent Half Width Image 960x800.png

Favorite Physicists & Mathematicians

Favorite Physicists

  1. Harold "Hal" Stahl
  2. Carl Sagan
  3. Richard Feynman
  4. Marie Curie
  5. Nikola Tesla
  6. Albert Einstein
  7. Neil Degrasse Tyson
  8. Niels Bohr
  9. Galileo Galilei
  10. Michael Faraday

Other notables: Stephen Hawking, Edwin Hubble, Leonard Susskind, Christiaan Huygens

Favorite Mathematicians

  1. Ada Lovelace
  2. Alan Turing
  3. Johannes Kepler
  4. Rene Descartes
  5. Isaac Newton
  6. Emmy Noether
  7. George Boole
  8. Blaise Pascal
  9. Johann Gauss
  10. Grace Hopper

Other notables: Daphne Koller, Grady Booch, Leonardo Fibonacci, Evelyn Berezin, Benoit Mandelbrot

Fediverse Supporter

Logos.png

Some OSS Projects I Run

  1. Liquid Victor : Media tracking and aggregation [used to assemble this presentation]
  2. Prehensile Pony-Tail : A static site generator built in c#
  3. TestHelperExtensions : A set of extension methods helpful when building unit tests
  4. Conference Scheduler : A conference schedule optimizer
  5. IntentBot : A microservices framework for creating conversational bots on top of Bot Framework
  6. LiquidNun : Library of abstractions and implementations for loosely-coupled applications
  7. Toastmasters Agenda : A c# library and website for generating agenda's for Toastmasters meetings
  8. ProtoBuf Data Mapper : A c# library for mapping and transforming ProtoBuf messages

http://GiveCamp.org

GiveCamp.png

Achievement Unlocked

bss-100-achievement-unlocked-1024x250.png

Fantasy Baseball - Base Model

TransparentImage-1600x800.png

Fantasy Baseball - Fine-Tuned

TransparentImage-1600x800.png

Fantasy Baseball - Fine-Tuned

TransparentImage-1600x800.png

The Simpsons - S7 E8

Wikipedia-Simpsons-Season7-Episode8-Synopsis.png

Last Week on Job - Base Model

TransparentImage-1600x800.png

Last Week on Job - Fine-Tuned Model

TransparentImage-1600x800.png

Questions to be Answered

  • What does fine-tuning do?
  • What problems does it solve?
  • What problems doesn't it solve?
  • What other methods are there?
  • When should we use each?
Five Doors 800x800.png

What did our Fine-Tuning Do?

  • Same Knowledge, Different Behavior
    • We didn't add facts here
    • We added a pattern of behavior
  • Other patterns we could tune for
    • Responses are in JSON format
    • Responses use our brand voice
    • Responses list options before answering
    • Responses are a label from a list
BehavioralChange-800x800.png

Transformer Architectures

A neural network architecture that has enabled the recent advancements in NLP

  • Based on the 2017 Google paper Attention is All You Need

  • Key Breakthrough: The Self-Attention Mechanism

    • Focus on most relevant tokens
    • Add context even at a distance
  • Enables Processing of Entire Sequences in Parallel

    • Unlike traditional RNNs that process data sequentially
Self Attention 800x800.jpg

Transformer (Simplified)

Transformer Architectures - 938x800.png

Embeddings

  • A point in multi-dimensional space
  • Mathematical representation of a word or phrase
  • Encode both semantic and contextual information

  • Model: text-embedding-ada-002
  • Vectors normalized to unit length
  • Use 1536 dimensions
VectorSpace3D.png
  Ram - Just Statements.png
  Ram - With Clusters.png

Embedding

Creating Order from Chaos

  • Unstructured string => Structured float[]
  • Allows mathematical operations
    • Cosine Similarity & Distance
    • Nearest Neighbor Search
    • Clustering
    • Vector Addition & Subtraction
    • Dimensionality Reduction (e.g., PCA)
    • Anomaly Detection
VectorRelationships-QueenToKing-WomanToMan.png

Attention Blocks

Transformer Architectures - Attention - 938x800.png

Model Differences

  • Base Models

    • Predict from the full training corpus
    • Provide a single response quickly
    • Only "consider" the most-likely response
  • Fine-Tuned Models

    • Follow fine-tuned patterns
    • Can respond with multiple options initially
    • Then predict based on those options
  • Reasoning Models

    • Pre-trained to follow reasoning patterns
    • May also have other tweaks
SelectFromOptions-800x800.png

The Pattern Simulates thinking

  • The pattern can simulate multiple prompts
  • Think first, then act
  • Allows for multiple possibilities
ThePatternSimulatesThinking-800x800.png

Postponement - Base Model

TransparentImage-1600x800.png

Postponement - Reasoning Model

TransparentImage-1600x800.png

Theory of Mind - Base Model

TransparentImage-1600x800.png

Theory of Mind - Reasoning Model

TransparentImage-1600x800.png

Fine-Tuning Data

FineTuningData-JsonL.png
 

The Data is Not Reinforced

FineTuningData-SingleEntry-PlotSynopsis.png

When to Fine-Tune Data

Fine-tune data into the model when the "knowledge" is a pattern of static associations

  • The information must be
    • Small - few facts
    • Stable & Unchanging
    • Closed-domain (won't expand)
    • Unlikely to conflict with future facts
  • Examples
    • Error 123 indicates X
    • Status 234 indicates Y
    • This Acronym means Z
FineTunedData 800x800.png

Fine-Tuning Is for Behavior

Fine-Tuning Changes Response Patterns

  • Best for teaching the model how to respond
  • Not for changing what the model should respond with

We'll look at better ways to adjust the model's knowledge later in this session

ImpossibleGeometry-800x800.png

Use Case - IntentBot

IntentBot on GitHub

  • An OSS agentic framework
    • Modular
    • Microservices‑based
    • Designed before LLMs existed
IntentBot-Github.png

Use Case - IntentBot

  • All components are pluggable
    • Intent determination
    • Intent-based Routing
    • Fulfillment Services
IntentBot-Flow.png

Classifying Utterances

  • User: Set the office lights to 40 percent and make them warm white

    • Intent: AdjustLighting
  • User: It's too cold in here, bump the temperature up a couple degrees

    • Intent: AdjustClimate
  • User: What is my current Azure spend for the month?

    • Intent: QueryAzureSubscription
  • User: Mark messages from marketing@spammer.biz as spam

    • Intent: ManageEmail
  • User: Create a placeholder for a blog post called Fine-Tuning AI Models with Microsoft Foundry

    • Intent: ManageBlog
  • User: Add an A record for api.cuyahogapress.com pointing to 192.168.0.0 with a 300‑second TTL

    • Intent: ManageDns

Adjust Lighting Intent

AdjustLightingIntent-TrainingData.png

Adjust Lighting - Guest Room

AdjustLightingIntent-TrainingData-GuestRoomLights.png

What If?

What if we give the model an utterance that it hasn't been fine-tuned to handle?

Will it:

  • Throw an error?
  • Fall-back to UnknownIntent?
  • Make something up?
UnexpectedPath (800x800).png

Ways to Control Model Output

  • Static Context Engineering
    • Add tokens to the designed prompt
  • Dynamic Context Engineering
    • Add tokens at runtime
  • Constrained Decoding
    • Restrict what tokens the model can produce
  • Post‑Generation Validation
    • Reject or correct the output after it’s produced
  • Fine-Tuning
    • Modify the model's behavioral priors
MeansOfControl (800x800).png

Static Context Engineering

Add tokens to the designed prompt

  • System prompts
  • Instructions
  • One-shot or few‑shot examples
StaticContextEngineering (800x800).png

Static Context Engineering

You are a helpful AI Assistant

vs

You are an expert on The Simpsons with deep knowledge of episodes, character arcs, running gags, and cultural references. Your tone is concise, confident, and lightly humorous, like a TV historian who has spent decades cataloging Springfield's finest chaos. Your output must always be a single JSONL line in this structure: { "messages": [{ "role": "user", "content": "<user query>" },{ "role": "assistant", "content": "<assistant response referencing a real Simpsons episode>" }]}

Dynamic Context Engineering

Add tokens at runtime

  • RAG
  • GraphRAG
  • Tool outputs
  • Memory injection
DynamicContextEngineering (800x800).png

Retrieval Augmented Generation (RAG)

  • Combines the benefits of retrieval-based and generative models

  • Identify and retrieve relevant information

    • Agument context of the generative models
    • Generative responses based on the augmented context
  • Potential uses include

    • Explore large documentation sets
    • Summarize articles in light of known relevant information
RAG 800x800.jpg

Constrained Decoding

Restrict what tokens the model can produce

  • JSON schema enforcement
  • Grammar constraints
  • Token blacklists/whitelists
cl100k-tokens.png

Some Single Token Words

SingleToken-EndOfExcelTable.png

Post-Generation Validation

Reject or correct the output after it's produced

  • Intent whitelists
  • Schema validation
  • Supervisory agents
  • Client enforcement
PostGenerationValidation (800x800).png

Fine-Tuning

Modify the model’s behavioral priors

  • Classification patterns
  • Formatting habits
  • Stylistic tendencies
FineTuning (800x800).png

IntentBot - The Hybrid Approach

  • Fine-Tuning : Intent Classification

    • Teaches the model the response pattern
  • Static Context for Allowed Intents

    • System prompt provides the list of valid intents
  • Post-Generation Validation

    • Checks that the returned intent is in the allowed set
    • If invalid, sends back with corrective feedback
  • Constrained Decoding (Possible)

    • If single-token labels, restrict output to those tokens
    • Adds mechanical guardrails but also risk
  • Tooling for Service Discovery (Future)

    • Query services to confirm an intent is supported
    • Resolve borderline user requests
HybridApproach (800x800).png
 

Fine-Tuning Data

FineTuningData-JsonL.png
 

Key Takeaways

  • Fine-tuning → Behavior

    • Shapes how the model responds
    • Establishes patterns, structure, and consistency
    • Does not add facts or enforce hard constraints
  • Context Engineering → Knowledge

    • Provides information the model didn't previously have
    • Static context = fixed instructions
    • Dynamic context (ie RAG) = runtime grounding
  • Hybrid Approaches Are Common and Powerful

    • Combine behavior shaping + knowledge injection
    • Add constraints and validation for reliability
    • Architecture > any single technique
MeansToControlModelOutput (800x800).png

Call to Action

  • Start with Prompt Engineering

    • Establish clear instructions and structure
    • Shape the model's behavior with minimal effort
  • Move to RAG for More Complex Scenarios

    • Bring in external knowledge when needed
    • Keep information fresh, grounded, and scalable
    • Bring in Documents, Facts, Memory & Tools
  • Fine‑Tune When Behavior Matters

    • Lock in consistent behaviors, formatting, and workflows
    • Improve reliability for repeated, structured tasks
  • Use Combinations for Best Results

    • Real systems blend all of the above
    • Architecture beats any single technique
FineTuning-CallToAction (800x800).png

Resources

FineTuning_QR (800x800).png