これは、論文で使用されるコードのリポジトリです。
論文を次のように引用してください。
@article { din2023jump ,
title = { Jump to Conclusions: Short-Cutting Transformers With Linear Transformations } ,
author = { Yom Din, Alexander and Karidi, Taelin and Choshen, Leshem and Geva, Mor } ,
journal = { arXiv preprint arXiv:2303.09435 } ,
year = { 2023 } ,
}gpt2およびWikipediaの文のプロットを作成するには、書面で次のように実行します。
get_wikipedia_sentences.py
( ./experiment/sentences/wikipedia_20K-sentences.pickle 、ウィキペディアからの20k文を含む)
add_tokenization.py
( ./experiment/gpt2/wikipedia_tokenized_train.pickleは、前のスクリプトによって生成されたファイルからの最初の9000文のトークン化とランダムなトークン位置を含むPickle、および./experiment/gpt2/wikipedia_tokenized_val.pickleを含むtokenizationsとランダムを含むランダムを含むPickleを含む。
add_linreg.py
( ./linreg/gpt2/wikipedia/i_j.pickle whereを作成します
add_plot_r2.py
( ./experiment/gpt2/wikipedia_r2_scores.pickleが含まれます./experiments/gpt2/plots/wikipedia/r2_scores_12.pdf gpt2/plots/wikipedia/r2_scores_12.pdfを作成します。
add_linreg_submodules.py
( ./linreg/gpt2/wikipedia/pi_a_b.pickle whereを作成します
add_results.py
( ./experiment/gpt2/wikipedia_results.pickleは(各検証セットサンプルに対して)上位10トークンを含む(各検証セットのサンプル)、および各レイヤーでのペーパーの5つのマッピングによると、上位1トークンのモデルの驚きを含みます。
plot_results.py
(前のファイルの出力の結果に基づいて、 ./experiment/gpt2/plots/wikipedia/ gpt2/plots/wikipedia/でいくつかのプロットを生成します)
bert-base-uncasedおよびWikipediaの文のプロットを作成するには、書面で次のように実行します。
get_wikipedia_sentences.py
(上記のgpt2と同じ、再実行する必要はありません)
bert_add_reps.py
( ./experiment/bert-base-uncased_mask/wikipedia_train.pickleトークン化、ランダムなトークンの位置、および前./experiment/bert-base-uncased_mask/wikipedia_val.pickleスクリプトによって作成されたファイルからの最初の9000文のマスクされたランダムトークンのマスクされたランダムトークンの表現を含むpickle次の3000文のすべてのレイヤーでのマスクされたランダムトークンの位置と表現)
bert_add_linreg.py
( ./linreg/bert-base-uncased_mask/wikipedia/i_j.pickle whereを作成します
bert_add_plot_r2.py
( ./experiment/bert-base-uncased_mask/wikipedia_r2_scores.pickleを作成します./experiments/bert-base-uncased_mask/plots/wikipedia/r2_scores_12.pdf bert-base-uncased_mask/plots/wikipedia/r2_scores_12.pdfを作成します。
bert_add_results.py
( ./experiment/bert-base-uncased_mask/wikipedia_results.pickle containg(各検証セットサンプル)トップ10トークンと、トップ1トークンのモデルの驚きを含む
plot_results.py(変更model_folder_name='bert-base-uncased_mask'およびplot_parts = False )
(前のファイルの出力の結果に基づいて./experiment/bert-base-uncased_mask/plots/wikipedia/ bert-base-uncased_mask/plots/wikipedia/でいくつかのプロットを生成します)
また、 gpt2-medium 、 gpt2-large 、 gpt2-xl 、 bert-large-uncasedのプロットを作成しました。それを行うには、比較的層状の方法で、シーケンス内の各スクリプトのヘッドの変数を変更する必要があります。
コードはPython 3.10.4と次のパッケージバージョンで実行されました。
torch.__version__ = 1.13.1+cu117
transformers.__version__ = 4.20.1
sklearn.__version__ = 1.2.0
pickle.format_version = 4.0
datasets.__version__ = 2.5.2 # used only to fetch Wikipedia sentences
spacy.__version__ = 3.5.0 # used only to fetch Wikipedia sentences
訓練されたマトリックスの一部は、https://huggingface.co/sashay/linear-shortcutにあります。