ScalphaGoZero

An independent implementation of DeepMind's AlphaGoZero in Scala, using Deeplearning4J (DL4J)

View the Project on GitHub maxpumperla/ScalphaGoZero

ScalphaGoZero Build Status

ScalphaGoZero is an independent implementation of DeepMind’s AlphaGo Zero in Scala, using Deeplearning4J (DL4J) to run neural networks. You can either run experiments with models built in DL4J directly or import prebuilt Keras models.

ScalphaGoZero is mainly an engineering effort to demonstrate how complex and successful systems in machine learning are not bound to Python anymore. With access to powerful tools like ND4J for advanced maths, DL4J for neural networks, and the mature infrastructure of the JVM, languages like Scala can offer a viable alternative for data scientists.

This project is a Scala port of the AlphaGo Zero module found in Deep Learning and the Game of Go.

Getting started

To run after cloning, do

cd ScalphaGoZero
sbt run

This application will set up two opponents, simulate some specified number of games between them using the AlphaGo Zero methodology and train one of the opponents with the experience data gained from the games. You can also accumulate training experience in a saved model and use that model later.

To use Keras model import you need to generate the resources first:

cd src/test/python
pip install tensorflow keras
python generate_h5_resources.py

The generated, serialized Keras models are put into src/main/resources and are picked up by the KerasModel class, as demonstrated in our tests.

GTP Client

It is possible to build a fat executable jar that can be used as a GTP client for Go front ends like Sabaki. First run sbt assembly to build the fat jar. The engine can be run as

java -jar target/scala-2.12/ScalphaGoZero-assembly-1.0.1.jar gtp

However, you should use the gtpClient.bat (on Windows) when configuring Sabaki. Go to Engines | Manage Engines in the top menu, then add a ScalphaGoZero engine as shown here.

add scalphaGoZero engine to Sabaki

Then, from the menu, do File | New. This allows you to configure a new game and have one or both players use the engine that you just added. It will attempt to load the model file from the models directory based on the board size specified. Currently, there is only a model file for 5x5 games. It is models/model_size_5_layers_2.model.

Sabaki play with ScalphaGoZero engine

When running, inofrmation and errors are logged to output.log.

Core Concepts

Quite a few concepts are needed to build an AlphaGoZero system, ScalphaGoZero is intended as a software developer friendly approach with clean abstractions to help users get started. Many of the concepts used here can be reused for other games, only the basics are really designed for the game of Go. For black, or white, or both, select the ScalphaGoZero engine that you just added and play the game.

Contribute

ScalphaGoZero can be improved in many ways, here are a few examples: