textattack.constraints.semantics.sentence_encoders package
Sentence Encoder Constraint
- textattack.constraints.semantics.sentence_encoders.bert package
- textattack.constraints.semantics.sentence_encoders.infer_sent package
- infer sent
- infer sent for sentence similarity
InferSent
- Infer sent model
InferSentModel
InferSentModel.build_vocab()
InferSentModel.build_vocab_k_words()
InferSentModel.encode()
InferSentModel.forward()
InferSentModel.get_batch()
InferSentModel.get_w2v()
InferSentModel.get_w2v_k()
InferSentModel.get_word_dict()
InferSentModel.is_cuda()
InferSentModel.prepare_samples()
InferSentModel.set_w2v_path()
InferSentModel.tokenize()
InferSentModel.update_vocab()
InferSentModel.training
- textattack.constraints.semantics.sentence_encoders.universal_sentence_encoder package
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:
Constraint
,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).
- textattack.constraints.semantics.sentence_encoders.sentence_encoder.get_angular_sim(emb1, emb2)[source]
Returns the _angular_ similarity between a batch of vector and a batch of vectors.
- textattack.constraints.semantics.sentence_encoders.sentence_encoder.get_neg_euclidean_dist(emb1, emb2)[source]
Returns the Euclidean distance between a batch of vectors and a batch of vectors.
Thought Vector Class
- class textattack.constraints.semantics.sentence_encoders.thought_vector.ThoughtVector(embedding=None, **kwargs)[source]
Bases:
SentenceEncoder
A constraint on the distance between two sentences’ thought vectors.
- Parameters:
word_embedding (textattack.shared.AbstractWordEmbedding) – The word embedding to use