Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
winer
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nlpworkers
winer
Commits
16b95b53
Commit
16b95b53
authored
1 year ago
by
Paweł Walkowiak
Browse files
Options
Downloads
Plain Diff
Merge branch 'update-to-0.7' into 'master'
Update to 0.7 See merge request
!8
parents
9f17e626
17aef862
Branches
Branches containing commit
1 merge request
!8
Update to 0.7
Pipeline
#14571
passed with stages
Stage:
Stage:
in 14 minutes and 34 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
requirements.txt
+1
-1
1 addition, 1 deletion
requirements.txt
src/winer_worker.py
+30
-24
30 additions, 24 deletions
src/winer_worker.py
with
31 additions
and
25 deletions
requirements.txt
+
1
−
1
View file @
16b95b53
--index-url https://pypi.clarin-pl.eu/simple/
nlp_ws
winer
==0.
6.2
post
7
winer
==0.
7.4
post
1
awscli
==1.22.57
PyYAML
==5.3.1
This diff is collapsed.
Click to expand it.
src/winer_worker.py
+
30
−
24
View file @
16b95b53
"""
Winer worker implementation.
"""
from
winer
import
Winer
,
allign_into_entities
from
winer.io
import
(
create_document_from_
clarin_json
,
create_entities_from_hf_outputs
,
read_clarin_json
,
extend_clarin_json
)
from
winer
import
Winer
,
allign_into_entities
,
get_sentences_from_document
import
clarin_json
from
clarin_json.containers
import
Span
import
nlp_ws
import
logging
_log
=
logging
.
getLogger
(
__name__
)
class
WinerWorker
(
nlp_ws
.
NLPWorker
):
...
...
@@ -24,7 +25,7 @@ class WinerWorker(nlp_ws.NLPWorker):
def
__init__
(
self
):
"""
Constructor.
"""
log
ging
.
info
(
"
Loading models...
"
)
_
log
.
info
(
"
Loading models...
"
)
self
.
_model
=
Winer
(
self
.
models_location
,
batch_size
=
self
.
batch_size
)
self
.
_model
.
_tokenizer
.
model_max_length
=
512
...
...
@@ -46,25 +47,30 @@ class WinerWorker(nlp_ws.NLPWorker):
worker will store result.
:type output_path: str
"""
# Read inputs
documents
=
[
read_clarin_json
(
input_path
)]
dto_documents
=
\
[
create_document_from_clarin_json
(
document
)
for
document
in
documents
]
tok_inputs
=
\
[
document
.
get_pretokenized_text
()
for
document
in
dto_documents
]
plain_inputs
=
[
document
.
get_text
()
for
document
in
dto_
document
s
]
# Read inputs
and open output
F_ASCII
=
task_options
.
get
(
"
ensure_ascii
"
,
False
)
with
clarin_json
.
open
(
output_path
,
"
w
"
,
ensure_ascii
=
F_ASCII
)
as
fout
:
with
clarin_json
.
open
(
input_path
,
"
r
"
)
as
fin
:
for
document
in
fin
:
# Pre-process document
plain_inputs
,
tokenized_inputs
,
sent_starts
=
\
get_sentences_from_document
(
document
)
# Process data
aggregations
=
self
.
_model
.
process
(
tok_inputs
)
# Process data
aggregations
=
self
.
_model
.
process
(
tok
enized
_inputs
)
# Aggregate results to entities.
entities
=
allign_into_entities
(
tok_inputs
,
aggregations
,
inputs_sentences
=
plain_inputs
)
# Aggregate results to entities
entities
=
allign_into_entities
(
tokenized_inputs
,
aggregations
,
inputs_sentences
=
plain_inputs
,
sentences_range
=
sent_starts
)
document
.
set_spans
(
[
Span
(
**
entity
)
for
sent_entities
in
entities
for
entity
in
sent_entities
],
"
ner
"
)
for
document
,
doc_entities
in
zip
(
documents
,
entities
):
extend_clarin_json
(
output_path
.
replace
(
'
.json
'
,
'
.clarin.json
'
),
document
,
create_entities_from_hf_outputs
(
doc_entities
)
)
# Write processed document
fout
.
write
(
document
)
This diff is collapsed.
Click to expand it.
Preview
0%
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