{"id":13640681,"url":"https://github.com/bogdan-kulynych/textfool","last_synced_at":"2025-12-30T17:23:54.010Z","repository":{"id":151156426,"uuid":"89886473","full_name":"bogdan-kulynych/textfool","owner":"bogdan-kulynych","description":"Plausible looking adversarial examples for text classification","archived":false,"fork":false,"pushed_at":"2018-12-16T12:57:11.000Z","size":87,"stargazers_count":92,"open_issues_count":4,"forks_count":32,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-08-03T01:17:21.723Z","etag":null,"topics":["adversarial-machine-learning","adversarial-samples","deep-learning","machine-learning"],"latest_commit_sha":null,"homepage":"","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/bogdan-kulynych.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-05-01T00:42:02.000Z","updated_at":"2024-05-09T02:50:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"27395012-3e5f-4d0c-8837-4266894505ee","html_url":"https://github.com/bogdan-kulynych/textfool","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bogdan-kulynych%2Ftextfool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bogdan-kulynych%2Ftextfool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bogdan-kulynych%2Ftextfool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bogdan-kulynych%2Ftextfool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bogdan-kulynych","download_url":"https://codeload.github.com/bogdan-kulynych/textfool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223816744,"owners_count":17207900,"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-machine-learning","adversarial-samples","deep-learning","machine-learning"],"created_at":"2024-08-02T01:01:13.401Z","updated_at":"2025-12-30T17:23:53.971Z","avatar_url":"https://github.com/bogdan-kulynych.png","language":"Python","funding_links":[],"categories":["Adversarial Robustness Libraries","Adversarial Robustness"],"sub_categories":[],"readme":"# Plausible looking adversarial examples for text classification\n\n**This repository is deprecated. Check out [trickster](https://github.com/spring-epfl/trickster) library and the \"[Evading classifiers in discrete domains with provable optimality guarantees](https://arxiv.org/abs/1810.10939)\" paper for an evolution and a more mature version of this approach to generating adversarial examples.**\n\n[![DOI](https://zenodo.org/badge/89886473.svg)](https://zenodo.org/badge/latestdoi/89886473)\n\nThis is a proof of concept aiming at producing \"imperceptible\" [adversarial examples](https://blog.openai.com/adversarial-example-research/) for text classifiers.\n\nFor instance, this are some adversarial examples produced by this code for a classifier of a tweet author's gender based on the tweet's text:\n\n![Examples of adversarial examples](images/examples.png)\n\n## Setup\n\n### System\nYou need Python 3, and all system dependencies possibly required by\n* Keras\n* NLTK\n* SpaCy\n\n### Python\n\n```\npip install -r requirements.txt\n```\n\n### NLP Data\n* SpaCy English language model:\n  ```\n  python -m spacy download en\n  ```\n* NLTK datasets (a prompt will appear upon running `paraphrase.py`)\n\n## Model\nTo train using default parameters simply run\n```\npython run_training.py\n```\nBy default will check for the CSV data set at `./data/twitter_gender_data.csv`, and save the model weights to `./data/model.dat`.\n\nShould attain about 66% accuracy on validation data set for gender recognition.\n\n### Data\nThis model uses Kaggle [Twitter User Gender Classification](https://www.kaggle.com/crowdflower/twitter-user-gender-classification) data.\n\n## Demo\nTo run the adversarial crafting script:\n```\npython run_demo.py\n```\nSuccess rate for crafting the adversarial example should be about 17%.\nBy default the script will write the crafted examples into `./data/adversarial_texts.csv`.\n\n## Paraphrasing\nThis module is rather reusable, although not immensely useful for anything practical. It provides a function that \"paraphrases\" a text by replacing some words with their WordNet synonyms, sorting by GloVe similarity between the synonym and the original context window. Relies on SpaCy and NLTK.\n\nExample of paraphrase:\n\n![Paraphrase example](images/paraphrase_example.png)\n\n\n## Citing notes\n\nPlease use [Zenodo link](https://zenodo.org/record/831638) to cite _textfool_. Not that this work is not published, and not peer-reviewed. _textfool_ has no relationship to _\"Deep Text Classification Can be Fooled.\"_ by B. Liang, H. Li, M. Su, P. Bian, X. Li, and W. Shi.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbogdan-kulynych%2Ftextfool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbogdan-kulynych%2Ftextfool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbogdan-kulynych%2Ftextfool/lists"}