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
7915a259
Unverified
Commit
7915a259
authored
Apr 18, 2024
by
Pavel Iakubovskii
Committed by
GitHub
Apr 18, 2024
Browse files
Fix donut token2json multiline (#30300)
* Fix multiline processing * Update test for token2json
parent
b65df514
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
1 deletion
+7
-1
src/transformers/models/donut/processing_donut.py
src/transformers/models/donut/processing_donut.py
+3
-1
tests/models/donut/test_processing_donut.py
tests/models/donut/test_processing_donut.py
+4
-0
No files found.
src/transformers/models/donut/processing_donut.py
View file @
7915a259
...
...
@@ -149,7 +149,9 @@ class DonutProcessor(ProcessorMixin):
end_token
=
end_token
.
group
()
start_token_escaped
=
re
.
escape
(
start_token
)
end_token_escaped
=
re
.
escape
(
end_token
)
content
=
re
.
search
(
f
"
{
start_token_escaped
}
(.*?)
{
end_token_escaped
}
"
,
tokens
,
re
.
IGNORECASE
)
content
=
re
.
search
(
f
"
{
start_token_escaped
}
(.*?)
{
end_token_escaped
}
"
,
tokens
,
re
.
IGNORECASE
|
re
.
DOTALL
)
if
content
is
not
None
:
content
=
content
.
group
(
1
).
strip
()
if
r
"<s_"
in
content
and
r
"</s_"
in
content
:
# non-leaf node
...
...
tests/models/donut/test_processing_donut.py
View file @
7915a259
...
...
@@ -35,6 +35,8 @@ class DonutProcessorTest(unittest.TestCase):
"zip"
:
"30301"
,
"phone"
:
"123-4567"
,
"nicknames"
:
[{
"nickname"
:
"Johnny"
},
{
"nickname"
:
"JD"
}],
"multiline"
:
"text
\n
with
\n
newlines"
,
"empty"
:
""
,
}
sequence
=
(
...
...
@@ -42,6 +44,8 @@ class DonutProcessorTest(unittest.TestCase):
"<s_state>GA</s_state><s_zip>30301</s_zip><s_phone>123-4567</s_phone>"
"<s_nicknames><s_nickname>Johnny</s_nickname>"
"<sep/><s_nickname>JD</s_nickname></s_nicknames>"
"<s_multiline>text
\n
with
\n
newlines</s_multiline>"
"<s_empty></s_empty>"
)
actual_json
=
self
.
processor
.
token2json
(
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