forked from urvashik/knnlm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
analysis_wiki.py
68 lines (42 loc) · 2.06 KB
/
analysis_wiki.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import numpy as np
import pandas as pd
import dask.dataframe as dd
import dask.array as da
import matplotlib.pyplot as plt
import seaborn as sns
from dask.diagnostics import ProgressBar
ProgressBar().register()
dists = np.load('saved_tensors/wikitext-103/test_proj_dist_cache.npy')
ranks = np.load('saved_tensors/wikitext-103/test_proj_rank_cache.npy')
pkg_locality = np.load('saved_tensors/wikitext-103/test_pkg_locality_cache.npy')
proj_locality = np.load('saved_tensors/wikitext-103/test_proj_locality_cache.npy')
correctness = np.load('saved_tensors/wikitext-103/test_proj_correctness_cache.npy')
locality = proj_locality + 2 * pkg_locality
dists = da.from_array(dists)
ranks = da.from_array(ranks)
locality = da.from_array(locality)
correctness = da.from_array(correctness)
arr_all = da.stack([dists, ranks, locality, correctness], axis=1)
ddf = dd.from_array(arr_all, columns=['dist', 'rank', 'locality', 'correctness'])
ddf = ddf[ddf['dist'] >= -15]
ddf = ddf.sort_values(['dist']).reset_index(drop=True)
ddf['overall_rank'] = ddf.groupby('locality').cumcount()
# dist - acc
bins = list(np.arange(0, 108794826, 100000))
ddf['rank_range'] = ddf['overall_rank'].map_partitions(pd.cut, bins)
dist_grouped = ddf.groupby(['locality', 'rank_range']).mean().reset_index().compute()
# dist_grouped['dist_right'] = dist_grouped['dist_range'].apply(lambda x: x.right)
dist_grouped.to_csv('figures/wiki_dist_correctness.csv')
fig, ax = plt.subplots(figsize=(6, 4))
sns.lineplot(x='dist', y='correctness', hue='locality', data=dist_grouped)
plt.savefig('figures/wiki_avg_correctness_by_dist_1024.pdf')
# rank - acc
grouped = ddf.groupby(['locality', 'rank']).mean().reset_index().compute()
grouped.to_csv('figures/wiki_rank.csv')
fig, ax = plt.subplots(figsize=(6, 4))
sns.scatterplot(x='rank', y='correctness', hue='locality', data=grouped, s=5)
plt.savefig('figures/wiki_avg_correctness_by_rank_1024.pdf')
# rank - dist
fig, ax = plt.subplots(figsize=(6, 4))
sns.scatterplot(x='rank', y='dist', hue='locality', data=grouped, s=5)
plt.savefig('figures/wiki_avg_dist_by_rank_1024.pdf')