This is the official repository for the paper "The Curious Case of Analogies: Investigating Analogical Reasoning in Large Language Models".
We recommend using the following versions for compatibility.
- PyTorch 2.3.1
- Cuda 12.4
conda env create -f environment.yml --name analogical_reasoningevaluate_knowledge.pyis used to obtain correct / incorrect test samples for each model.knockout_attention.pyis used to block specific attention edges to identify critical positions for answer resolution.entity_description.pyis used to obtain natural language descriptions of hidden states using Patchscopes.
evaluate_knowledge_swap_pair.pyis used in the first intervention experiment, where we replace the first entity pair with that of a correct analogy.patch.pyis used in the second error analysis experiment, where we patch the representations of e2 to the link.
run_dual_probe.pyis used to run probing experiments that can test whether and where models encode analogical structure in their internal representations.evaluate_story_analogy.pyis used to evaluate model performance on story analogies, as well as to obtain layer-wise token representations that can be used to calculate the Mutual Alignment Score (MAS).
- Follow the steps in
inspect_section{4_a,4_b,5,6}.ipynbto analyze and reproduce experimental results.