Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
9879a1d5
Unverified
Commit
9879a1d5
authored
Mar 08, 2022
by
NielsRogge
Committed by
GitHub
Mar 08, 2022
Browse files
Fix LayoutLMv2 test (#15939)
* Fix LayoutLMv2 test * Update black
parent
8b9ae455
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
11 deletions
+8
-11
tests/layoutlmv2/test_tokenization_layoutlmv2.py
tests/layoutlmv2/test_tokenization_layoutlmv2.py
+8
-11
No files found.
tests/layoutlmv2/test_tokenization_layoutlmv2.py
View file @
9879a1d5
...
...
@@ -31,14 +31,7 @@ from transformers.models.layoutlmv2.tokenization_layoutlmv2 import (
_is_punctuation
,
_is_whitespace
,
)
from
transformers.testing_utils
import
(
is_pt_tf_cross_test
,
require_pandas
,
require_scatter
,
require_tokenizers
,
require_torch
,
slow
,
)
from
transformers.testing_utils
import
is_pt_tf_cross_test
,
require_pandas
,
require_tokenizers
,
require_torch
,
slow
from
..test_tokenization_common
import
(
SMALL_TRAINING_CORPUS
,
...
...
@@ -1219,7 +1212,6 @@ class LayoutLMv2TokenizationTest(TokenizerTesterMixin, unittest.TestCase):
@
require_torch
@
slow
@
require_scatter
def
test_torch_encode_plus_sent_to_model
(
self
):
import
torch
...
...
@@ -1254,10 +1246,15 @@ class LayoutLMv2TokenizationTest(TokenizerTesterMixin, unittest.TestCase):
words
,
boxes
=
self
.
get_words_and_boxes
()
encoded_sequence
=
tokenizer
.
encode_plus
(
words
,
boxes
=
boxes
,
return_tensors
=
"pt"
)
batch_encoded_sequence
=
tokenizer
.
batch_encode_plus
(
[
words
,
words
],
[
boxes
,
boxes
],
return_tensors
=
"pt"
[
words
,
words
],
boxes
=
[
boxes
,
boxes
],
return_tensors
=
"pt"
)
# This should not fail
# We add dummy image keys (as LayoutLMv2 actually also requires a feature extractor
# to prepare the image input)
encoded_sequence
[
"image"
]
=
torch
.
randn
(
1
,
3
,
224
,
224
)
batch_encoded_sequence
[
"image"
]
=
torch
.
randn
(
2
,
3
,
224
,
224
)
# This should not fail
with
torch
.
no_grad
():
# saves some time
model
(
**
encoded_sequence
)
model
(
**
batch_encoded_sequence
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment