In [2]:
import math
z = [0, 2.0, 0, 0, 0, 0, 3.0]
z_exp = [math.exp(i) for i in z]
print(z_exp) # Result: [2.72, 7.39, 20.09, 54.6, 2.72, 7.39, 20.09]
sum_z_exp = sum(z_exp)
print(sum_z_exp) # Result: 114.98
softmax = [round(i / sum_z_exp, 3) for i in z_exp]
print(softmax)
In [120]:
import numpy as np
import train_until
debug = np.load('debug_step-2368963.npy').tolist()
key = list(debug.keys())
remap = train_until.mul_onehot_remap()
anno, dictionary = train_until.load('./dataset/MSR_en.csv', './dataset/MSR_en_dict.csv')
word_map = {}
for word in dictionary.keys():
word_map[dictionary[word]] = word
In [141]:
In [135]:
tar_id = train_until.mul_onehot2ids(debug[key[4]])
out_id = train_until.mul_onehot2ids(debug[key[1]])
In [144]:
tar_id
In [134]:
list(map(lambda x: [x[0], x[1] + 256], out_id[0]))
Out[134]:
In [124]:
out_id
Out[124]:
In [81]:
remap_inv = {}
for i in range(len(remap)):
remap_inv[remap[i]] = i
In [130]:
toid = lambda x: x[0] + x[1]*256
ID = remap_inv[toid(out_id[0,20])]
print(word_map[ID])
In [62]:
config = (32, 3)
index = 12345
T = [(index % config[0]**i) // config[0]**(i - 1) for i in range(1, 1 + config[1])]
print(T)
In [108]:
train_until.mul_onehot2ids(debug[key[4]][0,0].reshape([1,1,512]))
Out[108]:
In [119]:
[1]*5
Out[119]: