# Continued Pretraining for a Domain

> How continued pretraining teaches a model a field's language, what it costs, and the forgetting trap, explained simply for your AI interview.

**In short:** Continued pretraining keeps training a base model on a large amount of raw text from one field, using the same next-word goal. It teaches the field's words and patterns, but it costs a lot and can make the model forget general skills, so retrieval or fine-tuning often come first.

AI and LLM interview question Q302, Fine-tuning and adaptation. Advanced, occasional (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/continued-pretraining-for-a-domain

## Say it in 30 seconds

Continued pretraining means I take a base model and keep training it on a large amount of raw text from one field, like insurance claim notes. It uses the same next-word goal the model learned at the start, so it picks up the field's words and patterns. The risk is forgetting, so I mix general text back in. It is costly, so I try retrieval or fine-tuning first unless the field is far from normal text.

## Say it in 2 minutes

A base model has read a huge amount of general text, so it knows everyday English well. An insurer's claim notes use shorthand, policy codes and legal wording that barely show up in that text. Continued pretraining keeps training the base model on a large body of that raw domain text, with the same goal as before: predict the next word. Over time the model gets fluent in the field's language before anyone teaches it a task.

The main trap is forgetting. When the new text is very different from the old, the model can lose skills it had before. So I mix in general text, called replay, and I re-warm the learning rate, which is the step size for each update. In the 2024 Ibrahim study, run on two common pre-training datasets rather than a narrow field, that simple mix matched retraining from scratch, using only a fraction of the compute.

It is expensive. You need a lot of clean text, GPU time, and an evaluation to check that nothing broke. Facts also change, so a model trained on last year's policies goes stale. For fresh facts I reach for retrieval, where the model looks up current documents, and I fine-tune only for format or behaviour.

I'd choose continued pretraining when the field's language is far from web text and I have plenty of clean text, like a hospital's notes. Meditron, an open-source medical model, was built this way on curated PubMed articles and medical guidelines. It is a serious project, so I'd say so plainly and show the plan before anyone spends the compute.

## What is continued pretraining, in plain words?

A base model is what pretraining produces. It has read a huge pile of general text and learned to predict the next word. Continued pretraining means training that same model further on a new pile of raw text, with the same next-word goal. Nobody labels the text with answers.

The aim is to bring a field's language and patterns into the model before any task training. Picture a junior doctor who has finished medical school and then spends a long rotation on a cardiology ward, reading the ward's own protocols and case notes. The general training stays, and the ward's vocabulary goes on top. The AI version is a hospital group that wants a model to read discharge summaries written in its own shorthand.

- **Base model:** A model after pretraining, before any chat or task tuning.
- **Raw domain text:** Unlabelled text from one field: claim notes, contracts, clinical notes.
- **Replay:** Mixing old general text back into training so the model keeps its skills.
- **Catastrophic forgetting:** When new training wipes out skills the model had before.
- **Learning rate:** How big a step each update takes. Re-warming turns it up again.

Researchers call the domain version domain-adaptive pretraining. The 2020 paper Don't Stop Pretraining used that name for this idea.

## How does it differ from fine-tuning?

- **Continued pretraining: Raw text, no labels.** Trains on unlabelled text from the field. It adds the field's words and patterns.
- **Fine-tuning: Labelled examples.** Trains on question and answer pairs. It teaches a format, a tone or a task.
- **Both: Different jobs.** Continued pretraining comes first, then fine-tuning on examples. One adds the field's words and patterns, the other adds behaviour.

*Diagram, How continued pretraining works: Raw domain text goes in, and the base model keeps learning with the same next-word goal. The replay and re-warm step helps stop the old skills fading. The result is a new base model that knows the field, ready for later tuning.*
1. Raw text from the field goes in, with no labels.
2. Training batches pass on to the replay and re-warm steps.
3. Replay and a re-warmed learning rate help protect the old skills.

## Does it actually work?

Often, yes. The Don't Stop Pretraining study tested four domains, including biomedical papers and reviews, on eight classification tasks. A second phase of pretraining on in-domain text helped, whether labelled data was plentiful or scarce.

> "a second phase of pretraining in-domain (domain-adaptive pretraining) leads to performance gains, under both high- and low-resource settings" (Gururangan et al., ACL 2020)
>
> "Evaluations using four major medical benchmarks show significant performance gains over several state-of-the-art baselines before and after task-specific finetuning." (Chen et al., 2023)

Medicine is a clear case. Meditron is an open-source medical model. Its team started from Llama 2 and continued pretraining on a curated medical corpus, including selected PubMed articles, abstracts and medical guidelines. Its own tests showed gains over strong baselines, before and after task tuning.

## What goes wrong, and how do you stop it?

The model can get worse at things it did well before. Researchers call this catastrophic forgetting. In a 2024 study, Ibrahim and colleagues noted that new data often leaves the model weaker on old data. Their tests used two common pre-training datasets, so a narrow field may behave differently.

> "the distribution shift induced by new data typically results in degraded performance on previous data or poor adaptation to the new data." (Ibrahim et al., 2024)

*Diagram, Two ways to train on domain text: Train on domain text alone and the old skills fade. Mix in general text as replay and the field words are learned while the old skills mostly stay.*
1. Training on domain text alone can push out old skills.
2. Replayed general text keeps the old skills while the field words are learned.

The fix is simple to describe and fiddly to run. The same study found, on two common pre-training datasets, that re-warming the learning rate, decaying it again and replaying old data could match full retraining from scratch, using only a fraction of the compute. Gupta and colleagues found the cost of re-warming up front: the loss rises first, and the gain shows over a longer run.

1. **Clean the new text:** Remove duplicates, boilerplate and personal data first. Messy text teaches messy habits.
2. **Mix in replay:** Add general text so the model keeps everyday English and common reasoning.
3. **Re-warm, then decay:** Raise the learning rate a little, then bring it down again on a schedule. Expect the loss to rise at first.
4. **Test old and new skills:** Measure field tasks and general tasks after every run. A gain on one side and a loss on the other still counts as a failure.

Take a made-up mid-size insurer with 3 billion tokens of claim notes and policy wording. Its team adds 1 billion tokens of general text as replay. Each training step is 4 million tokens, so three quarters of every step comes from the company's own files. The numbers are illustrative, but the shape is what a real run plans for.

```python
# A made-up insurer's data mix for one continued-pretraining run (numbers are illustrative).
DOMAIN_TOKENS = 3_000_000_000   # claim notes and policy wordings
GENERAL_TOKENS = 1_000_000_000  # replayed general text, to limit forgetting
BATCH_TOKENS = 4_000_000        # tokens per training step

def batch_mix(domain, general, batch):
    # Share of each step taken from the company's own text.
    domain_share = domain / (domain + general)
    domain_per_step = round(batch * domain_share)
    return domain_share, domain_per_step, batch - domain_per_step

share, domain_step, general_step = batch_mix(DOMAIN_TOKENS, GENERAL_TOKENS, BATCH_TOKENS)
steps = (DOMAIN_TOKENS + GENERAL_TOKENS) // BATCH_TOKENS
print(f"Domain share of training: {share:.0%}")
print(f"Each step: {domain_step:,} domain tokens, {general_step:,} replayed general tokens")
print(f"Total steps: {steps:,}")
```

Output:

```text
Domain share of training: 75%
Each step: 3,000,000 domain tokens, 1,000,000 replayed general tokens
Total steps: 1,000
```

Each number is a decision the team has to defend: how much general text to keep, and whether the old-skill tests still pass after every run.

## When is it worth it, and when isn't it?

- **Worth it: Text far from the web.** The field's words and shorthand are rare online, and you have lots of clean text to train on.
- **Not worth it: Facts that change.** Policies, prices and news change often. Retrieval keeps up with that, and retraining does not.
- **Cost: A full project.** Plan GPU time for a long run, clean data, an evaluation, and repeat runs when the data changes.

My first question is what the model must know on the day someone asks. Stable language suits training. Changing facts suit retrieval.

### How would you choose for a legal team with 40,000 contracts?

A legal team has 40,000 contracts and lawyers who ask about clause wording every day. Retrieval suits this well: the model finds the right contract and answers from it, and the index updates when a contract changes. Continued pretraining would bake the old contracts into the weights, so answers go stale as clauses change. I would start with retrieval, and consider continued pretraining only if the team's wording is so unusual that the model struggles to read it at all.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: keep training a base model on raw text from one field.
- [ ] The same next-word goal, with no labels, unlike fine-tuning.
- [ ] Why it helps: the model picks up the field's words and patterns.
- [ ] The forgetting risk, and replay with a re-warmed learning rate as the fix.
- [ ] The costs: compute, clean data, evaluation and repeat runs.
- [ ] When retrieval or fine-tuning is the better first step.

**Common traps**

- Trap: "Feed it all our documents and it will know them." Better: Raw text teaches patterns more than exact facts. Facts that change need retrieval.
- Trap: "A bigger base model fixes the domain gap." Better: Size does not replace domain text. Measure the gap on your own tasks first.
- Trap: "Forgetting is rare, so just keep training." Better: Forgetting is well documented. Mix in replay and test old skills after every run.

## Can you spot the problem?

**Spot the risk:** Which team plan is most likely to cause forgetting?

A. Train only on 3 billion tokens of claim notes, then ship the model.
B. Mix in replayed general text, and check old skills after each run.
C. Clean the notes first to remove duplicates and personal data.
D. Use retrieval for policy lookups that change every month.

**Answer:** A. Training only on the company's own notes can pull the model away from everyday language. Replay and tests after each run catch that drift. The other three are the sensible steps.

**Quick check:** An insurer's policy wording changes every quarter. What should the assistant use to answer?

A. Continued pretraining on last year's policy text
B. Retrieval over the current policy documents
C. A larger base model with the same old policy text
D. A lower learning rate and no other changes

**Answer:** B. Facts that change often belong in retrieval, which reads the current documents on each question. Training bakes facts into the weights, so they go stale.

## Can you answer these from memory?

**Flash cards**

- **What is continued pretraining?** More next-word training on raw text from one field, before any task tuning.
- **How is it different from fine-tuning?** Raw unlabelled text teaches the field's words and patterns. Labelled examples teach a task or format.
- **What is replay?** Old general text mixed into training, so the model keeps its everyday skills.
- **What is catastrophic forgetting?** New training can erase old skills. Replay and tests after every run guard against it.
- **Does it always beat retrieval?** No. Facts that change often are better handled by retrieval.
- **What are the main costs?** Compute for a long run, clean data, evaluation, and repeat runs when the data changes.

## Likely follow-up questions

- Q281 Fine-tune vs RAG vs prompting: when to use which? https://designervenkat.online/interview/ai/fine-tuning-vs-rag-vs-prompting
- Q284 What is LoRA? https://designervenkat.online/interview/ai/what-is-lora
- Q294 How do you prepare a fine-tuning dataset? https://designervenkat.online/interview/ai/how-to-prepare-a-fine-tuning-dataset
- Q296 What is catastrophic forgetting? https://designervenkat.online/interview/ai/what-is-catastrophic-forgetting
- Q308 Fine-tuning cost vs inference savings? https://designervenkat.online/interview/ai/fine-tuning-cost-vs-inference-savings
