Skip to content

bias_direction

allennlp.fairness.bias_direction

[SOURCE]


A suite of differentiable methods to compute the bias direction or concept subspace representing binary protected variables.

BiasDirection

class BiasDirection:
 | def __init__(self, requires_grad: bool = False)

Parent class for bias direction classes.

Parameters

  • requires_grad : bool, optional (default = False)
    Option to enable gradient calculation.

PCABiasDirection

class PCABiasDirection(BiasDirection)

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. ArXiv, abs/2104.02797.

__call__

class PCABiasDirection(BiasDirection):
 | ...
 | 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.

PairedPCABiasDirection

class PairedPCABiasDirection(BiasDirection)

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. 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. ArXiv, abs/2104.02797.

__call__

class PairedPCABiasDirection(BiasDirection):
 | ...
 | 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.

TwoMeansBiasDirection

class TwoMeansBiasDirection(BiasDirection)

Two-means bias direction. Computes one-dimensional subspace that is the span of a specific concept (e.g. gender) as the normalized difference vector of the averages of seed word embedding sets.

Note

It is uncommon to utilize more than one direction to represent a concept.

Based on: Dev, S., & Phillips, J.M. (2019). Attenuating Bias in Word Vectors. AISTATS.

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. ArXiv, abs/2104.02797.

__call__

class TwoMeansBiasDirection(BiasDirection):
 | ...
 | 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 (embeddings1_batch_size, ..., dim) containing seed word embeddings related to a specific 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 size (embeddings2_batch_size, ..., dim) 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

seed_embeddings1 and seed_embeddings2 need NOT be the same size. Furthermore, the embeddings at the same positions in each of seed_embeddings1 and seed_embeddings2 are NOT expected to form seed word pairs.

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.

ClassificationNormalBiasDirection

class ClassificationNormalBiasDirection(BiasDirection):
 | def __init__(self)

Classification normal bias direction. Computes one-dimensional subspace that is the span of a specific concept (e.g. gender) as the direction perpendicular to the classification boundary of a linear support vector machine fit to classify seed word embedding sets.

Note

It is uncommon to utilize more than one direction to represent a concept.

Based on: Ravfogel, S., Elazar, Y., Gonen, H., Twiton, M., & Goldberg, Y. (2020). Null It Out: Guarding Protected Attributes by Iterative Nullspace Projection. ArXiv, abs/2004.07667.

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. ArXiv, abs/2104.02797.

__call__

class ClassificationNormalBiasDirection(BiasDirection):
 | ...
 | 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 (embeddings1_batch_size, ..., dim) containing seed word embeddings related to a specific 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 size (embeddings2_batch_size, ..., dim) 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

seed_embeddings1 and seed_embeddings2 need NOT be the same size. Furthermore, the embeddings at the same positions in each of seed_embeddings1 and seed_embeddings2 are NOT expected to form seed word pairs.

Note

All tensors are expected to be on the same device.

Note

This bias direction method is NOT differentiable.

Returns

  • bias_direction : torch.Tensor
    A unit tensor of size (dim, ) representing the concept subspace.