<jupyter_start><jupyter_text>Notes:- Important parameters: kernel size, no. of feature maps- 1-max pooling generally outperforms otehr types of pooling- Dropout has little effect- Gridsearch across kernel size in the range 1-10- Search no. of filters from 100-600 and dropout of 0.0-0.5- Explore tanh, relu, linear activation functions<jupyter_code>model_name = 'CNN_single_'
corpus = 'comment_text'<jupyter_output><empty_output><jupyter_text>Import data<jupyter_code>import os
import numpy as np
import pandas as pd
dir_path = os.path.realpath('..')
path = 'data/processed/test.csv'

full_path = os.path.join(dir_path, path)
df = pd.read_csv(full_path, header=0, index_col=0)
print("Dataset has {} rows, {} columns.".format(*df.shape))<jupyter_output>Dataset has 226998 rows, 1 columns.<jupyter_text>Pre-processing<jupyter_code>import pickle
from keras.preprocessing.sequence import pad_sequences
# load tokenizer
with open('tokenizer.pickle', 'rb') as handle:
    t = pickle.load(handle)

vocab_size = len(t.word_index) + 1
max_length = 1000

# integer encode and pad the documents
encoded_test = t.texts_to_sequences(df[corpus].astype(str))
padded_test = pad_sequences(encoded_test, maxlen=max_length, padding='post')<jupyter_output><empty_output><jupyter_text>Evaluation<jupyter_code>from keras.models import model_from_json
from sklearn.metrics import log_loss
def load_model(model_path):
    # load json and create model
    json_file = open(model_path+'.json', 'r')
    loaded_model_json = json_file.read()
    json_file.close()
    loaded_model = model_from_json(loaded_model_json)
    # load weights into new model
    loaded_model.load_weights(model_path+".h5")
    print("Loaded model from disk")
    return loaded_model
# load the model
model_path = os.path.join(dir_path, 'models', model_name)
model = load_model(model_path)

y_pred_proba = model.predict(padded_test, verbose=1, batch_size=1)
target = ['toxic', 'severe_toxic', 'obscene', 'threat', 'insult', 'identity_hate']
submission = pd.DataFrame(y_pred_proba, index=df.index, columns=target)
## Output submissions

path = 'data/submissions/' + model_name + '.csv'

dir_path = os.path.realpath('..')
full_path = os.path.join(dir_path, path)

submission.to_csv(full_path, header=True, index=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11644134321849106, 'fraction_numerical': 0.013519406890536415, 'mean_word_length': 6.191222570532916, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '603089', 'license': 'MIT', 'n_tokens_mistral': 824, 'n_tokens_neox': 785, 'n_words': 181, 'path': 'notebooks/11-jc-submission.ipynb', 'repo_name': 'joaeechew/toxic', 'size': '2293'}