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
8e09e336
Commit
8e09e336
authored
4 years ago
by
Mateusz Klimaszewski
Committed by
Mateusz Klimaszewski
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add restoring collapsed edges (gapping).
parent
826e57a7
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!9
Enhanced dependency parsing develop to master
,
!8
Enhanced dependency parsing
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
combo/predict.py
+2
-0
2 additions, 0 deletions
combo/predict.py
combo/utils/graph.py
+27
-0
27 additions, 0 deletions
combo/utils/graph.py
with
29 additions
and
0 deletions
combo/predict.py
+
2
−
0
View file @
8e09e336
...
...
@@ -207,6 +207,8 @@ class SemanticMultitaskPredictor(predictor.Predictor):
tree_tokens
=
tree_tokens
,
root_idx
=
self
.
vocab
.
get_token_index
(
"
root
"
,
"
deprel_labels
"
),
vocab_index
=
self
.
vocab
.
get_index_to_token_vocabulary
(
"
deprel_labels
"
))
empty_tokens
=
graph
.
restore_collapse_edges
(
tree_tokens
)
tree
.
tokens
.
extend
(
empty_tokens
)
return
tree
,
predictions
[
"
sentence_embedding
"
]
...
...
This diff is collapsed.
Click to expand it.
combo/utils/graph.py
+
27
−
0
View file @
8e09e336
...
...
@@ -85,3 +85,30 @@ def _dfs(graph, start, end):
if
next_state
in
path
:
continue
fringe
.
append
((
next_state
,
path
+
[
next_state
]))
def
restore_collapse_edges
(
tree_tokens
):
empty_tokens
=
[]
for
token
in
tree_tokens
:
deps
=
token
[
"
deps
"
].
split
(
"
|
"
)
for
i
,
d
in
enumerate
(
deps
):
if
"
>
"
in
d
:
# {head}:{empty_node_relation}>{current_node_relation}
# should map to
# For new, empty node:
# {head}:{empty_node_relation}
# For current node:
# {new_empty_node_id}:{current_node_relation}
# TODO consider where to put new_empty_node_id (currently at the end)
head
,
relation
=
d
.
split
(
'
:
'
,
1
)
ehead
=
f
"
{
len
(
tree_tokens
)
}
.
{
len
(
empty_tokens
)
+
1
}
"
empty_node_relation
,
current_node_relation
=
relation
.
split
(
"
>
"
,
1
)
deps
[
i
]
=
f
"
{
ehead
}
:
{
current_node_relation
}
"
empty_tokens
.
append
(
{
"
id
"
:
ehead
,
"
deps
"
:
f
"
{
head
}
:
{
empty_node_relation
}
"
}
)
token
[
"
deps
"
]
=
"
|
"
.
join
(
deps
)
return
empty_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