Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (7.2%) to scientific vocabulary
Repository
Basic Info
- Host: GitHub
- Owner: simreg
- Language: Python
- Default Branch: main
- Size: 9.98 MB
Statistics
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 0
Metadata Files
README.md
Installation
This work is built on HuggingFace's transformers library. To run the code you need to install this library to your local environment using the following command (preferably in a new environment, since it will override current version of transformers).
python setup.py install
Running experiments
The method runs in 3 stages 1. Train the bias model. 2. Extract D^B and train guidance model. 3. Train the main model.
Example of debiasing Hypothesis-only bias in MNLI dataset.
Stage 1
Train the bias model:
shell
cd examples/pytorch/text-classification
run_name=bert_hypothesis_only
out_dir=mnli_runs/${run_name}
python run_glue.py --model_name_or_path bert-base-uncased --output_dir ${out_dir} --task_name mnli \
--do_train --do_eval --per_device_train_batch_size 64 --weight_decay 0.1 --warmup_ratio 0.1 \
--learning_rate 2e-5 --num_train_epochs 10 --run_name ${run_name} \
--evaluation_strategy half_epoch --logging_first_step --no_pad_to_max_length --hypothesis_only --save_strategy half_epoch
Stage 2
Save the logits of the model for biased samples extraction:
```shell
cd examples/pytorch/text-classification/utils export PYTHONPATH=examples/pytorch/text-classification
Pick the checkpoint with lowest cross-entropy loss on the validation set.
modeldir="./mnliruns/berthypothesisonly/checkpoint-" python savelogits.py --modelnameorpath ${modeldir} --dotrain \ --taskname mnli --nopadtomaxlength --perdeviceevalbatchsize 256 \ --outputdir ${model_dir}/logits ```
Plot the confidence of the bias model:
shell
cd examples/pytorch/text-classification/utils
export PYTHONPATH=examples/pytorch/text-classification
model_dir="logits from previous section"
python logits_distribution.py --task_name mnli --do_eval \
--logits_path ${model_dir}/logits --output_dir ${model_dir}/logits
Extract the biased samples based on the picked confidence threshold
--- you can do the same for validation set (to evaluate on) --- :
shell
cd examples/pytorch/text-classification/utils
export PYTHONPATH=examples/pytorch/text-classification
SPLITS_DIR=../splits
mkdir "${SPLITS_DIR}/mnli_hypothesis_bias_splits"
confidence_threshold="pick one" # usually 0.8 is good enough
python extract_biased_samples.py --output_dir ${SPLITS_DIR}/mnli_hypothesis_bias_splits/train --bias_threshold ${confidence_threshold} \
--logits_path ./mnli_runs/hypothesis_only/logits/train_logits.bin --task_name mnli --do_train
Finally, for training with increasing similarity, train the "unbiased" guidance model:
shell
cd examples/pytorch/text-classification
python run_glue.py --model_name_or_path bert-base-uncased --task_name mnli --logging_first_step \
--output_dir mnli_runs/extrensic_debiasing/hypothesis_bias/bert_64_0.8_hypothesis_extrensic_debiasing --no_pad_to_max_length \
--do_train --do_eval --per_device_train_batch_size 64 --per_device_eval_batch_size 256 \
--weight_decay 0.1 --warmup_ratio 0.1 --save_strategy half_epoch --evaluation_strategy half_epoch \
--learning_rate 2e-5 --num_train_epochs 10 --run_name bert_64_0.8_hypothesis_extrensic_debiasing \
--remove_biased_samples_from_train --bias_indices ${SPLITS_DIR}/mnli_hypothesis_bias_splits/train/train_biased_correct_indices.bin
NOTE: for decreasing similarity use the model from stage 1.
Stage 3
```shell cd examples/pytorch/text-classification/
guidancemodeldir="" regularizedlayers="bert.embeddings bert.encoder.layer.0 bert.encoder.layer.6 bert.encoder.layer.10 bert.encoder.layer.11" batchsize=64 lambda=100 modelname=bertEDBXElinearckaeM-0M-6M-10M-11Me-0-6-10-11lambda${lambda}${batchsize}sim mnliSPLITPATH="${SPLITSDIR}/mnlihypothesisbiassplits/trainbiasedcorrectindices.bin"
python runglue.py --modelnameorpath bert-base-uncased \ --outputdir mnliruns/hypothesisdebiasingexample/${modelname} \ --taskname mnli --dotrain --doeval --perdevicetrainbatchsize ${batchsize} --perdeviceevalbatchsize ${batchsize} \ --learningrate 2e-5 --numtrainepochs ${epochs} --weakmodellayer ${regularizedlayers} \ --weakmodelpath ${guidancemodeldir} --regularizedlayers ${regularizedlayers} \ --regularizationmethod abscoscor --evaluationstrategy halfepoch \ --regularizationlambda ${lambda} --runname ${modelname} --weightdecay 0.1 --warmupratio 0.1 --nopadtomaxlength \ --loggingfirststep --regularizedtokens all --tokenaggregationstrategy mean --enforcesimilarity \ --regularizeonlybiased --biasindices ${mnliSPLITPATH} --wandbgroup ```
Owner
- Login: simreg
- Kind: user
- Repositories: 1
- Profile: https://github.com/simreg
Citation (CITATION.cff)
cff-version: "1.2.0"
date-released: 2020-10
message: "If you use this software, please cite it using these metadata."
title: "Transformers: State-of-the-Art Natural Language Processing"
url: "https://github.com/huggingface/transformers"
authors:
- family-names: Wolf
given-names: Thomas
- family-names: Debut
given-names: Lysandre
- family-names: Sanh
given-names: Victor
- family-names: Chaumond
given-names: Julien
- family-names: Delangue
given-names: Clement
- family-names: Moi
given-names: Anthony
- family-names: Cistac
given-names: Perric
- family-names: Ma
given-names: Clara
- family-names: Jernite
given-names: Yacine
- family-names: Plu
given-names: Julien
- family-names: Xu
given-names: Canwen
- family-names: "Le Scao"
given-names: Teven
- family-names: Gugger
given-names: Sylvain
- family-names: Drame
given-names: Mariama
- family-names: Lhoest
given-names: Quentin
- family-names: Rush
given-names: "Alexander M."
preferred-citation:
type: conference-paper
authors:
- family-names: Wolf
given-names: Thomas
- family-names: Debut
given-names: Lysandre
- family-names: Sanh
given-names: Victor
- family-names: Chaumond
given-names: Julien
- family-names: Delangue
given-names: Clement
- family-names: Moi
given-names: Anthony
- family-names: Cistac
given-names: Perric
- family-names: Ma
given-names: Clara
- family-names: Jernite
given-names: Yacine
- family-names: Plu
given-names: Julien
- family-names: Xu
given-names: Canwen
- family-names: "Le Scao"
given-names: Teven
- family-names: Gugger
given-names: Sylvain
- family-names: Drame
given-names: Mariama
- family-names: Lhoest
given-names: Quentin
- family-names: Rush
given-names: "Alexander M."
booktitle: "Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing: System Demonstrations"
month: 10
start: 38
end: 45
title: "Transformers: State-of-the-Art Natural Language Processing"
year: 2020
publisher: "Association for Computational Linguistics"
url: "https://www.aclweb.org/anthology/2020.emnlp-demos.6"
address: "Online"
GitHub Events
Total
Last Year
Dependencies
- accelerate >=0.5.0 test
- conllu * test
- datasets >=1.13.3 test
- elasticsearch * test
- faiss-cpu * test
- fire * test
- git-python ==1.0.3 test
- jiwer * test
- librosa * test
- matplotlib * test
- nltk * test
- pandas * test
- protobuf * test
- psutil * test
- pytest * test
- rouge-score * test
- sacrebleu >=1.4.12 test
- scikit-learn * test
- sentencepiece * test
- seqeval * test
- streamlit * test
- tensorboard * test
- tensorflow_datasets * test
- torchvision * test
- accelerate *
- datasets >=1.8.0
- protobuf *
- scikit-learn *
- scipy *
- sentencepiece *
- torch >=1.3
- transformers ==3.5.1
- deps *