-
Couldn't load subscription status.
- Fork 31k
Add t5 to pipeline(task='summarization') #3413
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 t5 to pipeline(task='summarization') #3413
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3413 +/- ##
==========================================
+ Coverage 77.56% 77.58% +0.02%
==========================================
Files 100 100
Lines 16970 16993 +23
==========================================
+ Hits 13162 13184 +22
- Misses 3808 3809 +1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my perspective, looks good. Would love test coverage to avoid breaking it accidentally!
src/transformers/pipelines.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in a previous PR, @thomwolf suggested that if a kwarg (like length_penalty) is on the config, it should only be exposed through generate_kwargs).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would favor to (re-)define the kwargs like max_length, min_length, do_sample, length_penalty in this function because the defaults in the config are defaults for generate() in general, but there are not good defaults for summarization. And to me pipelines is about easy-to-use so I think good general defaults for summarization should be defined here. Happy to discuss.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok that's quite an interesting case for T5 versus Bart because in Bart the pretrained model are task-specific so it make sense to have the task-specific generation hyper-parameters in the config while for T5 the pretrained model is generic so it would make more sense to have a way to specify task specific generation HP in the config.
In general, I'm not a fan of having model-specific hyper-parameters in general classes like pipelines.
What I would propose is maybe the following for T5 (open to discussion):
- have generic generation HP in the config like now
- also have a dict of class specific generation HP in the config which can override the generic HP.
Ex of config dic:
{
....
max_length: 100, # generic generation HP
length_penalty: 1.0,
task_specific_generation_params: {
"summarization": { # task id (e.g. name of the pipeline?)
max_length: 140,
length_penalty: 2.0
},
"translation_en_to_de": {
max_length: 160,
length_penalty: 3.0
},
},
}What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I like that idea!
Two questions:
- Should we enforce that all parameters defined in
task_specific_generation_paramshave to be already defined so that they can only override? - Do we allow "summarization" and "translation" if the config has no
task_specific_generation_paramsdefined?
src/transformers/pipelines.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why we would not optionally use pad_to_max_length here? Was not sure if I can add it, but for summarization when using a batched input, this is necessary. @LysandreJik @thomwolf @mfuntowicz
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work. A few tweaks regarding handling task-specific generation HPs if you can do it (see my comments).
src/transformers/pipelines.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok for now but we'll probably refactor this in the future to have framework-agnostic ensure_tensor_on_device and get_tensor_length methods (maybe have a base class and framework-specific derived class for instance).
src/transformers/pipelines.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok that's quite an interesting case for T5 versus Bart because in Bart the pretrained model are task-specific so it make sense to have the task-specific generation hyper-parameters in the config while for T5 the pretrained model is generic so it would make more sense to have a way to specify task specific generation HP in the config.
In general, I'm not a fan of having model-specific hyper-parameters in general classes like pipelines.
What I would propose is maybe the following for T5 (open to discussion):
- have generic generation HP in the config like now
- also have a dict of class specific generation HP in the config which can override the generic HP.
Ex of config dic:
{
....
max_length: 100, # generic generation HP
length_penalty: 1.0,
task_specific_generation_params: {
"summarization": { # task id (e.g. name of the pipeline?)
max_length: 140,
length_penalty: 2.0
},
"translation_en_to_de": {
max_length: 160,
length_penalty: 3.0
},
},
}What do you think?
23778d1 to
275f798
Compare
275f798 to
62ffb38
Compare
| args = ["input_ids", "attention_mask"] | ||
|
|
||
| if not isinstance(self.model.config, (DistilBertConfig, XLMConfig, RobertaConfig, BartConfig)): | ||
| if not isinstance(self.model.config, (DistilBertConfig, XLMConfig, RobertaConfig, BartConfig, T5Config)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, note that we can now remove the inputs_for_model from pipelines since #3116
Let's do it in another PR cleaning up pipelines later.
This PR: