Kaggle competition: Digit Recognizer
<SOS> metric: categorizationaccuracy Kaggle data source: digit-recognizer<prepare_output>
import tensorflow as tf
import numpy as np
import pandas as pd
df_pred=pd.DataFrame(predlist)
 df_pred.columns=['target']
frames=[df1,df_pred]
df2=pd.concat(frames, axis=1)
 display(df2.head() )<feature_engineering>
training = pd.read_csv('.. /input/digit-recognizer/train.csv' )
df2.loc[df2['target']=='target','target']=1
df2.loc[df2['target']=='not_target','target']=0
display(df2['target'].mean())
 df2=df2[['id','target']]
display(df2.shape)
 display(df2.head() )<save_to_csv>
x_train, y_train = training.iloc[:, 1:], training.iloc[:, 0:1]
df2.to_csv("submission.csv", index=False )<load_from_url>
x_train = x_train / 255
!wget --quiet https://raw.githubusercontent.com/tensorflow/models/master/official/nlp/bert/tokenization.py<import_modules>
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Conv2D(filters=32, kernel_size=5, padding="same", activation="relu", input_shape=[28, 28, 1]))
model.add(tf.keras.layers.Conv2D(filters=32, kernel_size=5, padding="same", activation="relu"))
model.add(tf.keras.layers.MaxPool2D(pool_size=2, strides=2, padding='valid'))
model.add(tf.keras.layers.Dropout(0.2))
model.add(tf.keras.layers.Conv2D(filters=64, kernel_size=3, padding="same", activation="relu"))
model.add(tf.keras.layers.Conv2D(filters=64, kernel_size=3, padding="same", activation="relu"))
model.add(tf.keras.layers.MaxPool2D(pool_size=2, strides=2, padding='valid'))
model.add(tf.keras.layers.Dropout(0.2))
model.add(tf.keras.layers.Flatten())
 model.add(tf.keras.layers.Dense(units=256, activation='relu'))
model.add(tf.keras.layers.Dropout(0.4))
model.add(tf.keras.layers.Dense(units=10, activation='softmax'))
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['sparse_categorical_accuracy'])
 model.summary()
import numpy as np
import pandas as pd
import tensorflow as tf
from tensorflow.keras import layers, models, optimizers
from tensorflow.keras.callbacks import ModelCheckpoint<load_from_csv>
model.fit(x_train, y_train, epochs=15 )
train = pd.read_csv("/kaggle/input/nlp-getting-started/train.csv")
 test = pd.read_csv("/kaggle/input/nlp-getting-started/test.csv")
 submission = pd.read_csv("/kaggle/input/nlp-getting-started/sample_submission.csv" )<categorify>
test = pd.read_csv('.. /input/digit-recognizer/test.csv')
 test = test / 255
test = test.values.reshape(-1, 28, 28, 1 )
def bert_encode(texts, tokenizer, max_len):
all_tokens = []
all_masks = []
all_segments = []
for text in texts:
text = tokenizer.tokenize(text)
 text = text[:max_len-2]
input_sequence = ["[CLS]"] + text + ["[SEP]"]
pad_len = max_len - len(input_sequence)
 tokens = tokenizer.convert_tokens_to_ids(input_sequence)
 tokens += [0] * pad_len
pad_masks = [1] * len(input_sequence)+ [0] * pad_len
segment_ids = [0] * max_len
all_tokens.append(tokens)
 all_masks.append(pad_masks)
 all_segments.append(segment_ids)
 return np.array(all_tokens), np.array(all_masks), np.array(all_segments )<data_type_conversions>
predictions = model.predict(test )
<categorify><EOS> 
export = pd.DataFrame([np.argmax(prediction)for prediction in predictions])
 export.index += 1
export = export.reset_index()
export.columns = ['ImageId', 'Label']
export.to_csv('submission.csv', index=False )