A Brief Overview & Applications

Francesca Lazzeri
Sep 9 · 6 min read

This article is authored by Matthew Muccio & Torrey Trahanovsky, Microsoft Student Partners, & Francesca Lazzeri, Microsoft ML Scientist.

In this article, we introduce the concept of Generative Adversarial Networks (GANs), by answering the following simple questions:

1. What are GANs?

2. How do GANs work?

3. How can you remember how GANs work?

4. Why are GANs useful?

5. When and where can GANs be used?

6. How can you get started and implement GANs with Python and Azure?

In our previous article on Deep Learning vs. Machine Learning, you learnt how these two concepts compare and how they fit into the broader category of artificial intelligence. The article also describes how deep learning can be applied to real-world scenarios such as fraud detection, voice and facial recognition, sentiment analytics, and time series forecasting.

This article helps you to understand how GANs work, why they are useful and how you can get started and implement them with Python and Azure.

  1. What are GANs?

A GAN is a class of machine learning systems containing two deep neural networks, where they compete in a zero-sum game against one another. In this internal game, each network’s gains and losses are ultimately balanced.

GANs are a type of generative models, which are an important subset of machine learning that require realistic and statistically accurate generation of target data.

Developed in 2014 by Ian Goodfellow and fellow researchers at the University of Montreal, and described by Yann LeCun, Facebook’s VP and Chief AI Scientist, as “the coolest idea in machine learning in the last twenty years,” GANs have incredible potential for innovative applications and use cases, particularly in the realms of art, music, and language. This is mainly due to a GAN’s powerful ability to recreate a new, similar data set based on an original training data set.

In a GAN there are two running machine learning models, that compete to improve the functioning of their counterpart, the opposing model. Both models work by learning object rules and using the same two methods to characterize neuron sets, but for opposing goals.

2. How do GANs work?

GANs make use of generative algorithms — contrasted from discriminative algorithms which classify input data, or features, by predicting their labels, categories, or fields — to determine the distribution or probability of a data point being classified as a particular feature based on its label, category, or field. These two aforementioned algorithms are executed by the discriminator and generator, respectively, as illustrated in the image below:

Generator versus Discriminator — Source: https://www.microsoft.com/en-us/research/blog/boundary-seeking-gans-new-method-adversarial-generation-discrete-data/

The GAN training algorithm involves training both the discriminator and the generator model in parallel. The algorithm is summarized in the figure below, taken from the original 2014 paper by Goodfellow, et al. titled Generative Adversarial Networks:

GAN training algorithm — Source: 2014 paper by Goodfellow, et al. titled “Generative Adversarial Networks”

The generator creates false sample sets that are as close to 1 as possible, 1 being mathematically true. With the discriminator attempting to identify sets that are 1 and discarding those that are false sets, essentially not 1 or mathematically true. However, the generator, cannot simply create a false set out of nothing, there is training of the model required in which it learns from true sets to create its own true sets. Then optimizes these creations again the discriminator.

Diving a bit more deeply into this, the generator, the false set creator, learns how classes are distributed. While the discriminator network or machine learning model, learns how to identify true classes, by learning how to adjust its definition of a true class via adjusting how it classifies the data set it is given.

The generator creates new and similar data points that it gives to the discriminator in the hopes of it classifying the data point as authentic, despite its actually being fake. It is important to note that there is a double feedback loop taking place in the architecture of a GAN; the discriminator is in a feedback loop with the true training data set, and the generator is in a feedback loop with the discriminator, continuously sending it very similar, but unauthentic data: the discriminator must have a true training data set in order to confirm authenticity of other data points. The final result is a data set that has very similar, while not being exactly the same, characteristics to the training data set.

3. How can you remember how GANs work?

The best way to remember this, is to imagine a game between two players, named, you guessed it, the Generator and Discriminator!

The player Discriminator, examines samples to determine “real” samples, and learns by dividing “real”/”fake” into 2 classes (using dissection). While the player, Generator, trains to fool the other player and learns by making improved “fake”’s (dissection as well). This, results in the ultimate optimized item they are tasks to compete in improving:

Generator versus Discriminator — Source: https://www.ugdsb.ca/jdh/2019/03/19/intermediate-girls-boys-basketball/

4. Why is this useful and who does benefit from GANs?

The benefits of having two competing machine learning models, is that the problem exists that the less efficient one model is, the higher the computational cost is. With GANs, each model is optimizing the other, resulting in the computational cost decreasing with the functioning efficiency of the model increasing.

From a non-computational perspective, GANs can result in an optimized method of encryption, design, or suggestions to already existing structures.

Those who benefit most from GANs are those with a problem that requires a lower computational cost, while also a very high degree of preciseness in output. The other benefiter of a GAN is those who have fewer initial data for an ML model, or optimizing a structure, than desired. Another benefit is for those who desire to test the security or efficiency of a creation, but cannot risk testing in a real world environment or spending time improving both the attacker and the defense in unison. Or if the data is too sensitive or against regulations to be viewed by the parties who are capable of testing.

5. When and where can GANs be used?

A GAN can be implemented when there is at least some existing real data for the Generator to base its false creations of. Without this pre-existing data, the Generator cannot create false classes and sets, to be an adversary to the Discriminator.

GANs can be used in essentially any industry that requires improvement. However, the best use cases come from pharmaceuticals in which drugs can be optimized in structure, based on the structure of other drugs. Also, in encryption in which a better algorithm can be developed that still functions.

Ultimately, generative adversarial networks, or GANs, have incredible potential in the field of machine learning, and have an expanding number of innovative use cases. Despite its being a relatively new technology, GANs are rapidly growing in popularity among machine learning professionals, students, and hobbyists alike, principally due to their unprecedented applications.

Although seemingly simple, being able to generate a data set with similar characteristics to that of an original training set has some powerful, modern use cases, including image generation, translation, and improvement, scientific exploration and research, as well as data visualization.

6. How can you get started and implement GANs with with Python and Azure?

  1. Classify handwritten digits by using a TensorFlow model
  2. Classify handwritten digits by using a TensorFlow estimator and Keras
  3. Classify images by using a Pytorch model
  4. Classify handwritten digits by using a Chainer model

Microsoft Azure

Any language. Any platform. Our team is focused on making the world more amazing for developers and IT operations communities with the best that Microsoft Azure can provide. If you want to contribute in this journey with us, contact us at medium@microsoft.com

Francesca Lazzeri

Written by

Senior Machine Learning Scientist at Microsoft. My goal is to make developers like you awesome at applied AI and Machine Learning. @frlazzeri on Twitter.

Microsoft Azure

Any language. Any platform. Our team is focused on making the world more amazing for developers and IT operations communities with the best that Microsoft Azure can provide. If you want to contribute in this journey with us, contact us at medium@microsoft.com

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade