Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Sciencebeam Gym
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sciencebeam
Sciencebeam Gym
Commits
83506e51
Commit
83506e51
authored
7 years ago
by
Daniel Ecer
Browse files
Options
Downloads
Patches
Plain Diff
added multi threading when loading files
parent
b15a4eec
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sciencebeam_gym/models/text/crf/crfsuite_training_pipeline.py
+8
-3
8 additions, 3 deletions
...ncebeam_gym/models/text/crf/crfsuite_training_pipeline.py
with
8 additions
and
3 deletions
sciencebeam_gym/models/text/crf/crfsuite_training_pipeline.py
+
8
−
3
View file @
83506e51
...
@@ -2,6 +2,7 @@ import logging
...
@@ -2,6 +2,7 @@ import logging
import
argparse
import
argparse
import
pickle
import
pickle
from
functools
import
partial
from
functools
import
partial
from
concurrent.futures
import
ThreadPoolExecutor
from
six
import
raise_from
from
six
import
raise_from
...
@@ -117,18 +118,22 @@ def train_model(file_list, cv_file_list, page_range=None, progress=True):
...
@@ -117,18 +118,22 @@ def train_model(file_list, cv_file_list, page_range=None, progress=True):
token_props_list_by_document
=
[]
token_props_list_by_document
=
[]
total
=
len
(
file_list
)
total
=
len
(
file_list
)
with
tqdm
(
total
=
total
,
leave
=
False
,
desc
=
'
loading files
'
,
disable
=
not
progress
)
as
pbar
:
with
tqdm
(
total
=
total
,
leave
=
False
,
desc
=
'
loading files
'
,
disable
=
not
progress
)
as
pbar
:
for
filename
,
cv_filename
in
zip
(
file_list
,
cv_file_list
)
:
with
ThreadPoolExecutor
(
max_workers
=
50
)
as
executor
:
token_props_list_by_document
.
append
(
process_fn
=
lambda
(
filename
,
cv_filename
):
(
load_and_convert_to_token_props
(
filename
,
cv_filename
,
page_range
=
page_range
)
load_and_convert_to_token_props
(
filename
,
cv_filename
,
page_range
=
page_range
)
)
)
pbar
.
update
(
1
)
for
result
in
executor
.
map
(
process_fn
,
zip
(
file_list
,
cv_file_list
)):
token_props_list_by_document
.
append
(
result
)
pbar
.
update
(
1
)
X
=
[
token_props_list_to_features
(
x
)
for
x
in
token_props_list_by_document
]
X
=
[
token_props_list_to_features
(
x
)
for
x
in
token_props_list_by_document
]
y
=
[
token_props_list_to_labels
(
x
)
for
x
in
token_props_list_by_document
]
y
=
[
token_props_list_to_labels
(
x
)
for
x
in
token_props_list_by_document
]
model
=
CrfSuiteModel
()
model
=
CrfSuiteModel
()
get_logger
().
info
(
'
training model (with %d documents)
'
,
len
(
X
))
model
.
fit
(
X
,
y
)
model
.
fit
(
X
,
y
)
return
serialize_model
(
model
)
return
serialize_model
(
model
)
def
save_model
(
output_filename
,
model_bytes
):
def
save_model
(
output_filename
,
model_bytes
):
get_logger
().
info
(
'
saving model to %s
'
,
output_filename
)
save_file_content
(
output_filename
,
model_bytes
)
save_file_content
(
output_filename
,
model_bytes
)
def
run
(
opt
):
def
run
(
opt
):
...
...
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