Theano

Theano was one of the earliest Python libraries for deep learning, developed at the University of Montreal. It allowed researchers to define, optimize and evaluate mathematical expressions involving multi-dimensional arrays - laying much of the groundwork for the deep learning libraries that followed.

Key Contributions

  • Introduced the idea of building a computation graph that could be optimized before execution
  • Provided automatic differentiation, making it easier to compute gradients for backpropagation
  • Supported GPU acceleration, which was groundbreaking for its time

A Simple Theano Example

import theano
import theano.tensor as T

x = T.dscalar("x")
y = x ** 2
f = theano.function([x], y)

print(f(4))  # Output: 16.0

Why It Matters Historically

Many higher-level libraries, including early versions of Keras, were originally built on top of Theano as a backend before TensorFlow became dominant. Theano's core ideas - symbolic computation graphs, automatic differentiation, and GPU support - directly influenced the design of virtually every deep learning framework that came after it.

Current Status

Development of Theano officially ended in 2017, with the team recommending users move to more actively maintained frameworks like TensorFlow and PyTorch - but it remains an important part of deep learning history.

Even though Theano is no longer maintained, understanding its symbolic computation graph approach makes it much easier to understand how TensorFlow's graph execution model works under the hood.

Coming Up Next

While Theano was built for Python, enterprise environments often run on Java - that's where Deeplearning4j comes in.

Reading a Computation Graph

Theano's central idea was to describe a calculation as a graph before running it. Each variable and operation is a node; edges show how values flow. When you write y = x ** 2 in Theano, no squaring happens yet — you have only described the relationship. The actual work waits until you compile the graph into a function and call it with real numbers. Separating "describe" from "execute" lets the library inspect the whole calculation and optimise it as a unit, something you cannot do when each line runs immediately.

From Symbolic Expressions to Compiled Functions

Once a graph is defined, theano.function compiles it. During compilation Theano simplifies redundant operations, fuses steps together, and can target a GPU — then hands back a callable you invoke like any function.

import theano
import theano.tensor as T

x = T.dscalar("x")
y = x ** 2
dy = T.grad(y, x)                 # symbolic derivative: 2*x
f = theano.function([x], [y, dy])
print(f(4))                       # [16.0, 8.0]

The T.grad call is the key: because the graph is symbolic, Theano can work out the derivative automatically. That automatic differentiation is what makes training neural networks practical, since backpropagation is just repeated gradient computation.

What Its Ideas Became

Theano is no longer developed, but almost every idea it pioneered lives on:

  • Computation graphs — the backbone of later graph-based execution in other frameworks.
  • Automatic differentiation — now standard in every deep learning library, whether graph-first or eager.
  • GPU acceleration from a high-level language — once rare, now expected.
  • A compile step that optimises the graph before running it.

Understanding Theano is less about using it today and more about seeing clearly why modern frameworks are built the way they are. When a newer library talks about defining a graph and then executing it, it is echoing the model Theano made popular.

The contrast with today's default style is instructive. Theano was strictly "define then run" — you built the whole graph first and could not inspect intermediate values easily, which made debugging awkward. Modern libraries added an eager mode that runs each operation immediately, so you can print a value mid-calculation like ordinary code, then optionally compile a graph later for speed. Seeing why that shift happened makes the trade-off between a static graph's optimisation and an eager style's ease of debugging much clearer.

Takeaway: Theano separated describing a calculation from running it, added automatic gradients, and pushed work onto the GPU. Those three moves shaped the libraries that replaced it, which is why its design is still worth knowing.

Ready to Master Data Science?

Join Uncodemy's Data Science Course and build real, job-ready skills with expert mentors.

Explore Course