Next, we will build a character based CNN model. We will start by creating embedding lookup with dimensions a number of characters and 50. First, the character set length is obtained from the character map:
def character_CNN(tf_char_map, char_map, char_embed_dim=50): char_set_len = len(char_map.keys())
Each convolution layer is initiated with a random variable for weights and biases. The convolution layer function will be called when the model is constructed:
def conv2d(x, W, b, strides=1): x = tf.nn.conv2d(x, W, strides=[1, strides, strides, 1], padding="SAME") x = tf.nn.bias_add(x, b) return tf.nn.relu(x)
Each layer is also followed by a max pooling layer, defined as follows:
def maxpool2d(x, k=2): return tf.nn.max_pool(x ...