forked from huggingface/transformers
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Niels Rogge
authored and
Niels Rogge
committed
Feb 21, 2022
1 parent
387e52d
commit fd1db5e
Showing
5 changed files
with
54 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,31 @@ | ||
from transformers import MarkupLMTokenizer, MarkupLMTokenizerFast | ||
import torch | ||
|
||
slow_tokenizer = MarkupLMTokenizer.from_pretrained("microsoft/markuplm-base") | ||
from transformers import MarkupLMTokenizer, MarkupLMTokenizerFast, LayoutLMv2TokenizerFast | ||
|
||
slow_encoding = slow_tokenizer( | ||
["hello", "world"], | ||
xpaths=["/html/body/div/li[1]/div/span", "/html/body/div/li[1]/div/span"], | ||
padding="max_length", | ||
max_length=20, | ||
return_tensors="pt", | ||
) | ||
|
||
# slow_tokenizer = MarkupLMTokenizer.from_pretrained("microsoft/markuplm-base") | ||
|
||
# slow_encoding = slow_tokenizer( | ||
# ["hello", "world"], | ||
# xpaths=["/html/body/div/li[1]/div/span", "/html/body/div/li[1]/div/span"], | ||
# padding="max_length", | ||
# max_length=20, | ||
# return_tensors="pt", | ||
# ) | ||
|
||
fast_tokenizer = MarkupLMTokenizerFast.from_pretrained("microsoft/markuplm-base") | ||
|
||
fast_encoding = fast_tokenizer( | ||
["hello", "world"], | ||
xpaths=["/html/body/div/li[1]/div/span", "/html/body/div/li[1]/div/span"], | ||
fast_tokenizer_bis = LayoutLMv2TokenizerFast.from_pretrained("microsoft/layoutlmv2-base-uncased") | ||
|
||
fast_encoding = fast_tokenizer_bis( | ||
["hello", "world", "how", "are", "you"], | ||
#xpaths=["/html/body/div/li[1]/div/span", "/html/body/div/li[1]/div/span", "html/body", "html/body/div"], | ||
nodes=[[1,2,3,4] for _ in range(5)], | ||
padding="max_length", | ||
max_length=20, | ||
max_length=2, | ||
return_tensors="pt", | ||
return_overflowing_tokens=True, | ||
) | ||
|
||
for k in slow_encoding.keys(): | ||
assert torch.allclose(slow_encoding[k], fast_encoding[k]) | ||
# for k in slow_encoding.keys(): | ||
# assert torch.allclose(slow_encoding[k], fast_encoding[k]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters