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)


[1.0, 7.38905609893065, 1.0, 1.0, 1.0, 1.0, 20.085536923187668]
32.47459302211832
[0.031, 0.228, 0.031, 0.031, 0.031, 0.031, 0.619]

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]:



Object `debug.max` not found.

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]:
[[69, 460],
 [183, 444],
 [214, 444],
 [56, 444],
 [169, 317],
 [69, 317],
 [69, 460],
 [69, 460],
 [69, 460],
 [69, 373],
 [69, 373],
 [69, 460],
 [69, 460],
 [69, 460],
 [69, 460],
 [69, 460],
 [173, 460],
 [69, 345],
 [240, 428],
 [195, 481],
 [195, 481],
 [46, 392],
 [236, 350],
 [46, 392],
 [69, 460],
 [4, 350],
 [46, 392],
 [46, 392]]

In [124]:
out_id


Out[124]:
array([[[  0,   0],
        [  0,   0],
        [  0,   0],
        [  0,   0],
        [  0,   0],
        [  0,   0],
        [  0,   0],
        [  0,   0],
        [  0,   0],
        [  0,   0],
        [  0,   0],
        [  0,   0],
        [  0,   0],
        [  0,   0],
        [  0,   0],
        [  0,   0],
        [  0,   0],
        [136,  23],
        [134,  33],
        [ 61, 117],
        [ 32,  33],
        [240, 172],
        [  4,  94],
        [236,  76],
        [ 69, 204],
        [  9, 228],
        [192, 180],
        [ 46, 136]]])

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])


weapons

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)


[25, 1, 12]

In [108]:
train_until.mul_onehot2ids(debug[key[4]][0,0].reshape([1,1,512]))


Out[108]:
array([[[ 69, 204]]])

In [119]:
[1]*5


Out[119]:
[1, 1, 1, 1, 1]