This repository contains the dataset and code for the paper `Mechanistic Interpretability of Socio-Political Frames in Language Models: an Exploration' by H. Asghari & S. Nenno presented at the ECML/PKDD workshop on Advances in Interpretable Machine Learning and Artificial Intelligence 2024 (AIMLAI24).
The project investigated two research questions: How well do LLMs generate socio-political frames and recognize their presence in texts? And can we localize the frames inside LLMs? These questions are explored through four experiments:
strict fatherand nurturing parent) within rewritten textsThe repository is organized according to the above experiments. It contains three datasets (in CSV format).
The first dataset contains 270 generated texts that evoke 10 different socio-political frames
from three different origins and by five LLMs.
These texts have been annotated by two annotators (with a third acting as tie-breaker).
The second dataset is the output of different zeroshot classification techniques on a subset of these texts.
The third dataset contains SF/NP-v-control data to extract L17 & L21 hidden dims for the last token.
Please see our paper for more explanation about these datasets.
If you find the dataset, code, or ideas useful, please consider citing our paper.
This folder contains all resources and scripts related to the generation of data and the preparation of datasets for the project.
story-frame-gen-202403.py: Script for generating data.data-generated-stories-frames-202505.csv: Contains generated text data.data-stories-for-probing-202405.csv: Dataset which contains SF/NP-v-control data to extract L17 & L21 hidden dims for the last token.data-stories-with-labels-202505.csv: Includes annotations for the generated data.statistics-table-one-202505.ipynb and statistics-table-two-202505.ipynb: Jupyter Notebooks used for generating statistical analyses.To generate data, run the following command:
python story-frame-gen-202403.py --model llama2 --output gen_stories.csv
Use statistics-table-one-202505.ipynb and statistics-table-two-202505.ipynb to produce Table 1 and Table 2 for the paper.
Zeroshot classification of two frames (strict fatherand nurturing parent) within rewritten texts
zshot-classification-202505.ipynb: Notebook to do a zeroshot analysis on our big-dataset of frames and say % each matches SF or NP along with confidence %statistics-table-three-202505.ipynb: Jupyter Notebook used for generating statistical analyses for table 3Use statistics-table-three-202505.ipynb to produce Table 3 for the paper.
Localization of SF/NP frames via the ROME causal tracing method
/rome: this folder is copied and modified from the original repository , see rome-repositorycausal-logistic-202505.ipynb: Jupyter Notebook used for ROME casual tracing methodProbing for the SF/NP within hidden layer 17 using RFE (detecting 1 key dimension for each)
logistic-hidden-SF-202505.ipynb: Notebook to extract L17 & L21 hidden dims for the last token on Llama3 model with SF/NP-v-control data & run logistic regression models on this data.We thank Jannes Meyer for organizing the code in this repository.
2 commits
Jupyter Notebook
77.7%
Python
22.3%
This repository contains the dataset and code for the paper `Mechanistic Interpretability of Socio-Political Frames in Language Models: an Exploration' by H. Asghari & S. Nenno presented at the ECML/PKDD workshop on Advances in Interpretable Machine Learning and Artificial Intelligence 2024 (AIMLAI24).
The project investigated two research questions: How well do LLMs generate socio-political frames and recognize their presence in texts? And can we localize the frames inside LLMs? These questions are explored through four experiments:
strict fatherand nurturing parent) within rewritten textsThe repository is organized according to the above experiments. It contains three datasets (in CSV format).
The first dataset contains 270 generated texts that evoke 10 different socio-political frames
from three different origins and by five LLMs.
These texts have been annotated by two annotators (with a third acting as tie-breaker).
The second dataset is the output of different zeroshot classification techniques on a subset of these texts.
The third dataset contains SF/NP-v-control data to extract L17 & L21 hidden dims for the last token.
Please see our paper for more explanation about these datasets.
If you find the dataset, code, or ideas useful, please consider citing our paper.
This folder contains all resources and scripts related to the generation of data and the preparation of datasets for the project.
story-frame-gen-202403.py: Script for generating data.data-generated-stories-frames-202505.csv: Contains generated text data.data-stories-for-probing-202405.csv: Dataset which contains SF/NP-v-control data to extract L17 & L21 hidden dims for the last token.data-stories-with-labels-202505.csv: Includes annotations for the generated data.statistics-table-one-202505.ipynb and statistics-table-two-202505.ipynb: Jupyter Notebooks used for generating statistical analyses.To generate data, run the following command:
python story-frame-gen-202403.py --model llama2 --output gen_stories.csv
Use statistics-table-one-202505.ipynb and statistics-table-two-202505.ipynb to produce Table 1 and Table 2 for the paper.
Zeroshot classification of two frames (strict fatherand nurturing parent) within rewritten texts
zshot-classification-202505.ipynb: Notebook to do a zeroshot analysis on our big-dataset of frames and say % each matches SF or NP along with confidence %statistics-table-three-202505.ipynb: Jupyter Notebook used for generating statistical analyses for table 3Use statistics-table-three-202505.ipynb to produce Table 3 for the paper.
Localization of SF/NP frames via the ROME causal tracing method
/rome: this folder is copied and modified from the original repository , see rome-repositorycausal-logistic-202505.ipynb: Jupyter Notebook used for ROME casual tracing methodProbing for the SF/NP within hidden layer 17 using RFE (detecting 1 key dimension for each)
logistic-hidden-SF-202505.ipynb: Notebook to extract L17 & L21 hidden dims for the last token on Llama3 model with SF/NP-v-control data & run logistic regression models on this data.We thank Jannes Meyer for organizing the code in this repository.
2 commits
Jupyter Notebook
77.7%
Python
22.3%