class_docstr: Constraint using cosine similarity between sentence encodings of x and
  x_adv.
  
  Args:
      threshold (:obj:`float`, optional): The threshold for the constraint to be met.
          Defaults to 0.8
      metric (:obj:`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).
class_docstr_tok: ["Constraint","using","cosine","similarity","between","sentence","encodings","of","x","and","x_adv",".","Args",":","threshold","(",":","obj",":","`","float","`",",","optional",")",":","The","threshold","for","the","constraint","to","be","met",".","Defaults","to","0.8","metric","(",":","obj",":","`","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",")","."]
code: def __init__(
      self,
      threshold=0.8,
      metric="cosine",
      compare_against_original=True,
      window_size=None,
      skip_text_shorter_than_window=False,
  ):
      super().__init__(compare_against_original)
      self.metric = metric
      self.threshold = threshold
      self.window_size = window_size
      self.skip_text_shorter_than_window = skip_text_shorter_than_window
  
      if not self.window_size:
          self.window_size = float("inf")
  
      if metric == "cosine":
          self.sim_metric = torch.nn.CosineSimilarity(dim=1)
      elif metric == "angular":
          self.sim_metric = get_angular_sim
      elif metric == "max_euclidean":
          # If the threshold requires embedding similarity measurement
          # be less than or equal to a certain value, just negate it,
          # so that we can still compare to the threshold using >=.
          self.threshold = -threshold
          self.sim_metric = get_neg_euclidean_dist
      else:
          raise ValueError(f"Unsupported metric {metric}.")
  
file_path: TextAttack/textattack/constraints/semantics/sentence_encoders/sentence_encoder.py
imports: from abc import ABC
  import math
  import numpy
  import torch
  from textattack.constraints import Constraint
label_desc: Use image node_id 1 to create a new SentenceEncoder object from inherited base classes: Constraint, ABC with example: obj = SentenceEncoder(threshold, metric, compare_against_original, window_size, skip_text_shorter_than_window)