Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Handle empty tokenization in perplexity and allow ad-hoc Advan… #802

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arnold-jr
Copy link

…cedAttackMetric

What does this PR do?

Handles empty input_ids when calculating complexity, which gave rise to RuntimeError when using "gpt2" as tokenizer.
Allows for adding metrics to AdvancedAttackMetric with configurable init params.

Summary

This PR cleans up some confusing errors related to perplexity calculation when handling empty inputs. Instead of a RuntimeError, the perplexity calc now throws a ValueError if empty inputs are encountered. It also adds some regression
tests around this error, and makes it possible to pass a different tokenizer to the perplexity calculation in AdvancedAttackMetric.

Additions

  • Added handling of empty tokenization during Perplexity calculation.
  • Added tests to test_metric_api to reproduce perplexity errors on empty inputs using "gpt2"
  • Added method for appending an ad-hoc metric to AdvancedAttackMetric.

Changes

  • Perplexity with "gpt2" no longer throws torch RuntimeError on empty input_ids

Deletions

Checklist

  • [x ] The title of your pull request should be a summary of its contribution.
  • [ x] Please write detailed description of what parts have been newly added and what parts have been modified. Please also explain why certain changes were made.
  • [ x] If your pull request addresses an issue, please mention the issue number in the pull request description to make sure they are linked (and people consulting the issue know you are working on it)
  • [ x] To indicate a work in progress please mark it as a draft on Github.
  • [ x] Make sure existing tests pass.
  • [ x] Add relevant tests. No quality testing = no merge.
  • [ x] All public methods must have informative docstrings that work nicely with sphinx. For new modules/files, please add/modify the appropriate .rst file in TextAttack/docs/apidoc.'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant