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
a0352637
Commit
a0352637
authored
1 year ago
by
Eva Bardou
Committed by
Yoann Schneider
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Evaluate NER tokens distance
parent
4df2bbd3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!327
Evaluate NER tokens distance
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dan/ocr/evaluate.py
+3
-0
3 additions, 0 deletions
dan/ocr/evaluate.py
dan/ocr/manager/metrics.py
+17
-0
17 additions, 0 deletions
dan/ocr/manager/metrics.py
dan/ocr/train.py
+6
-0
6 additions, 0 deletions
dan/ocr/train.py
with
26 additions
and
0 deletions
dan/ocr/evaluate.py
+
3
−
0
View file @
a0352637
...
...
@@ -51,6 +51,9 @@ def eval(rank, config, mlflow_logging):
model
.
load_model
()
metrics
=
[
"
cer
"
,
"
wer
"
,
"
wer_no_punct
"
,
"
time
"
]
if
config
[
"
dataset
"
][
"
tokens
"
]
is
not
None
:
metrics
.
append
(
"
ner
"
)
for
dataset_name
in
config
[
"
dataset
"
][
"
datasets
"
]:
for
set_name
in
[
"
test
"
,
"
val
"
,
"
train
"
]:
logger
.
info
(
f
"
Evaluating on set `
{
set_name
}
`
"
)
...
...
This diff is collapsed.
Click to expand it.
dan/ocr/manager/metrics.py
+
17
−
0
View file @
a0352637
...
...
@@ -32,6 +32,8 @@ class MetricManager:
+
list
(
map
(
attrgetter
(
"
end
"
),
tokens
.
values
()))
)
self
.
remove_tokens
:
re
.
Pattern
=
re
.
compile
(
r
"
([
"
+
layout_tokens
+
"
])
"
)
self
.
keep_tokens
:
re
.
Pattern
=
re
.
compile
(
r
"
([^
"
+
layout_tokens
+
"
])
"
)
self
.
metric_names
:
List
[
str
]
=
metric_names
self
.
epoch_metrics
=
defaultdict
(
list
)
...
...
@@ -69,6 +71,12 @@ class MetricManager:
text
=
REGEX_CONSECUTIVE_LINEBREAKS
.
sub
(
"
\n
"
,
text
)
return
REGEX_CONSECUTIVE_SPACES
.
sub
(
"
"
,
text
).
strip
()
def
format_string_for_ner
(
self
,
text
:
str
):
"""
Format string for NER computation: only keep layout tokens
"""
return
self
.
keep_tokens
.
sub
(
""
,
text
)
def
update_metrics
(
self
,
batch_metrics
):
"""
Add batch metrics to the metrics
...
...
@@ -100,6 +108,8 @@ class MetricManager:
case
"
wer
"
|
"
wer_no_punct
"
:
suffix
=
metric_name
[
3
:]
num_name
,
denom_name
=
"
edit_words
"
+
suffix
,
"
nb_words
"
+
suffix
case
"
ner
"
:
num_name
,
denom_name
=
"
edit_tokens
"
,
"
nb_tokens
"
case
"
loss
"
|
"
loss_ce
"
:
display_values
[
metric_name
]
=
round
(
float
(
...
...
@@ -152,6 +162,13 @@ class MetricManager:
map
(
editdistance
.
eval
,
split_gt
,
split_pred
)
)
metrics
[
"
nb_words
"
+
suffix
]
=
list
(
map
(
len
,
split_gt
))
case
"
ner
"
:
split_gt
=
list
(
map
(
self
.
format_string_for_ner
,
gt
))
split_pred
=
list
(
map
(
self
.
format_string_for_ner
,
prediction
))
metrics
[
"
edit_tokens
"
]
=
list
(
map
(
editdistance
.
eval
,
split_gt
,
split_pred
)
)
metrics
[
"
nb_tokens
"
]
=
list
(
map
(
len
,
split_gt
))
case
"
loss
"
|
"
loss_ce
"
:
metrics
[
metric_name
]
=
[
values
[
metric_name
],
...
...
This diff is collapsed.
Click to expand it.
dan/ocr/train.py
+
6
−
0
View file @
a0352637
...
...
@@ -34,6 +34,12 @@ def train(rank, params, mlflow_logging=False):
model
=
Manager
(
params
)
model
.
load_model
()
if
params
[
"
dataset
"
][
"
tokens
"
]
is
not
None
:
if
"
ner
"
not
in
params
[
"
training
"
][
"
metrics
"
][
"
train
"
]:
params
[
"
training
"
][
"
metrics
"
][
"
train
"
].
append
(
"
ner
"
)
if
"
ner
"
not
in
params
[
"
training
"
][
"
metrics
"
][
"
eval
"
]:
params
[
"
training
"
][
"
metrics
"
][
"
eval
"
].
append
(
"
ner
"
)
if
mlflow_logging
:
logger
.
info
(
"
MLflow logging enabled
"
)
...
...
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