Repository navigation
[WIP] Squad refactor - #1984
[WIP] Squad refactor#1984
Conversation
| - 'only_second': Only truncate the second sequence | ||
| - 'do_not_truncate': Does not truncate (raise an error if the input sequence is longer than max_length) | ||
| padding_strategy: if set to a strategy, the returned sequences will be padded according to the model's | ||
| padding index, up to their max length. If no max length is specified, no padding is done. |
There was a problem hiding this comment.
In the most general case for the user, we may want to allow passing a batch of sequence and just have them padded to the maximal sequence length in the batch (or probably the min between the model's max length and the maximal sequence length in the batch).
Should we prepare for that?
There was a problem hiding this comment.
I feel like we should do padding up to self.max_length if padding is asked even when no explicit max_length is provided to the method.
There was a problem hiding this comment.
Regarding the first comment, we don't currently manage sequence batching so it would require implementing an encode_batch method or similar beforehand, wouldn't it? As of right now, it shouldn't be too hard for the user to identify the longer sequence in its batches, but it would be a good idea to ease the process of tokenizing batches.
Totally agree with your second comment, this makes sense!
|
|
||
| @property | ||
| def pad_token_type_id(self): | ||
| """ Id of the padding token in the vocabulary. Log an error if used while not having been set. """ |
There was a problem hiding this comment.
we can remove Log an error if used while not having been set I think
thomwolf
left a comment
There was a problem hiding this comment.
That's really a lot cleaner, I like it very much.
Great work @LysandreJik!
|
|
||
| An example using these processors is given in the | ||
| `run_glue.py <https://github.com/huggingface/pytorch-transformers/blob/master/examples/run_glue.py>`__ script. No newline at end of file | ||
| `run_glue.py <https://github.com/huggingface/pytorch-transformers/blob/master/examples/run_glue.py>`__ script. |
There was a problem hiding this comment.
| `run_glue.py <https://github.com/huggingface/pytorch-transformers/blob/master/examples/run_glue.py>`__ script. | |
| `run_glue.py <https://github.com/huggingface/transformers/blob/master/examples/run_glue.py>`__ script. |
|
|
||
|
|
||
| Another example using these processors is given in the | ||
| `run_squad.py <https://github.com/huggingface/pytorch-transformers/blob/master/examples/run_squad.py>`__ script. No newline at end of file |
There was a problem hiding this comment.
| `run_squad.py <https://github.com/huggingface/pytorch-transformers/blob/master/examples/run_squad.py>`__ script. | |
| `run_squad.py <https://github.com/huggingface/transformers/blob/master/examples/run_squad.py>`__ script. |
Codecov Report
@@ Coverage Diff @@
## master #1984 +/- ##
==========================================
- Coverage 82.67% 79.56% -3.12%
==========================================
Files 111 113 +2
Lines 16162 16969 +807
==========================================
+ Hits 13362 13501 +139
- Misses 2800 3468 +668
Continue to review full report at Codecov.
|
|
Should be about ready to merge now. I made sure that I obtain somewhat the same results with fine-tuning + evaluating models with the old and new scripts. I could confirm it is the case for DistilBERT, BERT and XLNet. |
|
|
||
| self.max_len = max_len if max_len is not None else int(1e12) | ||
|
|
||
| # Padding side is right by default and over-riden in subclsses. If specified in the kwargs, it is changed. |
There was a problem hiding this comment.
Let's add it to the class docstring later to have it in the doc as well.
| ) | ||
|
|
||
| if pad_to_max_length and max_length is None and self.max_len > 10000: | ||
| logger.warning("Sequence can't be padded as the maximum ") |
|
Ok this is great, merging! @LysandreJik do you want to have a quick look at the two comments I wrote about doc/docstring and the incomplete warning? Merging now because these are small tweak and @mfuntowicz need this PR for his PR so I'll let you push a doc commit on master directly maybe. |
| pad_to_max_length: if set to True, the returned sequences will be padded according to the model's padding side and | ||
| padding index, up to their max length. If no max length is specified, the padding is done up to the model's max length. | ||
| The tokenizer padding sides are handled by the following strings: |
There was a problem hiding this comment.
@thomwolf Is that what you meant by class substring?
This PR aims to refactor SQuAD to make it usable with all models with question answering heads, and without having to build the entire tokenization pipeline as it is currently done.
SquadV1ProcessorandSquadV2Processor. They'll probably be merged into a singleSquadProcessoras the difference between the two versions is minimal.run_gluerefactor a few months ago that greatly simplified the tokenization pipelinetensorflow_datasets.attention_maskinstead ofinput_maskandtoken_type_idsinstead ofsegment_ids, among others.encodeandencode_plus, alongside tests.It is still a work on progress but some aspects of it are working.
Left to do
__init__.pyonly_firstargument which would only be used for testingrun_squad.pyscriptRunning sample
Here's the major difference from the user's perspective. Initially, to obtain the examples which were then converted to features, the user had to do as follows (taken from the current
run_squad.py), which only works for BERT/XLNet/DistilBERT/ALBERT:In order to obtain the exact same results, the user now has to do as follows, which will be completely model independant once the
sequence_a_is_docis integrated in our sequence pair tokenization methods:The same can be done by using TFDS instead, removing the need to specify a file. The two initial lines now become: