# Toy: writing one model's facts into another (after Plato's Imprint)

This is the code and results behind the "Write it in" tab on [/representations/](https://sciphi.pro/representations/). It is a laptop-scale toy after Divergent Labs' [Plato's Imprint](https://divergentlabs.xyz/blog/platos-imprint) and Hazy Research's [Plato's Key](https://hazyresearch.stanford.edu/blog/2026-11-25-platos-key). It is not a reproduction of either.

## Setup (`facets.py`, NumPy only)
- **The world.** 400 entities, each with 8 independent latent features. A relation reads one or two features, and its answer is the argmax over 10 values of a fixed linear map. That gives 8 + 28 = 36 relations.
- **Donor A.** Learns every relation inside features {1–4}, for all entities.
- **Recipient B.** Learns every relation inside a window of four features that overlaps A's by k ∈ {0,…,4}. It sees 100 held-out entities on only 3 of its 10 relations, chosen at random per entity. The other 7 are test facts, and the recipient gets roughly a third of them wrong.
- **Models.**
  - Entity embedding → ReLU MLP ("subject enrichment") → key → relation readout → logits.
  - A: key width 48, MLP width 512; its entity embeddings are trained with the rest of the network.
  - B: key width 64, MLP width 1024, embedding width 256. In the reported runs (`freezeE=True`, the default) only B's embedding table is frozen: it is a fixed random draw and is not updated. A still trains its embeddings.
  - Both are otherwise trained with full-batch Adam for 800 steps.
- **Align.**
  - Centred orthogonal Procrustes plus one global scale, fitted on the 300 anchor entities' keys, as in Plato's Key.
  - Ridge-regularised CCA picks the directions the two keys share (canonical correlation > 0.5).
  - "Shared" transfers only move B's key inside that subspace.
- **Write it in (donor unplugged).**
  - A closed-form edit of B's MLP down-projection W_d: min ‖U_edit ΔW − G‖² + λ‖U_bg ΔW‖² + μ‖ΔW‖², solved in Woodbury / push-through form.
  - U are B's own MLP features for the 100 edited entities and for 300 background entities. G is the gap to the target key.
  - There are no gradients and no target answers.
- **Controls.**
  - Random semi-orthogonal rotation at the same scale.
  - Shuffled anchor pairs.
  - Shuffled donor: another held-out entity's update is written in.
  - The relation's most common answer.
- **Metrics.**
  - Fixed: share of the recipient's wrong test facts that become right, split by whether the relation reads only shared features, one shared feature, or none.
  - Kept: share of the recipient's previously-correct training facts still correct, for other entities and for the edited entities themselves.

Run: `python3 facets.py <seed> <k> 800` writes `results/r_<seed>_<k>.json`. Then `python3 aggregate.py` writes `results/summary.md`. `export_web.py <k>` and `build_web_data.py <out.json>` produce `../imprint-data.json`. A single run takes about 30–60 s on one CPU core.

## Fixing retention (five seeds each)
The first scoping prototype (`research/toy-transfer-v1/`, internal) edited a narrow readout layer, with d_ff = 256 smaller than the 300 edits plus background facts. It kept only **30–47 %** of the recipient's prior facts.

1. **Wider, entity-level edit with null-space protection** (MLP width 1024 > 100 edits + 300 background; λ = 100). Prior facts of other entities kept: **96–100 %**. However, with *trained* entity embeddings the recipient's MLP features collapse to a few dimensions (one giant mean direction), so the protected edit cannot reach its targets. Shared facts fixed: **29–41 %**, against 14–28 % for the shuffled-donor control and about 27 % for the relation prior. See `results_trainedE/summary.md`.
2. **Shared-subspace targets.** Moving only the shared directions stops the edit from overwriting what only the recipient knows about the edited entities. Same-entity kept rises from 44–76 % (full key) to **92–99 %**.
3. **High-rank subject inputs** (only the recipient's entity embeddings are a frozen random table of width 256, standing in for an LLM's token embeddings; the donor still trains its embeddings). The recipient's features for different entities stay separable, so the null-space edit hits its targets exactly, and writing in equals the donor-on swap.

## Facet-overlap results (`results/summary.md`; mean ± sd, 5 seeds, λ = 100, shared-subspace edit, donor unplugged)

| features shared (k of 4) | CKA (anchors) | shared facts fixed | one-shared-feature facts fixed | no-shared-feature facts fixed | shuffled-donor control (shared facts) | most common answer (shared facts) | prior facts kept: other / same entity |
|---|---|---|---|---|---|---|---|
| 0 | 0.02 | – | – | 0 ± 0 | – | – | 100 / 100 |
| 1 | 0.21 | 98 ± 4 | 26 ± 3 | 6 ± 4 | 25 ± 8 | 39 ± 20 | 100 / 99 ± 2 |
| 2 | 0.39 | 91 ± 6 | 32 ± 3 | 13 ± 4 | 31 ± 7 | 33 ± 9 | 100 / 95 ± 2 |
| 3 | 0.58 | 87 ± 6 | 34 ± 8 | 23 ± 8 | 24 ± 3 | 27 ± 3 | 100 / 92 ± 5 |
| 4 | 0.91 | 95 ± 2 | – | – | 21 ± 2 | 25 ± 1 | 100 / 99 ± 0 |

All wrong answers combined, written in: 0, 19 ± 3, 42 ± 3, 63 ± 4 and 95 ± 2 % for k = 0…4. Overall prior facts kept: 99.3–100 %.

**Reading.** What transfers is what both models learned. Facts that read only shared features come across almost completely. Facts that read one shared feature come across partly. Facts that read only the recipient's own features stay at or below the controls, even though one world generated all of the data. The result depends on the toy's choices: independent latent features, a recipient with separable, high-rank subject inputs, and single-token answers.
