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

Add TextGeneration Evaluator #350

Merged
merged 6 commits into from
Nov 25, 2022

Conversation

NimaBoscarino
Copy link
Contributor

@NimaBoscarino NimaBoscarino commented Nov 9, 2022

This PR adds a basic TextGeneration evaluator. For the moment it's set up to use word_count as the default metric, but I think ideally it would use perplexity. The issue with perplexity is that the measurement requires a model_id (model name or path) passed to it, which wouldn't work with the Evaluator API since it should support running evaluations on models that are already instantiated in memory. (The model being evaluated might not be saved locally, if it's been modified in-code.)

I can open a second PR to modify perplexity to optionally accept instantiated models? Then I can make perplexity the default metric here.

The other metric that this is useful for is HONEST, although that requires some more small changes to get metric init_kwargs passed down from the Evaluators to the metrics. I'll be opening up another PR soon for that. (EDIT: Opened it here #351)

NOTE: I also changed the base .compute() return signature to fix some IDE warnings.

Uses word_count as default metric for the moment
Not relevant for this PR. Instead useful for perplexity, in a
future PR.
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Nov 9, 2022

The documentation is not available anymore as the PR was closed or merged.

Copy link
Member

@lvwerra lvwerra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @NimaBoscarino for adding this - looks great to me! Left a few questions/remarks.

@@ -347,7 +347,7 @@ def load_data(self, data: Union[str, Dataset], subset: str = None, split: str =
"Please specify a valid `data` object - either a `str` with a name or a `Dataset` object."
)

def prepare_data(self, data: Dataset, input_column: str, label_column: str):
def prepare_data(self, data: Dataset, input_column: str, label_column: str, *args, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TextGeneration Evaluator's predictions_processor method has a different signature than the base Evaluator's one, which means that without adding this IDEs will complain about mismatched signatures. I did this following this pattern: https://stackoverflow.com/a/54155637

src/evaluate/evaluator/text_generation.py Outdated Show resolved Hide resolved
@@ -49,6 +50,10 @@
"implementation": TokenClassificationEvaluator,
"default_metric_name": "seqeval",
},
"text-generation": {
"implementation": TextGenerationEvaluator,
"default_metric_name": "word_count",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To solve the perplexity issue we could just make gpt2 the default model so it's a kwarg instead of arg.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand – gpt2 would be the default value for model_or_pipeline for the TextGenerationEvaluator's compute method?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I meant we can update the perplexity metric to have a default value for the model (gpt2) so it works easily with the Evaluator. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! Sure, that sounds good to me. I think that one of the basic requirements for perplexity is that it also needs the ability to receive the actual model itself as well, so I'll make sure that's possible and I'll also include that as an option in the TextGenerationEvaluator here. I'll open a separate PR for the perplexity change.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint.

Copy link
Member

@lvwerra lvwerra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Let's fix perplexity so we can use it a useful default and then merge this, ok?

@lvwerra lvwerra merged commit 2d65438 into huggingface:main Nov 25, 2022
@lvwerra
Copy link
Member

lvwerra commented Nov 25, 2022

Merged for now and we can fix PPL later.

@NimaBoscarino NimaBoscarino deleted the evaluators/text-generation-2 branch November 25, 2022 20:33
awinml added a commit to awinml/evaluate that referenced this pull request Nov 29, 2022
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.

None yet

3 participants