class_docstr: PCA-based bias direction. Computes one-dimensional subspace that is the span
  of a specific concept (e.g. gender) using PCA. This subspace minimizes the sum of
  squared distances from all seed word embeddings.
  
  !!! Note
      It is uncommon to utilize more than one direction to represent a concept.
  
  Implementation and terminology based on Rathore, A., Dev, S., Phillips, J.M., Srikumar,
  V., Zheng, Y., Yeh, C.M., Wang, J., Zhang, W., & Wang, B. (2021).
  [VERB: Visualizing and Interpreting Bias Mitigation Techniques for
  Word Representations](https://api.semanticscholar.org/CorpusID:233168618).
  ArXiv, abs/2104.02797.
class_docstr_tok: ["PCA-based","bias","direction",".","Computes","one-dimensional","subspace","that","is","the","span","of","a","specific","concept","(","e.g",".","gender",")","using","PCA",".","This","subspace","minimizes","the","sum","of","squared","distances","from","all","seed","word","embeddings",".","!","!","!","Note","It","is","uncommon","to","utilize","more","than","one","direction","to","represent","a","concept",".","Implementation","and","terminology","based","on","Rathore",",","A.",",","Dev",",","S.",",","Phillips",",","J.M.",",","Srikumar",",","V.",",","Zheng",",","Y.",",","Yeh",",","C.M.",",","Wang",",","J.",",","Zhang",",","W.",",","&","Wang",",","B",".","(","2021",")",".","[","VERB",":","Visualizing","and","Interpreting","Bias","Mitigation","Techniques","for","Word","Representations","]","(","https",":","\/\/api.semanticscholar.org\/CorpusID:233168618",")",".","ArXiv",",","abs\/2104.02797","."]
docstr: # Parameters
  
  !!! Note
      In the examples below, we treat gender identity as binary, which does not accurately
      characterize gender in real life.
  
  seed_embeddings : `torch.Tensor`
      A tensor of size (batch_size, ..., dim) containing seed word embeddings related to
      a concept. For example, if the concept is gender, seed_embeddings could contain embeddings
      for words like "man", "king", "brother", "woman", "queen", "sister", etc.
  
  # Returns
  
  bias_direction : `torch.Tensor`
      A unit tensor of size (dim, ) representing the concept subspace.
docstr_tok: ["#","Parameters","!","!","!","Note","In","the","examples","below",",","we","treat","gender","identity","as","binary",",","which","does","not","accurately","characterize","gender","in","real","life",".","seed_embeddings",":","`","torch.Tensor","`","A","tensor","of","size","(","batch_size",",","...",",","dim",")","containing","seed","word","embeddings","related","to","a","concept",".","For","example",",","if","the","concept","is","gender",",","seed_embeddings","could","contain","embeddings","for","words","like","``","man","''",",","``","king","''",",","``","brother","''",",","``","woman","''",",","``","queen","''",",","``","sister","''",",","etc",".","#","Returns","bias_direction",":","`","torch.Tensor","`","A","unit","tensor","of","size","(","dim",",",")","representing","the","concept","subspace","."]
code: def __call__(self, seed_embeddings: torch.Tensor):
      """
  
      # Parameters
  
      !!! Note
          In the examples below, we treat gender identity as binary, which does not accurately
          characterize gender in real life.
  
      seed_embeddings : `torch.Tensor`
          A tensor of size (batch_size, ..., dim) containing seed word embeddings related to
          a concept. For example, if the concept is gender, seed_embeddings could contain embeddings
          for words like "man", "king", "brother", "woman", "queen", "sister", etc.
  
      # Returns
  
      bias_direction : `torch.Tensor`
          A unit tensor of size (dim, ) representing the concept subspace.
      """
  
      # Some sanity checks
      if seed_embeddings.ndim < 2:
          raise ConfigurationError(
              "seed_embeddings1 must have at least two dimensions."
          )
  
      with torch.set_grad_enabled(self.requires_grad):
          # pca_lowrank centers the embeddings by default
          # There will be two dimensions when applying PCA to
          # definitionally-gendered words: 1) the gender direction,
          # 2) all other directions, with the gender direction being principal.
          _, _, V = torch.pca_lowrank(seed_embeddings, q=2)
          # get top principal component
          bias_direction = V[:, 0]
          return self._normalize_bias_direction(bias_direction)
  
file_path: allennlp/allennlp/fairness/bias_direction.py
imports: import torch
  import sklearn
  import numpy
  from allennlp.common.checks import ConfigurationError
label_desc: Use image node_id 1 for calling the PCABiasDirection obj's underlying member method code with example usage: obj.__call__(seed_embeddings) and returns: self