-
Notifications
You must be signed in to change notification settings - Fork 1
/
post_processor.py
45 lines (35 loc) · 1.08 KB
/
post_processor.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
import os.path
import numpy as np
import pandas as pd
from UniTok import UniDep, Fut, Vocab
depth = 3
code_size = 192
path = f'saving/MIND-small/Depth{depth}-C{code_size}/export/'
key = f'd{depth}-c{code_size}'
code_per_depth = code_size // depth
codebooks = np.load(os.path.join(path, f'codebooks.npy'))
codes = np.load(os.path.join(path, f'codes.npy'))
# codebooks = codebooks.reshape(depth, code_per_depth, codebooks.shape[-1])
#
# for i in range(depth):
# codes[:, i] -= i * code_per_depth
np.save(os.path.join(path, f'{key}.codebooks.npy'), codebooks)
np.save(os.path.join(path, f'{key}.codes.npy'), codes)
if not os.path.exists('data/MIND-small/news-code'):
depot = UniDep('data/MIND-small/news')
data = {
'nid': list(range(codes.shape[0])),
}
df = pd.DataFrame(data)
Fut(
df,
depot,
id_col='nid',
).store('data/MIND-small/news-code')
depot = UniDep('data/MIND-small/news-code')
depot.set_col(
name=key,
values=codes.tolist(),
vocab=Vocab(name=key).reserve(code_size),
)
depot.export('data/MIND-small/news-code')