This project aims at building a RNN model with TensorFlow using a JSON-formatted dataset to detect a cuisine type from 20 classes based on the ingredients of recipes with varying length. In order to represent each word with a numeric vector, the pre-trained word embedding GloVe was used. Accuracy and the Cohen's Kappa metric are used to measure model's performance.
The data can be accessed here: Data
The GRU (gated recurrent units) cell is adopted in the optimized RNN. The number of units for each cell is 100, the time steps are 85, and the size of the input is 50. ReLU is used as the activation function in the last time step. Then, the output is fed into a dense layer to get the logits, which further go through the softmax activation function to get the 20 probabilities for each class. The highest probability corresponds to the predicted class. The cross entropy is used to compute the loss and the Adam optimizer is used to optimize the parameter of the model.

Fig 1. Tensorboard Computational Graph (left) and Simplified Flowchart (right)
The mathematical functions involved are shown below. Among them, W denotes the weights for all hidden cells and U represents the weights for all inputs x. V is the weights in the fully connected layer. Apparently, b and c are biases. It is worth mentioning that all hidden cells share the same weights W and all inputs share the same weights U across time in RNN.
Mathematical Functions Involved:

The effect of cells including basic cell, long short-term memory (LSTM) and gated recurrent unit (GRU), number of layers and dropout optimization technique have been investigated to improve the model's performance. Based on the optimized architecture which adopted one-layer GRU cell without dropout, the training set obtained the accuray of 83% and the loss of 0.53, and the test set obtained the accuracy of 75% and and the loss of 0.90 as shown below. The Cohen's Kappa was 0.72, indicating the model have favorable predictive power, rather than assigning labels randomly.


Fig 2. Accuracy (left) and Loss (right) For Training and Testing Data With Epochs (graphs from tensorboard)