Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lambo
Manage
Activity
Members
Labels
Plan
Issues
45
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
Syntactic Tools
lambo
Commits
e31253c7
Commit
e31253c7
authored
2 years ago
by
piotrmp
Browse files
Options
Downloads
Patches
Plain Diff
Subword splitting integration in segmenter.
parent
9fcf1532
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!2
Multiword generation
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/lambo/segmenter/lambo.py
+15
-3
15 additions, 3 deletions
src/lambo/segmenter/lambo.py
src/lambo/utils/printer.py
+1
-1
1 addition, 1 deletion
src/lambo/utils/printer.py
with
16 additions
and
4 deletions
src/lambo/segmenter/lambo.py
+
15
−
3
View file @
e31253c7
...
...
@@ -30,6 +30,7 @@ class Lambo():
:param provided_name: either a full model name (``LAMBO_no_pretraining-UD_Polish-PDB``), or language name (``Polish``) or ISO 639-1 code (``pl``)
:return: LAMBO segmenter based on the expected model
"""
# TODO handle splitter here
if
'
-
'
in
provided_name
:
# It's s regular name
model_name
=
provided_name
...
...
@@ -77,9 +78,13 @@ class Lambo():
"""
model
=
torch
.
load
(
model_path
/
(
model_name
+
'
.pth
'
),
map_location
=
torch
.
device
(
'
cpu
'
))
dict
=
Lambo
.
read_dict
(
model_path
/
(
model_name
+
'
.dict
'
))
return
cls
(
model
,
dict
)
splitter
=
None
if
(
model_path
/
(
model_name
+
'
_subwords.pth
'
)).
exists
():
from
lambo.subwords.splitter
import
LamboSplitter
splitter
=
LamboSplitter
.
from_path
(
model_path
,
model_name
)
return
cls
(
model
,
dict
,
splitter
)
def
__init__
(
self
,
model
,
dict
):
def
__init__
(
self
,
model
,
dict
,
splitter
=
None
):
"""
Create a new LAMBO segmenter from a given model and dictionary.
...
...
@@ -88,6 +93,7 @@ class Lambo():
"""
self
.
model
=
model
self
.
dict
=
dict
self
.
splitter
=
splitter
@staticmethod
def
read_dict
(
dict_path
):
...
...
@@ -150,7 +156,7 @@ class Lambo():
Perform the segmentation of the text. This involves:
* splitting the document into turns using turn markers from ``turn_regexp.txt``
* splitting the turns into sentences and tokens according to the model
'
s predictions
* splitting the turns into sentences and tokens according to the model
'
s predictions
(including splitting into subwords)
* modifying the output to account for special tokens (emojis and pauses)
:param text: input text
...
...
@@ -223,6 +229,12 @@ class Lambo():
if
token_end
:
# End of token
token
=
Token
(
turn_offset
+
token_begin
,
turn_offset
+
i
+
1
,
text
[
token_begin
:(
i
+
1
)],
mwtoken_end
)
if
mwtoken_end
:
subwords
=
self
.
splitter
.
split
(
token
.
text
)
if
len
(
subwords
)
==
1
:
token
.
is_multi_word
=
False
else
:
token
.
subwords
=
subwords
sentence
.
add_token
(
token
)
token_begin
=
-
1
if
sentence_end
:
...
...
This diff is collapsed.
Click to expand it.
src/lambo/utils/printer.py
+
1
−
1
View file @
e31253c7
...
...
@@ -20,7 +20,7 @@ def print_document_to_screen(document):
formatted
=
''
for
token
in
sentence
.
tokens
:
if
token
.
is_multi_word
:
formatted
+=
'
(
'
+
token
.
text
+
'
=
'
+
'
-
'
.
join
(
token
.
words
)
+
'
)
'
formatted
+=
'
(
'
+
token
.
text
+
'
=
'
+
'
-
'
.
join
(
token
.
sub
words
)
+
'
)
'
else
:
formatted
+=
'
(
'
+
token
.
text
+
'
)
'
print
(
'
TOKENS:
'
+
formatted
)
...
...
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