Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
combo
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
Syntactic Tools
combo
Commits
a2137989
Commit
a2137989
authored
Nov 23, 2020
by
Mateusz Klimaszewski
Committed by
Mateusz Klimaszewski
Jan 3, 2021
Browse files
Options
Downloads
Patches
Plain Diff
Fix deps prediction for MWE expressions.
parent
422d12c6
No related branches found
No related tags found
2 merge requests
!9
Enhanced dependency parsing develop to master
,
!8
Enhanced dependency parsing
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
combo/predict.py
+6
-7
6 additions, 7 deletions
combo/predict.py
combo/utils/graph.py
+4
-4
4 additions, 4 deletions
combo/utils/graph.py
tests/utils/test_graph.py
+4
-4
4 additions, 4 deletions
tests/utils/test_graph.py
with
14 additions
and
15 deletions
combo/predict.py
+
6
−
7
View file @
a2137989
...
...
@@ -12,7 +12,7 @@ from overrides import overrides
from
combo
import
data
from
combo.data
import
sentence2conllu
,
tokens2conllu
,
conllu2sentence
from
combo.utils
import
download
from
combo.utils
import
download
,
graph
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -195,10 +195,9 @@ class SemanticMultitaskPredictor(predictor.Predictor):
raise
NotImplementedError
(
f
"
Unknown field name
{
field_name
}
!
"
)
if
"
enhanced_head
"
in
predictions
and
predictions
[
"
enhanced_head
"
]:
import
combo.utils.graph
as
graph
tree
=
graph
.
sdp_to_dag_deps
(
arc_scores
=
np
.
array
(
predictions
[
"
enhanced_head
"
]),
graph
.
sdp_to_dag_deps
(
arc_scores
=
np
.
array
(
predictions
[
"
enhanced_head
"
]),
rel_scores
=
np
.
array
(
predictions
[
"
enhanced_deprel
"
]),
tree
=
tree
,
tree_tokens
=
tree_tokens
,
root_label
=
"
ROOT
"
,
vocab_index
=
self
.
vocab
.
get_index_to_token_vocabulary
(
"
deprel_labels
"
))
...
...
This diff is collapsed.
Click to expand it.
combo/utils/graph.py
+
4
−
4
View file @
a2137989
"""
Based on https://github.com/emorynlp/iwpt-shared-task-2020.
"""
from
typing
import
List
import
numpy
as
np
from
conllu
import
TokenList
def
sdp_to_dag_deps
(
arc_scores
,
rel_scores
,
tree
:
T
okenList
,
root_label
,
vocab_index
=
None
):
def
sdp_to_dag_deps
(
arc_scores
,
rel_scores
,
tree
_t
oken
s
:
List
,
root_label
,
vocab_index
=
None
)
->
None
:
# adding ROOT
tree_tokens
=
tree
.
tokens
tree_heads
=
[
0
]
+
[
t
[
"
head
"
]
for
t
in
tree_tokens
]
graph
=
adjust_root_score_then_add_secondary_arcs
(
arc_scores
,
rel_scores
,
tree_heads
,
root_label
)
...
...
@@ -25,7 +25,7 @@ def sdp_to_dag_deps(arc_scores, rel_scores, tree: TokenList, root_label, vocab_i
deps
=
'
|
'
.
join
(
f
'
{
h
}
:
{
r
}
'
for
h
,
r
in
zip
(
heads
,
rels
))
tree_tokens
[
i
-
1
][
"
deps
"
]
=
deps
tree_tokens
[
i
-
1
][
"
deprel
"
]
=
deprel
return
tree
return
def
adjust_root_score_then_add_secondary_arcs
(
arc_scores
,
rel_labels
,
tree_heads
,
root_idx
):
...
...
This diff is collapsed.
Click to expand it.
tests/utils/test_graph.py
+
4
−
4
View file @
a2137989
...
...
@@ -26,7 +26,7 @@ class GraphTest(unittest.TestCase):
expected_deps
=
[
"
2:ROOT
"
,
"
3:yes
"
,
"
1:yes
"
]
# when
tree
=
graph
.
sdp_to_dag_deps
(
empty_graph
,
graph_labels
,
tree
,
root_label
)
graph
.
sdp_to_dag_deps
(
empty_graph
,
graph_labels
,
tree
.
tokens
,
root_label
)
actual_deps
=
[
t
[
"
deps
"
]
for
t
in
tree
.
tokens
]
# then
...
...
@@ -51,7 +51,7 @@ class GraphTest(unittest.TestCase):
expected_deps
=
[
"
2:ROOT
"
,
"
3:graph_label
"
,
"
1:graph_label
"
]
# when
tree
=
graph
.
sdp_to_dag_deps
(
empty_graph
,
graph_labels
,
tree
,
root_label
)
graph
.
sdp_to_dag_deps
(
empty_graph
,
graph_labels
,
tree
.
tokens
,
root_label
)
actual_deps
=
[
t
[
"
deps
"
]
for
t
in
tree
.
tokens
]
# then
...
...
@@ -82,7 +82,7 @@ class GraphTest(unittest.TestCase):
expected_deps
=
[
"
0:ROOT
"
,
"
1:tree_label
"
,
"
1:graph_label
"
]
# when
tree
=
graph
.
sdp_to_dag_deps
(
arc_scores
,
graph_labels
,
tree
,
root_label
)
graph
.
sdp_to_dag_deps
(
arc_scores
,
graph_labels
,
tree
.
tokens
,
root_label
)
actual_deps
=
[
t
[
"
deps
"
]
for
t
in
tree
.
tokens
]
# then
...
...
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