Skip to content

Commit

Permalink
Merge pull request #428 from QData/api-rework
Browse files Browse the repository at this point in the history
API Rework
  • Loading branch information
qiyanjun committed Jun 10, 2021
2 parents 4015ad2 + 7a315ec commit 9a67b9e
Show file tree
Hide file tree
Showing 184 changed files with 25,041 additions and 11,874 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ dist/
# Weights & Biases outputs
wandb/

# Tensorboard logs
runs/

# checkpoints
checkpoints/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ Where should I start?
This is a great question, and one we get a lot. First of all, almost everything in TextAttack can be done in two ways: via the command-line or via the Python API. If you're looking to integrate TextAttack into an existing project, the Python API is likely for you. If you'd prefer to use built-in functionality end-to-end (training a model, running an adversarial attack, augmenting a CSV) then you can just use the command-line API.




For future developers, visit the :ref:`Installation <installation>` page for more details about installing TextAttack onto your own computer. To start making contributions, read the detailed instructions `here <https://github.com/QData/TextAttack/blob/master/CONTRIBUTING.md>`__.

TextAttack does three things very well:

1. Adversarial attacks (Python: ``textattack.shared.Attack``, Bash: ``textattack attack``)
Expand Down
File renamed without changes.
49 changes: 49 additions & 0 deletions docs/0_get_started/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Installation
==============

To use TextAttack, you must be running Python 3.6 or above. A CUDA-compatible GPU is optional but will greatly improve speed.

We recommend installing TextAttack in a virtual environment (check out this [guide](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/)).

There are two ways to install TextAttack. If you want to simply use as it is, install via `pip`. If you want to make any changes and play around, install it from source.

## Install with pip
Simply run

pip install textattack

## Install from Source
To install TextAttack from source, first clone the repo by running

git clone https://github.com/QData/TextAttack.git
cd TextAttack

Then, install it using `pip`.

pip install -e .

To install TextAttack for further development, please run this instead.

pip install -e .[dev]

This installs additional dependencies required for development.


## Optional Dependencies
For quick installation, TextAttack only installs esssential packages as dependencies (e.g. Transformers, PyTorch). However, you might need to install additional packages to run certain attacks or features.
For example, Tensorflow and Tensorflow Hub are required to use the TextFooler attack, which was proposed in [Is BERT Really Robust? A Strong Baseline for Natural Language Attack on Text Classification and Entailment](https://arxiv.org/abs/1907.11932) by Di Jin, Zhijing Jin, Joey Tianyi Zhou, and Peter Szolov.

If you attempting to use a feature that requires additional dependencies, TextAttack will let you know which ones you need to install.

However, during installation step, you can also install them together with TextAttack.
You can install Tensorflow and its related packages by running

pip install textattack[tensorflow]

You can also install other miscallenous optional dependencies by running

pip install textattack[optional]

To install both groups of packages, run

pip install textattack[tensorflow, optional]
33 changes: 33 additions & 0 deletions docs/0_get_started/quick_api_tour.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Quick Tour
==========================

Let us have a quick look at how TextAttack can be used to carry out adversarial attack.

Attacking a BERT model
------------------------------
Let us attack a BERT model fine-tuned for sentimental classification task. We are going to use a model that has already been fine-tuned on IMDB dataset using the Transformers library.

.. code-block::
>>> import transformers
>>> model = transformers.AutoModelForSequenceClassification.from_pretrained("textattack/bert-base-uncased-imdb")
>>> tokenizer = transformers.AutoTokenizer.from_pretrained("textattack/bert-base-uncased-imdb")
TextAttack requires both the model and the tokenizer to be wrapped by a :class:`~transformers.models.wrapper.ModelWrapper` class that implements the forward pass operation given a list of input texts. For models provided by Transformers library, we can also simply use :class:`~transformers.models.wrapper.HuggingFaceModelWrapper` class which implements both the forward pass and tokenization.

.. code-block::
>>> import textattack
>>> model_wrapper = textattack.models.wrappers.HuggingFaceModelWrapper(model, tokenizer)
Next, let's build the attack that we want to use. TextAttack provides prebuilt attacks in the form of :class:`~transformers.attack_recipes.AttackRecipe`. For this example, we will use :ref:TextFooler attack

Let us also load the IMDB dataset using 🤗 Datasets library. TextAttack also requires that the dataset

.. code-block::
>>> import datasets
>>> dataset = datasets.load_dataset("imdb", split="test")
224 changes: 0 additions & 224 deletions docs/1start/installation.rst

This file was deleted.

0 comments on commit 9a67b9e

Please sign in to comment.