Skip to main content

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

spe-encoder-0.0.3.tar.gz (4.8 kB view details)

Uploaded Source

File details

Details for the file spe-encoder-0.0.3.tar.gz.

File metadata

  • Download URL: spe-encoder-0.0.3.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for spe-encoder-0.0.3.tar.gz
Algorithm Hash digest
SHA256 8b49f061bd0dfe13a46e3127eb3d86fdffc117f3a48cdabf75960fef81cbef99
MD5 1f1b9ed6cb06e7695a6885ac6211826b
BLAKE2b-256 c879db4a61768bdc4601e37c5447c6dd7a3e2c5df37194a7c57bfc1b0dfed382

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page