Hippocampo-neocortical interaction as compressive retrieval-augmented generation.
The 29 matches
- [1] § Methods › Neocortical learning of sequential structure for inference and planning ↔ inference/rag_composition.py, lines 1–53 · score 0.89 · ef WEST gh, ab EAST cd, gh NORTH, SOUTH ef, inference, traces
- [2] § Results › Inference from memory as retrieval-augmented generation ↔ inference/rag_composition.py, lines 1–53 · score 0.84 · ef WEST gh, ab EAST cd, gh NORTH, SOUTH ef, inference, baselines
- [3] § Methods › Modelling hippocampal-neocortical interaction as retrieval-augmented generation › The compression and encoding of episodic memory ↔ full_model/memory_simulation.py, lines 1126–1165 · score 0.81 · sentence boundaries, coordinating conjunction, spaCy, commas, splitting, phrases
- [4] § Methods › Modelling hippocampal-neocortical interaction as retrieval-augmented generation › The compression and encoding of episodic memory ↔ full_model/narratives/utils.py, lines 455–491 · score 0.69 · short clause, spaCy, conjunctions, splitting, phrases, perplexity
- [5] § Results › Modelling consolidation and forgetting ↔ full_model/semantic_memory_standalone.py, lines 83–189 · score 0.66 · asking factual questions, correct answer, Semantic memory, Remember, embedding, prompt
- [6] § Methods › Modelling hippocampal-neocortical interaction as retrieval-augmented generation › Modelling the hippocampus ↔ scripts/dual_mhn.py, lines 1–19 · score 0.65 · modern Hopfield network, sequence memory, MHN, heteroassociative, autoassociative, vector
- [7] § Methods › Modelling hippocampal-neocortical interaction as retrieval-augmented generation › Analysing the HIPPOCORPUS and NFRD datasets ↔ full_model/collate_all_figures.py, lines 281–314 · score 0.65 · Naturalistic Free Recall, baseball, eyespy, oregontrail, pieman, recalled stories
- [8] § Results › Inspecting the hidden representations supporting inference ↔ inference/plot_family_reps.py, lines 449–483 · score 0.65 · Pearson correlation, pre trained GPT, family tree, random walk, location, nodes
- [9] § Results › Gist-based distortions and prior experience ↔ full_model/narratives/collate_figures.py, lines 2324–2364 · score 0.64 · L6 v2, MiniLM, cosine distance, Bergman, Roediger, PCA
- [10] § Results › The compression and encoding of episodic memory ↔ full_model/semantic_memory_standalone.py, lines 83–189 · score 0.63 · L6 v2, MiniLM, correct answer, Semantic memory, accuracy, embeddings
- [11] § Results › Neocortical learning of sequential structure for problem solving ↔ inference/graph_sequence_model.py, lines 737–884 · score 0.63 · trained spatial model, ab EAST, aggregated, child, loss, graphs
- [12] § Results › Gist-based distortions and prior experience ↔ full_model/narratives/utils.py, lines 27–51 · score 0.61 · young men, Ghosts, War, heard, Egulac, night
- [13] § Methods › Modelling hippocampal-neocortical interaction as retrieval-augmented generation › The compression and encoding of episodic memory ↔ full_model/narratives/utils.py, lines 289–299 · score 0.61 · XRAG_TOKEN, single token, phrases, perplexity, surprising
- [14] § Methods › Summary of models trained ↔ full_model/narratives/stories.py, lines 28–77 · score 0.61 · ROC Stories, LoRA, xRAG, v0, Instruct, Mistral
- [15] § Results › Modelling consolidation and forgetting ↔ full_model/memory_simulation.py, lines 176–297 · score 0.60 · asking factual questions, correct answer, Semantic memory, Remember, embedding, prompt
- [16] § Methods › Summary of models trained ↔ full_model/narratives/stories.py, lines 28–77 · score 0.60 · ROC Stories, LoRA, xRAG, v0, Instruct, Mistral
- [17] § Results › Neocortical learning of sequential structure for problem solving ↔ inference/plot_family_reps.py, lines 63–126 · score 0.58 · directed graph, family tree, children, grandchild, spouse, sibling
- [18] § Results › Event extension and contraction ↔ full_model/narratives/collate_figures.py, lines 1187–1291 · score 0.58 · omission errors, extension errors, updated stories, incomplete
- [19] § Results › Neocortical learning of sequential structure for problem solving ↔ inference/graph_sequence_model.py, lines 737–884 · score 0.58 · EAST zr, sz WEST, invalid, aggregated, entity, losses
- [20] § Results ↔ scripts/dual_mhn.py, lines 1–19 · score 0.57 · modern Hopfield network, nearest stored, MHN, sequence, memory
- [21] § Results › The compression and encoding of episodic memory ↔ full_model/narratives/bartlett_twostage.py, lines 377–436 · score 0.54 · L6 v2, MiniLM, original story, cosine, background, tokens
- [22] § Results › Changes in memory content over time ↔ full_model/LLM ratings/HIPPOCORPUS attributes comparison.ipynb, lines 1–52 · score 0.54 · OpenAI API, mini, rich, concrete, metrics, abstract
- [23] § Methods › Modelling hippocampal-neocortical interaction as retrieval-augmented generation › Modelling the hippocampus ↔ scripts/dual_mhn.py, lines 22–36 · score 0.53 · inverse temperature, softmax, MHN, heteroassociatively, autoassociative, Retrieval
- [24] § Results › Inspecting the hidden representations supporting inference ↔ inference/plot_family_reps.py, lines 486–519 · score 0.53 · family tree, pre trained, random walk, hidden, location, medium
- [25] § Methods › Summary of models trained ↔ inference/plot_family_reps.py, lines 449–483 · score 0.53 · train GPT, family trees, random walks, medium, graphs, inference
- [26] § Methods › Modelling hippocampal-neocortical interaction as retrieval-augmented generation › Analysing the HIPPOCORPUS and NFRD datasets ↔ full_model/LLM ratings/HIPPOCORPUS attributes comparison.ipynb, lines 1–52 · score 0.52 · OpenAI API, attributes, mini, HIPPOCORPUS, gpt, prompt
- [27] § Methods › Modelling hippocampal-neocortical interaction as retrieval-augmented generation › Analysing the HIPPOCORPUS and NFRD datasets ↔ full_model/LLM ratings/llm_specificity_analysis.py, lines 98–150 · score 0.51 · baseball, eyespy, oregontrail, pieman, recalled stories, NFRD
- [28] § Results › Changes in memory content over time ↔ full_model/LLM ratings/llm_specificity_analysis.py, lines 52–80 · score 0.50 · OpenAI API, mini, rich, concrete, abstract, gpt
- [29] § Methods › Summary of models trained ↔ full_model/narratives/bartlett_encoding_vs_consolidation.py, lines 47–87 · score 0.50 · LoRA, xRAG, v0, Instruct, Bartlett, Mistral
Paper
Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC
The paper is loaded when this pane is shown.
The authors' code
Python · 553 lines · 22 KB · MIT · 4 matches
- """
- Analogous to plot_reps.py but for the family tree model.
- Instead of spatial positions on a 3x3 grid, each person in the family tree
- has a *generation* (grandparent=0, parent=1, child=2). We ask whether
- the model's latent representations capture this generational structure.
- Graphs are created in code (so generation assignments are known), then
- random walks are sampled from them and fed to the model.
- """
- import random
- import string
- import time
- import numpy as np
- import torch
- import logging
- import networkx as nx
- from transformers import GPT2LMHeadModel, GPT2TokenizerFast
- from sklearn.decomposition import PCA
- from umap import UMAP
- import matplotlib.pyplot as plt
- from scipy.stats import pearsonr
- def set_seed(seed):
- random.seed(seed)
- np.random.seed(seed)
- torch.manual_seed(seed)
- if torch.cuda.is_available():
- torch.cuda.manual_seed_all(seed)
- torch.backends.cudnn.deterministic = True
- torch.backends.cudnn.benchmark = False
- set_seed(321)
- logging.basicConfig(level=logging.DEBUG,
- format='%(asctime)s - %(levelname)s - %(message)s')
- # ---------------------------------------------------------------------------
- # Family tree construction (with collision-free names)
- # ---------------------------------------------------------------------------
- _GENERATION_OFFSETS = {
- "PARENT_OF": 1, "CHILD_OF": -1,
- "GRANDPARENT_OF": 2, "GRANDCHILD_OF": -2,
- "SPOUSE_OF": 0, "SIBLING_OF": 0,
- }
- GENERATION_LABELS = {0: "Grandparent", 1: "Parent", 2: "Child"}
- def _generate_unique_names(n):
- """Generate n unique 2-letter lowercase names."""
- names = set()
- while len(names) < n:
- names.add("".join(random.choices(string.ascii_lowercase, k=2)))
- return list(names)
- def build_family_tree():
- """Build a random extended family tree with guaranteed unique names.
- Structure (10 people, 3 generations):
- Gen 0: GP1a, GP1b, GP2a, GP2b (4 grandparents)
- Gen 1: Parent1, Aunt/Uncle1, Parent2, Aunt/Uncle2 (4 parents-level)
- Gen 2: Child1, Child2 (2 children)
- Returns (G, node_names, generation_map)
- """
- names = _generate_unique_names(10)
- gp1a, gp1b = names[0], names[1]
- parent1, uncle1 = names[2], names[3]
- gp2a, gp2b = names[4], names[5]
- parent2, aunt2 = names[6], names[7]
- child1, child2 = names[8], names[9]
- # Build all relationships
- relationships = {
- # Grandparent family 1
- gp1a: {"SPOUSE_OF": [gp1b], "PARENT_OF": [parent1, uncle1]},
- gp1b: {"SPOUSE_OF": [gp1a], "PARENT_OF": [parent1, uncle1]},
- uncle1: {"CHILD_OF": [gp1a, gp1b], "SIBLING_OF": [parent1]},
- # Grandparent family 2
- gp2a: {"SPOUSE_OF": [gp2b], "PARENT_OF": [parent2, aunt2]},
- gp2b: {"SPOUSE_OF": [gp2a], "PARENT_OF": [parent2, aunt2]},
- aunt2: {"CHILD_OF": [gp2a, gp2b], "SIBLING_OF": [parent2]},
- # Base family
- parent1: {
- "SPOUSE_OF": [parent2], "PARENT_OF": [child1, child2],
- "CHILD_OF": [gp1a, gp1b], "SIBLING_OF": [uncle1],
- },
- parent2: {
- "SPOUSE_OF": [parent1], "PARENT_OF": [child1, child2],
- "CHILD_OF": [gp2a, gp2b], "SIBLING_OF": [aunt2],
- },
- child1: {"CHILD_OF": [parent1, parent2], "SIBLING_OF": [child2]},
- child2: {"CHILD_OF": [parent1, parent2], "SIBLING_OF": [child1]},
- }
- # Add grandparent <-> grandchild edges
- for gp in [gp1a, gp1b, gp2a, gp2b]:
- relationships[gp].setdefault("GRANDPARENT_OF", []).extend([child1, child2])
- for ch in [child1, child2]:
- relationships[ch].setdefault("GRANDCHILD_OF", []).extend([gp1a, gp1b, gp2a, gp2b])
- # Build directed graph
- G = nx.DiGraph()
- for person, rels in relationships.items():
- G.add_node(person)
- for rel_type, targets in rels.items():
- for target in targets:
- G.add_edge(person, target, relationship=rel_type)
- node_names = list(G.nodes)
- generation_map = {
- gp1a: 0, gp1b: 0, gp2a: 0, gp2b: 0,
- parent1: 1, uncle1: 1, parent2: 1, aunt2: 1,
- child1: 2, child2: 2,
- }
- return G, node_names, generation_map
- # ---------------------------------------------------------------------------
- # Random walk generation
- # ---------------------------------------------------------------------------
- def generate_random_walk(G, walk_length=50):
- """Return a walk string: node REL node REL … node"""
- current = random.choice(list(G.nodes))
- tokens = [current]
- for _ in range(walk_length):
- neighbors = list(G.successors(current))
- if not neighbors:
- break
- nxt = random.choice(neighbors)
- rel = G.edges[current, nxt]["relationship"]
- tokens.append(rel)
- tokens.append(nxt)
- current = nxt
- return " ".join(tokens)
- # ---------------------------------------------------------------------------
- # GPT wrapper & embedding extraction
- # ---------------------------------------------------------------------------
- def _default_entity_tokenizer_dir():
- """Return the canonical entity tokenizer path if it exists, else None."""
- from pathlib import Path
- path = Path(__file__).resolve().parent / "tokenizers" / "gpt2-medium_2letter_entities"
- if (path / "tokenizer.json").exists() or (path / "vocab.json").exists():
- return str(path)
- return None
- class GPTWrapper:
- def __init__(self, model_name="gpt2", tokenizer_name=None):
- logging.info(f"Loading model: {model_name}")
- self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
- self.model = GPT2LMHeadModel.from_pretrained(
- model_name, output_hidden_states=True
- )
- self.model.to(self.device)
- self.model.eval()
- emb_size = self.model.get_input_embeddings().weight.shape[0]
- # Resolve tokenizer: explicit > canonical entity tokenizer > model dir
- tok_path = tokenizer_name or model_name
- if tokenizer_name is None and not model_name.startswith("gpt2"):
- canon = _default_entity_tokenizer_dir()
- if canon is not None:
- candidate = GPT2TokenizerFast.from_pretrained(canon)
- if len(candidate) == emb_size:
- tok_path = canon
- logging.info(f"Using canonical entity tokenizer from {canon}")
- self.tokenizer = GPT2TokenizerFast.from_pretrained(tok_path)
- self.tokenizer.pad_token = self.tokenizer.eos_token
- logging.info(f"Model and tokenizer loaded successfully (vocab={len(self.tokenizer)}, emb={emb_size}).")
- def get_hidden_states_with_offsets(self, prompt, layer_idx):
- enc = self.tokenizer(
- prompt, return_tensors="pt", truncation=True,
- return_offsets_mapping=True,
- )
- offsets = enc["offset_mapping"][0].tolist()
- # Remove offset_mapping before passing to model (it's not a model input)
- model_inputs = {k: v.to(self.device) for k, v in enc.items() if k != "offset_mapping"}
- with torch.no_grad():
- out = self.model(**model_inputs)
- hidden_states = out.hidden_states[layer_idx].squeeze(0).detach().cpu().numpy()
- return hidden_states, offsets
- def get_all_hidden_states_with_offsets(self, prompt):
- """Single forward pass returning hidden states for *every* layer.
- Returns ``(all_hidden_states, offsets)`` where
- ``all_hidden_states[i]`` is the numpy array for layer *i*.
- """
- enc = self.tokenizer(
- prompt, return_tensors="pt", truncation=True,
- return_offsets_mapping=True,
- )
- offsets = enc["offset_mapping"][0].tolist()
- model_inputs = {k: v.to(self.device) for k, v in enc.items() if k != "offset_mapping"}
- with torch.no_grad():
- out = self.model(**model_inputs)
- all_hs = [h.squeeze(0).detach().cpu().numpy() for h in out.hidden_states]
- return all_hs, offsets
- def substring_positions(haystack, needle):
- result = []
- start = 0
- while True:
- idx = haystack.find(needle, start)
- if idx == -1:
- break
- result.append([idx, idx + len(needle)])
- start = idx + 1
- return result
- def gather_embeddings_for_span(offsets, hidden_states, span, flanking=True):
- """Gather hidden-state vectors for a character span.
- If *flanking* is True (default), the tokens immediately before and after
- the entity token(s) are included in the average. For the custom entity
- tokenizer these flanking tokens are the space characters that sit between
- the entity and the neighbouring relation token, and they carry rich
- contextual information about the entity's role in the family tree.
- """
- start_needed, end_needed = span
- n_tokens = len(offsets)
- entity_idxs = [i for i, (s, e) in enumerate(offsets)
- if not (e <= start_needed or s >= end_needed)]
- if not entity_idxs:
- return None
- if flanking:
- all_idxs = set(entity_idxs)
- min_idx, max_idx = min(entity_idxs), max(entity_idxs)
- if min_idx > 0:
- all_idxs.add(min_idx - 1)
- if max_idx < n_tokens - 1:
- all_idxs.add(max_idx + 1)
- vecs = [hidden_states[i] for i in sorted(all_idxs)]
- else:
- vecs = [hidden_states[i] for i in entity_idxs]
- return np.mean(vecs, axis=0)
- def average_locations_via_substring(prompt, offsets, hidden_states, locs,
- flanking=True, second_half_only=False):
- """Average entity representations across all occurrences in the prompt.
- When *flanking* is True the representation for each occurrence includes
- the entity token and its immediately adjacent tokens (typically spaces).
- When *second_half_only* is True, only occurrences whose character start
- position is in the second half of the prompt string are used.
- """
- half = len(prompt) // 2 if second_half_only else 0
- loc_means = {}
- for loc in locs:
- pos_list = substring_positions(prompt, loc)
- if not pos_list:
- continue
- if second_half_only:
- pos_list = [(s, e) for s, e in pos_list if s >= half]
- if not pos_list:
- continue
- vecs = [v for s, e in pos_list
- for v in [gather_embeddings_for_span(offsets, hidden_states,
- (s, e), flanking=flanking)]
- if v is not None]
- if vecs:
- loc_means[loc] = np.mean(vecs, axis=0)
- return loc_means
- # ---------------------------------------------------------------------------
- # Distance & correlation helpers
- # ---------------------------------------------------------------------------
- def calc_pearson_correlation(node_names, loc_mean_repr, generation_map):
- rec = [n for n in node_names if n in loc_mean_repr and n in generation_map]
- if len(rec) < 2:
- return float("nan")
- gen_d, rep_d = [], []
- for i in range(len(rec)):
- for j in range(i + 1, len(rec)):
- gen_d.append(abs(generation_map[rec[i]] - generation_map[rec[j]]))
- rep_d.append(np.linalg.norm(loc_mean_repr[rec[i]] - loc_mean_repr[rec[j]]))
- if len(gen_d) < 2:
- return float("nan")
- r, _ = pearsonr(gen_d, rep_d)
- return r
- def gather_boxplot_data(node_names, loc_mean_repr, generation_map):
- rec = [n for n in node_names if n in loc_mean_repr and n in generation_map]
- dist_map = {}
- for i in range(len(rec)):
- for j in range(i + 1, len(rec)):
- gd = abs(generation_map[rec[i]] - generation_map[rec[j]])
- rd = np.linalg.norm(loc_mean_repr[rec[i]] - loc_mean_repr[rec[j]])
- dist_map.setdefault(gd, []).append(rd)
- return dist_map
- def merge_dist_map(gmap, dmap):
- for d, lst in dmap.items():
- gmap.setdefault(d, []).extend(lst)
- # ---------------------------------------------------------------------------
- # Plotting
- # ---------------------------------------------------------------------------
- def plot_all_runs_in_one_pca(all_points, all_edges, model_name, reducer="pca"):
- if not all_points:
- return
- X = np.array([p["vector"] for p in all_points])
- X_c = X - X.mean(axis=0, keepdims=True)
- dim_red = PCA(n_components=2) if reducer == "pca" else UMAP(n_components=2)
- X_2d = dim_red.fit_transform(X_c)
- for i, c in enumerate(X_2d):
- all_points[i]["x2d"], all_points[i]["y2d"] = c[0], c[1]
- gens = sorted(set(p["generation"] for p in all_points))
- cmap = plt.get_cmap("tab10")
- plt.figure(figsize=(3, 3))
- for gi, g in enumerate(gens):
- pts = [p for p in all_points if p["generation"] == g]
- plt.scatter([p["x2d"] for p in pts], [p["y2d"] for p in pts],
- color=cmap(gi % 10), label=GENERATION_LABELS.get(g, f"Gen {g}"))
- for e in all_edges:
- i_, j_ = e["u_index"], e["v_index"]
- plt.plot([all_points[i_]["x2d"], all_points[j_]["x2d"]],
- [all_points[i_]["y2d"], all_points[j_]["y2d"]],
- "--", color=cmap(gens.index(all_points[i_]["generation"]) % 10), alpha=0.0)
- if model_name == "gpt2-medium":
- plt.legend()
- plt.savefig(f"{model_name}_family_combined_{reducer}.png", dpi=200, bbox_inches="tight")
- logging.info(f"Saved {model_name}_family_combined_{reducer}.png")
- def boxplot_of_dist_map(gmap, model_name):
- if not gmap:
- return
- keys = sorted(gmap.keys())
- tick = {0: "Same gen.", 1: "1 gen.", 2: "2 gen."}
- plt.figure(figsize=(3, 2))
- plt.boxplot([gmap[k] for k in keys], showfliers=False, showmeans=False)
- plt.xticks(range(1, len(keys) + 1), [tick.get(k, f"{k} gen.") for k in keys])
- plt.xlabel("Generational distance")
- plt.ylabel("Distance between rep.s")
- plt.savefig(f"{model_name}_family_boxplot.png", dpi=200, bbox_inches="tight")
- logging.info(f"Saved {model_name}_family_boxplot.png")
- def plot_embeddings_with_graph_edges(
- mean_repr, G, generation_map, model_name="gpt2", reducer="pca", title="",
- ):
- keys = sorted(mean_repr.keys())
- if len(keys) < 2:
- return
- X = np.array([mean_repr[k] for k in keys])
- X_c = X - X.mean(axis=0, keepdims=True)
- dim_red = PCA(n_components=2) if reducer == "pca" else UMAP(n_components=2)
- X_2d = dim_red.fit_transform(X_c)
- loc_idx = {k: i for i, k in enumerate(keys)}
- gens = sorted(set(generation_map.get(k, -1) for k in keys))
- cmap = plt.get_cmap("tab10")
- plt.figure(figsize=(3, 3))
- for gi, g in enumerate(gens):
- gk = [k for k in keys if generation_map.get(k, -1) == g]
- ix = [loc_idx[k] for k in gk]
- plt.scatter(X_2d[ix, 0], X_2d[ix, 1], color=cmap(gi % 10),
- label=GENERATION_LABELS.get(g, f"Gen {g}"))
- for i, k in zip(ix, gk):
- plt.annotate(k, (X_2d[i, 0], X_2d[i, 1]), xytext=(3, 3), textcoords="offset points")
- for u, v in G.edges():
- if u in loc_idx and v in loc_idx:
- i, j = loc_idx[u], loc_idx[v]
- plt.plot([X_2d[i, 0], X_2d[j, 0]], [X_2d[i, 1], X_2d[j, 1]], "k--", alpha=0.3)
- plt.title(title + f" ({reducer.upper()})")
- plt.legend()
- ts = str(int(time.time()))
- plt.savefig(f"{model_name}_family_single_{reducer}_{ts}.png", dpi=200, bbox_inches="tight")
- logging.info(f"Saved {model_name}_family_single_{reducer}_{ts}.png")
- # ---------------------------------------------------------------------------
- # Analysis functions
- # ---------------------------------------------------------------------------
- def multi_tree_allinone(model_name="gpt2", layer_idx=10, n_runs=300,
- walk_length=50, reducer="pca"):
- logging.info(f"multi_tree_allinone: {model_name}, {n_runs} runs")
- wrapper = GPTWrapper(model_name)
- all_points, all_edges, global_dist = [], [], {}
- pt_idx = 0
- for run in range(n_runs):
- logging.info(f"=== RUN {run+1}/{n_runs} ===")
- G, node_names, gen_map = build_family_tree()
- prompt = generate_random_walk(G, walk_length)
- hs, off = wrapper.get_hidden_states_with_offsets(prompt, layer_idx)
- loc_repr = average_locations_via_substring(prompt, off, hs, node_names)
- node_pt = {}
- for n in (n for n in node_names if n in loc_repr):
- all_points.append({"run_idx": run, "node_name": n,
- "vector": loc_repr[n], "generation": gen_map[n]})
- node_pt[n] = pt_idx; pt_idx += 1
- for u, v in G.edges():
- if u in node_pt and v in node_pt:
- all_edges.append({"u_index": node_pt[u], "v_index": node_pt[v]})
- merge_dist_map(global_dist, gather_boxplot_data(node_names, loc_repr, gen_map))
- plot_all_runs_in_one_pca(all_points, all_edges, model_name, reducer)
- boxplot_of_dist_map(global_dist, model_name)
- def single_tree_with_edge_lines(model_name="gpt2", layer_idx=10,
- walk_length=100000, reducer="pca"):
- G, node_names, gen_map = build_family_tree()
- prompt = generate_random_walk(G, walk_length)
- wrapper = GPTWrapper(model_name)
- hs, off = wrapper.get_hidden_states_with_offsets(prompt, layer_idx)
- loc_repr = average_locations_via_substring(prompt, off, hs, node_names)
- plot_embeddings_with_graph_edges(loc_repr, G, gen_map, model_name, reducer,
- title=f"{model_name} L{layer_idx}")
- def rolling_mean(vals, w=3):
- return [np.mean(vals[max(0, i - w + 1):i + 1]) for i in range(len(vals))]
- def correlation_vs_context_length_multi(models, layer_idx=12, context_lengths=None,
- n_runs=100, rolling_window=1):
- if context_lengths is None:
- context_lengths = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]
- labels = {"outputs_tree": "Our model", "gpt2-medium": "Pre-trained GPT-2"}
- # Pre-build graphs so both models see the same data
- runs = [(build_family_tree(), ) for _ in range(n_runs)]
- plt.figure(figsize=(3, 2))
- for model_name in models:
- wrapper = GPTWrapper(model_name)
- avg_corrs = []
- for L in context_lengths:
- corrs = []
- for (G, node_names, gen_map), in runs:
- prompt = generate_random_walk(G, L)
- hs, off = wrapper.get_hidden_states_with_offsets(prompt, layer_idx)
- loc_repr = average_locations_via_substring(prompt, off, hs, node_names)
- c = calc_pearson_correlation(node_names, loc_repr, gen_map)
- if not np.isnan(c):
- corrs.append(c)
- m = np.mean(corrs) if corrs else float("nan")
- avg_corrs.append(m)
- logging.info(f"[{model_name}] ctx={L}, r={m:.3f}")
- if rolling_window > 1:
- plt.plot(context_lengths, rolling_mean(avg_corrs, rolling_window),
- "o-", label=f"{model_name} (rolled)")
- color = "blue" if model_name == "gpt2-medium" else "red"
- plt.plot(context_lengths, avg_corrs, "o--",
- label=labels.get(model_name, model_name), color=color)
- plt.xlabel("Context length"); plt.ylabel("Pearson correlation")
- plt.title("Family: Correlation vs context length"); plt.legend()
- plt.savefig("comparison_family_correlation_vs_context_length.png", dpi=200, bbox_inches="tight")
- def correlation_vs_layer_multi(models, layer_indices=None, n_runs=100, walk_length=50):
- if layer_indices is None:
- layer_indices = list(range(24))
- labels = {"outputs_tree": "Our model", "gpt2-medium": "Pre-trained GPT-2"}
- # Pre-build graphs + walks so both models see identical data
- runs = []
- for _ in range(n_runs):
- G, names, gm = build_family_tree()
- prompt = generate_random_walk(G, walk_length)
- runs.append((prompt, G, names, gm))
- plt.figure(figsize=(3, 2))
- for model_name in models:
- wrapper = GPTWrapper(model_name)
- avg = {}
- for layer_idx in layer_indices:
- corrs = []
- logging.info(f" Layer {layer_idx} for {model_name}...")
- for prompt, G, names, gm in runs:
- hs, off = wrapper.get_hidden_states_with_offsets(prompt, layer_idx)
- loc_repr = average_locations_via_substring(prompt, off, hs, names)
- c = calc_pearson_correlation(names, loc_repr, gm)
- if not np.isnan(c):
- corrs.append(c)
- avg[layer_idx] = np.mean(corrs) if corrs else float("nan")
- logging.info(f"[{model_name}] L{layer_idx} r={avg[layer_idx]:.3f}")
- color = "blue" if model_name == "gpt2-medium" else "red"
- plt.plot(list(avg.keys()), list(avg.values()), "o--",
- label=labels.get(model_name, model_name), color=color)
- plt.xlabel("Layer index"); plt.ylabel("Pearson correlation")
- plt.title("Family: Correlation vs layer"); plt.legend()
- plt.savefig("comparison_family_correlation_vs_layer.png", dpi=200, bbox_inches="tight")
- # ---------------------------------------------------------------------------
- # Entry point
- # ---------------------------------------------------------------------------
- if __name__ == "__main__":
- import argparse
- parser = argparse.ArgumentParser()
- parser.add_argument("--smoke", action="store_true")
- args = parser.parse_args()
- model_to_test = "outputs_tree"
- if args.smoke:
- n_pca, n_single, n_corr = 5, 1, 3
- ctx_lens = [10, 30]
- layers = [6, 12, 18]
- else:
- n_pca, n_single, n_corr = 300, 3, 100
- ctx_lens = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]
- layers = list(range(24))
- multi_tree_allinone("gpt2-medium", 12, n_pca, 50, "pca")
- for _ in range(n_single):
- single_tree_with_edge_lines("gpt2-medium", 12, 100000, "pca")
- multi_tree_allinone(model_to_test, 12, n_pca, 50, "pca")
- for _ in range(n_single):
- single_tree_with_edge_lines(model_to_test, 12, 100000, "pca")
- models = ["gpt2-medium", model_to_test]
- correlation_vs_context_length_multi(models, 12, ctx_lens, n_corr)
- correlation_vs_layer_multi(models, layers, n_corr, 50)
plot_family_reps.py at commit ed8901b, under MIT · at the source
Overview
- Nuffield Department of Clinical Neurosciences, University of Oxford, Oxford, UK
- Institute of Cognitive Neuroscience, University College London, London, UK
- Queen Square Institute of Neurology, University College London, London, UK
Abstract
Many aspects of learning, memory, and problem solving involve interplay between episodic (hippocampal) and semantic (neocortical) systems, but the neural mechanisms supporting this are unclear. We present a computational model in which sequential experiences are encoded in hippocampus in compressed form and replayed to train a neocortical generative network. This network captures the gist of specific episodes and extracts statistical patterns that generalise to new situations, enabling efficient reconstruction of the past and prediction of the future. The two systems interact during encoding, recall and problem solving, with the hippocampus retrieving relevant episodic information into working memory as a basis for generation using the ‘general knowledge’ of the neocortical network. We simulate this interaction as ‘retrieval-augmented generation’, with the addition of mechanisms to compress episodic memories into hippocampus and to consolidate them into neocortex. The model explains changes to memories over time, including schema-based distortions, and shows how episodic and semantic memory contribute to problem solving.
Reproduced under the paper's license (CC BY), from the paper cited above.
Repositories
Its files are read in the Code ↔ Paper reader above, with 29 matches between paragraphs and lines of code.
ellie-as/hippocampal-neocortical-RAG
ed8901b5cb93a2a4b68d9524e75efcb921798aec, 28 May 2026Availability: 1 check, the latest on 27 September 2026: the link answers
- 27 September 2026: the link answers
73 files
- full_model/
Inspect saved narratives.ipynb , Jupyter, 177 lines - full_model/
LLM ratings/ , Jupyter, 313 lines, 2 matchesHIPPOCORPUS attributes comparison.ipynb - full_model/
LLM ratings/ , Python, 417 lines, 2 matchesllm_specificity_analysis .py - full_model/
collate_all_figures.py , Python, 1,119 lines, 1 match - full_model/
lora_config.py , Python, 153 lines - full_model/
memory_simulation.py , Python, 1,477 lines, 2 matches - full_model/
narratives/ , Python, 248 linesanalyze_ckpt_pca.py - full_model/
narratives/ , Python, 649 lines, 1 matchbartlett_encoding_vs_con solidation.py - full_model/
narratives/ , Python, 703 lines, 1 matchbartlett_twostage.py - full_model/
narratives/ , Python, 2,523 lines, 2 matchescollate_figures.py - full_model/
narratives/ , Python, 1,606 linesplot.py - full_model/
narratives/ , Python, 184 linesplot_config.py - full_model/
narratives/ , Python, 419 linesplot_embeddings_standalo ne.py - full_model/
narratives/ , Python, 148 linesprobe_stage1.py - full_model/
narratives/ , Python, 297 linesrun_all.py - full_model/
narratives/ , Python, 392 lines, 2 matchesstories.py - full_model/
narratives/ , Python, 754 lines, 3 matchesutils.py - full_model/
narratives/ , Python, 201 lineswordcloud_from_ckpts.py - full_model/
rate_simulated_llm_attri , Python, 374 linesbutes.py - full_model/
semantic_memory_standalo , Python, 561 lines, 2 matchesne.py - full_model/
xRAG/ , Python, 50 linessrc/ dense_retrieval/ build_index.py - full_model/
xRAG/ , Python, 214 linessrc/ dense_retrieval/ colbert_retrieval.py - full_model/
xRAG/ , Python, 49 linessrc/ dense_retrieval/ colbert_server.py - full_model/
xRAG/ , Python, 102 linessrc/ dense_retrieval/ doc2embedding.py - full_model/
xRAG/ , Python, 176 linessrc/ dense_retrieval/ retrieve.py - full_model/
xRAG/ , Python, 28 linessrc/ dense_retrieval/ score.py - full_model/
xRAG/ , Python, 448 linessrc/ dense_retrieval/ train_retriever.py - full_model/
xRAG/ , Python, 59 linessrc/ dense_retrieval/ tsv2mmap.py - full_model/
xRAG/ , Python, 496 linessrc/ eval/ run_eval.py - full_model/
xRAG/ , Python, 356 linessrc/ eval/ utils.py - full_model/
xRAG/ , Python, 16 linessrc/ language_modeling/ lm_utils.py - full_model/
xRAG/ , Python, 409 linessrc/ language_modeling/ preprocessing.py - full_model/
xRAG/ , Python, 114 linessrc/ language_modeling/ profiler.py - full_model/
xRAG/ , Python, 792 linessrc/ language_modeling/ train.py - full_model/
xRAG/ , Python, 253 linessrc/ language_modeling/ utils.py - full_model/
xRAG/ , Python, 1 linesrc/ model/ SFR/ __init__.py - full_model/
xRAG/ , Python, 70 linessrc/ model/ SFR/ modeling_sfr.py - full_model/
xRAG/ , Python, 3 linessrc/ model/ __init__.py - full_model/
xRAG/ , Python, 1 linesrc/ model/ xMistral/ __init__.py - full_model/
xRAG/ , Python, 126 linessrc/ model/ xMistral/ modeling_xmistral.py - full_model/
xRAG/ , Python, 1 linesrc/ model/ xMixtral/ __init__.py - full_model/
xRAG/ , Python, 124 linessrc/ model/ xMixtral/ modeling_xmixtral.py - full_model/
xRAG/ , Python, 1 linesrc/ utils/ __init__.py - full_model/
xRAG/ , Python, 140 linessrc/ utils/ utils.py - hpc_model/
__init__.py , Python, 2 lines - hpc_model/
cache_details.py , Python, 53 lines - hpc_model/
cache_xrag.py , Python, 155 lines - hpc_model/
model_eval.py , Python, 405 lines - hpc_model/
paths.py , Python, 32 lines - hpc_model/
plotting.py , Python, 178 lines - hpc_model/
run_all.py , Python, 235 lines - inference/
build_figure6_full.py , Python, 655 lines - inference/
collate_inf_figures.py , Python, 1,865 lines - inference/
export_figure6_panels.py , Python, 189 lines - inference/
generate_figures.py , Python, 120 lines - inference/
graph_sequence_model.py , Python, 888 lines, 2 matches - inference/
plot_family_reps.py , Python, 553 lines, 4 matches - inference/
plot_reps.py , Python, 501 lines - inference/
rag_composition.py , Python, 1,006 lines, 2 matches - inference/
run_config.py , Python, 54 lines - scripts/
dual_mhn.py , Python, 396 lines, 3 matches - scripts/
entity_tokenizer.py , Python, 139 lines - scripts/
episodic_memory_dual.py , Python, 360 lines - scripts/
gpt.py , Python, 30 lines - scripts/
graph_utils.py , Python, 140 lines - scripts/
hpc.py , Python, 48 lines - scripts/
hpc_utils.py , Python, 32 lines - scripts/
run_clm.py , Python, 649 lines - scripts/
source_data.py , Python, 203 lines - scripts/
story_utils.py , Python, 11 lines - scripts/
tree_utils.py , Python, 156 lines - LICENSE, License, 21 lines
- README.md, Text, 59 lines
Zenodo 20215885
Availability: 1 check, the latest on 27 September 2026: the link answers (HTTP 200)
- 27 September 2026: the link answers (HTTP 200)
Code availability
Code for all simulations can be found at https://
Reproduced under the paper's license (CC BY), from the paper cited above.
Tracing map
Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.
What the map holds:
- 2 repositories of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
- 71 scripts, each with its path and the digest of its content;
- 29 matches between paragraphs of the paper and lines of the code (method lexical-v1);
- neither the text of the paper nor the code itself.
Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.
Data
Datasets cited
- huggingface.co/
datasets/ , at Hugging Face; found in the referencestarekziade/ wikipedia-topics
Data availability
All datasets used are publicly available, and the codebase for the project loads the data required for each simulation automatically. Source data for all figures are provided with this paper. Source data are provided in this paper.
Reproduced under the paper's license (CC BY), from the paper cited above.
Versions
The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.
Version 1, 27 September 2026: the first record
Recorded: type, language, journal, volume, issue, pages, dates, 2 authors, 3 keywords, 11 MeSH terms, 75 references.
Cite
This paper
Spens, E., & Burgess, N. (2026). Hippocampo-neocortical interaction as compressive retrieval-augmented generation. Nature communications, 17(1), 7971. https://
BibTeX
@article{spens2026hippoc
author = {Spens, Eleanor and Burgess, Neil},
title = {{Hippocampo-neocortical
journal = {Nature communications},
year = {2026},
month = jun,
volume = {17},
number = {1},
pages = {7971},
publisher = {Nature Publishing Group},
issn = {2041-1723},
doi = {10.1038/
url = {https://
pmid = {42350398},
pmcid = {PMC13447824}
}
RIS
TY - JOUR
AU - Spens, Eleanor
AU - Burgess, Neil
TI - Hippocampo-neocortical interaction as compressive retrieval-augmented generation
T2 - Nature communications
J2 - Nat Commun
PY - 2026
DA - 2026/
VL - 17
IS - 1
SP - 7971
SN - 2041-1723
PB - Nature Publishing Group
DO - 10.1038/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1038/
"type": "article-journal",
"title": "Hippocampo-neocortical interaction as compressive retrieval-augmented generation",
"container-title": "Nature communications",
"author": [
{
"family": "Spens",
"given": "Eleanor"
},
{
"family": "Burgess",
"given": "Neil"
}
],
"container-title-short":
"volume": "17",
"issue": "1",
"page": "7971",
"DOI": "10.1038/
"PMID": "42350398",
"PMCID": "PMC13447824",
"ISSN": "2041-1723",
"publisher": "Nature Publishing Group",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
6,
25
]
]
}
}
The tracing map gets a citation of its own once an author has validated it and it has a DOI.
Similar papers
The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.
- [1] doi:10.1016/j.cub.2026.05.068 [code]
- An abstract relational map emerges in the human medial prefrontal cortex with consolidation.Journal: Current biology : CBIn common: statsmodels, seaborn, pandas, 3 other tools, 6 references
- [2] doi:10.1126/sciadv.aeg6797 [code]
- Dorsoventral gradient of theta sweeps in the medial entorhinal cortex.Journal: Science advancesIn common: UMAP, NetworkX, statsmodels, 6 other tools, author Neil Burgess
- [3] doi:10.1038/s41467-026-71428-6 [code]
- Binding items to contexts through conjunctive neural representations with the method of loci.Journal: Nature communicationsIn common: statsmodels, seaborn, scikit-learn, 4 other tools, 5 references
- [4] doi:10.1038/s42003-026-10957-8 [code]
- Brain defence by the extracellular matrix protein Cochlin.Journal: Communications biologyIn common: Hugging Face Transformers, UMAP, NetworkX, 9 other tools
- [5] doi:10.64898/2026.03.30.714220 [code]
- An integrated single cell and spatial omics atlas of human prenatal developmentJournal: bioRxiv (preprint)In common: Hugging Face Transformers, UMAP, NetworkX, 9 other tools
- [6] doi:10.1038/s41467-026-74358-5 [code]
- Brain-inspired spatial intelligence for embodied agents.Journal: Nature communicationsIn common: Hugging Face Transformers, NetworkX, Pillow, 7 other tools, 2 references
- [7] doi:10.7554/elife.107933 [code]
- Modality-agnostic decoding of vision and language from fMRI.Journal: eLifeIn common: Hugging Face Transformers, Pillow, statsmodels, 7 other tools, 2 references
- [8] doi:10.1038/s42256-026-01254-4 [code]
- Neural sampling from cognitive maps enables goal-directed imagination and planning.Journal: Nature machine intelligenceIn common: NetworkX, PyTorch, seaborn, 3 other tools, computational modeling (no new data), 4 references
- [9] doi:10.1016/j.isci.2026.116825 [code]
- Social hierarchy shapes behavioral and transcriptional responses to chronic stress and ketamine in male mice.Journal: iScienceIn common: UMAP, NetworkX, Pillow, 8 other tools
- [10] doi:10.1038/s41598-026-43529-1 [code]
- A spiking neural network inspired by neuroscience and psychology for Western mode- and key-conditioned music learning and composition.Journal: Scientific reportsIn common: NetworkX, Pillow, PyTorch, 6 other tools, computational modeling (no new data), 1 reference
Contribute
The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.
Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 2 repositories of the authors' code, each at its verified commit and with its license, 71 scripts, and 29 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:df8facdf2f1fddbe…
Add the badge to its README
The badge links the code to this page. Copy one of these into the README of the paper's code: only you decide where it goes, and nothing is changed for you.
Markdown
[, paste the snippet at the top, then “Commit changes…” and, to review it first, “Create a new branch and start a pull request”. You open the pull request; OSCR asks for no permission.
Request its removal
To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).
Discussion, reproductions, activity
Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.
Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
