Experiments

Exploratory AI research — attention patterns, self-organizing systems, and algorithm implementations.

Transformer Attention Visualization

An interactive experiment exploring how multi-head self-attention patterns evolve across layers in a pre-trained BERT model, revealing what linguistic structures different attention heads capture.

Goal

Understand what information different attention heads in a transformer model attend to, and whether distinct heads specialize in capturing different linguistic phenomena (e.g., syntactic dependencies, coreference, positional patterns).

Method

Using the `bertviz` library and a pre-trained `bert-base-uncased` model, I extracted attention weight matrices for all 12 layers × 12 heads on a set of carefully chosen sentences. I then visualized the attention patterns and manually annotated which heads appeared to track syntactic dependencies (subject-verb, noun-adjective), positional patterns (attending to adjacent tokens), and semantic relationships (coreference, entity linking). The experiment used 50 sentences from the Penn Treebank covering diverse syntactic structures. For each sentence, I compared the attention patterns against gold-standard dependency parse trees to quantify how well specific heads align with syntactic structure.

Key Insight

Several attention heads show strong specialization: heads in layers 2–4 tend to capture local syntactic dependencies (e.g., determiners attending to their nouns), while heads in layers 8–11 capture longer-range semantic relationships. Notably, head 8-10 (layer 8, head 10) consistently attends from verbs to their subject nouns across diverse sentence structures, suggesting it has learned a subject-verb dependency detector. This aligns with findings from Clark et al. (2019) "What Does BERT Look At?" and provides intuition for why transformer representations are so effective for downstream NLP tasks.

Neural Cellular Automata for Pattern Self-Organization

An experiment training a neural network to act as a local update rule for a cellular automaton, enabling complex global patterns (like a target image) to emerge from purely local interactions.

Goal

Investigate whether a small neural network can learn a local update rule that causes a grid of cells to self-organize into a target pattern, and whether the resulting system exhibits robustness properties like self-repair after damage.

Method

Following the approach of Mordvintsev et al. (2020) "Growing Neural Cellular Automata", I trained a small convolutional neural network (3×3 kernel, 128 hidden channels) to serve as the update rule for a 2D cellular automaton. Each cell has a 16-dimensional state vector; the network takes the local 3×3 neighborhood as input and outputs a state update. Training used a "growing" objective: starting from a single seed cell, the automaton must grow to fill a 40×40 grid matching a target emoji image (🦎) within 64–96 steps. The loss is the pixel-wise MSE between the automaton's RGB channels and the target image. To encourage robustness, random cell states were zeroed out during training (damage augmentation).

Key Insight

The trained neural cellular automaton successfully grows the target pattern from a single seed cell and, remarkably, self-repairs after up to 50% of cells are randomly destroyed. This emergent robustness was not explicitly trained for — it arose naturally from the local update dynamics. The experiment demonstrates that complex global behavior can emerge from simple local rules, a principle relevant to understanding biological morphogenesis and designing fault-tolerant distributed systems. The learned update rule generalizes: the same network can grow the pattern from any initial seed position in the grid.