This notebook trains a model to detect toxicity in online comments. It uses a CNN architecture for text classification trained on the Wikipedia Talk Labels: Toxicity dataset and pre-trained GloVe embeddings which can be found at: http://nlp.stanford.edu/data/glove.6B.zip (source page: http://nlp.stanford.edu/projects/glove/).
This model is a modification of example code found in the Keras Github repository and released under an MIT license. For further details of this license, find it online or in this repository in the file KERAS_LICENSE.
(TODO: nthain) - Move to README
Prior to running the notebook, you must:
In [1]:
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import pandas as pd
from model_tool import ToxModel
In [2]:
SPLITS = ['train', 'dev', 'test']
wiki = {}
debias = {}
random = {}
for split in SPLITS:
wiki[split] = '../data/wiki_%s.csv' % split
debias[split] = '../data/wiki_debias_%s.csv' % split
random[split] = '../data/wiki_debias_random_%s.csv' % split
In [9]:
hparams = {'epochs': 4}
In [10]:
MODEL_NAME = 'cnn_debias_random_tox_v3'
debias_random_model = ToxModel(hparams=hparams)
debias_random_model.train(random['train'], random['dev'], text_column = 'comment', label_column = 'is_toxic', model_name = MODEL_NAME)
In [11]:
random_test = pd.read_csv(random['test'])
debias_random_model.score_auc(random_test['comment'], random_test['is_toxic'])
Out[11]:
In [12]:
MODEL_NAME = 'cnn_wiki_tox_v3'
wiki_model = ToxModel(hparams=hparams)
wiki_model.train(wiki['train'], wiki['dev'], text_column = 'comment', label_column = 'is_toxic', model_name = MODEL_NAME)
In [13]:
wiki_test = pd.read_csv(wiki['test'])
wiki_model.score_auc(wiki_test['comment'], wiki_test['is_toxic'])
Out[13]:
In [6]:
MODEL_NAME = 'cnn_debias_tox_v3'
debias_model = ToxModel(hparams=hparams)
debias_model.train(debias['train'], debias['dev'], text_column = 'comment', label_column = 'is_toxic', model_name = MODEL_NAME)
In [8]:
debias_test = pd.read_csv(debias['test'])
debias_model.score_auc(debias_test['comment'], debias_test['is_toxic'])
Out[8]:
In [ ]: