Inspiration

Language models have never seen a map, yet they answer geography questions surprisingly well. In 2023, Gurnee and Tegmark showed that a straight-line readout of a model's hidden state can recover where places are. Marshall Wace asked us to open a door to a new world, and we realised one was sitting inside every AI: a hidden Earth that nobody drew and nobody has explored. We wanted to visit it, see what it gets wrong, find out where it puts places that do not exist, and then find out if we could rewrite it.

What it does

TERRA INCOGNITA reads, explores and edits the map of the world inside a language model.

  • The map. 40,485 real places (from Gurnee and Tegmark's dataset) are plotted on a 3D globe where the model believes they are, with lines to where they really are.
  • New worlds. Type any name, real or invented ("Hogwarts", "Krasnovik"), and watch it land where the model imagines it, with an uncertainty cloud.
  • Edit the map. Drag Paris onto Sydney. We overwrite the model's internal state for "Paris" (not the prompt, not the weights), and it starts answering that Paris uses the Australian dollar and lies in the Southern Hemisphere.
  • Move, keep identity. A gentler edit moves a city's location while it keeps its identity (Berlin keeps the Brandenburg Gate but gets a July winter).
  • Rewrite the world. Move up to three cities at once and ask questions that depend on all of them.
  • The model's political map. The world's borders redrawn from where the model believes places are.
  • Three models, three Earths. Switch between Qwen 2.5 7B and Gemma 4 (12B and 31B) and compare their worlds.

How we built it

1. Reading the hidden state. For each place we run the prompt "What are the lat/lon coordinates of name" and record the residual-stream vector \(\mathbf{h}^{(\ell)} \in \mathbb{R}^{3584}\) at the last token of the name, at every layer \(\ell\) of Qwen 2.5 7B Instruct.

2. The probe. A linear map from that vector to a point on the unit sphere:

$$ \hat{\mathbf{p}} = W^\top \mathbf{h} + \mathbf{b}, \qquad \mathbf{p} = (\cos\phi\cos\lambda, \cos\phi\sin\lambda, \sin\phi) $$

where \(\phi\) is latitude and \(\lambda\) is longitude. We predict \((x, y, z)\) rather than \((\phi, \lambda)\) because longitude jumps from \(+180^\circ\) to \(-180^\circ\) at the dateline, which a linear model cannot follow. \(W\) is fitted by ridge regression,

$$ \min_{W,\mathbf{b}} \sum_i \lVert W^\top \mathbf{h}_i + \mathbf{b} - \mathbf{p}_i \rVert^2 + \alpha \lVert W \rVert_F^2, $$

with \(\alpha\) chosen by closed-form leave-one-out. Errors are great-circle distances, \(d = R \arccos(\hat{\mathbf{p}} \cdot \mathbf{p})\) with \(R = 6371\) km, always measured on places the probe never saw (5-fold out-of-fold). We picked the layer on the hardest split, with whole countries held out: layer 21. A bootstrap ensemble of 20 probes gives the uncertainty cloud.

3. Editing by activation patching. To make the model read "Paris" as "Sydney", we run the same question with "Sydney", capture its hidden states on the name tokens, and during the prompt's single forward pass (the prefill) write them over Paris's states at layers 4 to 7:

$$ \mathbf{h}^{(\ell)}_{t} \leftarrow \mathbf{h}^{(\ell)}_{t, \text{Sydney}}, \qquad \ell \in \lbrace 4, \dots, 7 \rbrace $$

Every generated token then attends to the patched keys and values, so the edit carries through the whole answer without changing the text or the weights.

4. Testing the edit honestly. After each edit we ask five "ripple" questions: country, currency, language, hemisphere and the season in July. Answer keys come from GeoNames. We compare against a random control that adds a vector of the same size at the same layers and tokens:

$$ \mathbf{h}^{(\ell)}_{t} \leftarrow \mathbf{h}^{(\ell)}_{t} + \lVert \Delta^{(\ell)}_t \rVert \mathbf{u}, \qquad \mathbf{u} \sim \text{uniform on the unit sphere} $$

If random noise of the same size changed the answers, the edit would just be breaking the model.

5. The move edit adds a push along the probe's own location direction instead of swapping the whole city, so the city keeps its identity.

6. The political map. We lay a \(1^\circ\) grid over the Earth. Each cell takes a distance-weighted vote of its 12 nearest believed positions (out-of-fold readings of all 40,270 places with a known country). Cells far from any believed place become sea. The cells are then merged into country shapes with shapely.

7. Stack. Qwen runs in PyTorch on Apple silicon (MPS) with forward hooks. Gemma 4 runs in MLX at 4-bit, with each decoder layer wrapped to read and write the residual stream, since MLX has no hooks. Both share one backend interface, and only one model is held in the 36 GB of memory at a time. The backend is FastAPI; the frontend is globe.gl. Everything runs offline on one laptop, and every number in the app is read from a results file produced by a script.

Results (Qwen 2.5 7B)

Measure Result
Median error on places the probe never saw (40,485 places) 829 km (whole countries held out: 1,986 km; guessing the average: 6,430 km)
Swap edit success, 100 fresh cross-hemisphere pairs 95% (same-size random control: 0%)
Move edit: location moved and identity kept, 40 fresh pairs 60% (control moved the location 0%)
Rewrite the world, 40 random three-city worlds 97% of moved cities fully moved (control 0%)
Invented names landing where their sound suggests 31 / 48 (chance 7%)
Right hemisphere: said aloud vs read from the hidden map (270 cities) 72% vs 95%

Success means at least 80% of the scoreable ripple answers switch to the target city. The 95% figures are re-measured on fresh pairs, because we chose to patch every token of the name after looking at earlier failures.

Three Earths. On the same 10,000 globe places, the median error is 1,033 km for Qwen and 902 km for Gemma 4 31B. The two models disagree with each other by about 1,100 km per place, so each is wrong in its own way. Gemma 4 12B's best probe sits at layer 4 of 48, which we are still investigating.

Challenges we ran into

  • Choosing the layer honestly. On a random train/test split, layer 24 looked best (626 km median error). But a random split lets the probe use a place's neighbours as a shortcut. When we held out whole countries, layer 24's error rose to 2,205 km and layer 21 did best (1,986 km). We had fixed the rule in advance, so we used layer 21 and report its 829 km rather than the flattering 626 km.
  • Honest evaluation. Random train/test splits let the probe cheat using a place's neighbours. We choose layers on the stricter test with whole countries held out, and every edit headline is re-measured on fresh pairs that were never used for tuning.
  • Edits at the wrong depth give an inconsistent world. Patching from layer 8 onwards changed the country and currency but not the hemisphere ("Paris is in Australia, in the Northern Hemisphere"). Sweeping layer bands found 4 to 7, where the whole picture moves together.
  • Names of different lengths. "Paris" is one token and "Rio de Janeiro" is several. Patching only the last token worked 87% of the time on fresh pairs; patching every name token, aligned from the right, raised it to 95%. The same alignment lets us swap invented names.
  • A system prompt in the way. Qwen's default system prompt mentions "Alibaba Cloud", which broke an early edit of Alibaba. The name search now only looks inside the user's message.
  • The model fails its own test. The unedited Qwen says Seoul and Madrid are in the Southern Hemisphere, so we only score cities it answers correctly before any edit.
  • No hooks in MLX. Gemma needed every layer wrapped by hand. Gemma 4 31B at full precision needs about 70 GB, so we ran it at 4-bit, swapping models in and out of the laptop's 36 GB.
  • Hackathon physics. A game running on the same laptop made one evaluation take three times longer. Lesson learned.

Accomplishments that we're proud of

  • A live, causal edit of a 7B model's beliefs that works on 95% of fresh pairs, with a matched random control at 0%.
  • "The map knows more than the mouth." Asked directly, Qwen says Dublin, Birmingham and Munich are in the Southern Hemisphere. Its hidden map puts them at about \(56^\circ\)N, \(57^\circ\)N and \(51^\circ\)N. Reading the hidden state can beat asking the model.
  • Invented places land where their sound suggests, so the model has a geography even for worlds that do not exist.
  • Every number in the app links to the file it came from.

What we learned

  • A model's knowledge is readable with a straight line. Location is linearly encoded from about the middle of the network onwards.
  • Where you edit matters as much as what you edit. Early layers move the whole concept; later edits leave half the old world behind.
  • Controls are everything. Without the same-size random control, "the answer changed" proves nothing.
  • Models disagree. Two models trained on similar text still carry different Earths, about 1,100 km apart per place.
  • The honest limits: a probe shows that information is readable, not how the model uses it, and the swap edit replaces a city's identity (Paris then names the Sydney Opera House). The political map also reflects which places are in the dataset as much as the model.

What's next

  • Fix and re-run the Gemma 4 12B extraction, and compare how the map sharpens with model size.
  • Other hidden worlds: time ("where does the model put 2008?"), people and companies.
  • Use the gap between the hidden map and the spoken answer as a tool for auditing what a model believes before trusting it.

Prior work: Gurnee and Tegmark 2023, "Language Models Represent Space and Time" (arXiv 2310.02207), whose place list we use; Chen et al. 2023 on causal interventions in spatial representations (arXiv 2312.16257).

Built With

Share this project:

Updates

Submission history