Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
emoUS-public
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
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
general
dsml
emoUS-public
Commits
2a4e214b
Commit
2a4e214b
authored
3 years ago
by
zqwerty
Browse files
Options
Downloads
Patches
Plain Diff
add dst unified evaluate
parent
731a92b3
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
convlab2/dst/evaluate_unified_datasets.py
+50
-0
50 additions, 0 deletions
convlab2/dst/evaluate_unified_datasets.py
with
50 additions
and
0 deletions
convlab2/dst/evaluate_unified_datasets.py
0 → 100644
+
50
−
0
View file @
2a4e214b
import
json
from
pprint
import
pprint
def
evaluate
(
predict_result
):
predict_result
=
json
.
load
(
open
(
predict_result
))
metrics
=
{
'
TP
'
:
0
,
'
FP
'
:
0
,
'
FN
'
:
0
}
acc
=
[]
for
sample
in
predict_result
:
pred_state
=
sample
[
'
predictions
'
][
'
state
'
]
gold_state
=
sample
[
'
state
'
]
predicts
=
sorted
(
list
({(
domain
,
slot
,
''
.
join
(
value
.
split
()).
lower
())
for
domain
in
pred_state
for
slot
,
value
in
pred_state
[
domain
].
items
()
if
len
(
value
)
>
0
}))
labels
=
sorted
(
list
({(
domain
,
slot
,
''
.
join
(
value
.
split
()).
lower
())
for
domain
in
gold_state
for
slot
,
value
in
gold_state
[
domain
].
items
()
if
len
(
value
)
>
0
}))
flag
=
True
for
ele
in
predicts
:
if
ele
in
labels
:
metrics
[
'
TP
'
]
+=
1
else
:
metrics
[
'
FP
'
]
+=
1
for
ele
in
labels
:
if
ele
not
in
predicts
:
metrics
[
'
FN
'
]
+=
1
flag
&=
(
predicts
==
labels
)
acc
.
append
(
flag
)
TP
=
metrics
.
pop
(
'
TP
'
)
FP
=
metrics
.
pop
(
'
FP
'
)
FN
=
metrics
.
pop
(
'
FN
'
)
precision
=
1.0
*
TP
/
(
TP
+
FP
)
if
TP
+
FP
else
0.
recall
=
1.0
*
TP
/
(
TP
+
FN
)
if
TP
+
FN
else
0.
f1
=
2.0
*
precision
*
recall
/
(
precision
+
recall
)
if
precision
+
recall
else
0.
metrics
[
f
'
slot_f1
'
]
=
f1
metrics
[
f
'
slot_precision
'
]
=
precision
metrics
[
f
'
slot_recall
'
]
=
recall
metrics
[
'
accuracy
'
]
=
sum
(
acc
)
/
len
(
acc
)
return
metrics
if
__name__
==
'
__main__
'
:
from
argparse
import
ArgumentParser
parser
=
ArgumentParser
(
description
=
"
calculate DST metrics for unified datasets
"
)
parser
.
add_argument
(
'
--predict_result
'
,
'
-p
'
,
type
=
str
,
required
=
True
,
help
=
'
path to the prediction file that in the unified data format
'
)
args
=
parser
.
parse_args
()
print
(
args
)
metrics
=
evaluate
(
args
.
predict_result
)
pprint
(
metrics
)
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