Giter Site home page Giter Site logo

alfatti / influence-patterns Goto Github PK

View Code? Open in Web Editor NEW

This project forked from caleblu/influence-patterns

0.0 0.0 0.0 7.14 MB

Code for the paper https://arxiv.org/pdf/2011.00740.pdf

License: MIT License

Shell 0.16% Python 42.17% Jupyter Notebook 57.67%

influence-patterns's Introduction

influence-patterns

Code for the Neurips 2021 paper "Influence Patterns for Explaining Information Flow in BERT" https://arxiv.org/pdf/2011.00740.pdf

Prerequisites

the official folder is a forked and modified from an earlier version of official bert implementation https://github.com/tensorflow/models/tree/master/official

We found such modification to be necessary since our method involves fundamentally modifying the computational graph of the model, tracking gradients in each layer of the model and separating the gradients from attention heads and skip connections.

Data for agreement tasks including wiki.vocab and marvin_linzen_dataset.tsv are based on repos from

Model checkpoints are downloaded from https://github.com/google-research/bert. (L = 6, H = 512 is used in the paper for agreement tasks).

Dependencies

  • tensorflow 2.1.0
  • python 3.6
  • scipy, numpy, tqdm
  • networkx
  • plotly
  • transformers (for sst-2 only)

Influence Patterns

Replication of Figure 3a and 3b

A end to end demonstration of using the code base to replicate figure 3a and 3b can be found in influence_pattern_demo.ipynb.

Core Components

The core methods of influence patterns are in influence_extractor.py, and modifications of the bert code in official/, mostly under official/nlp/modeling/layers and official/nlp/modeling/networks/transformer_encoder.py. An example of extracting influence pattern metadata for 1000 examples of SVA-Across Object clauses (250 examples each for SS, SP, PS, PP):

python influence_extractor.py --alpha 50 --num_example 250 --bert-dir /YOUR_PATH_TO_BERT_MODEL/uncased_L-6_H-512_A-8/   --sentence_type obj_rel_across_anim  --baseline_type 'mask'  --mask_indice 7 --threshold 0 --cuda 1

influence-patterns's People

Contributors

caleblu 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.