Sentence embedding technique for textual adversarial attacks
Project description
About
Semantics Preserving Encoder is a simple, fully supervised sentence embedding technique for textual adversarial attacks.
Setup
You should be able to run this package with Python 3.6+. To use Semantics Preserving Encoder simply run pip with command:
pip install spe-encoder
Usage
This package is easy to use or integrate into any Python project as follows:
from spe import spe
input_sentences = input_sentences = [
"The quick brown fox jumps over the lazy dog.",
"I am a sentence for which I would like to get its embedding"]
output_vectors = spe(input_sentences)
Possible modifications
You can utilise the default classifiers specified in paper Semantics Preserving Encoder or extend/ replace with your own classifiers by placing them in the "classifiers" project folder. The script will auto detect these changes. Note: Currently, only fastText classifiers are supported.
You can also define your own vector dimension for the output vectors through an optional second parameter of 'spe' method. Otherwise, 10 is used as a default value.
my_vector_dimensions = 5
output_vectors = spe(input_sentences, my_vector_dimensions)
Citation
Please cite the arXiv paper if you use SemanticsPreservingEncoder in your work:
@article{herel2022preserving,
title={Preserving Semantics in Textual Adversarial Attacks},
author={Herel, David and Cisneros, Hugo and Mikolov, Tomas},
journal={arXiv preprint arXiv:2211.04205},
year={2022}
}
License
SemanticsPreservingEncoder is MIT licensed. See the LICENSE file for details.
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
File details
Details for the file spe-encoder-0.0.2.tar.gz
.
File metadata
- Download URL: spe-encoder-0.0.2.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65b45194d1b8a44d9cdecace67ba6e135b82bd90ea6291aa9f99176bf95f3609 |
|
MD5 | 0ff21c8c120e24088ed4d8c8b2862f5c |
|
BLAKE2b-256 | d6e637b637279dce218f0434edd8b313c28d7348a5b5c490343421f5d4920c6e |