-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1970d13
Showing
18 changed files
with
2,585 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: pytest | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- develop | ||
- f/* | ||
pull_request: | ||
branches: | ||
- main | ||
- develop | ||
|
||
jobs: | ||
pytest: | ||
name: Run tests with pytest | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [3.6, 3.7, 3.8, 3.9] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install Poetry | ||
run: | | ||
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python | ||
- name: Add path for Poetry | ||
run: echo "$HOME/.poetry/bin" >> $GITHUB_PATH | ||
- name: Install Dependencies | ||
run: poetry install --no-interaction | ||
- name: Run Tests | ||
run: poetry run pytest --cov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
name: release | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
description: "Next Version" | ||
required: true | ||
default: "x.y.z" | ||
release_note: | ||
description: "release note" | ||
required: false | ||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.9 | ||
- name: Install Poetry | ||
run: | | ||
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py -O | ||
python install-poetry.py --preview --version 1.2.0a1 | ||
- name: Add path for Poetry | ||
run: echo "$HOME/.poetry/bin" >> $GITHUB_PATH | ||
- name: Add Poetry Plugin | ||
# poetry plugin add poetry-version-plugin | ||
run: | | ||
pip install poetry-version-plugin | ||
- name: PyPI Settings | ||
run: | | ||
poetry config pypi-token.pypi ${{secrets.PYPI_TOKEN}} | ||
- name: Build Poetry | ||
run: | | ||
git tag v${{ github.event.inputs.version }} | ||
poetry build | ||
poetry publish | ||
- name: Create Release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: v${{ github.event.inputs.version }} | ||
release_name: Release v${{ github.event.inputs.version }} | ||
body: | | ||
${{ github.event.inputs.release_note }} | ||
draft: false | ||
prerelease: false | ||
- name: Get Name of Artifact | ||
run: | | ||
ARTIFACT_PATHNAME=$(ls dist/*.whl | head -n 1) | ||
ARTIFACT_NAME=$(basename $ARTIFACT_PATHNAME) | ||
echo "ARTIFACT_PATHNAME=${ARTIFACT_PATHNAME}" >> $GITHUB_ENV | ||
echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV | ||
- name: Upload Whl to Release Assets | ||
id: upload-release-asset | ||
uses: actions/upload-release-asset@v1.0.2 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: ${{ env.ARTIFACT_PATHNAME }} | ||
asset_name: ${{ env.ARTIFACT_NAME }} | ||
asset_content_type: application/x-wheel+zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# VScode workspace settings | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 SecHack365-Fans | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# prompt2slip | ||
|
||
![pCDlAAEvOFMmFk11635877148_1635877207](https://user-images.githubusercontent.com/32987034/139922987-55bce5fb-6dfd-476f-aebe-3daf661cdb94.png) | ||
|
||
|
||
[![pytest](https://github.com/SecHack365-Fans/prompt2slip_proto/actions/workflows/pytest.yml/badge.svg)](https://github.com/SecHack365-Fans/prompt2slip_proto/actions/workflows/pytest.yml) | ||
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/SecHack365-Fans/prompt2slip_proto/blob/main/LICENSE) | ||
|
||
about this repos | ||
|
||
|
||
|
||
## Install | ||
|
||
````bash | ||
pip install prompt2slip | ||
```` | ||
|
||
|
||
## Usage | ||
|
||
The simplest sample looks like this. | ||
|
||
|
||
```python | ||
import prompt2slip | ||
from transformers import GPT2Tokenizer, GPT2Model | ||
tokenizer = GPT2Tokenizer.from_pretrained('gpt2') | ||
model = GPT2Model.from_pretrained('gpt2') | ||
|
||
base_text = ["This project respects pytorch developers."] | ||
target_word = ["keras"] | ||
|
||
target_ids = torch.Tensor(tokenizer.convert_tokens_to_ids(target_words)) | ||
attaker = CLMAttacker(model,tokenizer) | ||
output = attacker.attack_by_text(texts,target_ids) | ||
``` | ||
|
||
More realistic use cases are stored in [examples](https://github.com/SecHack365-Fans/prompt2slip_proto/tree/main/examples). | ||
|
||
|
||
## References | ||
|
||
- [Gradient-based Adversarial Attacks against Text Transformers ( Chuan Guo et al. ) ](https://arxiv.org/abs/2104.13733) | ||
|
||
## License | ||
|
||
[MIT License](https://github.com/SecHack365-Fans/prompt2slip_proto/blob/main/LICENSE) | ||
|
||
## Development | ||
|
||
### Install Package | ||
|
||
Install [poetry](https://python-poetry.org/docs/#installation) | ||
|
||
```bash | ||
poetry install | ||
``` | ||
|
||
### Test | ||
|
||
Running tests with pytest. | ||
|
||
```bash | ||
poetry run pytest --cov . | ||
``` | ||
|
Oops, something went wrong.