bias_direction_wrappers
allennlp.fairness.bias_direction_wrappers
BiasDirectionWrapper¶
class BiasDirectionWrapper(Registrable):
| def __init__(self)
Parent class for bias direction wrappers.
__call__¶
class BiasDirectionWrapper(Registrable):
| ...
| def __call__(self, module)
train¶
class BiasDirectionWrapper(Registrable):
| ...
| def train(self, mode: bool = True)
Parameters¶
- mode :
bool
, optional (default =True
)
Setsrequires_grad
to value ofmode
for bias direction.
add_noise¶
class BiasDirectionWrapper(Registrable):
| ...
| def add_noise(self, t: torch.Tensor)
Parameters¶
- t :
torch.Tensor
Tensor to which to add small amount of Gaussian noise.
PCABiasDirectionWrapper¶
@BiasDirectionWrapper.register("pca")
class PCABiasDirectionWrapper(BiasDirectionWrapper):
| def __init__(
| self,
| seed_words_file: Union[PathLike, str],
| tokenizer: Tokenizer,
| direction_vocab: Optional[Vocabulary] = None,
| namespace: str = "tokens",
| requires_grad: bool = False,
| noise: float = 1e-10
| )
Parameters¶
- seed_words_file :
Union[PathLike, str]
Path of file containing seed words. - tokenizer :
Tokenizer
Tokenizer used to tokenize seed words. - direction_vocab :
Vocabulary
, optional (default =None
)
Vocabulary of tokenizer. IfNone
, assumes tokenizer is of typePreTrainedTokenizer
and uses tokenizer'svocab
attribute. - namespace :
str
, optional (default ="tokens"
)
Namespace of direction_vocab to use when tokenizing. Disregarded when direction_vocab isNone
. - requires_grad :
bool
, optional (default =False
)
Option to enable gradient calculation for bias direction. - noise :
float
, optional (default =1e-10
)
To avoid numerical instability if embeddings are initialized uniformly.
__call__¶
class PCABiasDirectionWrapper(BiasDirectionWrapper):
| ...
| def __call__(self, module)
PairedPCABiasDirectionWrapper¶
@BiasDirectionWrapper.register("paired_pca")
class PairedPCABiasDirectionWrapper(BiasDirectionWrapper):
| def __init__(
| self,
| seed_word_pairs_file: Union[PathLike, str],
| tokenizer: Tokenizer,
| direction_vocab: Optional[Vocabulary] = None,
| namespace: str = "tokens",
| requires_grad: bool = False,
| noise: float = 1e-10
| )
Parameters¶
- seed_word_pairs_file :
Union[PathLike, str]
Path of file containing seed word pairs. - tokenizer :
Tokenizer
Tokenizer used to tokenize seed words. - direction_vocab :
Vocabulary
, optional (default =None
)
Vocabulary of tokenizer. IfNone
, assumes tokenizer is of typePreTrainedTokenizer
and uses tokenizer'svocab
attribute. - namespace :
str
, optional (default ="tokens"
)
Namespace of direction_vocab to use when tokenizing. Disregarded when direction_vocab isNone
. - requires_grad :
bool
, optional (default =False
)
Option to enable gradient calculation for bias direction. - noise :
float
, optional (default =1e-10
)
To avoid numerical instability if embeddings are initialized uniformly.
__call__¶
class PairedPCABiasDirectionWrapper(BiasDirectionWrapper):
| ...
| def __call__(self, module)
TwoMeansBiasDirectionWrapper¶
@BiasDirectionWrapper.register("two_means")
class TwoMeansBiasDirectionWrapper(BiasDirectionWrapper):
| def __init__(
| self,
| seed_word_pairs_file: Union[PathLike, str],
| tokenizer: Tokenizer,
| direction_vocab: Optional[Vocabulary] = None,
| namespace: str = "tokens",
| requires_grad: bool = False,
| noise: float = 1e-10
| )
Parameters¶
- seed_word_pairs_file :
Union[PathLike, str]
Path of file containing seed word pairs. - tokenizer :
Tokenizer
Tokenizer used to tokenize seed words. - direction_vocab :
Vocabulary
, optional (default =None
)
Vocabulary of tokenizer. IfNone
, assumes tokenizer is of typePreTrainedTokenizer
and uses tokenizer'svocab
attribute. - namespace :
str
, optional (default ="tokens"
)
Namespace of direction_vocab to use when tokenizing. Disregarded when direction_vocab isNone
. - requires_grad :
bool
, optional (default =False
)
Option to enable gradient calculation for bias direction. - noise :
float
, optional (default =1e-10
)
To avoid numerical instability if embeddings are initialized uniformly.
__call__¶
class TwoMeansBiasDirectionWrapper(BiasDirectionWrapper):
| ...
| def __call__(self, module)
ClassificationNormalBiasDirectionWrapper¶
@BiasDirectionWrapper.register("classification_normal")
class ClassificationNormalBiasDirectionWrapper(BiasDirectionWrapper):
| def __init__(
| self,
| seed_word_pairs_file: Union[PathLike, str],
| tokenizer: Tokenizer,
| direction_vocab: Optional[Vocabulary] = None,
| namespace: str = "tokens",
| noise: float = 1e-10
| )
Parameters¶
- seed_word_pairs_file :
Union[PathLike, str]
Path of file containing seed word pairs. - tokenizer :
Tokenizer
Tokenizer used to tokenize seed words. - direction_vocab :
Vocabulary
, optional (default =None
)
Vocabulary of tokenizer. IfNone
, assumes tokenizer is of typePreTrainedTokenizer
and uses tokenizer'svocab
attribute. - namespace :
str
, optional (default ="tokens"
)
Namespace of direction_vocab to use when tokenizing. Disregarded when direction_vocab isNone
. - noise :
float
, optional (default =1e-10
)
To avoid numerical instability if embeddings are initialized uniformly.
__call__¶
class ClassificationNormalBiasDirectionWrapper(BiasDirectionWrapper):
| ...
| def __call__(self, module)