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.4.tar.gz (4.8 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: spe-encoder-0.0.4.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.4.tar.gz
Algorithm Hash digest
SHA256 c45e0995fe8f102b6b561a340e12799eebd68f0d88958d8bd3be62fc0465384a
MD5 fab06e993c627ba6495acaa4513946be
BLAKE2b-256 b671b101a1ced13d448d72e65afd7030e4334a84ebef59682d8c1cf7ebf8ab67

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