Top AI Repos โ open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
๐ฃ๏ธ Tool to generate adversarial text examples and test machine learning models against them
| Date | Stars |
|---|---|
| 2026-07-31 | 405 |
| 2026-08-07 | 405 |
| 2026-08-08 | 405 |
| 2026-08-16 | 405 |
| 2026-08-17 | 405 |
| 2026-08-18 | 405 |
| 2026-09-01 | 404 |
| 2026-09-07 | 403 |
| 2026-09-16 | 402 |
| 2026-09-25 | 402 |
| 2026-11-04 | 402 |
Today
โ stars today
This week
โ stars this week
This month
โ stars this month
Momentum
0.0
growth rate 0.00%/day
<div align="center">
<img src="adversary_name.png"></img>
</div>
<br>
[](https://travis-ci.com/airbnb/artificial-adversary)
[](https://github.com/100/Cranium/blob/master/LICENSE)
This repo is primarily maintained by [Devin Soni](https://github.com/100/) and [Philbert Lin](https://github.com/philin).
Note that this project is under active development. If you encounter bugs, please report them in the `issues` tab.
## Introduction
When classifying user-generated text, there are many ways that users can modify their content to avoid detection. These methods are typically cosmetic modifications to the texts that change the raw characters or words used, but leave the original meaning visible enough for human readers to understand. Such methods include replacing characters with similar looking ones, removing or adding punctuation and spacing, and swapping letters in words. For example `please wire me 10,000 US DOLLARS to bank of scamland` is probably an obvious scam message, but `[email protected] me 10000 US DoLars to,BANK of ScamIand` would fool many classifiers.
This library allows you to generate texts using these methods, and simulate these kind of attacks on your machine learning models. By exposing your model to these texts offline, you will be able to better prepare for them when you encounter them in an online setting. Compared to other libraries, this one differs in that it treats the model as a black box and uses only generic attacks that do not depend on knowledge of the model itself.
## Installation
```
pip install Adversary
python -m textblob.download_corpora
```
## Usage
See [`Example.ipynb`](https://github.com/airbnb/artificial-adversary/blob/master/Example.ipynb) for a quick illustrative example.
```python
from Adversary import Adversary
gen = Adversary(verbose=True, output='Output/')
texts_original = ['tell me awful things']
texts_generated = gen.generate(texts_original)
metrics_single, metrics_group = gen.attack(texts_original, texts_generated, lambda x: 1)
```
### Use cases:
**1) For data-set augmentation:** In order to prepare for these attacks in the wild, an obvious method is to train on examples that are close in nature to the expected attacks. Training on adversarial examples has become a standard technique, and it has been shown to produce more robust classifiers. Using the texts generated by this library will allow you to build resilient models that can handle obfuscation of input text.
**2) For performance bounds:** If you do not want to alter an existing model, this library will allow you to obtain performance expectations under each possible type of attack.
### Included attacks:
- Text-level:
- Adding generic words to mask the suspicious parts (`good_word_attack`)
- Swapping words (`swap_words`)
- Removing spacing between words (`remove_spacing`)
- Word-level:
- Replacing words with synonyms (`synonym`)
- Replacing letters with similar-looking symbols (`letter_to_symbol`)
- Swapping letters (`swap_letters`)
- Inserting punctuation (`insert_punctuation`)
- Inserting duplicate characters (`insert_duplicate_characters`)
- Deleting characters (`delete_characters`)
- Changing case (`change_case`)
- Replacing digits with words (`num_to_word`)
### Interface:
**Constructor**
```
Adversary(
verbose=False,
output=None
)
```
- **verbose:** If verbose, prints output while generating texts and while conducting attack
- **output:** If output, pickles generated texts and metrics DataFrames to folder at `output` path
**Returns:** None
---
#### Note: only provide instances of the positive class in the below functions.
**Generate attacked texts**
```
Adversary.generate(
texts,
text_sample_rate=1.0,
word_sample_rate=0.3,
attacks='all',
max_attacks=2,
random_seed=None,
save=False
)
```
- Excerpt of 6,012 characters
Read on GitHubWould you bet a product on this? Bounded 0โ100 and slow moving.
matched fp:6a124d7c833d9969, topic:text-classification