DEV Community

Cover image for Introduction to Machine Learning with TensorFlow
MichaelPaulKunz
MichaelPaulKunz

Posted on

Introduction to Machine Learning with TensorFlow

Machine Learning

When we program a computer to "think" in ways that superficially resemble human thought, it's called machine learning. Machine learning is the building block of artificial intelligence, which powers auto-complete and fraud detection software as well as automated playlists and recommended videos for Spotify and YouTube. Machine learning is famously used in facial recognition software and in targeted ad algorithms.

Complex Algebra

Recognizing images is something the human mind does effortlessly, but it takes a lot for a computer to perform the same task. Image recognition software begins with a series of neurons, which are defined as numbers ranging from 0 to 1. Whichever number a neuron holds is its activation, and the closer to 1, the more activated it is.

We can model any grey-scale image as a matrix of neurons. Each neuron corresponds to a pixel, and its activation corresponds to its darkness of shade, with darker pixels being closer to 0 and lighter pixels being closer to 1. An AI algorithm tasked with identifying an image would start with the matrix of pixels and pass them through a series of hidden layers with progressively fewer neurons until it reaches the output layer. These layers act kind of like a game of 21 questions. The first layer may determine if the image is of a plant, animal, person, or object. If it determines it is an animal, the next layer may determine what species, and so on. In theory, the more layers involved, the more accurate the image identification will be, but each layer consumes a lot of run time memory. 3Blue1brown goes into detail about a four-layered neural network tasked with visually identifying numbers written in a wide range of styles.

The neurons in a neural network are connected through layers with different "weights" that in turn have different "biases." Each of these terms translates to a variable in a few complex algebraic equations. Two foundational equations for machine learning are the Sigmoid function, represented as s(x) = 1 / 1 + e^-x and ReLU -- rectified linear unit -- represented by the simpler and more accurate equation ReLU(a) = max(0,a). All of this heady math is beyond the scope of this article and above my pay-grade. Fortunately in computer science, we stand on the shoulders of giants, and there are libraries and APIs out there that give developers access to complex machine learning algorithms without all the number crunching.

TensorFlow

TensorFlow is an open source library developed by the Google Brain team that affords lay people the powers of machine learning. It was written in C++ and can be utilized in JavaScript or Python. You know that daunting diagram in the banner image? TensorFlow reduces the most complicated parts of that network to just a few lines of code.

Alt Text

TensorFlow derives its name from the tensor data structure that can store any number of scalers, vectors, or matrices. While TensorFlow's job is to abstract away the algebraic details of machine learning, it's important to note that an image is itself a matrix of pixels, and so machine learning can be powered by a GPU instead of a CPU. TensorFlow is accelerated by WebGL, an open-source JavaScript graphics API.

ml5.js

ml5 is an open source library and community that builds upon the TensorFlow library. ml5 doesn't require any other dependencies besides TensorFlow, so it's surprisingly easy to get started with. You can fork this image-recognition app from their GitHub and have the power of machine learning at your fingertips.

Conclusion

  • Machine learning is a rapidly developing field that increasingly powers our daily lives
  • Machine learning algorithms are powered by complex algebraic equations
  • Open source libraries like TensorFlow and ml5 give us the power of machine learning without needing a PHD in advanced mathematics

Sources:

Top comments (0)