textattack.constraints.grammaticality.language_models package
non-pre Language Models:
- textattack.constraints.grammaticality.language_models.google_language_model package
- textattack.constraints.grammaticality.language_models.learning_to_write package
GPT2 Language Models:
- class textattack.constraints.grammaticality.language_models.gpt2.GPT2(model_name='gpt2', **kwargs)[source]
Bases:
LanguageModelConstraint
A constraint based on the GPT-2 language model.
from “Better Language Models and Their Implications” (openai.com/blog/better-language-models/)
- Parameters
model_name – id of GPT2 model
Language Models Constraint
- class textattack.constraints.grammaticality.language_models.language_model_constraint.LanguageModelConstraint(max_log_prob_diff=None, compare_against_original=True)[source]
Bases:
Constraint
,ABC
Determines if two sentences have a swapped word that has a similar probability according to a language model.
- Parameters
max_log_prob_diff (float) – the maximum decrease in log-probability in swapped words from x to x_adv
compare_against_original (bool) – If True, compare new x_adv against the original x. Otherwise, compare it against the previous x_adv.