Unverified Commit 7bac5183 authored by Bruno Alvisio's avatar Bruno Alvisio Committed by GitHub
Browse files

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: default avatarSylvain Gugger <35901082+sgugger@users.noreply.github.com>

---------
Co-authored-by: default avatarSylvain Gugger <35901082+sgugger@users.noreply.github.com>
parent 3499c49c
...@@ -724,18 +724,18 @@ class BatchEncoding(UserDict): ...@@ -724,18 +724,18 @@ class BatchEncoding(UserDict):
# tensor = tensor[None, :] # tensor = tensor[None, :]
self[key] = tensor self[key] = tensor
except: # noqa E722 except Exception as e:
if key == "overflowing_tokens": if key == "overflowing_tokens":
raise ValueError( raise ValueError(
"Unable to create tensor returning overflowing tokens of different lengths. " "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." "Please see if a fast version of this tokenizer is available to have this feature available."
) ) from e
raise ValueError( raise ValueError(
"Unable to create tensor, you should probably activate truncation and/or padding with" "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" " '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" f" features (`{key}` in this case) have excessive nesting (inputs type `list` where type `int` is"
" expected)." " expected)."
) ) from e
return self return self
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment