{"id":19731585,"url":"https://github.com/shunk031/attention-meets-perturbation","last_synced_at":"2025-08-18T19:07:03.601Z","repository":{"id":47772483,"uuid":"299042628","full_name":"shunk031/attention-meets-perturbation","owner":"shunk031","description":"📝 Official Implementation of \"Attention Meets Perturbation: Robust and Interpretable Attention with Adversarial Training\"","archived":false,"fork":false,"pushed_at":"2021-08-13T15:31:56.000Z","size":1461,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-30T02:38:22.329Z","etag":null,"topics":["adversarial-training","allennlp","attention-mechanism","binary-classification","ieee","interpretability","natural-language-inference","natural-language-processing","pytorch","question-answering","robustness"],"latest_commit_sha":null,"homepage":"http://shunk031.github.io/attention-meets-perturbation/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shunk031.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-09-27T13:51:36.000Z","updated_at":"2024-04-15T06:22:58.000Z","dependencies_parsed_at":"2022-08-26T18:50:30.015Z","dependency_job_id":null,"html_url":"https://github.com/shunk031/attention-meets-perturbation","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/shunk031/attention-meets-perturbation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shunk031%2Fattention-meets-perturbation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shunk031%2Fattention-meets-perturbation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shunk031%2Fattention-meets-perturbation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shunk031%2Fattention-meets-perturbation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shunk031","download_url":"https://codeload.github.com/shunk031/attention-meets-perturbation/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shunk031%2Fattention-meets-perturbation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271043635,"owners_count":24689793,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adversarial-training","allennlp","attention-mechanism","binary-classification","ieee","interpretability","natural-language-inference","natural-language-processing","pytorch","question-answering","robustness"],"created_at":"2024-11-12T00:21:56.892Z","updated_at":"2025-08-18T19:07:03.563Z","avatar_url":"https://github.com/shunk031.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Attention Meets Perturbations: Robust and Interpretable Attention with Adversarial Training\n\n[![CoRR preprint arXiv:2009.12064](http://img.shields.io/badge/cs.CL-arXiv%3A2009.12064-B31B1B.svg)](http://arxiv.org/abs/2009.12064)\n[![IEEE Access](https://img.shields.io/badge/Accepted-IEEE%20Access-%2300629B%09)](https://doi.org/10.1109/ACCESS.2021.3093456)\n[![Demo Page Build](https://github.com/shunk031/attention-meets-perturbation/actions/workflows/gh-pages.yml/badge.svg)](https://github.com/shunk031/attention-meets-perturbation/actions/workflows/gh-pages.yml)\n\n|                                        |                                           |\n|----------------------------------------|-------------------------------------------|\n| ![model](./.github/assets/BC-model.png)| ![Figure 1](./.github/assets/figure1.png) |\n\n**Attention Meets Perturbations: Robust and Interpretable Attention with Adversarial Training**  \nShunsuke Kitada and Hitoshi Iyatomi\n\n- Preprint: https://arxiv.org/abs/2009.12064\n- Accepted for publication in the [IEEE Access](https://doi.org/10.1109/ACCESS.2021.3093456).\n\nAbstract: *Although attention mechanisms have been applied to a variety of deep learning models and have been shown to improve the prediction performance, it has been reported to be vulnerable to perturbations to the mechanism. To overcome the vulnerability to perturbations in the mechanism, we are inspired by adversarial training (AT), which is a powerful regularization technique for enhancing the robustness of the models. In this paper, we propose a general training technique for natural language processing tasks, including AT for attention (Attention AT) and more interpretable AT for attention (Attention iAT). The proposed techniques improved the prediction performance and the model interpretability by exploiting the mechanisms with AT. In particular, Attention iAT boosts those advantages by introducing adversarial perturbation, which enhances the difference in the attention of the sentences. Evaluation experiments with ten open datasets revealed that AT for attention mechanisms, especially Attention iAT, demonstrated (1) the best performance in nine out of ten tasks and (2) more interpretable attention (i.e., the resulting attention correlated more strongly with gradient-based word importance) for all tasks. Additionally, the proposed techniques are (3) much less dependent on perturbation size in AT.*\n\n## Install and Run the experiments\n\n![Python 3.7](https://img.shields.io/badge/python-3.7%2B-brightgreen.svg)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Powered by AllenNLP](https://img.shields.io/badge/Powered%20by-AllenNLP-blue.svg)](https://github.com/allenai/allennlp)\n\n### Install requirements\n\n```shell\npip install -U pip poetry setuptools\npoetry install\n```\n\n### Prepare for spaCy\n\n```shell\npython -m spacy download en\n```\n\n### Prepare dataset for the experiments\n\n- for all dataset\n\n```shell\nallennlp make-dataset all\n```\n\n- for specific dataset (e.g., SST)\n\n```shell\nallennlp make-dataset sst\n```\n\n### Run training models\n\n\u003cdetails\u003e\n  \u003csummary\u003efor binary classification (BC) tasks\u003c/summary\u003e\n\n```shell\n# for SST\nCUDA_VISIBLE_DEVICES=0 GPU=0 allennlp train \\\n    config/sst/train.jsonnet \\\n    -s output/sst/weighted\n\n# for Newsgroups\nCUDA_VISIBLE_DEVICES=0 GPU=0 allennlp train \\\n    config/newsgroups/train.jsonnet \\\n    -s output/newsgroups/weighted\n\n# for IMDB\nCUDA_VISIBLE_DEVICES=0 GPU=0 allennlp train \\\n    config/imdb/train.jsonnet \\\n    -s output/imdb/weighted\n\n# for AGNews\nCUDA_VISIBLE_DEVICES=0 GPU=0 allennlp train \\\n    config/ag_news/train.jsonnet \\\n    -s output/ag_news/weighted\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003efor question answering (QA) tasks\u003c/summary\u003e\n\n```shell\n# For CNN\nCUDA_VISIBLE_DEVICES=0 GPU=0 allennlp train \\\n    config/cnn/train.jsonnet \\\n    -s output/cnn/vanilla\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003efor natural language inference (NLI) tasks\u003c/summary\u003e\n\n```shell\n# For SNLI\n$ CUDA_VISIBLE_DEVICES=9 GPU=0 allennlp train \\\n    config/snli/train.jsonnet \\\n    -s output/snli/vanilla\n```\n\u003c/details\u003e\n\n## Citation\n\nIf you find this code or idea useful, please cite it as below.\n\n\n```bibtex\n@article{kitada2020attention,\n  title   = {Attention Meets Perturbations: Robust and Interpretable Attention with Adversarial Training},\n  author  = {Shunsuke Kitada and Hitoshi Iyatomi},\n  journal = {IEEE Access},\n  year={2021},\n  volume={9},\n  number={},\n  pages={92974-92985},\n  doi={10.1109/ACCESS.2021.3093456}\n}\n```\n\n## Reference\n\n- S. Kitada and H. Iyatomi, \"Attention Meets Perturbations: Robust and Interpretable Attention With Adversarial Training,\" in *IEEE Access*, vol. 9, pp. 92974-92985, 2021, doi: [10.1109/ACCESS.2021.3093456](https://doi.org/10.1109/ACCESS.2021.3093456).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshunk031%2Fattention-meets-perturbation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshunk031%2Fattention-meets-perturbation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshunk031%2Fattention-meets-perturbation/lists"}