Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PSTAL étudiant.e.s
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Carlos Ramisch
PSTAL étudiant.e.s
Commits
127f0b3b
Commit
127f0b3b
authored
6 months ago
by
Carlos Ramisch
Browse files
Options
Downloads
Patches
Plain Diff
Add option to build character instead of word vocabulary
parent
452f2211
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/conllulib.py
+7
-2
7 additions, 2 deletions
lib/conllulib.py
with
7 additions
and
2 deletions
lib/conllulib.py
+
7
−
2
View file @
127f0b3b
...
@@ -195,7 +195,7 @@ class CoNLLUReader(object):
...
@@ -195,7 +195,7 @@ class CoNLLUReader(object):
###############################
###############################
def
to_int_and_vocab
(
self
,
col_name_dict
,
extra_cols_dict
=
{}):
def
to_int_and_vocab
(
self
,
col_name_dict
,
extra_cols_dict
=
{}
,
chars
=
False
):
"""
"""
Transforms open `self.infile` into lists of integer indices and associated
Transforms open `self.infile` into lists of integer indices and associated
vocabularies. Vocabularies are created on the fly, according to the file
vocabularies. Vocabularies are created on the fly, according to the file
...
@@ -210,6 +210,7 @@ class CoNLLUReader(object):
...
@@ -210,6 +210,7 @@ class CoNLLUReader(object):
extra_cols_dict = {
"
head
"
:int}
extra_cols_dict = {
"
head
"
:int}
means that column
"
head
"
will also be encoded, but with no vocabulary
means that column
"
head
"
will also be encoded, but with no vocabulary
associated. Instead, column values are directly encoded with function int.
associated. Instead, column values are directly encoded with function int.
`chars` will build a character vocabulary instead of words.
Returns a tuple of 2 dicts, `int_list` and `vocab`, with same keys as those
Returns a tuple of 2 dicts, `int_list` and `vocab`, with same keys as those
in `col_name_dict` and `extra_cols_dict`, and results as values (list of
in `col_name_dict` and `extra_cols_dict`, and results as values (list of
integers and vocabulary dict, respectively)
\
integers and vocabulary dict, respectively)
\
...
@@ -228,6 +229,10 @@ class CoNLLUReader(object):
...
@@ -228,6 +229,10 @@ class CoNLLUReader(object):
for
s
in
self
.
readConllu
():
for
s
in
self
.
readConllu
():
# IMPORTANT : only works if "col_name" is the same as in lambda function definition!
# IMPORTANT : only works if "col_name" is the same as in lambda function definition!
for
col_name
in
col_name_dict
.
keys
():
for
col_name
in
col_name_dict
.
keys
():
if
chars
:
for
tok
in
s
:
int_list
[
col_name
].
append
([
vocab
[
col_name
][
c
]
for
c
in
tok
[
col_name
]])
else
:
int_list
[
col_name
].
append
([
vocab
[
col_name
][
tok
[
col_name
]]
for
tok
in
s
])
int_list
[
col_name
].
append
([
vocab
[
col_name
][
tok
[
col_name
]]
for
tok
in
s
])
for
col_name
,
col_fct
in
extra_cols_dict
.
items
():
for
col_name
,
col_fct
in
extra_cols_dict
.
items
():
int_list
[
col_name
].
append
(
list
(
map
(
col_fct
,
[
tok
[
col_name
]
for
tok
in
s
])))
int_list
[
col_name
].
append
(
list
(
map
(
col_fct
,
[
tok
[
col_name
]
for
tok
in
s
])))
...
...
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