{"id":13633756,"url":"https://github.com/jind11/TextFooler","last_synced_at":"2025-04-18T14:33:14.521Z","repository":{"id":36265982,"uuid":"206163038","full_name":"jind11/TextFooler","owner":"jind11","description":"A Model for Natural Language Attack on Text Classification and Inference","archived":false,"fork":false,"pushed_at":"2022-12-08T10:46:49.000Z","size":2903,"stargazers_count":494,"open_issues_count":23,"forks_count":79,"subscribers_count":15,"default_branch":"master","last_synced_at":"2024-11-09T03:36:11.311Z","etag":null,"topics":["adversarial-attacks","bert","bert-model","natural-language-inference","natural-language-processing","text-classification"],"latest_commit_sha":null,"homepage":null,"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/jind11.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-03T20:06:21.000Z","updated_at":"2024-10-22T18:46:09.000Z","dependencies_parsed_at":"2023-01-17T01:01:28.314Z","dependency_job_id":null,"html_url":"https://github.com/jind11/TextFooler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jind11%2FTextFooler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jind11%2FTextFooler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jind11%2FTextFooler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jind11%2FTextFooler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jind11","download_url":"https://codeload.github.com/jind11/TextFooler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249505464,"owners_count":21282882,"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","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-attacks","bert","bert-model","natural-language-inference","natural-language-processing","text-classification"],"created_at":"2024-08-01T23:00:51.178Z","updated_at":"2025-04-18T14:33:13.653Z","avatar_url":"https://github.com/jind11.png","language":"Python","funding_links":[],"categories":["Open Source Security Tools","Python","Technical Resources"],"sub_categories":["Open Source/Access Responsible AI Software Packages"],"readme":"# TextFooler\nA Model for Natural Language Attack on Text Classification and Inference\n\nThis is the source code for the paper: [Jin, Di, et al. \"Is BERT Really Robust? Natural Language Attack on Text Classification and Entailment.\" arXiv preprint arXiv:1907.11932 (2019)](https://arxiv.org/pdf/1907.11932.pdf). If you use the code, please cite the paper:\n\n```\n@article{jin2019bert,\n  title={Is BERT Really Robust? Natural Language Attack on Text Classification and Entailment},\n  author={Jin, Di and Jin, Zhijing and Zhou, Joey Tianyi and Szolovits, Peter},\n  journal={arXiv preprint arXiv:1907.11932},\n  year={2019}\n}\n```\n\n## Data\nOur 7 datasets are [here](https://bit.ly/nlp_adv_data).\n\n## Prerequisites:\nRequired packages are listed in the requirements.txt file:\n```\npip install -r requirements.txt\n```\n\n## How to use\n\n* Run the following code to install the **esim** package:\n\n ```\ncd ESIM\npython setup.py install\ncd ..\n```\n\n* (Optional) Run the following code to pre-compute the cosine similarity scores between word pairs based on the [counter-fitting word embeddings](https://drive.google.com/open?id=1bayGomljWb6HeYDMTDKXrh0HackKtSlx).\n\n```\npython comp_cos_sim_mat.py [PATH_TO_COUNTER_FITTING_WORD_EMBEDDINGS]\n```\n\n* Run the following code to generate the adversaries for text classification:\n\n```\npython attack_classification.py\n```\n\nFor Natural langauge inference:\n\n```\npython attack_nli.py\n```\n\nExamples of run code for these two files are in [run_attack_classification.py](https://github.com/jind11/TextFooler/blob/master/run_attack_classification.py) and [run_attack_nli.py](https://github.com/jind11/TextFooler/blob/master/run_attack_nli.py). Here we explain each required argument in details:\n\n  * --dataset_path: The path to the dataset. We put the 1000 examples for each dataset we used in the paper in the folder [data](https://github.com/jind11/TextFooler/tree/master/data).\n  * --target_model: Name of the target model such as ''bert''.\n  * --target_model_path: The path to the trained parameters of the target model. For ease of replication, we shared the [trained BERT model parameters](https://drive.google.com/drive/folders/1wKjelHFcqsT3GgA7LzWmoaAHcUkP4c7B?usp=sharing), the [trained LSTM model parameters](https://drive.google.com/drive/folders/108myH_HHtBJX8MvhBQuvTGb-kGOce5M2?usp=sharing), and the [trained CNN model parameters](https://drive.google.com/drive/folders/1Ifowzfers0m1Aw2vE8O7SMifHUhkTEjh?usp=sharing) on each dataset we used.\n  * --counter_fitting_embeddings_path: The path to the counter-fitting word embeddings.\n  * --counter_fitting_cos_sim_path: This is optional. If given, then the pre-computed cosine similarity scores based on the counter-fitting word embeddings will be loaded to save time. If not, it will be calculated.\n  * --USE_cache_path: The path to save the USE model file (Downloading is automatic if this path is empty).\n  \nTwo more things to share with you:\n\n1. In case someone wants to replicate our experiments for training the target models, we shared the used [seven datasets](https://drive.google.com/open?id=1N-FYUa5XN8qDs4SgttQQnrkeTXXAXjTv) we have processed for you!\n\n2. In case someone may want to use our generated adversary results towards the benchmark data directly, [here it is](https://drive.google.com/drive/folders/12yeqcqZiEWuncC5zhSUmKBC3GLFiCEaN?usp=sharing).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjind11%2FTextFooler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjind11%2FTextFooler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjind11%2FTextFooler/lists"}