Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
combo
Manage
Activity
Members
Labels
Plan
Issues
20
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
2
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
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
combo
Commits
142eead6
Commit
142eead6
authored
1 year ago
by
Maja Jablonska
Browse files
Options
Downloads
Patches
Plain Diff
Add an option to ignore turns in text segmentation
parent
1e1002f5
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!46
Merge COMBO 3.0 into master
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
combo/data/tokenizers/lambo_tokenizer.py
+10
-3
10 additions, 3 deletions
combo/data/tokenizers/lambo_tokenizer.py
combo/main.py
+5
-3
5 additions, 3 deletions
combo/main.py
tests/data/tokenizers/test_lambo_tokenizer.py
+8
-0
8 additions, 0 deletions
tests/data/tokenizers/test_lambo_tokenizer.py
with
23 additions
and
6 deletions
combo/data/tokenizers/lambo_tokenizer.py
+
10
−
3
View file @
142eead6
...
...
@@ -34,10 +34,11 @@ class LamboTokenizer(Tokenizer):
return
tokens
def
segment
(
self
,
text
:
str
)
->
List
[
List
[
str
]]:
def
segment
(
self
,
text
:
str
,
turns
:
bool
=
False
)
->
List
[
List
[
str
]]:
"""
Full segmentation - segment into sentences
Full segmentation - segment into sentences
.
:param text:
:param turns: segment into sentences by splitting on sentences or on turns. Default: sentences.
:return:
"""
...
...
@@ -46,13 +47,19 @@ class LamboTokenizer(Tokenizer):
sentence_tokens
=
[]
for
turn
in
document
.
turns
:
for
sentence
in
turn
.
sentence
s
:
if
turn
s
:
sentence_tokens
=
[]
for
sentence
in
turn
.
sentences
:
if
not
turns
:
sentence_tokens
=
[]
for
token
in
sentence
.
tokens
:
if
len
(
token
.
subwords
)
>
0
:
sentence_tokens
.
extend
([
s
for
s
in
token
.
subwords
])
else
:
sentence_tokens
.
append
(
token
.
text
)
if
not
turns
:
sentences
.
append
(
sentence_tokens
)
if
turns
:
sentences
.
append
(
sentence_tokens
)
return
sentences
This diff is collapsed.
Click to expand it.
combo/main.py
+
5
−
3
View file @
142eead6
...
...
@@ -78,10 +78,10 @@ flags.DEFINE_string(name="tensorboard_name", default="combo",
help
=
"
Name of the model in TensorBoard logs.
"
)
flags
.
DEFINE_string
(
name
=
"
config_path
"
,
default
=
""
,
help
=
"
Config file path.
"
)
flags
.
DEFINE_boolean
(
name
=
"
save_matrices
"
,
default
=
True
,
help
=
"
Save relation distribution matrices.
"
)
flags
.
DEFINE_list
(
name
=
"
datasets_for_vocabulary
"
,
default
=
[
"
train
"
],
help
=
""
)
flags
.
DEFINE_boolean
(
name
=
"
turns
"
,
default
=
False
,
help
=
"
Segment into sentences on sentence break or on turn break.
"
)
# Finetune after training flags
flags
.
DEFINE_string
(
name
=
"
finetuning_training_data_path
"
,
default
=
""
,
...
...
@@ -107,6 +107,8 @@ flags.DEFINE_boolean(name="finetuning", default=False,
help
=
"
Finetuning mode for training.
"
)
flags
.
DEFINE_string
(
name
=
"
tokenizer_language
"
,
default
=
"
English
"
,
help
=
"
Tokenizer language.
"
)
flags
.
DEFINE_boolean
(
name
=
"
save_matrices
"
,
default
=
True
,
help
=
"
Save relation distribution matrices.
"
)
flags
.
DEFINE_enum
(
name
=
"
predictor_name
"
,
default
=
"
combo-lambo
"
,
enum_values
=
[
"
combo
"
,
"
combo-spacy
"
,
"
combo-lambo
"
],
help
=
"
Use predictor with whitespace, spacy or lambo (recommended) tokenizer.
"
)
...
...
@@ -434,7 +436,7 @@ def run(_):
else
:
tokenizer
=
LamboTokenizer
(
tokenizer_language
)
with
open
(
FLAGS
.
input_file
,
"
r
"
,
encoding
=
'
utf-8
'
)
as
file
:
input_sentences
=
tokenizer
.
segment
(
file
.
read
())
input_sentences
=
tokenizer
.
segment
(
file
.
read
()
,
turns
=
FLAGS
.
turns
)
predictions
=
predictor
.
predict
(
input_sentences
)
with
open
(
FLAGS
.
output_file
,
"
w
"
)
as
file
:
for
prediction
in
tqdm
(
predictions
):
...
...
This diff is collapsed.
Click to expand it.
tests/data/tokenizers/test_lambo_tokenizer.py
+
8
−
0
View file @
142eead6
...
...
@@ -13,6 +13,14 @@ class LamboTokenizerTest(unittest.TestCase):
self
.
assertListEqual
([
t
.
text
for
t
in
tokens
],
[
'
Hello
'
,
'
cats
'
,
'
.
'
,
'
I
'
,
'
love
'
,
'
you
'
])
def
test_segment_text
(
self
):
tokens
=
self
.
lambo_tokenizer
.
segment
(
'
Hello cats. I love you.
\n\n
Hi.
'
)
self
.
assertListEqual
(
tokens
,
[[
'
Hello
'
,
'
cats
'
,
'
.
'
],
[
'
I
'
,
'
love
'
,
'
you
'
,
'
.
'
],
[
'
Hi
'
,
'
.
'
]])
def
test_segment_text_with_turns
(
self
):
tokens
=
self
.
lambo_tokenizer
.
segment
(
'
Hello cats. I love you.
\n\n
Hi.
'
,
turns
=
True
)
self
.
assertListEqual
(
tokens
,
[[
'
Hello
'
,
'
cats
'
,
'
.
'
,
'
I
'
,
'
love
'
,
'
you
'
,
'
.
'
],
[
'
Hi
'
,
'
.
'
]])
def
test_tokenize_sentence_with_multiword
(
self
):
tokens
=
self
.
lambo_tokenizer
.
tokenize
(
'
I don
\'
t like apples.
'
)
self
.
assertListEqual
([
t
.
text
for
t
in
tokens
],
...
...
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