Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
DAN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Automatic Text Recognition
DAN
Commits
58b0789a
Commit
58b0789a
authored
1 year ago
by
Solene Tarride
Browse files
Options
Downloads
Patches
Plain Diff
Map unknown characters
parent
de28eb7f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dan/datasets/extract/extract.py
+3
-0
3 additions, 0 deletions
dan/datasets/extract/extract.py
dan/datasets/extract/utils.py
+8
-4
8 additions, 4 deletions
dan/datasets/extract/utils.py
with
11 additions
and
4 deletions
dan/datasets/extract/extract.py
+
3
−
0
View file @
58b0789a
...
...
@@ -371,8 +371,11 @@ class ArkindexExtractor:
text
.
replace
(
self
.
mapping
.
linebreak
.
display
,
self
.
mapping
.
space
.
display
)
for
text
in
self
.
data
[
"
train
"
].
values
()
]
tokenizer
=
Tokenizer
(
training_corpus
=
train_corpus
,
charset
=
self
.
language_tokens
,
unknown_token
=
self
.
unknown_token
,
outdir
=
self
.
output
/
"
language_model
"
,
mapping
=
self
.
mapping
,
tokens
=
self
.
tokens
,
...
...
This diff is collapsed.
Click to expand it.
dan/datasets/extract/utils.py
+
8
−
4
View file @
58b0789a
...
...
@@ -131,9 +131,7 @@ def get_vocabulary(tokenized_text: List[str]) -> set[str]:
Compute set of vocabulary from tokenzied text.
:param tokenized_text: List of tokenized text.
"""
return
sorted
(
set
([
token
for
doc
in
tokenized_text
for
token
in
doc
.
split
()
if
token
!=
""
])
)
return
sorted
(
set
([
token
for
doc
in
tokenized_text
for
token
in
doc
.
split
()]))
@dataclass
...
...
@@ -148,6 +146,8 @@ class Tokenizer:
"""
training_corpus
:
List
[
str
]
charset
:
List
[
str
]
unknown_token
:
str
outdir
:
Path
mapping
:
LMTokenMapping
tokens
:
Optional
[
EntityType
]
=
None
...
...
@@ -225,7 +225,11 @@ class Tokenizer:
Tokenize text into a string of space-separated characters.
:param text: Text to be tokenized.
"""
return
"
"
.
join
(
self
.
encode
(
list
(
text
)))
return
"
"
.
join
(
self
.
encode
(
[
char
if
char
in
self
.
charset
else
self
.
unknown_token
for
char
in
text
]
)
)
def
encode
(
self
,
text
:
List
[
str
])
->
List
[
str
]:
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment