'How to use Keras CNN for categorical classification on multidimensional non-image data?

I had read somewhere that CNN's can also be used on non-image data and figured I would give it a shot by attempting to write a python script which could play the mobile game '2048'. Ive searched far and wide but cant find any solution to my confusion on how I'm supposed to pass the data to the input layer of the CNN.

The Setup
'2048' consists of a 4x4 square of numbers in which after swiping either up, down, left or right, any adjacent tiles of the same number merge together and add up to create a new number of twice the size. Numbers randomly spawn in powers of 2 and the goal is to merge enough tiles to get the 2048 tile.

To prevent biases, I decided to one-hot encode the number tiles up until the value 2048 e.g.

one_hot = dict([
    (2,    np.array([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])),
    (4,    np.array([0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0])),
    (8,    np.array([0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0])),
    (16,   np.array([0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0])),
    (32,   np.array([0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0])),
    (64,   np.array([0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0])),
    (128,  np.array([0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0])),
    (256,  np.array([0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0])),
    (512,  np.array([0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0])),
    (1024, np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0])),
    (2048, np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]))
])

Combining this with the 4x4 nature of the '2048' square, the input data (batch size ignored) is of dimension (4, 4, 11).

Id like to pass this data to the CNN and have it classify the best of the four "swiping directions". The output shape should be (4).

The Question
Using Keras, how should i be passing data of this dimension to the input layer and what should I be doing in regards to the channels?

Should I use Conv2d layers and use the one-hot encoded categories as the channels like this?

inputs = keras.Input(shape=(4, 4, 11), batch_size=self.parameters.batch_size)

or should I use Conv3d layers and choose an arbitrary amount of channels like this?

inputs = keras.Input(shape=(4, 4, 11, 3), batch_size=self.parameters.batch_size)

or is there any other way of doing this that I don't know about?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source