parameters: (x, y)
return_statement: return {'class': tf.argmax(prediction, 1), 'prob': prediction}, loss, train_op
docstring: 2 layer Convolutional network to predict from sequence of words
    to a class.
docstring_summary: 2 layer Convolutional network to predict from sequence of words
    to a class.
docstring_tokens: 2 layer Convolutional network to predict from sequence of words to a class .
function: def cnn_model(x, y):
    """2 layer Convolutional network to predict from sequence of words
    to a class."""
    # Convert indexes of words into embeddings.
    # This creates embeddings matrix of [n_words, EMBEDDING_SIZE] and then
    # maps word indexes of the sequence into [batch_size, sequence_length,
    # EMBEDDING_SIZE].
    y = tf.one_hot(y, 15, 1, 0)
    word_vectors = learn.ops.categorical_variable(x, n_classes=n_words,
        embedding_size=EMBEDDING_SIZE, name='words')
    word_vectors = tf.expand_dims(word_vectors, 3)
    with tf.variable_scope('CNN_Layer1'):
      # Apply Convolution filtering on input sequence.
      conv1 = tf.contrib.layers.convolution2d(word_vectors, N_FILTERS,
                                              FILTER_SHAPE1, padding='VALID')
      # Add a RELU for non linearity.
      conv1 = tf.nn.relu(conv1)
      # Max pooling across output of Convolution+Relu.
      pool1 = tf.nn.max_pool(conv1, ksize=[1, POOLING_WINDOW, 1, 1],
          strides=[1, POOLING_STRIDE, 1, 1], padding='SAME')
      # Transpose matrix so that n_filters from convolution becomes width.
      pool1 = tf.transpose(pool1, [0, 1, 3, 2])
    with tf.variable_scope('CNN_Layer2'):
      # Second level of convolution filtering.
      conv2 = tf.contrib.layers.convolution2d(pool1, N_FILTERS,
                                              FILTER_SHAPE2, padding='VALID')
      # Max across each filter to get useful features for classification.
      pool2 = tf.squeeze(tf.reduce_max(conv2, 1), squeeze_dims=[1])
  
    # Apply regular WX + B and classification.
    prediction, loss = learn.models.logistic_regression(pool2, y)
  
    train_op = tf.contrib.layers.optimize_loss(
        loss, tf.contrib.framework.get_global_step(),
        optimizer='Adam', learning_rate=0.01)
  
    return {'class': tf.argmax(prediction, 1), 'prob': prediction}, loss, train_op
function_tokens: def cnn_model ( x , y ) : # Convert indexes of words into embeddings. # This creates embeddings matrix of [n_words, EMBEDDING_SIZE] and then # maps word indexes of the sequence into [batch_size, sequence_length, # EMBEDDING_SIZE]. y = tf . one_hot ( y , 15 , 1 , 0 ) word_vectors = learn . ops . categorical_variable ( x , n_classes = n_words , embedding_size = EMBEDDING_SIZE , name = 'words' ) word_vectors = tf . expand_dims ( word_vectors , 3 ) with tf . variable_scope ( 'CNN_Layer1' ) : # Apply Convolution filtering on input sequence. conv1 = tf . contrib . layers . convolution2d ( word_vectors , N_FILTERS , FILTER_SHAPE1 , padding = 'VALID' ) # Add a RELU for non linearity. conv1 = tf . nn . relu ( conv1 ) # Max pooling across output of Convolution+Relu. pool1 = tf . nn . max_pool ( conv1 , ksize = [ 1 , POOLING_WINDOW , 1 , 1 ] , strides = [ 1 , POOLING_STRIDE , 1 , 1 ] , padding = 'SAME' ) # Transpose matrix so that n_filters from convolution becomes width. pool1 = tf . transpose ( pool1 , [ 0 , 1 , 3 , 2 ] ) with tf . variable_scope ( 'CNN_Layer2' ) : # Second level of convolution filtering. conv2 = tf . contrib . layers . convolution2d ( pool1 , N_FILTERS , FILTER_SHAPE2 , padding = 'VALID' ) # Max across each filter to get useful features for classification. pool2 = tf . squeeze ( tf . reduce_max ( conv2 , 1 ) , squeeze_dims = [ 1 ] ) # Apply regular WX + B and classification. prediction , loss = learn . models . logistic_regression ( pool2 , y ) train_op = tf . contrib . layers . optimize_loss ( loss , tf . contrib . framework . get_global_step ( ) , optimizer = 'Adam' , learning_rate = 0.01 ) return { 'class' : tf . argmax ( prediction , 1 ) , 'prob' : prediction } , loss , train_op