Last month marked a milestone that I believe will change the software industry forever. Google open-sourced TensorFlow, the internal library they use for almost all of their artificial intelligence products. It didn't take me a second to run a pip install tensorflow on my machine.
And I have a clear diagnosis: it's the most powerful tool I've ever touched in my life, but its learning curve is a reinforced concrete wall.
The Static Computational Graph Paradigm
If you come from using friendly libraries like Scikit-Learn, TensorFlow (currently in its 0.6 version) is going to look like alien code to you. You don't program a standard logical flow; you program a mathematical circuit.
In TensorFlow, you first define a "Static Computational Graph" and then you execute it inside a "Session". You literally have to create placeholders (placeholders) for the data you are going to inject in the future.
I tried to build the most absurd neural network possible: a simple linear regression (high school math) just to grasp the syntax:
import tensorflow as tf
import numpy as np
# 1. DEFINIMOS EL GRAFO (No se calcula nada aún, solo se dibuja el circuito)
# Marcadores para inyectar nuestros datos (X) y resultados esperados (Y)
X = tf.placeholder("float")
Y = tf.placeholder("float")
# Variables que la red va a "aprender" (Pesos y Sesgos)
W = tf.Variable(np.random.randn(), name="peso")
b = tf.Variable(np.random.randn(), name="sesgo")
# La fórmula del modelo: Predicción = X * W + b
prediccion = tf.add(tf.mul(X, W), b)
# Función de coste (Error Cuadrático Medio) a minimizar
coste = tf.reduce_sum(tf.pow(prediccion - Y, 2)) / 2
# Optimizador Gradient Descent
optimizador = tf.train.GradientDescentOptimizer(learning_rate=0.01).minimize(coste)
# 2. EJECUCIÓN (Lanzamos la chispa en el circuito)
init = tf.initialize_all_variables()
with tf.Session() as sess:
sess.run(init)
# Supongamos que inyectamos datos de entrenamiento aquí en un bucle for
# sess.run(optimizador, feed_dict={X: datos_x, Y: datos_y})
print("Modelo entrenado. Los datos por fin fluyen.")
The abstraction is brutal. You are writing Python, but under the hood, you're actually building a highly optimized C++ operation tree that will then be shipped to your GPU to execute partial derivatives at lightning speed.
Reflection: The democratization of the incomprehensible
Having the exact same tool Google uses in their data centers installed on my laptop is a hacker dream. But the technical friction is overwhelmingly high. TensorFlow forces you to think in tensors (multidimensional arrays), data shapes, and error gradients.
Will Machine Learning eventually become a standard tool in any web developer's belt? With this level of complexity, I doubt it. It's way too mathematical for a business logic developer. My intuition tells me that in the coming years we'll see the rise of high-level "wrappers" (libraries built on top of TensorFlow) that will hide all this hell of Sessions and Graphs, allowing us to define neural networks with a couple of lines of code. Until then, we'll keep suffering through linear algebra.