In [1]:
from dali.core import MatOps, Mat, SGD, AdaGrad, RMSProp, AdaDelta, Adam, GRU, Graph, NoBackprop, config
import numpy as np

In [2]:
config.default_device = 'cpu'

In [3]:
# this works
x = Mat(2, 3)
h = Mat(2, 3)
print((x+h).dims())


(2, 3)

In [4]:
x = Mat(np.arange(6).reshape(2,3))

In [5]:
x.sum(axis=0)


Out[5]:
[
    [  3.000   5.000   7.000]
]

In [6]:
MatOps.softmax(x, axis=0)


Out[6]:
[
    [  0.047   0.047   0.047]
    [  0.953   0.953   0.953]
]

In [8]:
MatOps.softmax_cross_entropy(x, Mat([0,0,0], dtype=np.int32), axis=0)


Out[8]:
[
    [  3.049   3.049   3.049]
]

In [9]:
params = [Mat(np.random.randn(3,3))]
sgd = SGD(params)

In [10]:
gru.memory_to_memory_layer.


  File "<ipython-input-10-9212afb775fa>", line 1
    gru.memory_to_memory_layer.
                               ^
SyntaxError: invalid syntax

In [4]:
sgd


Out[4]:
<test_dali.SGD at 0x10e560570>

In [5]:
params[0].dw


Out[5]:
array([[ 0.,  0.,  0.],
       [ 0.,  0.,  0.],
       [ 0.,  0.,  0.]], dtype=float32)

In [6]:
params[0].w


Out[6]:
array([[ 1.49149013,  0.82652575, -0.29154852],
       [-1.35542476,  0.68018013,  1.32109797],
       [-1.33052015, -0.99618644, -1.64559519]], dtype=float32)

In [7]:
#sgd.create_gradient_caches(params)

In [8]:
gru = GRU(10, 10)

In [9]:
gru.initial_states().shape


Out[9]:
(1, 10)

In [41]:
params[0].dw += 1
sgd.step(params)

In [32]:
sgd.step_size = 0.5

In [51]:
params


Out[51]:
[[
     [ -0.136  -0.136  -0.136]
     [ -0.136  -0.136  -0.136]
     [ -0.136  -0.136  -0.136]
 ]]

In [52]:
MatOps.hstack(
    [
        Mat(3,3)
    ]
)


Out[52]:
[
    [  0.000   0.000   0.000]
    [  0.000   0.000   0.000]
    [  0.000   0.000   0.000]
]

In [ ]:


In [ ]:


In [12]:
x.name = "bob"

In [13]:
x.name


Out[13]:
'bob'

In [17]:
# this throws an exception
x = test_dali.Mat(2, 3)
h = test_dali.Mat(3, 3)
#print( test_dali.Mat.add_mofos(x,h).dims() )
print((x / h).dims())


---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-17-31fd0707900e> in <module>()
      3 h = test_dali.Mat(3, 3)
      4 #print( test_dali.Mat.add_mofos(x,h).dims() )
----> 5 print((x / h).dims())

/Users/jonathanraiman/Desktop/Coding/dali-cython/dali/tensor/Mat.pyx in test_dali.Mat.__truediv__ (test_dali.cpp:7760)()
    275         cdef Mat output = Mat(0,0)
    276         if type(other) is Mat:
--> 277             output.matinternal = self.matinternal.operator_divide((<Mat>other).matinternal)
    278         elif type(other) is float or type(other) is int:
    279             output.matinternal = self.matinternal.operator_divide((<dtype>other))

RuntimeError: Matrices cannot be element-wise divided, they do not have the same dimensions.

In [18]:
# this succeeds
x = test_dali.Mat(2, 3)
h = test_dali.Mat(3, 3)
layer = test_dali.RNN(2, 3, 3)
o = layer.activate(x, h)
print(o.dims())


(3, 3)

In [19]:
# this throws an exception
x = test_dali.Mat(2, 3)
h = test_dali.Mat(2, 3)
layer = test_dali.RNN(2, 3, 3)
o = layer.activate(x, h)
print(o.dims())


---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-19-82be0e072bda> in <module>()
      3 h = test_dali.Mat(2, 3)
      4 layer = test_dali.RNN(2, 3, 3)
----> 5 o = layer.activate(x, h)
      6 print(o.dims())

/Users/jonathanraiman/Desktop/Coding/dali-cython/dali/layers/Layers.pyx in test_dali.RNN.activate (test_dali.cpp:20685)()
    167     def activate(self, Mat input_vector, Mat prev_hidden):
    168         cdef Mat output = Mat(0,0)
--> 169         output.matinternal = self.layerinternal.activate(input_vector.matinternal, prev_hidden.matinternal)
    170         return output
    171 

RuntimeError: Disagreement on inner dimension on input pair 1

In [20]:
layer.hidden_size


Out[20]:
3

In [21]:
x.__add__(h)


Out[21]:
[
    [  0.000   0.000   0.000]
    [  0.000   0.000   0.000]
]

In [22]:
(x + h).dims()


Out[22]:
(2, 3)

In [23]:
x * h


Out[23]:
[
    [  0.000   0.000   0.000]
    [  0.000   0.000   0.000]
]

In [24]:
vocab = test_dali.Vocab(["a", "b", "c"], True)

In [25]:
layer = test_dali.Layer(5, 3)

In [26]:
params = layer.parameters()

In [27]:
param = params[0]

In [28]:
layer.parameters()


Out[28]:
[[
     [ -0.162   0.359   0.416  -0.237  -0.350]
     [ -0.242  -0.346   0.035  -0.211  -0.067]
     [ -0.272  -0.359  -0.231   0.057  -0.050]
 ], [
     [  0.111  -0.244  -0.225]
 ]]

In [29]:
slayer = test_dali.StackedInputLayer([5, 5, 5], 7)

In [30]:
slayer_knife = test_dali.Mat(5, 1)

In [31]:
slayer.activate([slayer_knife, slayer_knife, slayer_knife])


Out[31]:
[
    [ -0.209]
    [  0.165]
    [ -0.187]
    [  0.075]
    [  0.233]
    [  0.182]
    [ -0.099]
]

In [32]:
slayer.parameters()


Out[32]:
[[
     [  0.196  -0.014   0.030  -0.070  -0.103]
     [ -0.162  -0.160  -0.178  -0.121  -0.186]
     [  0.126  -0.004  -0.094   0.229   0.001]
     [ -0.086  -0.007   0.248   0.189   0.180]
     [  0.258   0.221   0.123   0.122   0.167]
     [  0.081  -0.214  -0.157  -0.126   0.210]
     [  0.162  -0.053   0.173   0.233   0.166]
 ], [
     [  0.010  -0.107   0.027   0.081  -0.027]
     [  0.228  -0.090   0.200   0.098   0.041]
     [ -0.133   0.177   0.074   0.113  -0.092]
     [ -0.061  -0.071  -0.233  -0.156   0.001]
     [  0.133   0.019  -0.230   0.093   0.018]
     [ -0.063  -0.047   0.238  -0.106  -0.041]
     [  0.207  -0.064  -0.074   0.153   0.172]
 ], [
     [ -0.239  -0.018  -0.117   0.090   0.111]
     [  0.176   0.037   0.144   0.120   0.226]
     [ -0.009  -0.021   0.233   0.143   0.201]
     [ -0.173  -0.208  -0.022   0.167  -0.216]
     [  0.043  -0.228   0.209  -0.227   0.051]
     [  0.066   0.093   0.061   0.250  -0.113]
     [ -0.129  -0.204   0.126  -0.036  -0.136]
 ], [
     [ -0.209]
     [  0.165]
     [ -0.187]
     [  0.075]
     [  0.233]
     [  0.182]
     [ -0.099]
 ]]

In [33]:
slayer2.parameters()


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-33-83a4bfae8ffd> in <module>()
----> 1 slayer2.parameters()

NameError: name 'slayer2' is not defined

In [34]:
test_dali.Graph.emplace_back(backprop)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-34-5e1742501ec2> in <module>()
----> 1 test_dali.Graph.emplace_back(backprop)

NameError: name 'backprop' is not defined

In [35]:
test_dali.Graph.backward()

In [ ]:


In [ ]:


In [36]:
from test_dali import Graph,LSTM, GRU, StackedInputLayer, Layer, Mat, LSTMState, StackedLSTM, random as drandom, MatOps

In [37]:
import pickle

In [38]:
slstm = StackedLSTM([5,5], [3,3,3])

In [39]:
slstm.parameters()[0].w


Out[39]:
array([[-0.02497441,  0.16305113,  0.18151763, -0.08400205, -0.11042526],
       [ 0.10933146, -0.18804523,  0.20556858, -0.23619464,  0.2658439 ],
       [-0.07216391,  0.27044287,  0.12013584,  0.01419726,  0.09242144]], dtype=float32)

In [40]:
slstm2 = pickle.loads(pickle.dumps(slstm))
slstm2.parameters()[0]


Out[40]:
[
    [ -0.025   0.163   0.182  -0.084  -0.110]
    [  0.109  -0.188   0.206  -0.236   0.266]
    [ -0.072   0.270   0.120   0.014   0.092]
]

In [41]:
mat = drandom.uniform(-4, 4, (100,100))

In [ ]: