Skip to content

Commit 3fb7a8c

Browse files
committed
Add warnings to eval.jl
Deprecate eval_SC_chucks in favour of eval_SC_chunks (fixing typo) and adding warning regarding homophones/homographs in accuracy_comprehension
1 parent 4c320e4 commit 3fb7a8c

File tree

1 file changed

+68
-20
lines changed

1 file changed

+68
-20
lines changed

src/eval.jl

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ function eval_SC_loose end
2525
"""
2626
accuracy_comprehension(S, Shat, data)
2727
28-
Evaluate comprehension accuracy.
28+
Evaluate comprehension accuracy for training data.
29+
NOTE: in case of homophones/homographs in the dataset, the correct/incorrect values for base and inflections may be misleading! See below for more information.
2930
3031
# Obligatory Arguments
3132
- `S::Matrix`: the (gold standard) S matrix
@@ -47,16 +48,19 @@ accuracy_comprehension(
4748
base=[:Lexeme],
4849
inflections=[:Person, :Number, :Tense, :Voice, :Mood]
4950
)
50-
51-
accuracy_comprehension(
52-
S_val,
53-
Shat_val,
54-
latin_train,
55-
target_col=:Words,
56-
base=["Lexeme"],
57-
inflections=[:Person, :Number, :Tense, :Voice, :Mood]
58-
)
5951
```
52+
53+
# Note
54+
In case of homophones/homographs in the dataset, the correct/incorrect values for base and inflections may be misleading!
55+
Consider the following example: The wordform "Äpfel" in German can be nominative plural, genitive plural and accusative plural.
56+
Let's assume we have a dataset in which "Äpfel" occurs in all three case/number combinations (i.e. there are homographs).
57+
If all these wordforms have the same semantic vectors (e.g. because they are derived from word2vec or fasttext which typically
58+
have a single vector per unique wordform), the predicted semantic vector of the wordform "Äpfel" will be equally correlated
59+
with all three case/number combinations in the dataset. In such cases, while the algorithm in this function can unambiguously
60+
conclude that the correct surface form "Äpfel" was comprehended, which of the three possible rows is the correct one will be
61+
picked somewhat non-deterministically (see https://docs.julialang.org/en/v1/base/collections/#Base.argmax). It is thus possible
62+
that the algorithm will then use the genitive plural instead of the intended nominative plural as the ground plural, and will
63+
report that "case" was comprehended incorrectly.
6064
"""
6165
function accuracy_comprehension(
6266
S,
@@ -78,10 +82,16 @@ function accuracy_comprehension(
7882
dfr.r_target = corMat[diagind(corMat)]
7983
dfr.correct = [dfr.target[i] == dfr.form[i] for i = 1:size(dfr, 1)]
8084

85+
if length(data[:, target_col]) != length(Set(data[:, target_col]))
86+
@warn "This dataset contains homophones/homographs. Note that some of the results on the correctness of comprehended base/inflections may be misleading. See documentation of this function for more information."
87+
end
88+
8189
if !isnothing(inflections)
8290
all_features = vcat(base, inflections)
83-
else
91+
elseif !isnothing(base)
8492
all_features = base
93+
else
94+
all_features = []
8595
end
8696

8797
for f in all_features
@@ -110,7 +120,9 @@ end
110120
inflections = nothing,
111121
)
112122
113-
Evaluate comprehension accuracy.
123+
Evaluate comprehension accuracy for validation data.
124+
NOTE: in case of homophones/homographs in the dataset, the correct/incorrect values for base and inflections may be misleading! See below for more information.
125+
114126
115127
# Obligatory Arguments
116128
- `S_val::Matrix`: the (gold standard) S matrix of the validation data
@@ -137,6 +149,18 @@ accuracy_comprehension(
137149
inflections=[:Person, :Number, :Tense, :Voice, :Mood]
138150
)
139151
```
152+
153+
# Note
154+
In case of homophones/homographs in the dataset, the correct/incorrect values for base and inflections may be misleading!
155+
Consider the following example: The wordform "Äpfel" in German can be nominative plural, genitive plural and accusative plural.
156+
Let's assume we have a dataset in which "Äpfel" occurs in all three case/number combinations (i.e. there are homographs).
157+
If all these wordforms have the same semantic vectors (e.g. because they are derived from word2vec or fasttext which typically
158+
have a single vector per unique wordform), the predicted semantic vector of the wordform "Äpfel" will be equally correlated
159+
with all three case/number combinations in the dataset. In such cases, while the algorithm in this function can unambiguously
160+
conclude that the correct surface form "Äpfel" was comprehended, which of the three possible rows is the correct one will be
161+
picked somewhat non-deterministically (see https://docs.julialang.org/en/v1/base/collections/#Base.argmax). It is thus possible
162+
that the algorithm will then use the genitive plural instead of the intended nominative plural as the ground plural, and will
163+
report that "case" was comprehended incorrectly.
140164
"""
141165
function accuracy_comprehension(
142166
S_val,
@@ -160,6 +184,10 @@ function accuracy_comprehension(
160184

161185
append!(data_combined, data_train, promote=true)
162186

187+
if length(data_combined[:, target_col]) != length(Set(data_combined[:, target_col]))
188+
@warn "This dataset contains homophones/homographs. Note that some of the results on the correctness of comprehended base/inflections may be misleading. See documentation of this function for more information."
189+
end
190+
163191
corMat = cor(Shat_val, S, dims = 2)
164192
top_index = [i[2] for i in argmax(corMat, dims = 2)]
165193

@@ -435,7 +463,7 @@ function eval_SC(
435463

436464
# for first parts
437465
for j = 1:num_chucks-1
438-
correct += eval_SC_chucks(
466+
correct += eval_SC_chunks(
439467
SChat_d,
440468
SC_d,
441469
(j - 1) * batch_size + 1,
@@ -445,7 +473,7 @@ function eval_SC(
445473
verbose && ProgressMeter.next!(pb)
446474
end
447475
# for last part
448-
correct += eval_SC_chucks(
476+
correct += eval_SC_chunks(
449477
SChat_d,
450478
SC_d,
451479
(num_chucks - 1) * batch_size + 1,
@@ -504,7 +532,7 @@ function eval_SC(
504532

505533
# for first parts
506534
for j = 1:num_chucks-1
507-
correct += eval_SC_chucks(
535+
correct += eval_SC_chunks(
508536
SChat_d,
509537
SC_d,
510538
(j - 1) * batch_size + 1,
@@ -516,7 +544,7 @@ function eval_SC(
516544
verbose && ProgressMeter.next!(pb)
517545
end
518546
# for last part
519-
correct += eval_SC_chucks(
547+
correct += eval_SC_chunks(
520548
SChat_d,
521549
SC_d,
522550
(num_chucks - 1) * batch_size + 1,
@@ -529,13 +557,18 @@ function eval_SC(
529557
round(correct / l, digits=digits)
530558
end
531559

532-
function eval_SC_chucks(SChat, SC, s, e, batch_size)
560+
function eval_SC_chunks(SChat, SC, s, e, batch_size)
533561
rSC = cor(SChat[s:e, :], SC, dims = 2)
534562
v = [(rSC[i[1], i[1]+s-1] == rSC[i]) ? 1 : 0 for i in argmax(rSC, dims = 2)]
535563
sum(v)
536564
end
537565

538-
function eval_SC_chucks(SChat, SC, s, e, batch_size, data, target_col)
566+
function eval_SC_chucks(SChat, SC, s, e, batch_size)
567+
@warn "eval_SC_chucks is deprecated and will be removed in version 0.10 in favour of eval_SC_chunks"
568+
eval_SC_chunks(SChat, SC, s, e, batch_size)
569+
end
570+
571+
function eval_SC_chunks(SChat, SC, s, e, batch_size, data, target_col)
539572
rSC = cor(SChat[s:e, :], SC, dims = 2)
540573
v = [
541574
data[i[1]+s-1, target_col] == data[i[2], target_col] ? 1 : 0
@@ -544,13 +577,23 @@ function eval_SC_chucks(SChat, SC, s, e, batch_size, data, target_col)
544577
sum(v)
545578
end
546579

547-
function eval_SC_chucks(SChat, SC, s, batch_size)
580+
function eval_SC_chucks(SChat, SC, s, e, batch_size, data, target_col)
581+
@warn "eval_SC_chucks is deprecated and will be removed in version 0.10 in favour of eval_SC_chunks"
582+
eval_SC_chunks(SChat, SC, s, e, batch_size, data, target_col)
583+
end
584+
585+
function eval_SC_chunks(SChat, SC, s, batch_size)
548586
rSC = cor(SChat[s:end, :], SC, dims = 2)
549587
v = [(rSC[i[1], i[1]+s-1] == rSC[i]) ? 1 : 0 for i in argmax(rSC, dims = 2)]
550588
sum(v)
551589
end
552590

553-
function eval_SC_chucks(SChat, SC, s, batch_size, data, target_col)
591+
function eval_SC_chucks(SChat, SC, s, batch_size)
592+
@warn "eval_SC_chucks is deprecated and will be removed in version 0.10 in favour of eval_SC_chunks"
593+
eval_SC_chunks(SChat, SC, s, batch_size)
594+
end
595+
596+
function eval_SC_chunks(SChat, SC, s, batch_size, data, target_col)
554597
rSC = cor(SChat[s:end, :], SC, dims = 2)
555598
v = [
556599
data[i[1]+s-1, target_col] == data[i[2], target_col] ? 1 : 0
@@ -559,6 +602,11 @@ function eval_SC_chucks(SChat, SC, s, batch_size, data, target_col)
559602
sum(v)
560603
end
561604

605+
function eval_SC_chucks(SChat, SC, s, batch_size, data, target_col)
606+
@warn "eval_SC_chucks is deprecated and will be removed in version 0.10 in favour of eval_SC_chunks"
607+
eval_SC_chunks(SChat, SC, s, batch_size, data, target_col)
608+
end
609+
562610
"""
563611
eval_SC_loose(SChat, SC, k)
564612

0 commit comments

Comments
 (0)