QQFLY.NET
← Writing

A few thoughts on AlphaGo

On the Monday before AlphaGo’s May 2017 match with Ke Jie, I happened to reread the AlphaGo paper for unrelated reasons.

A May 2017 social post about rereading the AlphaGo paper

Then came AlphaGo’s games against Ke Jie. I watched the games and the press conferences, and found myself wanting to explain how the system worked—and to offer a few guesses about its behavior.

I had also just received a reply from David Silver to some questions I had sent him. From that exchange, it seemed that the training strategy of the AlphaGo playing in May 2017 had not changed substantially from the previous year. The explanation below therefore follows the paper David and Aja published in Nature in 2016.

How AlphaGo works

To explain how AlphaGo works, let me take a few liberties with the story of its creation. The scenes and dialogue below are made up.

An illustration introducing Aja Huang and DeepMind

Any account of AlphaGo has to mention Aja Huang. As an undergraduate at National Chiao Tung University in Taiwan, he had already reached amateur 6-dan in Go. He continued researching Go AI and eventually became AlphaGo’s lead programmer.

One thing to bear in mind: the state space of Go is far too large to exhaust by brute-force search.

A Go-board animation illustrating the large state space

Before AlphaGo, two major approaches in Go AI were supervised learning and Monte Carlo search. Let us start there.

Supervised learning

The obvious approach is to show the AI game records from strong human players and ask it to predict their moves. This is a classification problem: take a board position as input and output where to place the next stone.

But doing that well is hard. Before 2015, even the strongest supervised-learning Go systems managed only about 35% move-prediction accuracy. That was nowhere near enough to challenge the best human players.

Monte Carlo search

Monte Carlo search is a familiar tool for large planning problems. A Go AI needs to choose its next move. If it could estimate the eventual probability of winning from each candidate move, it could choose the one with the highest probability.

The difficulty is that every move opens up hundreds of possible replies. The state space is too large to determine the consequence of every choice by brute force.

Monte Carlo methods replace that exhaustive calculation with sampling. Starting from a candidate move, simulate continuations of the game and record their outcomes. After n sampled games, use the average success rate as an estimate for that move.

Monte Carlo sampling of continuations from a current state

For the theory, see Sutton’s book on reinforcement learning. Intuitively, Monte Carlo methods use observed frequencies in samples to estimate probabilities. Flip a fair coin enough times and the proportion of heads approaches 0.5.

Such methods became the state of the art in Go AI. Huang’s doctoral and postdoctoral research concerned Go strategies based on Monte Carlo methods.

From deep networks to fast rollouts

Huang arrives at DeepMind and keeps checking the Go rankings. Whether he uses supervised learning or Monte Carlo search, his AI is still only around 5-dan.

A fictional comic exchange between Aja Huang and David Silver

David Silver, fresh from teaching a reinforcement-learning class, finds him looking dejected by the roadside.

“Young man, I can tell you have extraordinary potential. I happen to have a secret manual. Put me down as first author when you publish in Nature, and it is yours.”

A film-image parody presenting a machine-learning method as a secret martial-arts manual

Huang receives the manual with due reverence. With Silver’s help, he trains a deep convolutional neural network—a supervised-learning policy network—on existing Go games. Move-prediction accuracy reaches 57%, and the network wins 97% of its games against the conventional GunGo program.

Against human players, however, that is still only around 6-dan. Perhaps a classifier is too concerned with the current position and lacks a view of the whole game. Could it be combined with Monte Carlo search?

The original search relies on random sampling. If the simulated continuations were guided by something resembling human play, perhaps the resulting value estimates would be better.

So the trained DCNN is used to guide the Monte Carlo sampling. The combination does indeed outperform the DCNN alone: in the reported comparison, it wins 87% of the games.[1]

[1] Maddison, Chris J., et al. “Move evaluation in go using deep convolutional neural networks.” arXiv preprint arXiv:1412.6564 (2014).

There is a problem: the DCNN is slow. A 13-layer CNN needs about 3 ms to calculate the next move. That is expensive when used repeatedly inside Monte Carlo simulation.

Does a sampling method really need such a powerful network at every step?

Huang instead trains a much simpler classifier: the rollout policy network, using hand-designed features and a linear softmax classifier. Its prediction accuracy is only 24.2%, but it takes just 2 μs to select a move. That makes it a much better companion for Monte Carlo search.

The AI may now be able to beat Huang himself. Against players such as Ke Jie, though, it is still out of its league.

The recurring fictional roadside conversation between Aja Huang and David Silver

Back to the roadside. Huang sits down for a cigarette; David returns with another book to sell.

Another secret-manual parody, this time introducing reinforcement learning

Self-play and reinforcement learning

Human players do not stop at learning the rules or copying other people’s moves. They improve by playing. Could an AI do the same?

With David’s help, Huang turns the DCNN into a reinforcement-learning policy network. Start with the network already trained through supervised learning, then let it play against itself. Judge the result, rather than prescribing every move: a win earns +1, a loss −1. Use that reward to determine the direction and size of the network’s weight updates.

By the time the team submits to Nature, the RL policy network wins 80% of its games against the original SL policy network.

How to use it remains a question. Taking its move prediction directly still lacks the broader perspective we want; putting it into Monte Carlo simulations is too slow.

The value network

Then David—or Huang—has another idea. Monte Carlo simulation is being used to estimate the value of a move. Could a deep network estimate that value directly?

This gives us the final network in the AlphaGo system: the value network. Its structure is broadly similar to the policy network, so it can extract similar features, but its output is a value rather than a move location.

That is a regression problem. During self-play, sample board positions and use the eventual win or loss to train the value network.

The resulting estimates are close in accuracy to those obtained by averaging Monte Carlo samples generated with the RL policy network. But evaluation with the value network is 15,000 times faster.

We now have the four networks used in AlphaGo:

Diagram of AlphaGo’s rollout, supervised-learning policy, reinforcement-learning policy, and value networks

In actual play, only the rollout policy network and the value network are used: the value-network estimate is combined with the estimate from Monte Carlo simulation using the fast rollout policy.

We have all seen the result.

A collage of match photographs and players’ reactions

Some curious behavior

The May 2017 matches also produced a few interesting observations:

  1. AlphaGo tended to win by only a small number of points. When ahead, it played more conservatively; when behind, it became more aggressive. At times that could look almost like it was giving its opponent a chance.
  2. In the pair-Go game with Gu Li, AlphaGo wanted to resign in the middle game. My guess is that its value network considered the position lost. Gu Li disagreed, and AlphaGo, playing Black, went on to make several apparently bad moves.

Some media coverage preferred to explain these things in human terms, giving the impression that AlphaGo had human feelings or intentions.

A reaction meme joking about sensational, anthropomorphic coverage

From my email exchange with David Silver, I confirmed that this version of AlphaGo was still trained with reinforcement learning, recording a reward of ±1 after each self-play game.

The following explanations are therefore my own speculation, not conclusions from DeepMind.

Why win by so little? Training records the win or loss, not the final point margin. When two similarly strong players compete, close results are likely. My guess is that AlphaGo’s training data therefore concentrated on games won or lost by a small margin.

It may have seen relatively few positions from which it could win by a large margin. Faced with an opportunity for a very high score, it might be less able to maintain its level of play and instead “choose” a more conservative course.

One possible experiment would be to use the final score margin as the reward, rather than simply +1 or −1.

Why make bad moves after trying to resign? During self-play, an AlphaGo that falls behind has little chance of recovering, since its opponent is another AlphaGo of the same strength. Perhaps its policy therefore improves little in those losing states.

There are countless bad moves available from a given state. A reward of −1 discourages one bad choice, but does not necessarily guide the system toward a good one.

One possible approach would be to give AlphaGo deliberately bad starting positions and let it play weaker opponents, such as the first AlphaGo or the SL policy network. It might then still be able to improve its play from those positions.

My guess about the May 2017 version is that its overall algorithm remains much the same as the previous year’s, perhaps with changes to the CNN that improve feature extraction. We will have to wait for DeepMind’s next paper to know.

I admire DeepMind more each time I reread that Nature paper. Methods like these really do seem to bring general AI a little closer.

I say all this as a robotics PhD student who knows neither Go nor machine learning. Please go easy on me.

← Writing