Introduction to the Microsoft CNTK v2.0 Library

I wrote an article titled “Introduction to the Microsoft CNTK v2.0 Library” in the July 2017 issue of Microsoft MSDN Magazine. See

The CNTK library is a powerful set of functions that allow a developer to create deep neural networks (DNNs). A DNN can take several forms including ordinary neural networks with many hidden layers (often useful for business data), convolutional neural networks (CNNs) for image recognition, and long short-term memory (LSTM) recurrent networks for natural language processing.

The library itself is written in C++ for fast performance. However, the most common way to use CNTK v2.0 is to write a Python language script and call into the CNTK API. In my article, I demonstrate how to create and use a simple neural network. For example, this Python code accesses CNTK and sets up a neural network with one hidden layer with two nodes:

import numpy as np
import cntk as C

input_dim = 4
hidden_dim = 2
output_dim = 3
print("Creating a 4-2-3 tanh softmax NN for Iris data ") 
  with default_options(init = glorot_uniform()):
    hLayer = C.layers.Dense(hidden_dim,
      activation=C.ops.tanh, name='hidLayer')(input_Var)  
    oLayer = Dense(output_dim, activation=C.ops.softmax,
  nnet = oLayer
# etc. etc.

The version 2.0 of CNTK was released on June 1, 2017. Version 2.0 is very different from version 1 — so much so that I view the two versions as two completely different systems. I see Microsoft CNTK as a direct competitor to Google’s TensorFlow library. TensorFlow has been around since early 2016, so TF has a huge lead over CNTK.

Both CNTK and TF have very steep learning curves. Both are low-level libraries so you must have a strong understanding of neural network concepts to use the libraries. In most situations, because I understand NNs very well, I prefer to write my NN code from scratch in C#. However, for deep NNs, CNTK and TF give you vastly faster performance, especially when you use the GPU version of either library.

Moral: A basic knowledge of machine learning is quickly becoming a must-have skill for software developers. The newly released CNTK v2.0 library is a giant step forward, but it requires a huge effort to learn.

This entry was posted in CNTK, Machine Learning. Bookmark the permalink.

One Response to Introduction to the Microsoft CNTK v2.0 Library

  1. Peter Boos says:

    Maybe you could write a few articles about deep NN, I’d love to read your thoughts about it.
    Since that gives more insight, as an engineer i see value of a NN, but the thoughts about what they do are very important for proper usage of them, its better to know a tool good, then to blindly use tool. One might pick the wrong saw and totally damage the end product. Not knowing what saw one needs to take, is thus risky. Currently i am trying to train one in c# but creating a train function is far from easy. Maybe some swarm emulation for weights, but to validate .. kinda hard problem.

Comments are closed.