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
01f849de
Commit
01f849de
authored
1 year ago
by
Solene Tarride
Browse files
Options
Downloads
Patches
Plain Diff
Add vocabulary size parameter for subword tokenizer
parent
9ccc888d
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dan/datasets/extract/__init__.py
+7
-0
7 additions, 0 deletions
dan/datasets/extract/__init__.py
dan/datasets/extract/extract.py
+5
-1
5 additions, 1 deletion
dan/datasets/extract/extract.py
dan/datasets/extract/utils.py
+1
-6
1 addition, 6 deletions
dan/datasets/extract/utils.py
with
13 additions
and
7 deletions
dan/datasets/extract/__init__.py
+
7
−
0
View file @
01f849de
...
...
@@ -147,6 +147,13 @@ def add_extract_parser(subcommands) -> None:
help
=
"
Images larger than this height will be resized to this width.
"
,
)
parser
.
add_argument
(
"
--subword-vocab-size
"
,
type
=
int
,
default
=
1000
,
help
=
"
Size of the vocabulary to train the sentencepiece subword tokenizer needed for language model.
"
,
)
# Formatting arguments
parser
.
add_argument
(
"
--image-format
"
,
...
...
This diff is collapsed.
Click to expand it.
dan/datasets/extract/extract.py
+
5
−
1
View file @
01f849de
...
...
@@ -78,6 +78,7 @@ class ArkindexExtractor:
keep_spaces
:
bool
=
False
,
image_extension
:
str
=
""
,
allow_empty
:
bool
=
False
,
subword_vocab_size
:
int
=
1000
,
)
->
None
:
self
.
folders
=
folders
self
.
element_type
=
element_type
...
...
@@ -93,8 +94,8 @@ class ArkindexExtractor:
self
.
image_extension
=
image_extension
self
.
allow_empty
=
allow_empty
self
.
mapping
=
LMTokenMapping
()
self
.
keep_spaces
=
keep_spaces
self
.
subword_vocab_size
=
subword_vocab_size
self
.
data
:
Dict
=
defaultdict
(
dict
)
self
.
charset
=
set
()
...
...
@@ -375,6 +376,7 @@ class ArkindexExtractor:
outdir
=
self
.
output
/
"
language_model
"
,
mapping
=
self
.
mapping
,
tokens
=
self
.
tokens
,
subword_vocab_size
=
self
.
subword_vocab_size
,
)
self
.
language_corpus
[
"
characters
"
]
=
[
tokenizer
.
char_tokenize
(
doc
)
for
doc
in
train_corpus
...
...
@@ -518,6 +520,7 @@ def run(
image_format
:
str
,
keep_spaces
:
bool
,
allow_empty
:
bool
,
subword_vocab_size
:
int
,
):
assert
database
.
exists
(),
f
"
No file found @
{
database
}
"
open_database
(
path
=
database
)
...
...
@@ -544,4 +547,5 @@ def run(
keep_spaces
=
keep_spaces
,
image_extension
=
image_format
,
allow_empty
=
allow_empty
,
subword_vocab_size
=
subword_vocab_size
,
).
run
()
This diff is collapsed.
Click to expand it.
dan/datasets/extract/utils.py
+
1
−
6
View file @
01f849de
...
...
@@ -134,7 +134,7 @@ class Tokenizer:
self
.
tokens
=
tokens
self
.
mapping
=
mapping
# Train the subword tokenizer
self
.
user_
subword_vocab_size
=
subword_vocab_size
self
.
subword_vocab_size
=
subword_vocab_size
self
.
sentencepiece_model
=
self
.
train_subword_tokenizer
()
@property
...
...
@@ -153,11 +153,6 @@ class Tokenizer:
def
special_tokens
(
self
)
->
List
[
str
]:
return
list
(
set
(
self
.
ner_tokens
+
self
.
mapping_tokens
))
@property
def
subword_vocab_size
(
self
):
n_words
=
len
(
set
([
word
for
doc
in
self
.
corpus
for
word
in
doc
.
split
()]))
return
min
(
self
.
user_subword_vocab_size
,
3
*
n_words
)
def
train_subword_tokenizer
(
self
):
"""
Train a sentencepiece model on the training corpus.
...
...
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