()
| 1 | def test_perplexity(): |
| 2 | from textattack.attack_results import SuccessfulAttackResult |
| 3 | from textattack.goal_function_results.classification_goal_function_result import ( |
| 4 | ClassificationGoalFunctionResult, |
| 5 | ) |
| 6 | from textattack.metrics.quality_metrics import Perplexity |
| 7 | from textattack.shared.attacked_text import AttackedText |
| 8 | |
| 9 | sample_text = "hide new secretions from the parental units " |
| 10 | sample_atck_text = "Ehide enw secretions from the parental units " |
| 11 | |
| 12 | results = [ |
| 13 | SuccessfulAttackResult( |
| 14 | ClassificationGoalFunctionResult( |
| 15 | AttackedText(sample_text), None, None, None, None, None, None |
| 16 | ), |
| 17 | ClassificationGoalFunctionResult( |
| 18 | AttackedText(sample_atck_text), None, None, None, None, None, None |
| 19 | ), |
| 20 | ) |
| 21 | ] |
| 22 | ppl = Perplexity(model_name="distilbert-base-uncased").calculate(results) |
| 23 | |
| 24 | assert int(ppl["avg_original_perplexity"]) == int(81.95) |
| 25 | |
| 26 | |
| 27 | def test_use(): |
nothing calls this directly
no test coverage detected