My Digital Twin
You fine-tune a small language model on your own, voluntarily shared texts — and experience first-hand how much, and how little, of it is really "you".
In a nutshell
What: In 16.1 you saw that a twin is made of proportions — how much Bee, how much Ant. Now you go a step further: you take a ready small language model and fine-tune it on your own texts until it writes on in your tone. A talking twin.
The core idea: the astonishing and the sobering lie close together. The model hits your style strikingly well — your favourite words, your sentence structure, your emojis. And yet it lacks the decisive thing: it has experienced nothing, means nothing, wants nothing. It is your surface, not your inside.
You need: your own texts (WhatsApp export, essays, diary — only yours), Python with
transformers and datasets, ideally on a Colab GPU.
What it's about
When you read a person's face, voice, language and network, you can build from it a model that imitates and predicts them — a digital twin. At its best it is a gift: a patient mirror that helps you understand yourself better. But in someone else's hand the same twin becomes a shackle: whoever can predict you accurately enough can also steer you — show you exactly the message that grips you, in the moment of your weakness.
So that you know both sides from your own experience, you build here your own small twin — small enough to see through, real enough to startle. And in doing so you hold up the golden rule: what is found out about you belongs to you. That is why everything here stays on your machine.
Before you start — consent and data protection
Use exclusively your own texts. A WhatsApp export also holds other people's messages — those are not yours and must not go into the training. Filter strictly to your own lines, remove names, addresses and phone numbers, and keep the data and the model on your machine (or in your private Colab). This is no formality but the core of the chapter: a twin should serve you, not dispose of others.
Step 1 — Collect your texts
Gather a few hundred of your own lines in a text file — one statement per line. The more, and the more typical, the better the twin hits your tone. The full code is on GitHub.
# my_texts.txt: only YOUR own lines, one per line
with open("my_texts.txt", encoding="utf-8") as f:
lines = [z.strip() for z in f if z.strip()]
# safety net: drop very short/empty lines
lines = [z for z in lines if len(z) > 10]
print(len(lines), "own text lines to learn from")
Step 2 — Fine-tune a small language model
We take a ready small GPT-2 and train it a few rounds further on your lines. It learns nothing new about the world — it learns your way of writing.
from datasets import Dataset
from transformers import (AutoTokenizer, AutoModelForCausalLM,
DataCollatorForLanguageModeling,
TrainingArguments, Trainer)
name = "gpt2" # small English language model
tok = AutoTokenizer.from_pretrained(name)
tok.pad_token = tok.eos_token # GPT-2 has no pad token of its own
ds = Dataset.from_dict({"text": lines}).map(
lambda b: tok(b["text"], truncation=True, max_length=64), batched=True)
model = AutoModelForCausalLM.from_pretrained(name)
collator = DataCollatorForLanguageModeling(tok, mlm=False) # causal LM (writing on)
args = TrainingArguments("my-twin", num_train_epochs=3,
per_device_train_batch_size=8, learning_rate=5e-5)
Trainer(model, args, train_dataset=ds, data_collator=collator).train()
Step 3 — Let the twin speak
Now you give it a sentence beginning and let it write on in your tone.
def write_like_me(start, length=40):
inp = tok(start, return_tensors="pt")
out = model.generate(**inp, max_new_tokens=length, do_sample=True,
top_p=0.9, temperature=0.9,
pad_token_id=tok.eos_token_id)
return tok.decode(out[0], skip_special_tokens=True)
for start in ["Today was", "I think that", "Hey, do you want to"]:
print("—", write_like_me(start))
What you should see
After a few rounds the twin sounds uncannily like you: the same phrases, the same length, the same emojis. Read its sentences and ask yourself of each: "Would I write that?" For many, yes — and exactly there it gets interesting. Because it hits your style without having a single one of your thoughts. It is an echo, not an I.
Worksheet
How much of it is me?
- Let the twin write ten sentences. For how many do you think "that could be mine"? What exactly does it hit — and what never?
- The twin hits your style, but not your thoughts. Name three things about you that are fundamentally not learnable from your texts.
- "A twin is a picture of the relationship, not of the person alone." Train separately on your chats with two different people. Do the two twins sound different?
- The twin as helper and as shackle: describe one situation where your own twin helps you — and one where, in someone else's hand, it becomes dangerous to you.
- The golden rule is: what is found out about you belongs to you. What would have to hold for you to allow a company to build a twin of you?
Show solution
1. Individual. Mostly it hits the surface well — word choice, tone, length, emojis. It never hits what you mean: facts about your life come out right by chance or not at all, and real intent is entirely absent.
2. For example: what you truly feel (rather than how you phrase it), your as-yet-unwritten thoughts, your future, your conscience. From style one can learn style — no inside.
3. As a rule yes: with one person you perhaps write tersely and factually, with the other playfully. The twin inherits exactly this relationship colouring — it is a picture of the chat, not only of you.
4. Benefit: a patient mirror that shows you how you sound, or that helps you phrase things. Danger: whoever owns your twin can predict and steer you — show you deliberately what grips you in a weak moment.
5. Individual, but sensible conditions: your informed consent, a clear purpose, purpose limitation, revocation and deletion at any time, and that you keep control — the twin serves you, does not dispose of you.
When it sticks
| Problem | Likely cause & fix |
|---|---|
CUDA out of memory | Lower per_device_train_batch_size to 4 or shorten max_length; in Colab pick the GPU runtime. |
| The twin babbles nonsense | Too few training lines or too many epochs (over-fitting). Collect more of your own texts or reduce the epochs. |
| It sounds nothing like you | Too little or too untypical material. Take more, more everyday lines of your own; a few hundred work wonders. |
| Other people's names appear | Foreign messages slipped in. Filter strictly to your own lines and remove names — before training. |
| Training extremely slow | It is running on the CPU. In Colab "change runtime type → GPU"; otherwise keep data and epochs small. |
Food for thought
- The most astonishing thing about this twin is how easily it comes about — and how little it still is. It is your echo: your sound without your ground. Whoever has once built this themselves no longer overrates any twin.
- And there is the Mule from Chapter 14: even the best twin only predicts what held yesterday. The person stays free to decide differently tomorrow — the unforeseen cannot be modelled.
- With this the great arc closes: from the single honest signal across face, voice, plant and animal to a whole society. To listen across the kingdoms — that is no crown, but a responsibility.
Extension
- Two twins, one person. Train one model each on your formal and your casual texts. How differently do the two write — and what does that say about your "five faces" from 16.1?
- The Turing test in miniature. Mix real and twin-generated sentences and let friends guess which are yours. How often are they wrong — and for which kind of sentence never?
- The limit of facts. Ask the twin for facts about you (birthday, favourite subject). Why does it invent instead of knowing? What does that say about the difference between style and knowledge?