textattack.constraints.grammaticality.language_models package
non-pre Language Models:
GPT2 Language Models:
Language Models Constraint
- class textattack.constraints.grammaticality.language_models.language_model_constraint.LanguageModelConstraint(max_log_prob_diff=None, compare_against_original=True)[source]
Bases:
textattack.constraints.constraint.Constraint
,abc.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.