Pass parent exception as context exception to provide clearer stack trace (#21636)
* Pass parent exception as context exception to provide clearer stack trace * Update src/transformers/tokenization_utils_base.py Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> --------- Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
This commit is contained in:
@@ -724,18 +724,18 @@ class BatchEncoding(UserDict):
|
||||
# tensor = tensor[None, :]
|
||||
|
||||
self[key] = tensor
|
||||
except: # noqa E722
|
||||
except Exception as e:
|
||||
if key == "overflowing_tokens":
|
||||
raise ValueError(
|
||||
"Unable to create tensor returning overflowing tokens of different lengths. "
|
||||
"Please see if a fast version of this tokenizer is available to have this feature available."
|
||||
)
|
||||
) from e
|
||||
raise ValueError(
|
||||
"Unable to create tensor, you should probably activate truncation and/or padding with"
|
||||
" 'padding=True' 'truncation=True' to have batched tensors with the same length. Perhaps your"
|
||||
f" features (`{key}` in this case) have excessive nesting (inputs type `list` where type `int` is"
|
||||
" expected)."
|
||||
)
|
||||
) from e
|
||||
|
||||
return self
|
||||
|
||||
|
||||
Reference in New Issue
Block a user