Git Product home page Git Product logo

causal-math's Introduction

Causal Analysis of Mathematical Reasoning in Neural Language Models

This repository contains the code for the paper "A Causal Framework to Quantify the Robustness of Mathematical Reasoning with Language Models".

Alessandro Stolfo*, Zhijing Jin*, Kumar Shridhar, Bernhard Schölkopf, Mrinmaya Sachan

Requirements

  • python==3.9
  • pytorch==1.11
  • pandas==1.4
  • spacy==3.3.1
  • transformers==4.20.0
  • wandb

Experiments

The intervention experiments can be run by setting the desired parameters in run_numeracy_exp.sh and then executing sh run_numeracy_exp.sh.

Intervention Types

The parameters representing the different intervention/effect combinations are the following:

  • 1b: DCE(N --> R)
  • 2: TCE(N --> R)
  • 3: DCE(S --> R)
  • 4: TCE(T --> R)

Models

The models on which this repo was tested are:

  • distilgpt2
  • gpt2
  • gpt2-medium
  • gpt2-large
  • gpt2-xl
  • EleutherAI/gpt-neo-1.3B
  • EleutherAI/gpt-neo-2.7B
  • EleutherAI/gpt-j-6B
  • gpt3/text-davinci-002

For GPT-3, the organization key and secret key are necessary to access the OpenAI APIs. If you want to experiment with it, paste the keys as the first (organization) and second (secret) lines in the openai_keys.txt file.

All the other models are accessed through Huggingface Transformers.

GPT-Neo-2.7B requires a GPU with at least 24GB of memory, and GPT-J-6B requires a GPU with at least 32 GB of memory.

Heatmaps

To obtain the data needed to plot the heatmaps reported in the paper, execute

python heatmap_experiments/heatmap_experiment.py [model] [device] [out_dir] not_random arabic [seed] statement [data_path] [max_n] disabled + [n_templates]"

This will store the average probabilities assigned to each possible groud-truth result in the range 0,...,max_n as a .csv file.

Other Papers / Resources

Part of this repo is based on the code for Finlayson et al. (2020)

causal-math's People

Contributors

alestolfo avatar

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.