Chapter 10. Machine Learning in the Cloud
However, no computation has taken place at this point: we have only constructed
a graph of the computation. To execute the graph, we input values for
X
,
B
,and
M
, and then apply the
eval
operator on
Y
, as follows. We use Numpy arrays to
initialize the tensors and, in a manner identical to TensorFlow, supply a dictionary
of bindings to the eval operator as follows.
x=[[np.asarray([[40,50]])]]
m=[[np.asarray([[1,2,3],[4,5,6]])]]
b=[[np.asarray([1.,1.,1.])]]
print(Y.eval ({ X:x , M: m , B: b }))
----- output -------------
array ([[[[ 241. , 331. , 421.]]]] , dtype=float32 )
CNTK also supports several other tensor container types, such as
Constant
, for
a scalar, vector, or other multidimensional tensor with values that do not change,
and
ParameterTensor
, for a tensor variab le whose value is to be modified during
network training.
Many more tensor operators exis t, and we cannot discuss them all h ere. How-
ever, one important class is the set of operators that ca n be used to build multilevel
neural networks. Called the layers library, they form a cri tical part of CNTK. One
of the most basic is the
Dense(dim)
layer, which creates a fully connected layer of
output dimension
dim
. Many other standard layer types exist, including Co nvolu-
tional, MaxPooling, AveragePo oli ng, and LSTM. Layers can also be stacked with
a simple operator called
sequential
. We show two examples taken directly from
the CNTK documentation [
27
]. The first is a standard five-level image recognition
network based on convolutional layers.
with default_options (activation =relu ):
conv_net = Sequential ([
# 3 layers of convolution and dimension reduction by pooling
Convolution ((5,5),32, pad=True),MaxPooling ((3,3), strides =(2,2)),
Convolution ((5,5),32, pad=True),MaxPooling ((3,3), strides =(2,2)),
Convolution ((5,5),64, pad=True),MaxPooling ((3,3), strides =(2,2)),
# 2 dense layers for classification
Dense (64),
Dense (10, activation= None )
])
The second example, on the next page, is a recurrent LSTM network that takes
words
embedded
in a vector of size 15 0, passes them to the LSTM, and produces
output through a dense network of dimension labelDim.
219