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.
Improve processor, add integration test
- Loading branch information
1 parent
88618dd
commit 47c172c
Showing
5 changed files
with
95 additions
and
23 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
37 changes: 21 additions & 16 deletions
37
src/transformers/models/markuplm/test_feature_extractor.py
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,23 +1,28 @@ | ||
from transformers import MarkupLMFeatureExtractor | ||
from transformers import MarkupLMFeatureExtractor, MarkupLMProcessor, MarkupLMTokenizer | ||
|
||
|
||
feature_extractor = MarkupLMFeatureExtractor() | ||
tokenizer = MarkupLMTokenizer.from_pretrained("microsoft/markuplm-base") | ||
|
||
html_string = """<HTML> | ||
processor = MarkupLMProcessor(feature_extractor, tokenizer) | ||
|
||
<HEAD> | ||
<TITLE>sample document</TITLE> | ||
</HEAD> | ||
|
||
<BODY BGCOLOR="FFFFFF"> | ||
<HR> <a href="http://google.com">Goog</a> <H1>This is one header</H1> <H2>This is a another Header</H2> <P>Travel | ||
from | ||
<P> | ||
<B>SFO to JFK</B> <BR> <B><I>on May 2, 2015 at 2:00 pm. For details go to confirm.com </I></B> <HR> <div | ||
style="color:#0000FF"> | ||
<h3>Traveler <b> name </b> is <p> John Doe </p> | ||
</div>""" | ||
def prepare_html_string(): | ||
html_string = """ | ||
<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> | ||
encoding = feature_extractor(html_string) | ||
for k, v in encoding.items(): | ||
print(k, v) | ||
<h1>This is a Heading</h1> <p>This is a paragraph.</p> | ||
</body> </html> | ||
""" | ||
|
||
return html_string | ||
|
||
|
||
encoding = processor(prepare_html_string()) | ||
# for k, v in encoding.items(): | ||
# print(k, v) | ||
|
||
print(encoding.input_ids) | ||
|
||
print(processor.decode(encoding.input_ids[0])) |
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