A Python library to perform homoglyph-based attacks on text. It supports both identical and non-identical homoglyphs across multiple languages.
Project description
SilverSpeak
This is a Python library to perform homoglyph-based attacks on text.
We also include the experiments supplementing the paper "SilverSpeak: Evading AI-Generated Text Detectors using Homoglyphs".
Installation
You can install this package from PyPI by running:
pip install silverspeak
Usage example
from silverspeak.homoglyphs.random_attack import random_attack
text = "Hello, world!"
attacked_text = random_attack(text, 0.1)
print(attacked_text)
Installation from source
First, you may want to work in a virtual environment. If you don't have one, you can create it by running:
python -m venv .venv
Then, activate it with:
source .venv/bin/activate
You can also use Conda, or any other tool of your preference.
The Python version used in this project is 3.11.0.
Also, remember to install the requirements by running:
pip install -r requirements.txt
And finally, install this package by running:
pip install -e .
Reproducing the experimental results from the paper
To reproduce the results, you'll need a free Hugging Face account. You can register for an account here: https://huggingface.co/
Then, you'll need to sign into your account using the CLI with a token that has write permissions (more information here). To do that, just run:
huggingface-cli login
[note] When prompted "Add token as git credential?", you should answer "Yes".
Then, set the MY_HUGGINGFACE_USER environment variable to the username of the account you just registered on Hugging Face by running:
export MY_HUGGINGFACE_USER='your_username'
Then, you can run the run_experiments.sh script. This script will run the experiments for all the models and datasets.
Finally, run the following command to generate the plots and tables:
python experiments/visualization.py
You will also find two notebooks (experiments/divergence_embeddings_attacks.ipynb and experiments/perplexity_tests.ipynb), to reproduce some smaller parts of the paper.
Datasets
We make our datasets, in versions with and without results, at the following URL: https://huggingface.co/silverspeak Specifically, the datasets are provided in two versions, one without the results of the experiments and one including them. The datasets are named as follows:
- Datasets without results:
silverspeak/cheatsilverspeak/essaysilverspeak/reutersilverspeak/writing_promptssilverspeak/realnewslike
- Datasets with results:
silverspeak/cheat_with_resultssilverspeak/essay_with_resultssilverspeak/reuter_with_resultssilverspeak/writing_prompts_with_resultssilverspeak/realnewslike_with_results
AI Disclaimer
We used AI code generation assitance from GitHub Copilot for this project. Nonetheless, the coding process has been essentially manual, with the AI code generator exclusively helping us to speed up the process.
Reproducibility statement
We have tested the code in this repository on a NVIDIA A100 GPU, and have run the experiments twice, independently, to ensure the results are reproducible. We confirm that the results obtained were identical, and thus expect no variation in the results when running the code again. We manually set random seeds where necessary to ensure reproducibility.
Side note: where does the name "SilverSpeak" come from?
The name SilverSpeak comes from the expression "Hablar en plata" in Spanish. While a literal translation would be "Speak in silver", it means "Speak clearly". Therefore, some people would understand the underlying meaning, while those unfamiliar with the expression would likely misunderstand it.
Homoglyph-based attacks are an effective evasion technique since they change the meaning that detectors perceive, while maintaining the same appearance to a human observer. We think the idea can be a metaphor of the system getting "lost in translation", especially considering that homoglyphs are frequently identical characters in different languages.
Hereby the rationale behind our choice of the name SilverSpeak to refer to the family of homoglyph-based attacks that we use in our paper. The attacks play with the understood meaning of the text, depending on who is the observer, taking advantage of codification differences across alphabets.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file silverspeak-2.2.0.tar.gz.
File metadata
- Download URL: silverspeak-2.2.0.tar.gz
- Upload date:
- Size: 61.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66bb4165ebceaf19a82dd928db67abf63c1eb94754f9dd6593beb33328c45166
|
|
| MD5 |
49a32ad132ce83f04e20c3bab44eec59
|
|
| BLAKE2b-256 |
e24c24f8a6f9cd80a896825f22f50cec344fce2f77ecdf5e1006cf9c13230b38
|
Provenance
The following attestation bundles were made for silverspeak-2.2.0.tar.gz:
Publisher:
python-publish.yml on ACMCMC/silverspeak
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
silverspeak-2.2.0.tar.gz -
Subject digest:
66bb4165ebceaf19a82dd928db67abf63c1eb94754f9dd6593beb33328c45166 - Sigstore transparency entry: 165654741
- Sigstore integration time:
-
Permalink:
ACMCMC/silverspeak@4489d7d94e5f177b2d4760db4e7efdc918d4b679 -
Branch / Tag:
refs/tags/v2.2.0 - Owner: https://github.com/ACMCMC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@4489d7d94e5f177b2d4760db4e7efdc918d4b679 -
Trigger Event:
release
-
Statement type:
File details
Details for the file silverspeak-2.2.0-py3-none-any.whl.
File metadata
- Download URL: silverspeak-2.2.0-py3-none-any.whl
- Upload date:
- Size: 62.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f4c9a250b9b716c0e569c31d2558701dd3fe9430eb8b219434b2f4b12fdbae5
|
|
| MD5 |
d2eed55f0cc93b9b99485947544eaf7d
|
|
| BLAKE2b-256 |
c760284c23522f0eba58d8147a6946da95301072b18a945cedceb5cf65849a10
|
Provenance
The following attestation bundles were made for silverspeak-2.2.0-py3-none-any.whl:
Publisher:
python-publish.yml on ACMCMC/silverspeak
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
silverspeak-2.2.0-py3-none-any.whl -
Subject digest:
5f4c9a250b9b716c0e569c31d2558701dd3fe9430eb8b219434b2f4b12fdbae5 - Sigstore transparency entry: 165654742
- Sigstore integration time:
-
Permalink:
ACMCMC/silverspeak@4489d7d94e5f177b2d4760db4e7efdc918d4b679 -
Branch / Tag:
refs/tags/v2.2.0 - Owner: https://github.com/ACMCMC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@4489d7d94e5f177b2d4760db4e7efdc918d4b679 -
Trigger Event:
release
-
Statement type: