Git Product home page Git Product logo

structural-grokking's Introduction

This repository can be used to reproduce plots and experiments from our ACL'23 paper: Grokking of Hierarchical Structure in Vanilla Transformers. Almost all of the structure of this codebase is borrowed from our earlier work on intrinsic compositionality.

Dependencies:

Note that this code has been tested with python 3.8.10.

  1. Install conda environment:
conda env create -f environment.yml
conda activate tree-reg
pip install -e .

Data:

Datasets used in this work can be found under data_utils. More specificially, data_utils/dyck_data contains Dyck, data_utils/question_formation_data contains Question-Formation and data_utils/tense_inflection_data contains Tense-Inflection.

Training

The script in train_transformers.py may be used to train transformer LMs of various sizes. Below trains a 6 layer transformer LM on question-formation.

# checkpoints saved under /path/to/save/dir
python train_transformers.py --dataset lm --save_dir /path/to/save/dir --encoder_n_layers 6

To modify number of training steps / checkpoint saving frequency, please take a look at trainin_utils.py.

Computing Tree Projections

For computing tree projections, take a look at transformer_lm_sci.py. We provide a minimal implementation of the tree projections method (for auto-regressive LMs) in the tree_projections folder.

โš ๏ธ Please note that this implementation is specifically made for models with causal masking and will not work for bi-directional models. If you want an implementation for bidirectional models, check out the original Tree Projections codebase.

Reproducing Plots

We provide all the raw data for reproducing plots in our paper. Please run the notebooks in the notebooks folder, after unzipping sci.tar.gz.

Citing this work

If you use ideas from this paper in your work, we kindly ask you to cite us as:

@inproceedings{
murty2023structure,
title={Grokking of Hierarchical Structure in Vanilla Transformers},
author={Shikhar Murty and Pratyusha Sharma and Jacob Andreas and Christopher D Manning},
booktitle={Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics},
year={2023},
}

Acknowledgements

A lot of our code is built on top of the following repositories:

structural-grokking's People

Contributors

murtyshikhar avatar

Stargazers

Chia avatar Allen Qingzhi Chen avatar  avatar Guangyuan Jiang avatar Kabir Ahuja avatar Cogito Ergo Sum avatar Jiaqi Wang avatar XLXW avatar  avatar Jeff Carpenter avatar Ryuichiro Hataya avatar Lei Wu avatar Dan Friedman avatar Pratyusha Sharma avatar Daman Arora avatar Harman Singh avatar  avatar

Watchers

 avatar Kostas Georgiou avatar

structural-grokking's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.