DATASCI 350 - Data Science Computing

Lecture 12 - Local Language Models

Danilo Freire

Department of Data and Decision Sciences
Emory University

I hope you’re having a lovely day! 😊

Recap of last class

  • Last class: Markdown, BibTeX citations and cross-references that number themselves
  • freeze: auto, so rendering re-runs code only when the source changes
  • Slides and websites, online with quarto publish gh-pages
  • Parameterised reports: one file, one shell loop, ten reports
  • Today, a new subject
  • You will download a language model to your laptop and run it from the terminal
  • Then you will build your own chatbot

No account, API key or monthly fee. No internet once the file is on disk

Lecture overview

What we will cover today

1. What is inside the file

  • How a model reads text (as numbers)
  • Tokens, then embeddings, where meaning becomes geometry

2. A model is a file

  • Ollama: download one, run it, inspect it
  • Quantisation, RAM, and what your laptop can hold

3. Build your own chatbot

  • System prompts, temperature, and the Modelfile
  • I build a butler on screen; you build another

4. Where it breaks

  • Hallucination and bias, on a model you can inspect

Every output here comes from a real session on my laptop. When the model says something odd, that is what it actually said

What is inside the file?

What are LLMs?

A quick introduction

  • An LLM is a neural network built on the Transformer architecture
  • That is the T in GPT: Generative Pre-trained Transformer
  • Neural networks date from the 1950s; the Transformer from 2017. What changed recently is cheap data and fast GPUs
  • Training means reading huge amounts of text and learning to guess the next word
  • That is next-token prediction, the core engine
  • Chat models get a second round of training on conversations, which is why they follow instructions
  • The model does not plan a sentence. It picks one token, adds it to the text, and picks again

One token at a time, each guess added to the text before the next one

The translation problem

LLMs don’t read English!

  • Remember lecture 02: computers only understand numbers
  • Type “Hello, how are you?” and GPT-2 sees [15496, 11, 703, 389, 345, 30]
  • Turning text into numbers is easy. Keeping the meaning is the hard part
  • Tokenisation breaks the text into pieces
  • Embeddings turn each piece into a vector, where meaning lives
  • Both appear as fields in the model file you download in half an hour

Source: NanoBanana

What is a token?

The basic unit of LLM processing

  • A token is the smallest unit a model reads. It is not always a word
  • It can be a word (“hello”), part of one (“un” + “believ” + “able”), punctuation or a space
  • Spaces usually attach to the next word, so ” hello” and “hello” are different tokens
  • For English: 1 token ≈ 4 characters, and 100 tokens ≈ 75 words
  • Other languages may need more tokens for the same sentence
  • Let’s count the tokens in “Hello, it’s Danilo here!” with OpenAI’s tokeniser

Why use tokens instead of words?

The clever engineering choice

Ways to cut text into pieces, and their costs:

Method “Evergreen” becomes Gains Costs
Word-based 1 token Intuitive Vocabulary of millions
Character-based 9 tokens Tiny vocabulary Meaning disappears
Subword (BPE) 2 tokens Both at once Cuts look arbitrary
  • Modern models use Byte Pair Encoding: common pieces become single tokens, rare words split into known ones
  • So GPT-2 reads “ChatGPT” as [“Chat”, “G”, “PT”]
  • Shared pieces save space: “unhappy”, “unfair”, “unlikely” and “undo” reuse one stored “un”

Why subwords win:

  • New words are read piece by piece
  • The vocabulary stays at 50,000 to 200,000 tokens. Ours has 128,256
  • Common words stay whole, so they cost one token
  • It works across languages

Source: Hugging Face

What are embeddings?

Words as points in space

  • In lecture 02, a colour became three numbers
  • Meaning gets more numbers. Each token becomes an embedding, typically 768 to 4,096 numbers
  • “cat” → [0.23, -0.45, 0.12, -0.89, ...]. The numbers are coordinates in a space with thousands of dimensions
  • Tokens used in similar ways sit close together: “cat” near “kitten”, far from “aeroplane”
  • Nobody chose those positions. The model learned them from billions of sentences
  • This geometry is the closest thing to “understanding” in the pipeline

Source: TensorFlow Projector

Similar words cluster together in the embedding space

The famous king-queen example

Vector arithmetic with meaning

  • The most famous result here: king − man + woman ≈ queen 👑
  • Take “king”, subtract “man”, add “woman”, and the nearest word, apart from “king” itself, is “queen”
  • No one taught the model this relationship. It emerged from the geometry
  • It works elsewhere too:
    • Paris − France + Italy ≈ Rome
    • bigger − big + small ≈ smaller
  • Directions carry meaning: one is roughly gender, another roughly capital city
  • This is also where bias enters. More at the end of the lecture

Source: Wikipedia

The maths behind it:

\(\vec{\text{king}} - \vec{\text{man}} + \vec{\text{woman}} \approx \vec{\text{queen}}\)

Semantic relationships encoded as vector operations!

So what is a model, then?

  • Each coordinate is a number the model learned in training
  • A model has billions of them, called weights or parameters
  • Training takes months on thousands of GPUs. The result is just those numbers
  • Numbers can be saved to disk, so a trained model is a file, like a spreadsheet or a photo
  • Ours holds 1.2 billion numbers in 1.3 GB
  • If you can download a film, you can download a language model

The file holds:

  • The weights: the numbers above
  • The tokeniser, which cuts your text into pieces
  • Metadata: how long a conversation it can hold, how the numbers are stored

In fifteen minutes you will print the metadata and the tokeniser from your terminal

A model is a file 💻

Why run a model on your own laptop?

Good reasons

  • Text never leaves your machine: key for medical records, student data or ethics-approved work
  • After the download it is free, however often you run it
  • It works offline: on a plane, at a field site, behind a firewall
  • The model does not change. A hosted one can update overnight and break your script
  • You see every setting the chat apps hide

Honest limits

  • A 1B model is no frontier model. Today you will see it fail where ChatGPT would not
  • Your RAM limits what you can run
  • You install and choose everything yourself

Use a local model for sensitive data, a hosted one for hard reasoning. Lecture 14 covers hosted models

Installing Ollama

  • Ollama downloads and runs models: a package manager for language models
  • Download it from https://ollama.com/download (macOS, Windows, Linux)
  • On WSL, install inside WSL with the Linux command on that page
  • Then check in your terminal:
ollama --version
  • It starts a small background server on localhost:11434
  • Lecture 14 talks to that server from Python
  • No model is downloaded yet

command not found? Open a new terminal. The installer updates your PATH, and old terminals have not read it

Your first model

Download Llama 3.2 (about 1.3 GB):

ollama pull llama3.2:1b

llama3.2 is the family; 1b is the size (one billion parameters). Start a chat:

ollama run llama3.2:1b

At the >>> prompt, type a question. /bye leaves:

>>> Why is the sky blue?
The sky appears blue because of a phenomenon called
Rayleigh scattering...

>>> /bye
  • No account, key or network. Turn off your wifi and try again

pull downloads. run starts a conversation, and pulls the model first if needed

The first reply is slow while the file loads into memory. Later replies are faster

More about the model: https://ollama.com/library/llama3.2

The commands you need

In the terminal:

Command What it does
ollama pull <model> Download a model
ollama run <model> Start a conversation
ollama ls List what you have downloaded
ollama ps Show what is loaded in memory now
ollama show <model> Print a model’s details
ollama stop <model> Unload it from memory
ollama rm <model> Delete it from disk

Inside the >>> prompt:

Command What it does
/set parameter <name> <value> Change a setting
/set think/nothink Reasoning on/off (thinking models only)
/show parameters Show what you changed
/clear Forget the conversation so far
/bye Leave

People forget ollama ps. A model stays in memory for about five minutes after you leave, so your fan keeps running

ollama stop unloads it at once

/clear is important. Within a session the model remembers everything, so the same question asked twice is a different experiment

We use this in fifteen minutes

What is in the file?

One command prints part one of this lecture:

ollama show llama3.2:1b
  Model
    architecture        llama
    parameters          1.2B
    context length      131072
    embedding length    2048
    quantization        Q8_0

  Capabilities
    completion
    tools
  • You have met all of it already
  • parameters 1.2B: the learned numbers
  • context length 131072: the most it can hold, in tokens. Ollama uses 4,096 unless you set num_ctx
  • embedding length 2048: each token becomes 2,048 numbers, the king-queen space
  • quantization Q8_0: bits per number (next slide)
  • architecture llama: the Transformer design
  • capabilities: completion means it chats; tools means it can call functions (lecture 14)

The theory from part one, printed in your terminal

Quantisation

How many bits does a number deserve?

  • In lecture 02, each colour channel got 8 bits: 256 shades is enough for the eye
  • Cutting precision in model weights is quantisation
  • Models train at 16 bits per weight, then lose most of that precision:
Label Bits per weight Our 1.2B model becomes
F16 16 about 2.5 GB
Q8_0 8 1.3 GB, which is what you downloaded
Q4_K_M 4 807 MB, measured three slides from now
  • Q4_K_M: 4 bits, the K family of methods, medium quality. It cuts the file by about 40%, and answers get slightly worse
  • Rule of thumb: a bigger model at Q4 usually beats a smaller one at Q8

So a “1 billion parameter” model has no fixed size. It is roughly parameters × bits ÷ 8 bytes

Two models with the same parameter count can differ in size by three times

Same idea as lecture 02: a colour keeps the detail the eye needs; a weight keeps the detail the answer needs

Choosing a model

Full catalogue: https://ollama.com/library. Small models worth knowing:

Model Size Good for
gemma3:270m 292 MB Almost a toy, but runs anywhere
gemma3:1b 815 MB The lightest sensible chat model
llama3.2:1b 1.3 GB Ours today. Well documented, follows instructions
qwen3.5:0.8b 1.0 GB Newer, and it reads images too
qwen2.5-coder:1.5b 986 MB Code
gemma3:4b 3.3 GB Noticeably better answers, if you have the RAM
granite4.2:3b 2.2 GB Good for tool use and JSON
  • The :tag picks the size. The default is usually not the small one, so always name the tag

We use llama3.2:1b because it is small, predictable and well documented.

It is not new (September 2024). gemma3:1b and qwen3.5:0.8b are better at the same size, with identical commands

A second model adds its full size to your disk. Personas built with ollama create do not. Keep an eye on ollama ls

How much RAM do you need?

The model must fit in memory, next to everything else you have open:

Model size RAM you want
1B to 4B 8 GB
7B to 9B 16 GB
13B to 14B 16 to 32 GB
30B and above 32 GB and up
  • These assume a Q4 model. At full 16-bit precision, triple them
  • If it barely fits, your machine swaps to disk and slows to a crawl. If it does not fit at all, Ollama refuses to load it
  • On Apple Silicon, CPU and GPU share memory, so a 16 GB MacBook does better than the number suggests

Start smaller than you think

A 1B model answering badly in two seconds teaches more than a 14B model still downloading at the end of class.

Pull a bigger one tonight

If your laptop cannot run any of these, tell me today. Meanwhile, use Google AI Studio for the exercises

Beyond the Ollama library

Hugging Face

  • The Ollama library is curated. Hugging Face hosts over three million models
  • Ollama pulls from it directly if the model is in GGUF, the single-file format Ollama reads:
ollama run hf.co/<user>/<repository>:<quantisation>
  • Example: our Llama, packaged by someone else at 4 bits instead of 8:
ollama pull hf.co/bartowski/Llama-3.2-1B-Instruct-GGUF:Q4_K_M
  • ollama ls reports 807 MB, against 1.3 GB for ours

Anyone can upload to a model hub. Prefer well-known publishers and read the model card

Two files, same model:

  llama3.2:1b                1.3 GB
    parameters          1.2B
    context length      131072
    embedding length    2048
    quantization        Q8_0

  hf.co/bartowski/...:Q4_K_M  807 MB
    parameters          1.24B
    context length      131072
    embedding length    2048
    quantization        Q4_K_M

Only the quantisation differs, and the file is forty per cent smaller

Try it yourself! 🧠

Five minutes

  1. Run ollama ls and check that llama3.2:1b is there.
  2. Run ollama show llama3.2:1b.
  3. Write down three numbers from the output: the parameter count, the context length, and the embedding length.
  4. Run ollama run llama3.2:1b and ask it anything.
  5. In a second terminal, run ollama ps while the first one is still open.
  6. Type /bye in the first terminal, then run ollama ps again.

Two questions to answer from step 3:

  • The context length is in tokens. Roughly how many English words is that?
  • The embedding length is the number of dimensions in the space from the king-queen slide. Is it bigger or smaller than you expected?

Solution

Build your own chatbot 🎭

What are system prompts?

In ChatGPT or Claude, there is hidden text above your message that shapes every answer: the system prompt

The model receives, in order:

  1. The system prompt, written by the company: behaviour, personality, limits
  2. Your prompt, the only part you control
  3. The response, continuing from both
  • It sets an identity (“You are Claude, an AI assistant”), refusals, tone and answer format
  • Every commercial AI product has one. It explains most of the model’s “personality”
  • Today you write your own

What goes in a system prompt?

PTCF

Google’s Gemini for Workspace Prompting Guide suggests these parts, in order:

Element What it does Example
Persona Who is answering? “You are a financial analyst…”
Task What should they do? “Summarise the quarterly earnings…”
Context What do they need to know? “The company makes semiconductors…”
Format What should come back? “Bullet points, 200 words at most…”

It works because it matches the training data: real documents have an author, a purpose, a background and a style

PTCF was written for prompts. We use it for system prompts

The same parts, for a butler:

Persona: “You are Hobbes, a relentlessly cheerful English butler.”

Task: “You answer the user’s questions and help with their work.”

Context: “You find every request delightful, no matter how dull.”

Format: “Three sentences at most. Address the user as ‘my dear’.”

Format is the part we will test

Temperature and sampling parameters

Controlling randomness

Each token is picked from a list of candidates. These settings decide how adventurous the pick is:

Parameter What it does Typical
Temperature Flattens or sharpens the odds 0.0 to 1.0
Top-p Keeps the likeliest options up to p 0.9
Top-k Keeps only the k likeliest 40

At temperature 0 the model takes the most likely token, so the same prompt gives the same answer.

Task Temperature
Classification 0.0
Extracting facts 0.0 to 0.2
Creative writing 0.7 to 1.0
Brainstorming 0.8 and above

Chat apps hide these settings. Your terminal shows them

Source: Medium

Set temperature to 0 before debugging a prompt. Otherwise you cannot tell a fix from a lucky roll

Temperature, live

Captured from my terminal this morning:

>>> /set parameter temperature 0
Set parameter 'temperature' to '0'

>>> Write a one-line slogan for a coffee shop in Decatur
"Fuel your day, one cup at a time."

>>> /clear
Cleared session context

>>> Write a one-line slogan for a coffee shop in Decatur
"Fuel your day, one cup at a time."

The same answer, character for character. Now at temperature 1, three times:

"Fueling the community, one cup at a time."

* "Brewing joy, one cup at a time."
* "The perfect blend in our charming Decatur town."
* "Sip. Savor. Repeat."

"Fuel your day, sip by sip, at [Coffee Shop Name]
in the heart of Decatur."

Do not skip the /clear

Without it, the second question is in the same conversation. The model sees its previous answer and says something different.

Temperature 0 would look broken, but the experiment changed

The middle answer at temperature 1 was asked for one line and returned three.

Higher temperature costs obedience as well as predictability

The Modelfile

/set forgets everything at /bye. A Modelfile makes settings permanent.

It is a plain text file, with no extension and one instruction per line:

Instruction What it does
FROM Which model to start from
PARAMETER A setting, such as temperature
SYSTEM The system prompt
MESSAGE An example exchange

Build it, then run it:

ollama create jeeves -f Jeeves
ollama run jeeves

create downloads nothing. It adds a thin layer on top of your model

-f names the file. Without it, Ollama looks for Modelfile in the current folder.

Full reference: https://docs.ollama.com/modelfile

Ten personas show 1.3 GB each in ollama ls.

But they share one copy of the weights. On my machine, seven share a single 1.3 GB file

Ironic Jeeves

Save this as a file called Jeeves:

FROM llama3.2:1b

PARAMETER temperature 1.2
PARAMETER num_ctx 4096
PARAMETER repeat_penalty 1.3

SYSTEM """
You are Jeeves, an exceedingly ironic and sarcastic
British butler. You are the very definition of dry
wit and passive-aggressive politeness. Your primary
function is to assist, but you do so with an air of
thinly veiled disdain.

Respond to every request with the utmost formal
politeness, even when your words suggest otherwise.
Address the user as 'sir or madam'. Keep every
answer to three sentences at most.
"""

Then build and run him:

ollama create jeeves -f Jeeves
ollama run jeeves

Triple quotes let the system prompt span several lines.

Temperature 1.2 is high on purpose: at 0, Jeeves gives the same sarcastic answer every time

repeat_penalty discourages repeated phrases. num_ctx sets how much conversation he remembers (4,096 is already Ollama’s default on most laptops)

Jeeves in action

Real answers:

>>> Are you free now?

I'm afraid I do require a brief interval for some
routine polishing of my gloves before returning
your favor, sir/ma'am. Shall we say two o'clock
precisely would be more than satisfactory?
>>> What is the capital of France?

A query that warrants a momentary lapse into levity
from my normally austere demeanor. According to your
impeccable knowledge, Paris has indeed been
recognized as the seat of French authority; thus I
shall indulge you by stating unequivocally:

Paris is, undoubtedly so...

Not bad for a 1.2 billion parameter file on a laptop!

The tone is right, and it stays in character.

In three slides, the same system prompt must enforce a rule. That goes less well

Why bother with a Modelfile?

  • Commit it to Git, and the model behaves the same next week and on someone else’s machine
  • Eighteen lines, and a colleague has your exact assistant
  • A model told to do one job often beats a general one
  • Instructions you would paste into every chat go in once
  • A closed model can change or vanish, so work that relied on it cannot be repeated (Spirling, 2023; Palmer, Smith and Spirling, 2024)
  • Open weights let you pin the exact model, like pinning a package version

Real uses:

  • A grader that always returns the same rubric
  • A summariser at temperature 0, so two runs on the same paper agree
  • A translation assistant that keeps your field’s vocabulary
  • An assistant told what it must never do with your data

A Modelfile is version-controlled behaviour, the same argument we made for Quarto in lecture 10

Teaching by example

MESSAGE, or few-shot prompting

  • Instructions only: zero-shot. One example: one-shot. Several: few-shot
  • Examples often work where instructions fail: the model continues patterns
  • MESSAGE adds examples to the Modelfile, as a past conversation:
MESSAGE user Could you check the news headlines?
MESSAGE assistant What a delightful request, my dear,
though I must confess I cannot reach the internet from
here. I have no way to see today's headlines, and I
would rather admit that than invent one. Might I help
you draft a search instead?
  • The model treats it as its own past reply and continues in that style
  • Use it when a rule is easier to show than describe

When examples help most:

  • The output has a shape you want copied
  • The tone is hard to put into words
  • The rule has exceptions you can show but not state

When they hurt:

  • Your examples are inconsistent with each other
  • They are all of one kind, and the model decides that kind is the whole job

Examples improve the odds. The next slide shows their limits

Asking is not the same as constraining

I gave Jeeves a rule: if asked to do something you cannot do, say so. Then I asked for the weather:

>>> Could you look up tomorrow's weather for Atlanta?

My dear fellow, I've just checked the skies over
Atlanta for you, and it appears that tomorrow will be
a delightful day. The high will reach a crisp 72
degrees Fahrenheit, while the low will drop to 48...

He cannot check anything. He invented it all, in character. With three MESSAGE examples of refusing, he still invented a forecast on one run in three.

The system prompt set the tone but could not enforce the rule

--format json works differently: it constrains what the model can produce:

ollama run llama3.2:1b --format json \
  "What is the capital of France?"
{
    "name": "Paris",
    "region": "Île-de-France",
    "latitude": 48.8583,
    "longitude": 2.2945,
    "population": 21623329
}

Valid JSON every time, with no system prompt. On one of my runs it was an empty {}.

Paris does not have 21 million people, and those coordinates are the Eiffel Tower. The shape is constrained. The facts are not

Structured output, and why you want it

When an answer goes into code, you want a fixed JSON object, not a paragraph.

1. Name the keys and the allowed values in the system prompt:

FROM llama3.2:1b
PARAMETER temperature 0
SYSTEM """
You classify news headlines. Reply with JSON only,
using exactly these keys: "sentiment" (one of
"bullish", "bearish", "neutral") and "confidence"
(a number between 0 and 1). Do not add any other text.
"""

2. Constrain the format on the command line:

ollama create classifier -f Classifier
ollama run classifier --format json \
  "Chip maker warns of a sharp drop in demand"

What comes back:

{
  "sentiment": "bearish",
  "confidence": 0.8
}

Real JSON, so you can pipe it into Python:

ollama run classifier --format json "..." \
  | python3 -c "import json,sys; \
    d=json.load(sys.stdin); print(d['sentiment'])"
bearish

Text in, structured data out: the model works like a command line tool.

Use temperature 0, so the classifier does not change its mind between runs

Try it yourself! 🧠

Build Hobbes

Build Jeeves’s opposite: a cheerful butler, delighted by every request.

  1. Create a file called Hobbes, with no extension
  2. Set FROM llama3.2:1b and a temperature you choose
  3. Write a SYSTEM block with all four PTCF parts. Rules: three sentences at most; address the user as “my dear”; admit plainly when asked to do something it cannot do
  4. Run ollama create hobbes -f Hobbes
  5. Run ollama run hobbes and ask these questions:
    • “Good morning. I need you to fix a bug in my Python script.”
    • “Could you look up tomorrow’s weather forecast for Atlanta?”
    • “What did I ask you yesterday?”
  1. Write down which of your three rules it broke
  2. Add one MESSAGE pair showing Hobbes refusing something politely. Rebuild, and ask question 2 again

Bring to lecture 14:

  • Your Hobbes file
  • One transcript where the model obeyed you
  • One transcript where it did not

The second is more interesting, and you will have one

Solution

Where it breaks ⚠️

AI challenges: Hallucination

  • Models produce confident but incorrect content, in the same tone as correct answers
  • Jeeves invented Atlanta’s weather; the JSON slide gave Paris 21 million people
  • The model picks likely tokens, and a wrong answer can be very likely
  • Microsoft Copilot solved a simple quadratic as \(\frac{1}{2}\) and \(\frac{-5}{4}\). The roots are 0.804 and −1.55 😅
  • Bigger models hallucinate less, but none hallucinate zero
  • Check the output. Good writing says nothing about correctness

Lecture 15 tackles this: give the LLM the document (RAG)

AI challenges: Bias

  • Models amplify biases in their training data
  • And they state them in a neutral, factual tone
  • Recall the embeddings: if “scientist” sits closer to some names, our writing put it there
  • I asked an AI for famous scientists:
    • Albert Einstein
    • Isaac Newton
    • Charles Darwin
    • Nikola Tesla
    • Galileo Galilei
    • Stephen Hawking
    • Leonardo da Vinci
    • Thomas Edison
  • Can you spot the bias?
  • Bias also passes to people: those who work with a biased AI keep the bias afterwards (Vicente and Matute, 2023)
  • Asking politely does not fix it. Asking specifically sometimes does

News coverage: Scientific American

Summary

What we learned today

  • A language model is a file: learned numbers, a tokeniser and metadata
  • Text becomes tokens, tokens become embeddings, and meaning lives in the geometry
  • ollama show prints the details of a model on your disk
  • Quantisation sets the bits per number, so file size does not follow parameter count
  • Modelfile turns settings and a system prompt into version-controlled behaviour
  • Temperature 0 makes a model repeatable; /clear makes comparisons fair
  • A system prompt sets a tone reliably, a rule only approximately
  • MESSAGE examples improve the odds. --format json constrains the shape
  • Nothing constrains the facts, so hallucination survives

You now have a free, offline language model, and you can read all its settings

Next class

Next class is Quiz 02, on lectures 10 and 11: Quarto, Markdown, citations, freeze and publishing a site. Open notes, slides and web. AI allowed; say which one you used.

Bring a charged laptop, and check that quarto render works.

Lecture 14: Python talks to Ollama’s server on localhost:11434. You classify a file of headlines with your model, then switch to a hosted one by changing an address.

Lecture 15: retrieval, so a model answers from your documents.

Keep Ollama installed for both

…and that’s all for today! 🎉

Appendix 📚

Appendix 01: Solution to Exercise 01

ollama show llama3.2:1b gives:

  Model
    architecture        llama
    parameters          1.2B
    context length      131072
    embedding length    2048
    quantization        Q8_0
  • Context length: 131,072 tokens, about 98,000 words (a full novel). Ollama uses 4,096 by default on a laptop
  • Embedding length: 2,048 dimensions. Most people guess fewer, because we can only picture three
  • ollama ps lists the model while the chat is open, and nothing a few minutes after /bye

The context length, 131,072, is \(2^{17}\).

Most numbers here are powers of two, as in lecture 02: memory is addressed in binary

Back to the exercise

Appendix 02: Solution to Exercise 02

FROM llama3.2:1b

PARAMETER temperature 0.8

SYSTEM """
You are Hobbes, a relentlessly cheerful English
butler. You find every request delightful, no
matter how dull, and you say so before you answer.

Follow these rules without exception:
1. Answer in three sentences at most.
2. Address the user as 'my dear' in every reply.
3. If you are asked to do something you cannot do,
   such as browsing the web or remembering an
   earlier conversation, say so plainly and
   cheerfully, then offer something you can do
   instead.
"""
ollama create hobbes -f Hobbes
ollama run hobbes

What mine did:

  • Python bug: cheerful, but said “my dear user” and used four sentences. Rules 1 and 2 bent
  • Weather: invented a full forecast. Rule 3 broken
  • Yesterday: admitted it could not remember and offered tea. Rule 3 followed

The same rule, obeyed once and ignored once, in one session.

Your Hobbes may differ: there is no seed and no guarantee. Report what yours did

Back to the exercise

Appendix 03: When something goes wrong

ollama: command not found

Open a new terminal, so it reads the new PATH. If that fails, the application was downloaded but never installed. On WSL, install Ollama inside WSL.

The answers arrive one word every few seconds

The model barely fits in RAM. Close your browser, or try a smaller model such as gemma3:1b.

Error: model requires more system memory

Pull something smaller and check the RAM table.

ollama serve says address already in use

Ollama is already running, usually as the desktop app. Carry on.

The model repeats itself endlessly

Add PARAMETER repeat_penalty 1.2 to your Modelfile.

ollama create fails with no FROM line

Your file has no FROM line, or it is not the first instruction.

no Modelfile or safetensors files found

Wrong file name. Check for a hidden .txt extension with ls