Skip to content

Commit 7c061ad

Browse files
committed
Add warnings about homophones to eval_SC and eval_SC_loose
1 parent fc159fe commit 7c061ad

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

src/eval.jl

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function accuracy_comprehension(
8585
dfr.correct = [dfr.target[i] == dfr.form[i] for i = 1:size(dfr, 1)]
8686

8787
if length(data[:, target_col]) != length(Set(data[:, target_col]))
88-
@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."
88+
@warn "accuracy_comprehension: 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."
8989
end
9090

9191
if !isnothing(inflections)
@@ -189,7 +189,7 @@ function accuracy_comprehension(
189189
append!(data_combined, data_train, promote=true)
190190

191191
if length(data_combined[:, target_col]) != length(Set(data_combined[:, target_col]))
192-
@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."
192+
@warn "accuracy_comprehension: 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."
193193
end
194194

195195
corMat = cor(Shat_val, S, dims = 2)
@@ -232,6 +232,9 @@ Assess model accuracy on the basis of the correlations of row vectors of Chat an
232232
C or Shat and S. Ideally the target words have highest correlations on the diagonal
233233
of the pertinent correlation matrices.
234234
235+
!!! note
236+
If there are homophones/homographs in the dataset, this evaluation method may be misleading: the predicted vector will be equally correlated with the target vector of both words and the one on the diagonal will not necessarily be selected as the most correlated. In such cases, supplying the dataset and `target_col` is recommended which enables taking into account homophones/homographs.
237+
235238
# Obligatory Arguments
236239
- `SChat::Union{SparseMatrixCSC, Matrix}`: the Chat or Shat matrix
237240
- `SC::Union{SparseMatrixCSC, Matrix}`: the C or S matrix
@@ -248,6 +251,11 @@ eval_SC(Shat_val, S_val)
248251
```
249252
"""
250253
function eval_SC(SChat::AbstractArray, SC::AbstractArray; digits=4, R=false)
254+
255+
if size(unique(SC, dims=1), 1) != size(SC, 1)
256+
@warn "eval_SC: The C or S matrix contains duplicate vectors (usually because of homophones/homographs). Supplying the dataset and target column is recommended for a realistic evaluation. See the documentation of this function for more information."
257+
end
258+
251259
rSC = cor(
252260
convert(Matrix{Float64}, SChat),
253261
convert(Matrix{Float64}, SC),
@@ -273,6 +281,9 @@ of the pertinent correlation matrices.
273281
The order is important. The fist gold standard matrix has to be corresponing
274282
to the SChat matrix, such as `eval_SC(Shat_train, S_train, S_val)` or `eval_SC(Shat_val, S_val, S_train)`
275283
284+
!!! note
285+
If there are homophones/homographs in the dataset, this evaluation method may be misleading: the predicted vector will be equally correlated with the target vector of both words and the one on the diagonal will not necessarily be selected as the most correlated. In such cases, supplying the dataset and target_col is recommended which enables taking into account homophones/homographs.
286+
276287
# Obligatory Arguments
277288
- `SChat::Union{SparseMatrixCSC, Matrix}`: the Chat or Shat matrix
278289
- `SC::Union{SparseMatrixCSC, Matrix}`: the training/validation C or S matrix
@@ -427,7 +438,10 @@ end
427438
Assess model accuracy on the basis of the correlations of row vectors of Chat and
428439
C or Shat and S. Ideally the target words have highest correlations on the diagonal
429440
of the pertinent correlation matrices. For large datasets, pass batch_size to
430-
process evaluation in chucks.
441+
process evaluation in chunks.
442+
443+
!!! note
444+
If there are homophones/homographs in the dataset, this evaluation method may be misleading: the predicted vector will be equally correlated with the target vector of both words and the one on the diagonal will not necessarily be selected as the most correlated. In such cases, supplying the dataset and target_col is recommended which enables taking into account homophones/homographs.
431445
432446
# Obligatory Arguments
433447
- `SChat`: the Chat or Shat matrix
@@ -455,6 +469,10 @@ function eval_SC(
455469
verbose = false
456470
)
457471

472+
if size(unique(SC, dims=1), 1) != size(SC, 1)
473+
@warn "eval_SC: The C or S matrix contains duplicate vectors (usually because of homophones/homographs). Supplying the dataset and target column is recommended for a realistic evaluation. See the documentation of this function for more information."
474+
end
475+
458476
l = size(SChat, 1)
459477
num_chucks = ceil(Int64, l / batch_size)
460478
verbose && begin
@@ -494,7 +512,7 @@ end
494512
Assess model accuracy on the basis of the correlations of row vectors of Chat and
495513
C or Shat and S. Ideally the target words have highest correlations on the diagonal
496514
of the pertinent correlation matrices. For large datasets, pass batch_size to
497-
process evaluation in chucks. Support homophones.
515+
process evaluation in chunks. Support homophones.
498516
499517
# Obligatory Arguments
500518
- `SChat::AbstractArray`: the Chat or Shat matrix
@@ -617,6 +635,10 @@ end
617635
Assess model accuracy on the basis of the correlations of row vectors of Chat and
618636
C or Shat and S. Count it as correct if one of the top k candidates is correct.
619637
638+
!!! note
639+
If there are homophones/homographs in the dataset, this evaluation method may be misleading: the predicted vector will be equally correlated with the target vector of both words and it is not guaranteed that the target on the diagonal will be among the k neighbours. In particular, `eval_SC` and `eval_SC_loose` with k=1 are not guaranteed to give the same result. In such cases, supplying the dataset and `target_col` is recommended which enables taking into account homophones/homographs.
640+
641+
620642
# Obligatory Arguments
621643
- `SChat::Union{SparseMatrixCSC, Matrix}`: the Chat or Shat matrix
622644
- `SC::Union{SparseMatrixCSC, Matrix}`: the C or S matrix
@@ -631,6 +653,14 @@ eval_SC_loose(Shat, S, k)
631653
```
632654
"""
633655
function eval_SC_loose(SChat, SC, k; digits=4)
656+
657+
if size(unique(SC, dims=1), 1) != size(SC, 1)
658+
@warn "eval_SC_loose: The C or S matrix contains duplicate vectors (usually because of homophones/homographs). Supplying the dataset and target column is recommended for a realistic evaluation. See the documentation of this function for more information."
659+
if k == 1
660+
@warn "eval_SC_loose: You set k=1. Note that if there are duplicate vectors in the S/C matrix, it is not guaranteed that eval_SC_loose with k=1 gives the same result as eval_SC."
661+
end
662+
end
663+
634664
total = size(SChat, 1)
635665
correct = 0
636666
rSC = cor(

0 commit comments

Comments
 (0)