GithubHelp home page GithubHelp logo

modifying-memory's Introduction

Modifying Memories of Transformer Models

This repository is a Re-implementation for creating the benchmarks in the paper Modifying Memories of Transformer Models. Due to randomness, the selected subset of facts for modification are different from the original paper.

Creating modification dataset for TREx

To generate modified facts:

1. Create conda environment (optional) and install requirements

conda create -n lama37 -y python=3.7 && conda activate lama37
pip install -r requirements.txt
python -m spacy download en

2. Download the data

mkdir lama_data && cd lama_data
wget https://dl.fbaipublicfiles.com/LAMA/data.zip
unzip data.zip
rm data.zip
cd ..

3. Download pretrained BERT-Base model

For a full list of available models, please refer to the LAMA repo.

bash ./download_bert_base.sh

4. Randomly select the questions and generate modified answers

python create_trex.py

By default, a dict mapping uuids to the modified answers are stored in modification/change_list_{num_modified_facts}.json. You can use this dict to finetune the model on the supporting facts on TREx and test it on the corresponding LAMA probes.

For example, the answer of the fact with uuid 6904327c-5211-4edb-ad8c-bcefee2149c6 (in lama_data/data/TREx/P276.jsonl) is modified from Atlanta to Ukraine. You could use all the masked sub_surface sentences in P276.jsonl for finetuning the model, and the template [X] is located in [Y]. for predicate P276 to generate the masked probing sentence for test. These templates are given in lama_data/data/relations.jsonl if you followed our Step 2.

Creating modification for zsRE

The zsRE implementation is based on KILT.

1. Download the data

mkdir zsre_data && cd zsre_data
wget http://dl.fbaipublicfiles.com/KILT/structured_zeroshot-train-kilt.jsonl
cd .. 

2. Generate the data

Since a finetuned model can easily achieve perfect test accuracy in our setting, we simply choose any fact with at least one eval question for modification.

Examples

The examples are given in modification.zip. We give an example subset of 32 modified facts for TREx in modification/change_list_32.json. For zsRE, we give an example train/eval split (modification/zsre_train_unmodified.jsonl and modification/zsre_eval_unmodified.jsonl), and a subset of 32 modified facts (modification/zsre_train_modified_32.jsonl and modification/zsre_eval_modified_32.jsonl).

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.