Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Data Augmentation for Metonymy Resolution
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
friebolin
Data Augmentation for Metonymy Resolution
Commits
8ef10463
Commit
8ef10463
authored
2 years ago
by
kulcsar
Browse files
Options
Downloads
Patches
Plain Diff
document evaluate
parent
69c97729
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Code/evaluation.py
+23
-12
23 additions, 12 deletions
Code/evaluation.py
with
23 additions
and
12 deletions
Code/evaluation.py
+
23
−
12
View file @
8ef10463
...
...
@@ -20,7 +20,19 @@ metric=evaluate.load("accuracy")
torch
.
cuda
.
empty_cache
()
def
evaluate_model
(
model
,
name
,
test_dataset
,
learning_rate
,
batch_size
,
imdb
=
False
):
def
evaluate_model
(
model
,
name
,
test_dataset
,
batch_size
,
imdb
=
False
):
"""
Evaluation for model. Iterates over test set and computes accuracy, f1, precision
and recall based on outputs of models and true labels.
Params:
model:mode -> model trained in train loop
name:str -> name of the model (for input format)
test_dataset: list of dictionaries -> test dataset
batch_size: int -> batch size for test dataset
imdb: bool -> whether or not imdb dataset is used
Returns: Accuracy, F1, Precision, Recall
"""
torch
.
cuda
.
empty_cache
()
print
(
"
eval swp
"
)
metric
=
evaluate
.
combine
([
"
accuracy
"
,
"
f1
"
,
"
precision
"
,
"
recall
"
])
...
...
@@ -55,29 +67,28 @@ def evaluate_model(model, name,test_dataset, learning_rate, batch_size, imdb=Fal
'
end_position
'
:
batch
[
3
],
'
labels
'
:
batch
[
4
]}
outputs
=
model
(
**
inputs
)
print
(
"
len of outputs:
"
,
len
(
outputs
))
print
(
"
outputs 1:
"
,
outputs
[
1
].
size
())
print
(
"
labels size:
"
,
batch
[
3
].
size
())
prediction
=
torch
.
argmax
(
outputs
[
1
],
dim
=-
1
)
print
(
"
prediciton sizes:
"
,
prediction
)
outputs
=
model
(
**
inputs
)
#get logits
prediction
=
torch
.
argmax
(
outputs
[
1
],
dim
=-
1
)
#get predictions
if
name
[
0
]
==
"
b
"
:
if
imdb
==
False
:
metric
.
add_batch
(
predictions
=
prediction
,
references
=
batch
[
5
])
else
:
print
(
"
batch 3:
"
,
batch
[
3
])
metric
.
add_batch
(
predictions
=
prediction
,
references
=
batch
[
3
])
if
name
[
0
]
==
"
r
"
:
metric
.
add_batch
(
predictions
=
prediction
,
references
=
batch
[
4
])
res
=
metric
.
compute
()
#print(f"learning rate {learning_rate}: ", res)
res
=
metric
.
compute
()
return
res
def
compute_metrics
(
eval_pred
):
print
(
"
eval salami
"
)
""""
Compute metrics function to apply predictions and references to
accuracy, f1, precision and recall, also used in salami train loop.
Params:
eval_pred: tuple ->(logits, labels)
Returns: Accuracy, F1, Precision, Recall
"""
metric
=
evaluate
.
combine
([
"
accuracy
"
,
"
f1
"
,
"
precision
"
,
"
recall
"
])
logits
,
labels
=
eval_pred
predictions
=
np
.
argmax
(
logits
,
axis
=-
1
)
...
...
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