Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
nerval
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Named Entity Recognition
nerval
Commits
2ac2b607
Commit
2ac2b607
authored
2 years ago
by
Yoann Schneider
Browse files
Options
Downloads
Patches
Plain Diff
Some small refactoring
parent
25a70324
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!20
Some small refactoring
Pipeline
#104003
passed
2 years ago
Stage: test
Changes
24
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
tests/test_compute_scores.py
+47
-38
47 additions, 38 deletions
tests/test_compute_scores.py
tests/test_parse_bio.py
+10
-17
10 additions, 17 deletions
tests/test_parse_bio.py
tests/test_run.py
+95
-72
95 additions, 72 deletions
tests/test_run.py
tox.ini
+2
-2
2 additions, 2 deletions
tox.ini
with
154 additions
and
129 deletions
tests/test_compute_scores.py
+
47
−
38
View file @
2ac2b607
...
...
@@ -3,48 +3,57 @@ import pytest
from
nerval
import
evaluate
fake_annot_entity_count
=
{
"
All
"
:
3
,
"
DAT
"
:
1
,
"
LOC
"
:
1
,
"
PER
"
:
1
}
fake_predict_entity_count
=
{
"
All
"
:
3
,
"
DAT
"
:
1
,
"
***
"
:
1
,
"
PER
"
:
1
}
fake_matches
=
{
"
All
"
:
1
,
"
PER
"
:
1
,
"
LOC
"
:
0
,
"
DAT
"
:
0
}
expected_scores
=
{
"
***
"
:
{
"
P
"
:
0.0
,
"
R
"
:
None
,
"
F1
"
:
None
,
"
predicted
"
:
1
,
"
matched
"
:
0
,
"
Support
"
:
None
,
},
"
DAT
"
:
{
"
P
"
:
0.0
,
"
R
"
:
0.0
,
"
F1
"
:
0
,
"
predicted
"
:
1
,
"
matched
"
:
0
,
"
Support
"
:
1
},
"
All
"
:
{
"
P
"
:
0.3333333333333333
,
"
R
"
:
0.3333333333333333
,
"
F1
"
:
0.3333333333333333
,
"
predicted
"
:
3
,
"
matched
"
:
1
,
"
Support
"
:
3
,
},
"
PER
"
:
{
"
P
"
:
1.0
,
"
R
"
:
1.0
,
"
F1
"
:
1.0
,
"
predicted
"
:
1
,
"
matched
"
:
1
,
"
Support
"
:
1
},
"
LOC
"
:
{
"
P
"
:
None
,
"
R
"
:
0.0
,
"
F1
"
:
None
,
"
predicted
"
:
None
,
"
matched
"
:
0
,
"
Support
"
:
1
,
},
}
@pytest.mark.parametrize
(
"
test_input, expected
"
,
"
annot,predict,matches
"
,
[
(
(
fake_annot_entity_count
,
fake_predict_entity_count
,
fake_matches
),
expected_scores
,
{
"
All
"
:
3
,
"
DAT
"
:
1
,
"
LOC
"
:
1
,
"
PER
"
:
1
},
{
"
All
"
:
3
,
"
DAT
"
:
1
,
"
***
"
:
1
,
"
PER
"
:
1
},
{
"
All
"
:
1
,
"
PER
"
:
1
,
"
LOC
"
:
0
,
"
DAT
"
:
0
},
)
],
)
def
test_compute_scores
(
test_input
,
expected
):
assert
evaluate
.
compute_scores
(
*
test_input
)
==
expected
def
test_compute_scores
(
annot
,
predict
,
matches
):
assert
evaluate
.
compute_scores
(
annot
,
predict
,
matches
)
==
{
"
***
"
:
{
"
P
"
:
0.0
,
"
R
"
:
None
,
"
F1
"
:
None
,
"
predicted
"
:
1
,
"
matched
"
:
0
,
"
Support
"
:
None
,
},
"
DAT
"
:
{
"
P
"
:
0.0
,
"
R
"
:
0.0
,
"
F1
"
:
0
,
"
predicted
"
:
1
,
"
matched
"
:
0
,
"
Support
"
:
1
,
},
"
All
"
:
{
"
P
"
:
0.3333333333333333
,
"
R
"
:
0.3333333333333333
,
"
F1
"
:
0.3333333333333333
,
"
predicted
"
:
3
,
"
matched
"
:
1
,
"
Support
"
:
3
,
},
"
PER
"
:
{
"
P
"
:
1.0
,
"
R
"
:
1.0
,
"
F1
"
:
1.0
,
"
predicted
"
:
1
,
"
matched
"
:
1
,
"
Support
"
:
1
,
},
"
LOC
"
:
{
"
P
"
:
None
,
"
R
"
:
0.0
,
"
F1
"
:
None
,
"
predicted
"
:
None
,
"
matched
"
:
0
,
"
Support
"
:
1
,
},
}
This diff is collapsed.
Click to expand it.
tests/test_parse_bio.py
+
10
−
17
View file @
2ac2b607
# -*- coding: utf-8 -*-
from
pathlib
import
Path
import
pytest
from
nerval
import
evaluate
NO_EXIST_BIO
=
"
no_exist.bio
"
EMPTY_BIO
=
"
tests/test_empty.bio
"
BAD_BIO
=
"
tests/test_bad.bio
"
FAKE_ANNOT_BIO
=
"
tests/test_annot.bio
"
FAKE_PREDICT_BIO
=
"
tests/test_predict.bio
"
BIOESLU_BIO
=
"
tests/bioeslu.bio
"
END_OF_FILE_BIO
=
"
tests/end_of_file.bio
"
expected_parsed_annot
=
{
"
entity_count
"
:
{
"
All
"
:
3
,
"
DAT
"
:
1
,
"
LOC
"
:
1
,
"
PER
"
:
1
},
"
labels
"
:
[
...
...
@@ -179,22 +172,22 @@ expected_parsed_end_of_file = {
@pytest.mark.parametrize
(
"
test_input, expected
"
,
[
(
FAKE_ANNOT_BIO
,
expected_parsed_annot
),
(
FAKE_PREDICT_BIO
,
expected_parsed_predict
),
(
EMPTY_BIO
,
None
),
(
BIOESLU_BIO
,
expected_parsed_annot
),
(
END_OF_FILE_BIO
,
expected_parsed_end_of_file
),
(
pytest
.
lazy_fixture
(
"
fake_annot_bio
"
)
,
expected_parsed_annot
),
(
pytest
.
lazy_fixture
(
"
fake_predict_bio
"
)
,
expected_parsed_predict
),
(
pytest
.
lazy_fixture
(
"
empty_bio
"
)
,
None
),
(
pytest
.
lazy_fixture
(
"
bioeslu_bio
"
)
,
expected_parsed_annot
),
(
pytest
.
lazy_fixture
(
"
end_of_file_bio
"
)
,
expected_parsed_end_of_file
),
],
)
def
test_parse_bio
(
test_input
,
expected
):
assert
evaluate
.
parse_bio
(
test_input
)
==
expected
def
test_parse_bio_bad_input
():
def
test_parse_bio_bad_input
(
bad_bio
):
with
pytest
.
raises
(
Exception
):
evaluate
.
parse_bio
(
BAD_BIO
)
evaluate
.
parse_bio
(
bad_bio
)
def
test_parse_bio_no_input
():
with
pytest
.
raises
(
AssertionError
):
evaluate
.
parse_bio
(
NO_EXIST_BIO
)
evaluate
.
parse_bio
(
Path
(
"
not_a_bio
"
)
)
This diff is collapsed.
Click to expand it.
tests/test_run.py
+
95
−
72
View file @
2ac2b607
...
...
@@ -3,88 +3,111 @@ import pytest
from
nerval
import
evaluate
THRESHOLD
=
0.30
FAKE_ANNOT_BIO
=
"
tests/test_annot.bio
"
FAKE_PREDICT_BIO
=
"
tests/test_predict.bio
"
EMPTY_BIO
=
"
tests/test_empty.bio
"
FAKE_BIO_NESTED
=
"
tests/test_nested.bio
"
BIO_FOLDER
=
"
test_folder
"
CSV_FILE
=
"
test_mapping_file.csv
"
expected_scores_nested
=
{
"
All
"
:
{
"
P
"
:
1.0
,
"
R
"
:
1.0
,
"
F1
"
:
1.0
,
"
predicted
"
:
3
,
"
matched
"
:
3
,
"
Support
"
:
3
,
},
"
PER
"
:
{
"
P
"
:
1.0
,
"
R
"
:
1.0
,
"
F1
"
:
1.0
,
"
predicted
"
:
1
,
"
matched
"
:
1
,
"
Support
"
:
1
},
"
LOC
"
:
{
"
P
"
:
1.0
,
"
R
"
:
1.0
,
"
F1
"
:
1.0
,
"
predicted
"
:
2
,
"
matched
"
:
2
,
"
Support
"
:
2
,
},
}
expected_scores
=
{
"
***
"
:
{
"
P
"
:
0.0
,
"
R
"
:
None
,
"
F1
"
:
None
,
"
predicted
"
:
1
,
"
matched
"
:
0
,
"
Support
"
:
None
,
},
"
DAT
"
:
{
"
P
"
:
0.0
,
"
R
"
:
0.0
,
"
F1
"
:
0
,
"
predicted
"
:
1
,
"
matched
"
:
0
,
"
Support
"
:
1
},
"
All
"
:
{
"
P
"
:
0.3333333333333333
,
"
R
"
:
0.3333333333333333
,
"
F1
"
:
0.3333333333333333
,
"
predicted
"
:
3
,
"
matched
"
:
1
,
"
Support
"
:
3
,
},
"
PER
"
:
{
"
P
"
:
1.0
,
"
R
"
:
1.0
,
"
F1
"
:
1.0
,
"
predicted
"
:
1
,
"
matched
"
:
1
,
"
Support
"
:
1
},
"
LOC
"
:
{
"
P
"
:
None
,
"
R
"
:
0.0
,
"
F1
"
:
None
,
"
predicted
"
:
None
,
"
matched
"
:
0
,
"
Support
"
:
1
,
},
}
@pytest.mark.parametrize
(
"
test_input, expected
"
,
[
((
FAKE_ANNOT_BIO
,
FAKE_PREDICT_BIO
,
THRESHOLD
,
True
),
expected_scores
),
((
FAKE_BIO_NESTED
,
FAKE_BIO_NESTED
,
THRESHOLD
,
True
),
expected_scores_nested
),
],
"
annotation, prediction, expected
"
,
(
(
pytest
.
lazy_fixture
(
"
fake_annot_bio
"
),
pytest
.
lazy_fixture
(
"
fake_predict_bio
"
),
{
"
***
"
:
{
"
P
"
:
0.0
,
"
R
"
:
None
,
"
F1
"
:
None
,
"
predicted
"
:
1
,
"
matched
"
:
0
,
"
Support
"
:
None
,
},
"
DAT
"
:
{
"
P
"
:
0.0
,
"
R
"
:
0.0
,
"
F1
"
:
0
,
"
predicted
"
:
1
,
"
matched
"
:
0
,
"
Support
"
:
1
,
},
"
All
"
:
{
"
P
"
:
0.3333333333333333
,
"
R
"
:
0.3333333333333333
,
"
F1
"
:
0.3333333333333333
,
"
predicted
"
:
3
,
"
matched
"
:
1
,
"
Support
"
:
3
,
},
"
PER
"
:
{
"
P
"
:
1.0
,
"
R
"
:
1.0
,
"
F1
"
:
1.0
,
"
predicted
"
:
1
,
"
matched
"
:
1
,
"
Support
"
:
1
,
},
"
LOC
"
:
{
"
P
"
:
None
,
"
R
"
:
0.0
,
"
F1
"
:
None
,
"
predicted
"
:
None
,
"
matched
"
:
0
,
"
Support
"
:
1
,
},
},
),
(
pytest
.
lazy_fixture
(
"
nested_bio
"
),
pytest
.
lazy_fixture
(
"
nested_bio
"
),
{
"
All
"
:
{
"
P
"
:
1.0
,
"
R
"
:
1.0
,
"
F1
"
:
1.0
,
"
predicted
"
:
3
,
"
matched
"
:
3
,
"
Support
"
:
3
,
},
"
PER
"
:
{
"
P
"
:
1.0
,
"
R
"
:
1.0
,
"
F1
"
:
1.0
,
"
predicted
"
:
1
,
"
matched
"
:
1
,
"
Support
"
:
1
,
},
"
LOC
"
:
{
"
P
"
:
1.0
,
"
R
"
:
1.0
,
"
F1
"
:
1.0
,
"
predicted
"
:
2
,
"
matched
"
:
2
,
"
Support
"
:
2
,
},
},
),
),
)
def
test_run
(
test_input
,
expected
):
# print(evaluate.run(*test_input))
assert
evaluate
.
run
(
*
test_input
)
==
expected
def
test_run
(
annotation
,
prediction
,
expected
):
assert
(
evaluate
.
run
(
annotation
=
annotation
,
prediction
=
prediction
,
threshold
=
0.3
,
verbose
=
False
,
)
==
expected
)
def
test_run_empty_bio
():
def
test_run_empty_bio
(
empty_bio
):
with
pytest
.
raises
(
Exception
):
evaluate
.
run
(
EMPTY_BIO
,
EMPTY_BIO
,
THRESHOLD
)
evaluate
.
run
(
empty_bio
,
empty_bio
,
0.3
)
def
test_run_empty_entry
():
with
pytest
.
raises
(
TypeError
):
evaluate
.
run
(
None
,
None
,
THRESHOLD
)
evaluate
.
run
(
None
,
None
,
0.3
)
def
test_run_multiple
():
@pytest.mark.parametrize
(
"
threshold
"
,
([
0.3
]))
def
test_run_multiple
(
csv_file
,
folder_bio
,
threshold
):
with
pytest
.
raises
(
Exception
):
evaluate
.
run_multiple
(
CSV_FILE
,
BIO_FOLDER
,
THRESHOLD
)
evaluate
.
run_multiple
(
csv_file
,
folder_bio
,
threshold
)
This diff is collapsed.
Click to expand it.
tox.ini
+
2
−
2
View file @
2ac2b607
[tox]
envlist
=
nerval
skipsdist
=
True
[testenv
:nerval
]
[testenv]
commands
=
pytest
{posargs}
deps
=
pytest
pytest-lazy-fixture
-rrequirements.txt
This diff is collapsed.
Click to expand it.
Prev
1
2
Next
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