<jupyter_start><jupyter_text>Simple 1D (and shallow 2D) convnet and model inspection example<jupyter_code># Import libraries
# Load data
# Format data into 1D (single variable) long 2D arrays
# Conv net Model spec

def max_pool_2x1(tensor_in):
    return tf.nn.max_pool(tensor_in, ksize=[1, 2, 1, 1], strides=[1, 2, 1, 1],
        padding='SAME')

def conv_model(X, y):
    # reshape X to 4d tensor with 2nd and 3rd dimensions being image width and height
    # final dimension being the number of color channels
    X = tf.reshape(X, [-1, 100, 1, 1])
    # first conv layer will compute 32 features for each 5x1 strip
    with tf.variable_scope('conv_layer1'):
        h_conv1 = skflow.ops.conv2d(X, n_filters=32, filter_shape=[5, 1], 
                                    bias=True, activation=tf.nn.relu)
        h_pool1 = max_pool_2x1(h_conv1)
    # second conv layer will compute 64 features for each 5x1 strip
    with tf.variable_scope('conv_layer2'):
        h_conv2 = skflow.ops.conv2d(h_pool1, n_filters=64, filter_shape=[5, 1], 
                                    bias=True, activation=tf.nn.relu)
        h_pool2 = max_pool_2x1(h_conv2)
        # reshape tensor into a batch of vectors
        h_pool2_flat = tf.reshape(h_pool2, [-1, 5 * 5 * 64])
    # densely connected layer with 1024 neurons
    h_fc1 = skflow.ops.dnn(h_pool2_flat, [1024], activation=tf.nn.relu, dropout=0.5)
    return skflow.models.logistic_regression(h_fc1, y)

# # Training and predicting
# classifier3 = skflow.TensorFlowEstimator(
#     model_fn=conv_model, n_classes=10, batch_size=100, steps=20000,
#     learning_rate=0.001)
# Model fit - once and compare to linear regression
# Convnet
convnet = skflow.TensorFlowEstimator(
    model_fn=conv_model, n_classes=10, batch_size=100, steps=20000,
    learning_rate=0.001,verbose=0)

convnet.fit(traindata,trainlabs1D-1)
# lr.fit(both_c,tt_c.squeeze())
# print(accuracy_score(testlabs1D-1,convnet.predict(testdata)))
scores_convnet = cross_validation.cross_val_score(convnet, both_c, tt_c.squeeze()-1, cv=5,scoring='accuracy') #'f1_weighted')

print(scores_convnet)
print(np.mean(scores_convnet))
# Weight inspection<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10902427851580394, 'fraction_numerical': 0.05084745762711865, 'mean_word_length': 3.8859060402684564, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '304583', 'license': 'MIT', 'n_tokens_mistral': 850, 'n_tokens_neox': 775, 'n_words': 182, 'path': 'tf/Convnet.ipynb', 'repo_name': 'mathewzilla/whiskfree', 'size': '2183'}