-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add correlation study of overfitting
- Loading branch information
1 parent
0891f62
commit 626a8d3
Showing
7 changed files
with
33,596 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import math | ||
|
||
from scipy.stats import pearsonr, spearmanr | ||
from tqdm import tqdm | ||
|
||
import numpy as np | ||
import torch | ||
|
||
from fairseq.data import Dictionary | ||
|
||
dictionary = Dictionary.load('data-bin/wikitext103-bpe/dict.txt') | ||
print(len(dictionary)) | ||
|
||
bpe_cont = "@@" | ||
bpe_toks = { | ||
i | ||
for i in range(len(dictionary)) | ||
if dictionary[i].endswith(bpe_cont) | ||
} | ||
|
||
bpe_len = len(bpe_cont) | ||
|
||
tokens = np.load('tokens.npy') | ||
lm_scores = np.load('scores.npy') | ||
knn_scores = np.load('knn_only_scores.npy') | ||
|
||
# calculate Pearson's correlation | ||
corr, _ = pearsonr(lm_scores, knn_scores) | ||
print('LM vs KNN Pearsons correlation: %.3f' % corr) | ||
|
||
# calculate Pearson's correlation | ||
corr, _ = spearmanr(lm_scores, knn_scores) | ||
print('LM vs KNN Spearmans correlation: %.3f' % corr) | ||
|
||
|
||
for ep in [10, 20, 30, 50, 100, 150, 200]: | ||
print(ep) | ||
overfit_scores = np.load('overfit_lm_scores_checkpoint' + str(ep) + '.npy') | ||
assert len(tokens) == len(lm_scores) | ||
assert len(knn_scores) == len(tokens) | ||
assert len(overfit_scores) == len(tokens) | ||
|
||
# calculate Pearson's correlation | ||
corr, _ = pearsonr(overfit_scores, knn_scores) | ||
print('OverfitLM vs KNN Pearsons correlation: %.3f' % corr) | ||
|
||
# calculate Pearson's correlation | ||
corr, _ = spearmanr(overfit_scores, knn_scores) | ||
print('OverfitLM vs KNN Spearmans correlation: %.3f' % corr) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.