Build Tensorflow from Source with Swig and Bazel without Root

Sometimes we may need to install Tensorflow from source without root access to the server, such as a cluster environment. This is even more true when you need to configure Tensorflow with your own environment: e.g., different Cuda and CuDNN versions. This post describes how to compile Bazel, Swig from source, and use them to compile Tensorflow.

Continue reading “Build Tensorflow from Source with Swig and Bazel without Root”

A Tutorial on Restricted Boltzmann Machines

Restricted Boltzmann Machines (RBMs) is an unsupervised machine learning method that significantly contributes the early rise of deep learning in 2006: A Fast Learning Algorithm for Deep Belief Networks. Since then it becomes an important element in the Deep Learning family. Interestingly, RBMs manifest the idea of both probabilistic graphical models and neural networks. This post aims to provide an introduction to RBMs. Most of the formulas here are from [1].

Boltzmann Machines are energy-based models [2] where the joint probability distribution is characterized by a scalar energy to each configuration of the variables. In energy-based models, inference consists of clamping the values of a set of variables, and finding configurations of the remaining variables that minimize the energy function; learning consists in finding an energy function that minimizes the energy of observed variables.  Boltzmann machines are also probabilistic graphical models using graph-based representation to factorize the probability distribution. Restricted Boltzmann Machines is a type of Boltzmann machine with special constraints – only a certain type of connection is allowed.
This post starts by introducing energy-based models, including the graphical representation of the model and its learning with gradient descent of log-likelihood. This post then discusses Boltzmann machines by placing a specific energy function in energy-based models. Restricted Boltzmann Machines are further discussed with the introduction of restrictions in Boltzmann Machines connections.

Continue reading “A Tutorial on Restricted Boltzmann Machines”

Notes on Transitioning to TensorFlow 1.0

Tensorflow 1.0 is awesome, many nice features, including GridLSTM, LayerNormalization, CRF, etc. There is even a transitioning script that helps automatically converts your file from 0.x to 1.x. However, the official transitioning script does not include many changes that need to be made in my previous LSTM code. This post will list the changes that I discovered, and I hope it will make your life easier. If you have other problems, search the function name in the new API, you should find the corresponding new version. Note that sometimes the order of parameters may differ.

tf.nn.rnn_cell -> tf.contrib.rnn
tf.nn.seq2seq -> tf.contrib.legacy_seq2seq

virtualenv cannot find module in site-packages

My Tensorflow mysteriously failed at the server. Without root access, I have to compile it from the source, to configure the GPU device. The error is module not found. Tried to pip install the module multiple times, but it still does not work. I can see the package in my site-packages directory, changed access to executable, but still not working.

It turns out that, I have set the PYTHONPATH variable in my ~/.bashrc, and pip installed packages to that specified directory. When I was trying to import the package, it could not find from the virtualenv directories. After removed the PYTHONPATH from my ~/.bashrc, everything works like a charm.

Beta Distribution


In this post, I am going to talk about Beta Distribution and some intuitive interpretations behind it.

An Example
Suppose we have two coins (A and B), and we are making a statistical experiment to identify whether these coins are biased or not. For coin A, we tossed 5 times and the results are: 1,0,0,0,0. (1 indicates Head and 0 indicates Tail). For coin B, we tossed 10 times and the results are: 1,1,0,0,0,0,0,0,0,0. The probability for theses two coins to be Tail are identical: 0.2. Is it safe to say, both coins equally favour the Tail?

Continue reading “Beta Distribution”

Not able to connect to Google Compute Engine on port 22

Google has provided its infrastructure via Google Cloud Platform to developers for building applications, as an alternative to Amazon Web Service. The setup of a new instance is simple and intuitive, however, it is frustrating not being able to connect to the instance via ssh. After some research, I found out how to resolve the problem, and I hope it can help others who are having the same issue.

The Problem
Connection Failed: We are not able to connect to the VM on port 22.
I could not even telnet IP 22

The Solution
1. Activate Google Cloud Shell
2. Add a rule to the firewall to allow traffic from port 22:
gcloud compute firewall-rules create allowssh –allow tcp:22 –source-ranges

How to read a paper

The first principle is that you must not fool yourself — and you are the easiest person to fool.  – Richard Feynman

It is often helpful to read with questions in mind. This post summarizes a list of questions worthy asking while reading a paper. I would like to make this post a living document about how to read a paper, as I read more materials and gain more understanding of scientific research. The content of this post is largely from the references listed at the end.  Continue reading “How to read a paper”