How TensorFlow is taking the tension out of Machine Learning!

Brooke Smyth
6 min readSep 27, 2021

--

Machine Learning and Deep Learning are both becoming well-known phrases in the current era — but details of the specific tools they require are less ubiquitous. I’d like to discuss one of the most popular Machine Learning tools and how it compares to the others.

TensorFlow is probably the most popular Machine Learning tool among researchers today. The Data Incubator calculated that the rating for TensorFlow is nine standard deviations higher than the rating for the second highest machine learning tool, Keras. TensorFlow was written by the Google Brain Team in 2015, and its front end is written in python, while its backend is written in C++. This combination of different programming languages was chosen by design; python has an intuitive API and excellent tools for pre-processing of data (such as NumPy), while the core functions written in C++ are able to perform operations with great speed.

TensorFlow uses a combination of machine learning and deep learning to yield insights and predictions. So what exactly is machine learning? The goal of machine learning is to train a system to learn from data and make an educated decision. Even though the phrase “machine learning” and “deep learning” are often used as synonyms, there is a slight difference between the two. Deep learning is a specific subset of machine learning which uses neural networks. It surpasses lower level machine learning in its ability to know when its predictions are inaccurate, which it can then fine-tune on its own; normal machine learning does not know when its predictions are inaccurate and requires an engineer to come in and make adjustments. The neural network mechanism which underlies deep learning is complex and would require a whole slew of articles/posts to do it justice, but since it is a big part of TensorFlow it would be remiss not to include some kind of summary. Neural networks is loosely based on the way biological neurons communicate in the brain, and is comprised of layers containing “neurons” or nodes which pass information to the layer of nodes above them, and so on until the final layer of nodes, where each node in the final layer represents a certain prediction. To illustrate how a neural model works, consider the example of getting it to recognize a hand-written digit.

Photo from TIBC (https://www.tibco.com/reference-center/what-is-a-neural-network)

The first layer in the network would represent all of the pixels in the image, and each node would represent one pixel. Each node represents how much color is in each pixel, using a numeric scale where zero equals back and one equals white. Each of these nodes would then connect with each node in the next layer, where every node is in charge of recognizing a different, small piece of a curve or edge. The input connections from each first layer node to each of the different second layer nodes are given different weights (levels of how important its feedback is to the purpose of the second layer node it is going to). The purpose of each neuron in this second layer might be to piece together the info from the individual pixel nodes into small segments of curves or edges. To do this, each second layer node sums up the info from each first layer node and passes it up to the nodes above them (again each connection is given a particular weight). The degree to which some nodes are more activated in this second layer than others affects how the next layer will be activated and how it will interpret the information. Now we are into the third layer. The roles in these nodes might be to piece together the segments of curves and edges into the actual shapes that form numbers. These nodes would then pass up this information to the nodes in the final layer above, whose job would be to put together the shapes that form numbers to come up with an actual digit. Another important thing to note about this process involves the way that summing works: during this process, the summed result representing input from all the lower level nodes will oftentimes be a number greater than one, so in order to preserve the 0–1 numeric color scale, the sum is often multiplied by a number, called an activator, before being passed up to the next layer.

This is only a bare-bones description of the process, but is sufficient for explaining the basics of how TensorFlow works. When building a model in TensorFlow, you are able to specify how many layers you want, as well as how many nodes in each layer. You can also specify the activation of all the nodes in a particular layer. (For a video tutorial which introduces the basic syntax, you can head to this link.) In addition to facilitating machine learning models, TensorFlow also enables deployment. Deployment is the process of applying the model to a different dataset than it was trained on, making it an active tool which can make many different kinds of predictions and diagnoses Machine Learning Models have been trained to diagnosis of diabetic retinopathy, help farmers spot diseased plants, and predict extreme weather conditions.

As with all other tools and libraries, TensorFlow has its pros and cons. TensorFlow has many Pros; it is able to debug nodes on its own with TensorBoard, which resolves issues without having to dive into the whole nitty-gritty code. It also uses Keras, an excellent machine learning library in its own right, as a wrapper, which provides features such as pipelining, estimators, and eager execution. TensorFlow can also employ a wide range of operations, which can be deployed on all machine types. It is also compatible with a wide variety of languages (C++, JavaScript, Python, C#, Ruby, and Swift). In addition, TensorFlow utilizes a good degree of parallelism and hardware acceleration; therefore it is able to delegate certain processes onto specific elements of the hardware, providing more efficiency than running everything on the CPU alone. A user can decide whether to run the code in the CPU or GPU (Graphic Processing Unit). This parallelism helps decrease memory allocation. TensorFlow is also able to utilize an additional architectural element called the Tensor Processing Unit (TPU) which Google developed to perform linear algebra computations more quickly than either the Central Processing Unit (CPU) or Graphic Processing Unit (GPU). Now that TensorFlow’s many virtues have been extolled, it is time to discuss the cons. TensorFlow updates frequently (about every 2–3 months) which requires more user time and system memory, hampering productivity. Additionally, there are confusing naming conventions. It has several functions which have similar sounding names, but which carry out different functions. For example: tf.layers.conv2d, tf.layers.Conv2d are almost identical, yet have different functions. Another con is that the TPU can only be utilized when executing a model, not when training it. Additionally, not as many features are available to Windows users. The biggest con of all is that TensorFlow carries out operations much more slowly than its competitors.

Speaking of TensorFlow’s competitors, there are a few which stand out. Some of the most popular alternatives are PyTorch, OpenCV, and ApacheSpark. The primary reason for developers choosing PyTorch is listed on stackshare as “more developer friendly,” whereas the top reason developers listed for TensorFlow was “High Performance.” As for OpenCV, according to stackshare it falls more under the umbrella of image processing and management than TensorFlow does, and developers listed “Computer Vision” as the primary reason for choosing it. Apache Spark is another machine learning library, however its main strengths are for the processing of substantial amounts of data, whereas TensorFlow is much more rooted in the “Machine Learning” category. Again, the main thing which distinguishes TensorFlow from its competitors is that while it can perform a wide range of powerful operations, it functions at a much slower rate, so this is something to keep in mind if speed is a priority.

All in all, TensorFlow is a state of the art machine learning and deep learning library, with the ability to perform high power computations, manipulate features of neural networks in a very user-friendly way, and deploy models which can help diagnose and predict certain trends. Even though it’s lack of speed is not inconsequential, TensorFlow still seems to come out on top when compared to its competitors.

--

--