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
76877ba9
Commit
76877ba9
authored
2 years ago
by
umlauf
Browse files
Options
Downloads
Patches
Plain Diff
CEL + mean
parent
67e76a5c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Code/mean_deviation_results.py
+37
-13
37 additions, 13 deletions
Code/mean_deviation_results.py
Code/test_loss.py
+14
-22
14 additions, 22 deletions
Code/test_loss.py
Code/train.py
+34
-16
34 additions, 16 deletions
Code/train.py
with
85 additions
and
51 deletions
Code/mean_deviation_results.py
+
37
−
13
View file @
76877ba9
...
...
@@ -185,33 +185,57 @@ high_reloc_f1 = [0.927651139742319, 0.9285014691478942, 0.9384164222873901, 0.93
high_reloc_prec
=
[
0.9454545454545454
,
0.9349112426035503
,
0.9430255402750491
,
0.9482071713147411
,
0.9375
]
high_reloc_rec
=
[
0.9105058365758755
,
0.9221789883268483
,
0.933852140077821
,
0.9260700389105059
,
0.933852140077821
]
#MixUp:
mixup_sem_acc
=
[
0.8821585903083701
,
0.8733480176211453
,
0.8777533039647577
,
0.8821585903083701
,
0.8788546255506607
]
mixup_sem_f1
=
[
0.6805970149253731
,
0.6587537091988132
,
0.7008086253369273
,
0.6898550724637681
,
0.6944444444444444
]
mixup_sem_prec
=
[
0.7702702702702703
,
0.74
,
0.7065217391304348
,
0.7531645569620253
,
0.7225433526011561
]
mixup_sem_rec
=
[
0.6096256684491979
,
0.5935828877005348
,
0.6951871657754011
,
0.6363636363636364
,
0.6684491978609626
]
#Train
mixup_sem_acc_train
=
[
1.0
,
1.0
,
0.9987980769230769
,
0.9987980769230769
,
1.0
]
mixup_sem_f1_train
=
[
1.0
,
1.0
,
0.9970326409495549
,
0.9970326409495549
,
1.0
]
mixup_sem_prec_train
=
[
1.0
,
1.0
,
1.0
,
1.0
,
1.0
]
mixup_sem_rec_train
=
[
1.0
,
1.0
,
0.9940828402366864
,
0.9940828402366864
,
1.0
]
mixup_comp_acc
=
[
0.8087885985748219
,
0.7957244655581948
,
0.7790973871733967
,
0.7933491686460807
,
0.7957244655581948
]
mixup_comp_f1
=
[
0.7294117647058824
,
0.7034482758620688
,
0.6804123711340208
,
0.6958041958041957
,
0.7114093959731543
]
mixup_comp_prec
=
[
0.7948717948717948
,
0.7906976744186046
,
0.7615384615384615
,
0.796
,
0.7737226277372263
]
mixup_comp_rec
=
[
0.6739130434782609
,
0.6335403726708074
,
0.6149068322981367
,
0.6180124223602484
,
0.6583850931677019
]
mixup_rel_acc
=
[
0.9478435305917753
,
0.9518555667001003
,
0.9408224674022067
,
0.9438314944834504
,
0.9358074222668004
]
mixup_rel_f1
=
[
0.9488188976377954
,
0.9525691699604744
,
0.9407035175879396
,
0.9444444444444444
,
0.9357429718875502
]
mixup_rel_prec
=
[
0.9601593625498008
,
0.9678714859437751
,
0.972972972972973
,
0.9635627530364372
,
0.966804979253112
]
mixup_rel_rec
=
[
0.9377431906614786
,
0.9377431906614786
,
0.9105058365758755
,
0.9260700389105059
,
0.9066147859922179
]
# Original array
array1
=
high
_comp_acc
array1
=
mixup
_comp_acc
#array2= roberta_context_split_comp_acc
array2
=
high
_comp_f1
array3
=
high
_comp_prec
array4
=
high
_comp_rec
array2
=
mixup
_comp_f1
array3
=
mixup
_comp_prec
array4
=
mixup
_comp_rec
#print(array)
r1
=
np
.
mean
(
array1
)
f1
=
np
.
mean
(
array2
)
prec
=
np
.
mean
(
array3
)
rec
=
np
.
mean
(
array4
)
print
(
"
\n
Mean:
"
,
r1
)
print
(
"
\n
Mean:
"
,
f1
)
print
(
"
\n
Mean:
"
,
prec
)
print
(
"
\n
Mean:
"
,
rec
)
rec
=
np
.
mean
(
array4
)
print
(
"
\n
Mean
Accuracy
:
"
,
r1
)
print
(
"
\n
Mean
F1
:
"
,
f1
)
print
(
"
\n
Mean
Precision
:
"
,
prec
)
print
(
"
\n
Mean
Recall
:
"
,
rec
)
r2
=
np
.
std
(
array1
)
f1
=
np
.
std
(
array2
)
prec
=
np
.
std
(
array3
)
rec
=
np
.
std
(
array4
)
print
(
"
\n
std:
"
,
r2
)
print
(
"
\n
std:
"
,
f1
)
print
(
"
\n
std:
"
,
prec
)
print
(
"
\n
std:
"
,
rec
)
print
(
"
\n
std
Accuracy
:
"
,
r2
)
print
(
"
\n
std
F1
:
"
,
f1
)
print
(
"
\n
std
Precision
:
"
,
prec
)
print
(
"
\n
std
Recall
:
"
,
rec
)
# r3 = np.var(array1)
# f1 = np.var(array2)
...
...
This diff is collapsed.
Click to expand it.
Code/test_loss.py
+
14
−
22
View file @
76877ba9
...
...
@@ -25,10 +25,10 @@ target = torch.tensor([0.6000, 0.4000, 0.4000, 0.6000])
l
=
0.4
logits
=
torch
.
tensor
([[
0.9391
,
-
1.2892
],
[
-
0.1607
,
0.1771
],
[
-
0.1707
,
0.17871
],
[
-
0.1807
,
0.1971
]],
dtype
=
torch
.
float32
)
#one_hot = torch.zeros(target.shape[0], len(logits[1]), dtype=torch.float32)
#one_hot[torch.arange(target.shape[0]), target] = 1
print
()
results
=
torch
.
tensor
([])
for
i
in
range
(
logits
.
shape
[
0
]):
lg
=
logits
[
i
:
i
+
1
,:]
...
...
@@ -37,31 +37,23 @@ for i in range(logits.shape[0]):
value_r
=
round
(
value
,
1
)
print
(
"
Logits:
"
,
lg
)
print
(
"
Value_r
"
,
value_r
)
#integer flag ?? Für abfrag ist value int? Aber wie wenn auch 1.0 = Float?
if
value
==
1
or
value
==
0
:
one_hot
=
torch
.
tensor
([
1
-
value
,
value
])
#creating one-hot vector e.g. [0. ,1.]
loss_clear_labels
=
-
((
one_hot
[
0
]
*
logprobs
[
0
][
0
])
+
(
one_hot
[
1
]
*
logprobs
[
0
][
1
]))
print
(
"
Clear Labels Loss:
"
,
loss_clear_labels
)
#
print("Clear Labels Loss: ", loss_clear_labels)
results
=
torch
.
cat
((
loss_mixed_labels
.
view
(
1
),
results
),
dim
=
0
)
print
(
"
Results Clear Labels:
"
,
results
)
#
print("Results Clear Labels: ", results)
else
:
if
value_r
==
l
:
mixed_vec
=
torch
.
tensor
([
l
,
1
-
l
])
print
(
"
Mixed Vec:
"
,
mixed_vec
)
logprobs
=
torch
.
nn
.
functional
.
log_softmax
(
lg
,
dim
=
1
)
print
(
"
Log:
"
,
logprobs
)
#loss_mixed_labels = -torch.mul(mixed_vec, logprobs).sum()
loss_mixed_labels
=
-
((
mixed_vec
[
0
]
*
logprobs
[
0
][
0
])
+
(
mixed_vec
[
1
]
*
logprobs
[
0
][
1
]))
print
(
"
Loss Mixed Lables l:
"
,
loss_mixed_labels
)
results
=
torch
.
cat
((
loss_mixed_labels
.
view
(
1
),
results
),
dim
=
0
)
print
(
"
Results Mixed 1:
"
,
results
)
else
:
mixed_vec
=
torch
.
tensor
([
1
-
l
,
l
])
logprobs
=
torch
.
nn
.
functional
.
log_softmax
(
lg
,
dim
=
1
)
#loss_mixed_labels = -torch.mul(mixed_vec, logprobs).sum()
loss_mixed_labels
=
-
((
mixed_vec
[
0
]
*
logprobs
[
0
][
0
])
+
(
mixed_vec
[
1
]
*
logprobs
[
0
][
1
]))
print
(
"
Mixed Labels 1-l:
"
,
loss_mixed_labels
)
results
=
torch
.
cat
((
loss_mixed_labels
.
view
(
1
),
results
),
dim
=
0
)
print
(
"
Results Mixed 2:
"
,
results
)
mixed_vec
=
torch
.
tensor
([
value_r
,
1
-
value_r
])
print
(
"
Mixed Vec:
"
,
mixed_vec
)
logprobs
=
torch
.
nn
.
functional
.
log_softmax
(
lg
,
dim
=
1
)
print
(
"
Log:
"
,
logprobs
)
#loss_mixed_labels = -torch.mul(mixed_vec, logprobs).sum()
loss_mixed_labels
=
-
((
mixed_vec
[
0
]
*
logprobs
[
0
][
0
])
+
(
mixed_vec
[
1
]
*
logprobs
[
0
][
1
]))
print
(
"
Loss Mixed Lables l:
"
,
loss_mixed_labels
)
results
=
torch
.
cat
((
loss_mixed_labels
.
view
(
1
),
results
),
dim
=
0
)
print
(
"
Results Mixed 1:
"
,
results
)
print
(
"
Results all
"
,
results
)
average_loss
=
results
.
mean
()
#compute the average
print
(
"
Avg
"
,
average_loss
)
...
...
This diff is collapsed.
Click to expand it.
Code/train.py
+
34
−
16
View file @
76877ba9
...
...
@@ -139,42 +139,60 @@ def train(model, name, seed,gradient_accumulation_steps,mixup, threshold, lambda
return
evaluation_test
,
evaluation_train
#log base e
#Fkt vom Meeting
#BINARY
def
cross_entropy
(
logits
,
target
,
l
):
results
=
torch
.
tensor
([],
device
=
'
cuda
'
)
for
i
in
range
(
logits
.
shape
[
0
]):
lg
=
logits
[
i
:
i
+
1
,:]
lg
=
logits
[
i
:
i
+
1
,:]
#comment
t
=
target
[
i
]
#makes the logits in log (base e) probabilities
logprobs
=
torch
.
nn
.
functional
.
log_softmax
(
lg
,
dim
=
1
)
value
=
t
.
item
()
#gets Item (0. or 1.)
if
value
==
1
or
value
==
0
:
one_hot
=
torch
.
tensor
([
1
-
value
,
value
],
device
=
'
cuda:0
'
)
#creating one-hot vector e.g. [0. ,1.]
#class 1 and 2 mixed
loss_clear_labels
=
-
((
one_hot
[
0
]
*
logprobs
[
0
][
0
])
+
(
one_hot
[
1
]
*
logprobs
[
0
][
1
]))
#print("Clear Labels: ", loss_clear_labels)
results
=
torch
.
cat
((
loss_clear_labels
.
view
(
1
),
results
),
dim
=
0
)
#print("Results Clear Label: ", results)
else
:
value_r
=
round
(
value
,
1
)
#to make it equal to lambda_value e.g. 0.4
if
value_r
==
l
:
#create vector: e.g. [l, 1-l]
mixed_vec
=
torch
.
tensor
([
l
,
1
-
l
],
device
=
'
cuda
'
)
loss_mixed_labels_1
=
-
((
mixed_vec
[
0
]
*
logprobs
[
0
][
0
])
+
(
mixed_vec
[
1
]
*
logprobs
[
0
][
1
]))
#print("Mixed Labels1: ", loss_mixed_labels_1)
results
=
torch
.
cat
((
loss_mixed_labels_1
.
view
(
1
),
results
),
dim
=
0
)
#print("Results Mixed Label1: ", results)
else
:
mixed_vec
=
torch
.
tensor
([
1
-
l
,
l
],
device
=
'
cuda
'
)
loss_mixed_labels_2
=
-
((
mixed_vec
[
0
]
*
logprobs
[
0
][
0
])
+
(
mixed_vec
[
1
]
*
logprobs
[
0
][
1
]))
#print("Mixed Labels2: ", loss_mixed_labels_2)
results
=
torch
.
cat
((
loss_mixed_labels_2
.
view
(
1
),
results
),
dim
=
0
)
#print("Results Mixed Label2: ", results)
#Wert mit Flag
mixed_vec
=
torch
.
tensor
([
value_r
,
1
-
value_r
])
print
(
"
Mixed Vec:
"
,
mixed_vec
)
logprobs
=
torch
.
nn
.
functional
.
log_softmax
(
lg
,
dim
=
1
)
print
(
"
Log:
"
,
logprobs
)
#loss_mixed_labels = -torch.mul(mixed_vec, logprobs).sum()
loss_mixed_labels
=
-
((
mixed_vec
[
0
]
*
logprobs
[
0
][
0
])
+
(
mixed_vec
[
1
]
*
logprobs
[
0
][
1
]))
print
(
"
Loss Mixed Lables l:
"
,
loss_mixed_labels
)
results
=
torch
.
cat
((
loss_mixed_labels
.
view
(
1
),
results
),
dim
=
0
)
print
(
"
Results Mixed 1:
"
,
results
)
# if value_r == l:
# #create vector: e.g. [l, 1-l]
# mixed_vec = torch.tensor([l, 1-l], device='cuda')
# #class left class, right class?
# loss_mixed_labels_1 = -((mixed_vec[0] * logprobs[0][0]) + (mixed_vec[1] * logprobs[0][1]))
# #
# #print("Mixed Labels1: ", loss_mixed_labels_1)
# results = torch.cat((loss_mixed_labels_1.view(1), results), dim=0)
# #print("Results Mixed Label1: ", results)
# else:
# mixed_vec = torch.tensor([1-l, l], device='cuda')
# loss_mixed_labels_2 = -((mixed_vec[0] * logprobs[0][0]) + (mixed_vec[1] * logprobs[0][1]))
# #print("Mixed Labels2: ", loss_mixed_labels_2)
# results = torch.cat((loss_mixed_labels_2.view(1), results), dim=0)
# #print("Results Mixed Label2: ", results)
print
(
"
ALL BATCH Results:
"
,
results
)
batch_loss
=
results
.
mean
()
#compute average
#print("Batch Loss: ", batch_loss)
return
batch_loss
#noch in eine if schleife (beide mixed labels)
#evt. nicht immer torch.cat aufrufen
#Matrix -> 2 dim
#pro Zeile Label wenn gleich -> Standard instanz
# wenn ungleich mixed
...
...
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