Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
punctuator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nlpworkers
punctuator
Commits
fd0d1a14
Commit
fd0d1a14
authored
Aug 24, 2020
by
Michał Pogoda
Committed by
Szymon Ciombor
Aug 24, 2020
Browse files
Options
Downloads
Patches
Plain Diff
Fix non-space whitespace characters destroying predictions
parent
a588bad7
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/utils.py
+23
-1
23 additions, 1 deletion
src/utils.py
worker.py
+4
-1
4 additions, 1 deletion
worker.py
with
27 additions
and
2 deletions
src/utils.py
+
23
−
1
View file @
fd0d1a14
...
...
@@ -6,7 +6,8 @@ from typing import Optional
import
yaml
PROJECT_ROOT
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
"
/
"
.
join
(
__file__
.
split
(
"
/
"
))
+
"
/..
"
))
PROJECT_ROOT
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
"
/
"
.
join
(
__file__
.
split
(
"
/
"
))
+
"
/..
"
))
def
get_config
()
->
dict
:
...
...
@@ -52,6 +53,26 @@ def remove_punctuation(text: str) -> str:
return
""
.
join
(
filter
(
lambda
x
:
x
.
isalnum
()
or
x
.
isspace
(),
text
))
def
unify_whitespaces
(
text
:
str
)
->
str
:
"""
Maps all whitespace characters into a simple
'
'
Args:
text (str): Text containing multiple forms of whitespace
Returns:
str: Text with a single form of whitespace
"""
result
=
""
for
c
in
text
:
if
c
.
isspace
():
result
+=
"
"
else
:
result
+=
c
return
result
def
preprocess
(
text
:
str
)
->
str
:
"""
Makes sure that input is in the same format as training data (no non-alphanum chars, no double spaces,
all lowercase etc.)
...
...
@@ -63,6 +84,7 @@ def preprocess(text: str) -> str:
str: Text in training-data format
"""
text
=
remove_punctuation
(
text
)
text
=
unify_whitespaces
(
text
)
text
=
remove_multiple_spaces
(
text
)
text
=
text
.
lower
()
text
=
text
.
strip
()
...
...
This diff is collapsed.
Click to expand it.
worker.py
+
4
−
1
View file @
fd0d1a14
...
...
@@ -23,11 +23,14 @@ class Worker(nlp_ws.NLPWorker):
self
.
config
[
"
deployment
"
][
"
device
"
],
)
self
.
model
.
train
(
False
)
def
process
(
self
,
input_file
:
str
,
task_options
:
dict
,
output_file
:
str
)
->
None
:
"""
Implementation of example tasks that copies files.
"""
with
open
(
input_file
,
"
r
"
)
as
f
:
text
=
preprocess
(
f
.
read
())
text
=
str
(
f
.
read
())
text
=
preprocess
(
text
)
text_processed
=
apply_actions_punctuation
(
text
,
self
.
chunk_size
,
self
.
tokenizer
,
self
.
model
,
self
.
threshold
)
...
...
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