Kaggle competition: Kannada MNIST
sample_sub=pd.read_csv('.. /input/nlp-getting-started/sample_submission.csv')
 submit=pd.DataFrame({'id':sample_sub['id'].values.tolist() ,'target':flat_predictions})
 submit.to_csv('submission.csv',index=False )<install_modules>
train=pd.read_csv("/kaggle/input/Kannada-MNIST/train.csv")
 test=pd.read_csv("/kaggle/input/Kannada-MNIST/test.csv" )
!pip install -U pip
!pip install tweet-preprocessor
!pip install -q tf-nightly
!pip install -q tf-models-nightly<choose_model_class>
ids=test.id
test=test.drop(["id"],axis=1)
 train_result=train.label
train=train.drop(["label"],axis=1)
 test=test.iloc[:,:].values
test=test.reshape(-1,28,28,1)
 y=train_result.iloc[:].values
x=train.iloc[:,:].values
x=x.reshape(-1,28,28,1)
 x, test= x/255.0,test/255.0
ps = PorterStemmer()
lc = LancasterStemmer()
sb = SnowballStemmer("english")
 for dirname, _, filenames in os.walk('/kaggle/input'):
for filename in filenames:
print(os.path.join(dirname, filename)) 
<define_variables>
datagen = ImageDataGenerator(
 rotation_range=10,
zoom_range = 0.25,
width_shift_range=0.25,
height_shift_range=0.25 )
tf.random.set_seed(123)
 np.random.seed(123)
 start_time = time.time()<load_from_csv>
Sequential=keras.Sequential
Conv2D=keras.layers.Conv2D
MaxPool2D=keras.layers.MaxPool2D
Dense=keras.layers.Dense
Flatten=keras.layers.Flatten
Dropout=keras.layers.Dropout
BatchNormalization=keras.layers.BatchNormalization
data = pd.read_csv('/kaggle/input/nlp-getting-started/train.csv')
 test = pd.read_csv('/kaggle/input/nlp-getting-started/test.csv' )<string_transform>
def generate_model() :
model=Sequential()
model.add(Conv2D(filters = 64, kernel_size =(3,3),padding = 'same',
activation ='relu', input_shape =(28,28,1)))
 model.add(Conv2D(filters = 64, kernel_size =(3,3),padding = 'same',
activation ='relu', input_shape =(28,28,1)))
 model.add(BatchNormalization())
 model.add(MaxPool2D(pool_size=(2,2),strides=(2,2)))
 model.add(Dropout(0.3))
model.add(Conv2D(filters = 128, kernel_size =(3,3),padding = 'same',
activation ='relu'))
model.add(Conv2D(filters = 128, kernel_size =(3,3),padding = 'same',
activation ='relu'))
model.add(Conv2D(filters = 128, kernel_size =(3,3),padding = 'same',
activation ='relu'))
model.add(BatchNormalization())
 model.add(MaxPool2D(pool_size=(2,2),strides=(2,2)))
 model.add(Dropout(0.3))
model.add(Flatten())
 model.add(Dense(256, activation = "relu"))
model.add(Dropout(0.3))
model.add(Dense(10, activation = "softmax"))
model.compile(keras.optimizers.Adam(0.0001),
loss="sparse_categorical_crossentropy",
metrics=["accuracy"] 
)
 return model
stopwords_en = stopwords.words('english')
 def unicode_to_ascii(s):
return ''.join(c for c in unicodedata.normalize('NFD', s)if unicodedata.category(c)!= 'Mn')
 twitter_p.set_options(twitter_p.OPT.URL)
 def preprocess_sentence(w):
w = twitter_p.clean(w)
 w = unicode_to_ascii(w.lower().strip())
 w = re.sub(r"([@
w = re.sub(r'[" "]+', " ", w)
 w = ' '.join([word for word in w.split(' ')if word not in stopwords_en])
 w = w.rstrip().strip()
return w<feature_engineering>
x_train, x_test, y_train, y_test=train_test_split(x,y,test_size=0.2 )
data = data.fillna(value='')
 data['text'] = data['text'].apply(func=preprocess_sentence)
 data['keyword'] = data['keyword'].apply(func=preprocess_sentence)
 test = test.fillna(value='')
 test['text'] = test['text'].apply(func=preprocess_sentence)
 test['keyword'] = test['keyword'].apply(func=preprocess_sentence )<define_variables>
model=generate_model()
history = model.fit_generator(datagen.flow(x_train,y_train, batch_size=40),
epochs = 45,
validation_data=(x_test,y_test),
validation_steps=int(x_test.shape[0]/40),
verbose = 1, steps_per_epoch=x_train.shape[0] / 40 )
tokenizer = bert.tokenization.FullTokenizer(vocab_file=os.path.join(gs_folder_bert, 'vocab.txt'), do_lower_case=True)
 print('Vocab Size:', len(tokenizer.vocab))<feature_engineering>
predictions=model.predict_classes(test)
 output=pd.DataFrame({"id":ids, "label":predictions})
 output.to_csv("submission.csv",index=False )