How to brew a beer with Artificial Intelligence.

Koen Van den Heuvel
7 min readMar 5, 2018

--

Summary

Publicly available Brewdog beer recipes and Untappd beer ratings are used to create and train an artificial neural beer network (ANBN). Using this ANBN new beer recipes can be evaluated. At the end a new beer recipe is shown that will most likely taste like a Brewdog beer and be rated high on Untappd.

DIY Dog

Craft-beer brewery Brewdog got me into brewing. I love the beers. I love their punk attitude.

A few years ago they published all their beer recipes in an online book: DIY-Dog.

I downloaded the book and extracted all the recipes into a data structure to do some analysis.

Brewdog recipes have a typical style. Brewdog is into hoppy beers with 33% of the beers in the IPA category and 20% in the stout/porter category.

67 different hops are used, 8 are used a lot. 93 different malts are used, 7 are used a lot. 6 yeasts are used. Most beers are mashed using a similar mashing schedule and temperatures.

UNTAPPD

Untappd is a beer rating app that is used by a lot of beer enthousiasts.

Although the rating system is simple with scores between 0 and 5 the resulting rating has value. At least it provides an indication on what beers are liked by the crowd and which are not.

It took me a few hours to look up all the beer ratings for the Brewdog beers and add them into my data structure.

Looking at the ratings of the Brewdog beers a few things can be observed.

As already observed by other people, beer ratings are correlated with the alcohol percentage, the brewery and the style of beer.

ABV of Brewdog beers vs Untappd rating

In this small data set IBU (bitterness) and ratings do not correlate that well, nor ABV and IBU.

I also couldn’t find any other significant correlation of beer rating with other recipe parameters.

Amount of dry hop vs. Untappd rating.

Do high alcohol beers taste better? Do certain styles taste better than others? Are there such big differences between breweries? All questions I don’t know the answer to but one thing is for sure I cannot drink those 12% barrel aged stouts all day ;-)

ARTIFICIAL NEURAL BEER NETWORK

We already know that high alcohol beers are rated high. But what makes one 6% beer be rated higher than another 6% beer. What makes a beer great?

Looking at all the DIYDOG recipes this is difficult to understand for the human brain, at least my brain.

Maybe some artificial intelligence can help here? An artificial neural beer network, “ANBN”, sounds cool to me! Neural networks are very successful at recognizing things like images and speech. What neural networks can do well is categorise things based on a lot of information. The relation between the input and the output can be very complex but a neural network can be trained to make sense of this. The neural network can learn to perform better and better using a lot of input information and an expected output. And that is what we have: as input we have 250 recipes and as output we have 250 ratings! Typical neural networks are trained with 50,000 datapoints. Compared to this our set is very limited so we will not be able to create the best beer in the world. Don’t take this too seriously, this project is just for fun.

Software and heaps of documentation are available for free that help you get started with AI. For this exercise I’m using Tensorflow and Python.

FEATURE EXTRACTION

The Brewdog recipes use a lot of different ingredients. Since the number of recipes is limited I had to reduce the data and extract the features that mater the most.

Malt

In the majority of beer recipes, the bulk of the malt is pils malt or pale malt. Other malts are added in smaller quantities and those give tastes like caramel and coffee. These added malts also have the biggest influence on the beer color of EBC.

To reduce the data set I created one number for the amount of pils malt and another number for the total amount of special malts. Next to that I added booleans for the 8 special malt that are used the most (caramalt, munich, crystal 150, wheat, oats, carafa special 1, carafa special 2, Rye).

Hops

Typical for Brewdog recipes different hops are used per beer. Interestingly most of the time the same group of hops are used per hop addition.

To reduce the data set I created one number for the amount of hops per addition. And added booleans for the 8 hops that are used the most (amarillo, centenial, simcoe, chinook, citra, columbus, cascade).

Yeast

5 yeasts are used. I create booleans for these (WLP099, Wyeast 1056, Wyeast 1272, Wyeast 2007, Wyeast 3522, Wyeast 3711).

pH and fermentation temperature

pH and fermentation temperature are kept as number.

Clean-up the data

After removing a number of recipes with incomplete data or rating, I ended up with a data set of 226 recipes and ratings.

Recipes and ratings nicely in a 2D structure ready to get mashed…

BUILDING AN ARTIFICIAL NEURAL BEER NETWORK

Using Tensorflow and Python I created a 3-layer artificial neural beer network and started playing around.

For training and testing I had to split the data set into two. One set to train the neural network and the other to test. Care has to be taken not to over train the network. Also playing with the size of the different layers gave different results.

Training the network (blue = training set, red = test set)

I ended up using layers with 50, 75 and 50 nodes. 70 training epochs seems to be the maximum not to over train the network.

Furthermore I tested different neural network optimizers. The Adam optimizer gave the best results, thanks Adam, I owe you a beer!

The ANBN performs very well. For example, the Untappd rating of Punk IPA is 3.83 and the ANBN predicted this to be 3.77, that’s close.

CREATING A NEW BEER

Now that we got an ANBN that can estimate the rating of beer based on a recipe we can start to evaluate our own creations.

To do this I generated 1,000 random beer recipes. Since ratings highly correlate with the beer ABV, I had to introduce some smarts into the random beer recipe generator to not create a whiskey instead of a beer.

I limited the total amount of malt to 4.75 kg, 3 different hops, 3 special malts, one yeast, a fermentation temperature and a pH. The amount of hops was also limited per addition.

Set of 1,000 random beer recipes ready for some artificial tasting…

Next, I used the trained ANBN to evaluate the recipes and predict the ratings.

Within a fraction of a second the following recipe came out as the top beer:

  • Name: Artificial Dog
  • 3 kg pale malt
  • 1.7 kg special malt (combination of Oats, Carafel Special Type 1, Carafel Special Type 2)
  • 54 gr hop start (combination of Amarillo, Simcou and Citra)
  • 43 gr hop middle (combination of Amarillo, Simcou and Citra)
  • 8 gr hop end (combination of Amarillo, Simcou and Citra)
  • 310 gr hop dryhop (combination of Amarillo, Simcou and Citra)
  • Yeast: WLP099
  • pH: 4.6
  • Fermentation temperature: 23 C
  • Estimated Untappd rating: 4.67

FINAL THOUGHTS

Will artificial intelligence create our future beers? Probably not. Most likely it will become an extra tool in developing beers. Imagine an application that the brewer uses to develop new beers. The software not only calculates ABV, IBU and EBC but now also predicts the rating on Untappd. By playing around with the recipe the brewer can create new beers or optimize existing recipes. The tool will be a living system with new ratings continuously improving the neural network. Having ratings per batch instead of per beer might further improve the system and help to evaluate small optimizations. For this a brewery could develop their own rating app and use a QR code on every bottle to indicate the batch number.

This was a fun exercise, hope you like it.

Cheers,

Koen

--

--