SPARKNLP-828: Raise error when exceeding max input length #13774
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 introduces an exception in transformer based annotators. If an invalid value is used to set the max input length, an exception is thrown (limit is 512, or 4096 for the longformer). This exception exists on the scala side but was missing in python. These exceptions are now in sync.
This is done by introducing a new property
HasMaxSentenceLengthLimit
:spark-nlp/python/sparknlp/common/properties.py
Lines 438 to 476 in cce5dc8
A note regarding this has also been added to the documentation.
Motivation and Context
Users have been experiencing issues when trying to translate long texts. This should make it clear, that very long inputs are not intended for these models. Users should use a Sentence Detector to split the text to smaller chunks first and this new change will avoid exception by not allowing users to set anything larger than 512 in maxInputLength parameter. (a bug only on Python side)
How Has This Been Tested?
Existing tests have been amended to cover this behaviour. Missing tests were added for some annotators.
Screenshots (if appropriate):
Types of changes
Checklist: