class_docstr: Paired-PCA-based bias direction. Computes one-dimensional subspace that is the span
  of a specific concept (e.g. gender) as the first principle component of the
  difference vectors between seed word embedding pairs.
  
  !!! Note
      It is uncommon to utilize more than one direction to represent a concept.
  
  Based on: T. Bolukbasi, K. W. Chang, J. Zou, V. Saligrama, and A. Kalai. [Man is to
  computer programmer as woman is to homemaker? debiasing word embeddings]
  (https://api.semanticscholar.org/CorpusID:1704893).
  In ACM Transactions of Information Systems, 2016.
  
  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: ["Paired-PCA-based","bias","direction",".","Computes","one-dimensional","subspace","that","is","the","span","of","a","specific","concept","(","e.g",".","gender",")","as","the","first","principle","component","of","the","difference","vectors","between","seed","word","embedding","pairs",".","!","!","!","Note","It","is","uncommon","to","utilize","more","than","one","direction","to","represent","a","concept",".","Based","on",":","T.","Bolukbasi",",","K.","W.","Chang",",","J.","Zou",",","V.","Saligrama",",","and","A.","Kalai",".","[","Man","is","to","computer","programmer","as","woman","is","to","homemaker","?","debiasing","word","embeddings","]","(","https",":","\/\/api.semanticscholar.org\/CorpusID:1704893",")",".","In","ACM","Transactions","of","Information","Systems",",","2016",".","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_embeddings1 : `torch.Tensor`
      A tensor of size (batch_size, ..., dim) containing seed word
      embeddings related to a concept group. For example, if the concept is gender,
      seed_embeddings1 could contain embeddings for linguistically masculine words, e.g.
      "man", "king", "brother", etc.
  
  seed_embeddings2: `torch.Tensor`
      A tensor of the same size as seed_embeddings1 containing seed word
      embeddings related to a different group for the same concept. For example,
      seed_embeddings2 could contain embeddings for linguistically feminine words, e.g.
      "woman", "queen", "sister", etc.
  
  !!! Note
      For Paired-PCA, the embeddings at the same positions in each of seed_embeddings1 and
      seed_embeddings2 are expected to form seed word pairs. For example, if the concept
      is gender, the embeddings for ("man", "woman"), ("king", "queen"), ("brother", "sister"), etc.
      should be at the same positions in seed_embeddings1 and seed_embeddings2.
  
  !!! Note
      All tensors are expected to be on the same device.
  
  # 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_embeddings1",":","`","torch.Tensor","`","A","tensor","of","size","(","batch_size",",","...",",","dim",")","containing","seed","word","embeddings","related","to","a","concept","group",".","For","example",",","if","the","concept","is","gender",",","seed_embeddings1","could","contain","embeddings","for","linguistically","masculine","words",",","e.g",".","``","man","''",",","``","king","''",",","``","brother","''",",","etc",".","seed_embeddings2",":","`","torch.Tensor","`","A","tensor","of","the","same","size","as","seed_embeddings1","containing","seed","word","embeddings","related","to","a","different","group","for","the","same","concept",".","For","example",",","seed_embeddings2","could","contain","embeddings","for","linguistically","feminine","words",",","e.g",".","``","woman","''",",","``","queen","''",",","``","sister","''",",","etc",".","!","!","!","Note","For","Paired-PCA",",","the","embeddings","at","the","same","positions","in","each","of","seed_embeddings1","and","seed_embeddings2","are","expected","to","form","seed","word","pairs",".","For","example",",","if","the","concept","is","gender",",","the","embeddings","for","(","``","man","''",",","``","woman","''",")",",","(","``","king","''",",","``","queen","''",")",",","(","``","brother","''",",","``","sister","''",")",",","etc",".","should","be","at","the","same","positions","in","seed_embeddings1","and","seed_embeddings2",".","!","!","!","Note","All","tensors","are","expected","to","be","on","the","same","device",".","#","Returns","bias_direction",":","`","torch.Tensor","`","A","unit","tensor","of","size","(","dim",",",")","representing","the","concept","subspace","."]
code: def __call__(
      self,
      seed_embeddings1: torch.Tensor,
      seed_embeddings2: torch.Tensor,
  ):
      """
  
      # Parameters
  
      !!! Note
          In the examples below, we treat gender identity as binary, which does not accurately
          characterize gender in real life.
  
      seed_embeddings1 : `torch.Tensor`
          A tensor of size (batch_size, ..., dim) containing seed word
          embeddings related to a concept group. For example, if the concept is gender,
          seed_embeddings1 could contain embeddings for linguistically masculine words, e.g.
          "man", "king", "brother", etc.
  
      seed_embeddings2: `torch.Tensor`
          A tensor of the same size as seed_embeddings1 containing seed word
          embeddings related to a different group for the same concept. For example,
          seed_embeddings2 could contain embeddings for linguistically feminine words, e.g.
          "woman", "queen", "sister", etc.
  
      !!! Note
          For Paired-PCA, the embeddings at the same positions in each of seed_embeddings1 and
          seed_embeddings2 are expected to form seed word pairs. For example, if the concept
          is gender, the embeddings for ("man", "woman"), ("king", "queen"), ("brother", "sister"), etc.
          should be at the same positions in seed_embeddings1 and seed_embeddings2.
  
      !!! Note
          All tensors are expected to be on the same device.
  
      # Returns
  
      bias_direction : `torch.Tensor`
          A unit tensor of size (dim, ) representing the concept subspace.
      """
  
      # Some sanity checks
      if seed_embeddings1.size() != seed_embeddings2.size():
          raise ConfigurationError(
              "seed_embeddings1 and seed_embeddings2 must be the same size."
          )
      if seed_embeddings1.ndim < 2:
          raise ConfigurationError(
              "seed_embeddings1 and seed_embeddings2 must have at least two dimensions."
          )
  
      with torch.set_grad_enabled(self.requires_grad):
          paired_embeddings = seed_embeddings1 - seed_embeddings2
          _, _, V = torch.pca_lowrank(
              paired_embeddings,
              q=min(
                  paired_embeddings.size(0), paired_embeddings.size(1)
              )
              - 1,
              center=False,
          )
          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 PairedPCABiasDirection obj's underlying member method code with example usage: obj.__call__(seed_embeddings1, seed_embeddings2) and returns: self