{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":19018,"databundleVersionId":2703900,"sourceType":"competition"},{"sourceId":11650,"sourceType":"datasetVersion","datasetId":8327}],"dockerImageVersionId":30626,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nfrom tqdm import tqdm\nfrom sklearn.model_selection import train_test_split\nimport tensorflow as tf\nfrom keras.models import Sequential\nfrom sklearn import preprocessing, decomposition, model_selection, metrics, pipeline\nfrom keras.layers import GlobalMaxPooling1D, Conv1D, MaxPooling1D, Flatten, Bidirectional, SpatialDropout1D\nfrom keras.preprocessing import sequence, text\nfrom keras.callbacks import EarlyStopping\n\n\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n%matplotlib inline\nfrom plotly import graph_objs as go\nimport plotly.express as px\nimport plotly.figure_factory as ff","metadata":{"execution":{"iopub.status.busy":"2023-12-15T16:00:53.556373Z","iopub.execute_input":"2023-12-15T16:00:53.556801Z","iopub.status.idle":"2023-12-15T16:00:53.569714Z","shell.execute_reply.started":"2023-12-15T16:00:53.556768Z","shell.execute_reply":"2023-12-15T16:00:53.568230Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Detect hardware, return appropriate distribution strategy\ntry:\n    # TPU detection. No parameters necessary if TPU_NAME environment variable is\n    # set: this is always the case on Kaggle.\n    tpu = tf.distribute.cluster_resolver.TPUClusterResolver()\n    print('Running on TPU ', tpu.master())\nexcept ValueError:\n    tpu = None\n\nif tpu:\n    tf.config.experimental_connect_to_cluster(tpu)\n    tf.tpu.experimental.initialize_tpu_system(tpu)\n    strategy = tf.distribute.experimental.TPUStrategy(tpu)\nelse:\n    # Default distribution strategy in Tensorflow. Works on CPU and single GPU.\n    strategy = tf.distribute.get_strategy()\n\nprint(\"REPLICAS: \", strategy.num_replicas_in_sync)","metadata":{"execution":{"iopub.status.busy":"2023-12-15T16:02:12.303822Z","iopub.execute_input":"2023-12-15T16:02:12.304223Z","iopub.status.idle":"2023-12-15T16:02:12.313153Z","shell.execute_reply.started":"2023-12-15T16:02:12.304192Z","shell.execute_reply":"2023-12-15T16:02:12.311714Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/jigsaw-multilingual-toxic-comment-classification/jigsaw-toxic-comment-train.csv')\nvalidation = pd.read_csv('/kaggle/input/jigsaw-multilingual-toxic-comment-classification/validation.csv')\ntest = pd.read_csv('/kaggle/input/jigsaw-multilingual-toxic-comment-classification/test.csv')","metadata":{"execution":{"iopub.status.busy":"2023-12-15T16:06:17.064164Z","iopub.execute_input":"2023-12-15T16:06:17.064576Z","iopub.status.idle":"2023-12-15T16:06:19.484555Z","shell.execute_reply.started":"2023-12-15T16:06:17.064544Z","shell.execute_reply":"2023-12-15T16:06:19.483345Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.drop(['severe_toxic','obscene','threat','insult','identity_hate'],axis=1,inplace=True)\ntrain = train.loc[:12000,:]\ntrain.shape","metadata":{"execution":{"iopub.status.busy":"2023-12-15T16:06:42.143324Z","iopub.execute_input":"2023-12-15T16:06:42.143812Z","iopub.status.idle":"2023-12-15T16:06:42.188605Z","shell.execute_reply.started":"2023-12-15T16:06:42.143773Z","shell.execute_reply":"2023-12-15T16:06:42.187156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['comment_text'].apply(lambda x:len(str(x).split())).max()\n#max number of words that can be in a single comment","metadata":{"execution":{"iopub.status.busy":"2023-12-15T16:06:55.030026Z","iopub.execute_input":"2023-12-15T16:06:55.030444Z","iopub.status.idle":"2023-12-15T16:06:55.116599Z","shell.execute_reply.started":"2023-12-15T16:06:55.030412Z","shell.execute_reply":"2023-12-15T16:06:55.115451Z"},"trusted":true},"execution_count":null,"outputs":[]}]}