Note: An extended version of this has been accepted to the Mech Interp Workshop at ICML as well as the Workshop on Compositional Learning: Safety, Interpretability, and Agents at ICML. This project was collaborative with Susie Park and Kushal Jain and mentored by Bart Bussmann and Patrick Leask. It was the first real mech interp project for the three of us, so we owe a lot to Bart and Patrick.
What we roughly worked on, was to investigate how composition is represented in a (toy) transformer model. The motivation came from Relational Composition in Neural Networks: A Survey and Call to Action from Wattenberg & Viegas, which push for a better understanding of compositional representation in models. Compositional representation is for example in the sentences “Alice lives in Paris. Bob lives in London”, the model needs to keep track of lives_in(Alice, Paris) and lives_in(Bob, London) and not only the individual names or cities.
The transformer model we investigated only had ~580k parameters. This is tiny by modern standards, but also huge compared to e.g. linear regression. And we trained it specifically for this relational composition task, on a made up vocabulary of 100 tokens, where we constructed triplets of tokens in context (E1, R, E2) and asked the model for one of them, given the other two. What struck me here, is that our results were real clear. Like close to 100% in all ways we investigated. It’s kind of beautiful how well all the mech interp techniques work when looking into these very specific settings. This can make you really excited to do the same on big models after. But these are different. For example, we also tried to replicate some of the findings on a Gemma variant, but there the results were a lot less clean. I still think that work on toy models can provide useful intuitions that carry over (and we did not try too hard on Gemma).
Our main finding, besides dissecting the circuit the model uses fully, was to find that the address that the model constructs, in order to know which of the triplets to query for the correct information, is additive. That means you can construct it by just summing up the individual vectors of the two components and get the composite in that way in an almost exact way. I think we were most surprised by this result.
$$ \text{address}(E_1, R) \approx \mu + u_{E_1} + v_R $$
Another cool touch is that through this work a lot of the tricks that I had learned during working through the ARENA curriculum, I was able to apply here. E.g. the causal tests (to do activation patching and observing changes in final logits) were super clean: If you only replace one half of the address-composite, the final logit becomes split between now two equally likely answers. If you also replace the second one it shifts completely. The logit movement here is symmetrical even in the raw values themselves.
Overall I really enjoyed this experience, and learned a lot - not just from the technical perspective but also from how to manage a project, and how to manage mentors. Patrick and Bart were great and often unblocked us, but it was important that we present our results and questions in a clear way, so that it’s also obvious where/if we are stuck, or what specifically we need feedback on.