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
a2137989
Commit
a2137989
authored
4 years ago
by
Mateusz Klimaszewski
Committed by
Mateusz Klimaszewski
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix deps prediction for MWE expressions.
parent
422d12c6
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!9
Enhanced dependency parsing develop to master
,
!8
Enhanced dependency parsing
Changes
3
Hide 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,12 +195,11 @@ 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
"
]),
rel_scores
=
np
.
array
(
predictions
[
"
enhanced_deprel
"
]),
tree
=
tree
,
root_label
=
"
ROOT
"
,
vocab_index
=
self
.
vocab
.
get_index_to_token_vocabulary
(
"
deprel_labels
"
))
graph
.
sdp_to_dag_deps
(
arc_scores
=
np
.
array
(
predictions
[
"
enhanced_head
"
]),
rel_scores
=
np
.
array
(
predictions
[
"
enhanced_deprel
"
]),
tree_tokens
=
tree_tokens
,
root_label
=
"
ROOT
"
,
vocab_index
=
self
.
vocab
.
get_index_to_token_vocabulary
(
"
deprel_labels
"
))
return
tree
,
predictions
[
"
sentence_embedding
"
]
...
...
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,8 +82,8 @@ 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
self
.
assertEqual
(
actual_deps
,
expected_deps
)
\ No newline at end of file
self
.
assertEqual
(
actual_deps
,
expected_deps
)
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