token type ids can be set by optional argument up to python wrapper #1418
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds an optional token_type_ids argument to Encoder.translate_batch, to facilitate BERT models with multiple input features (sentence-sentence entailment, context and question answering etc.). The token_type_ids vector is optional at the pybind level, and overloaded into the future_batch_async functions, with all previous endpoints preserved for backwards compatibility.
Closes #1383.
Type of change
Please delete options that are not relevant.
Testing
The code passes all C++ and python tests. For validation, the modified encoder was tested with both a bert-base-uncased and fine tuned bert-tiny for inference on the train split of the MRPC dataset (sentence pairs), and all output logits verified equal (<10e-12) to the output of a hugging face loaded model at full precision, when passing token_type_ids to both. When quantized, the logits are no longer equal, but the token_type_ids demonstrably improve the classifier accuracy.
Checklist: