textattack.constraints.semantics.sentence_encoders package
Sentence Encoder
Sentence Encoder Class
- class textattack.constraints.semantics.sentence_encoders.sentence_encoder.SentenceEncoder(threshold=0.8, metric='cosine', compare_against_original=True, window_size=None, skip_text_shorter_than_window=False)[source]
Bases:
textattack.constraints.constraint.Constraint
,abc.ABC
Constraint using cosine similarity between sentence encodings of x and x_adv.
- Parameters
threshold (
float
, optional) – The threshold for the constraint to be met. Defaults to 0.8metric (
str
, optional) – The similarity metric to use. Defaults to cosine. Options: [‘cosine, ‘angular’]compare_against_original (bool) – If True, compare new x_adv against the original x. Otherwise, compare it against the previous x_adv.
window_size (int) – The number of words to use in the similarity comparison. None indicates no windowing (encoding is based on the full input).
Thought Vector Class
- class textattack.constraints.semantics.sentence_encoders.thought_vector.ThoughtVector(embedding=WordEmbedding, **kwargs)[source]
Bases:
textattack.constraints.semantics.sentence_encoders.sentence_encoder.SentenceEncoder
A constraint on the distance between two sentences’ thought vectors.
- Parameters
word_embedding (textattack.shared.AbstractWordEmbedding) – The word embedding to use