Can we teach AI to taste?
No, or not in this article at least. But could we teach AI the language of taste? Maybe!
As a student, fine wines are almost entirely absent from my life. However, the (somewhat magical) marketing that powers the industry has always been of interest. How can something as simple as fermented grape juice be so varied that one vintage pairs perfectly with a specific cheese from another continent, and the next is only to be enjoyed with grilled seabass? Is it all in the imagination?
With every bottle comes a consistently creative description which serves to aid both sales and enjoyment at the same time. An example from Majestic:
An easily enjoyable Chardonnay that combines fresh apple, nectarine and tangerine flavours with subtle creaminess, hints of toasted almonds and a gently spicy complexity. Try this with seared scallops served with black pudding.
This language is so characteristic of a wine description that I was certain an AI could come up with equally inventive sentences.
After some time collecting a few thousand examples from across the web, it was time to crack out Keras.
RNNs (Recurrent Neural Networks) have been the tool of choice for many recent text-generation problems. In essence, they start with some partially-complete sentence and try to predict what the next character will be. This differs from more traditional methods on a fundamental level: the model has to learn words, punctuation and grammar itself.
It only takes a few lines of Python to define the model architecture:
The key layers here are:
- Embedding: converts text to numerical vectors so that they can be efficiently used for computation.
- LSTM (Long Short-Term Memory): gives the network its ability to learn about the structure of words and sentences.
After some initial tinkering, the results weren’t great:
2800Ingy, sowe tropical aromas of uraly and rich, close with glass.The Partrigions is quarity aromas that stink put of Itoa’s thlight. the little 6Jote take bads are Chardonnay as vanilla at great mhink with notes and fresh.
One issue with this approach is the start of the sentence. Initially, the model has no previous characters to base its prediction on, so it’s essentially random. To solve this, I cheated and gave the model a helping hand by starting off the descriptions with “This [grape] is”. This led to slightly improved results…
This Malbec is followed by shows a rich and ‘athed citrus bubblesh encention on the east Save Orien of rarberry and spice pleasant finish.
…which were still pretty terrible.
The remarkable thing about machine learning is that a tiny change to a couple of model parameters can make a colossal difference to accuracy. After some solid experimentation, collecting and cleaning more data, and refining the model architecture, the results were looking better:
This Sauvignon Blanc is full-bodied with peppery dark notes and dried herbs. This mouthwatering clear character and full body supported by elegant savoury, subtle Souilley Sipult Farnes has long.
A white wine with peppery dark notes... hmm…
Nevertheless, this showed that the model was now fairly well suited to the problem. Now, it was just a matter of leaving it to train on the whole dataset for a significant amount of time. Many hours later..
This Pinot Noir is even with its ripe peach, quince and orange mineral notes. Intense and elegant on the palate with delicately sweet fruit notes on the finish.
This Merlot is rich, deep, full and lovely with savoury fruit flavours and hints of leather. This is a real varietal in which this wine is well-planted on its own or with food.
Taking a step back: I think it’s unbelievable that by learning from just a few thousand examples an algorithm can teach itself almost perfect English, even if with a limited purpose.
That said, I don’t think the people who write wine descriptions will be out of a job any time soon. These generated descriptions are plucked from thin air and I would hope there is at least some truth to the real text you see on the back of a bottle.
Side note: if anyone does start a business along these lines, please call it sommel.ai.
If you enjoyed this article, feel free to say hi@xav.ai!