{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":19018,"databundleVersionId":2703900,"sourceType":"competition"},{"sourceId":10059645,"sourceType":"datasetVersion","datasetId":5490576}],"dockerImageVersionId":30762,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np \nimport pandas as pd \nfrom tqdm import tqdm\nfrom sklearn.model_selection import train_test_split\nimport tensorflow as tf\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import LSTM, GRU,SimpleRNN\nfrom tensorflow.keras.layers import Dense, Activation, Dropout\nfrom tensorflow.keras.layers import Embedding\nfrom tensorflow.keras.layers import BatchNormalization\nfrom tensorflow.python.keras.utils import np_utils\nfrom sklearn import preprocessing, decomposition, model_selection, metrics, pipeline\nfrom tensorflow.keras.layers import GlobalMaxPooling1D, Conv1D, MaxPooling1D, Flatten, Bidirectional, SpatialDropout1D\nfrom tensorflow.keras.preprocessing import sequence, text\nfrom tensorflow.keras.callbacks import EarlyStopping\nfrom wordcloud import WordCloud\nfrom tensorflow.keras.preprocessing.text import one_hot\nimport gensim\nfrom tensorflow.keras.preprocessing.text import Tokenizer\nfrom sklearn.metrics import classification_report,accuracy_score\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\nfrom PIL import Image, ImageDraw, ImageFont\nfrom tensorflow.keras.preprocessing.sequence import pad_sequences\nfrom sklearn.metrics import confusion_matrix\nimport sklearn.metrics as metrics\nfrom sklearn.metrics import confusion_matrix\nimport seaborn as sn","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:56:34.260988Z","iopub.execute_input":"2025-04-17T15:56:34.261283Z","iopub.status.idle":"2025-04-17T15:57:00.518575Z","shell.execute_reply.started":"2025-04-17T15:56:34.261248Z","shell.execute_reply":"2025-04-17T15:57:00.517895Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:00.520318Z","iopub.execute_input":"2025-04-17T15:57:00.521222Z","iopub.status.idle":"2025-04-17T15:57:00.528446Z","shell.execute_reply.started":"2025-04-17T15:57:00.521183Z","shell.execute_reply":"2025-04-17T15:57:00.527465Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data= pd.read_csv('/kaggle/input/jigsaw-multilingual-toxic-comment-classification/jigsaw-toxic-comment-train.csv')\nvalidation_data = pd.read_csv('/kaggle/input/jigsaw-multilingual-toxic-comment-classification/validation.csv')\ntest_data = pd.read_csv('/kaggle/input/jigsaw-multilingual-toxic-comment-classification/test.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:00.529566Z","iopub.execute_input":"2025-04-17T15:57:00.529844Z","iopub.status.idle":"2025-04-17T15:57:04.055857Z","shell.execute_reply.started":"2025-04-17T15:57:00.5298Z","shell.execute_reply":"2025-04-17T15:57:04.055164Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:04.058168Z","iopub.execute_input":"2025-04-17T15:57:04.05884Z","iopub.status.idle":"2025-04-17T15:57:04.064664Z","shell.execute_reply.started":"2025-04-17T15:57:04.058798Z","shell.execute_reply":"2025-04-17T15:57:04.063772Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:04.065636Z","iopub.execute_input":"2025-04-17T15:57:04.065965Z","iopub.status.idle":"2025-04-17T15:57:04.114838Z","shell.execute_reply.started":"2025-04-17T15:57:04.065924Z","shell.execute_reply":"2025-04-17T15:57:04.113956Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"validation_data.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:04.115882Z","iopub.execute_input":"2025-04-17T15:57:04.116154Z","iopub.status.idle":"2025-04-17T15:57:04.123772Z","shell.execute_reply.started":"2025-04-17T15:57:04.11613Z","shell.execute_reply":"2025-04-17T15:57:04.122955Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_data.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:04.124755Z","iopub.execute_input":"2025-04-17T15:57:04.125054Z","iopub.status.idle":"2025-04-17T15:57:04.136106Z","shell.execute_reply.started":"2025-04-17T15:57:04.12503Z","shell.execute_reply":"2025-04-17T15:57:04.135289Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data.drop(['severe_toxic','obscene','threat','insult','identity_hate'],axis=1,inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:04.137046Z","iopub.execute_input":"2025-04-17T15:57:04.137282Z","iopub.status.idle":"2025-04-17T15:57:04.158209Z","shell.execute_reply.started":"2025-04-17T15:57:04.13726Z","shell.execute_reply":"2025-04-17T15:57:04.157521Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:04.159064Z","iopub.execute_input":"2025-04-17T15:57:04.159294Z","iopub.status.idle":"2025-04-17T15:57:04.172493Z","shell.execute_reply.started":"2025-04-17T15:57:04.159272Z","shell.execute_reply":"2025-04-17T15:57:04.17178Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data[\"toxic\"].value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:04.175321Z","iopub.execute_input":"2025-04-17T15:57:04.175573Z","iopub.status.idle":"2025-04-17T15:57:04.193356Z","shell.execute_reply.started":"2025-04-17T15:57:04.17555Z","shell.execute_reply":"2025-04-17T15:57:04.192523Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data= train_data.loc[:15000,:]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:04.194481Z","iopub.execute_input":"2025-04-17T15:57:04.19523Z","iopub.status.idle":"2025-04-17T15:57:04.202589Z","shell.execute_reply.started":"2025-04-17T15:57:04.195205Z","shell.execute_reply":"2025-04-17T15:57:04.201812Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:04.20352Z","iopub.execute_input":"2025-04-17T15:57:04.203832Z","iopub.status.idle":"2025-04-17T15:57:04.216003Z","shell.execute_reply.started":"2025-04-17T15:57:04.203793Z","shell.execute_reply":"2025-04-17T15:57:04.215215Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data[\"toxic\"].value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:04.216977Z","iopub.execute_input":"2025-04-17T15:57:04.217212Z","iopub.status.idle":"2025-04-17T15:57:04.227266Z","shell.execute_reply.started":"2025-04-17T15:57:04.21719Z","shell.execute_reply":"2025-04-17T15:57:04.226477Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"fig = plt.figure(figsize=(5,5))\nsns.countplot(x=train_data['toxic'],data=train_data)\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:04.228204Z","iopub.execute_input":"2025-04-17T15:57:04.22852Z","iopub.status.idle":"2025-04-17T15:57:04.445872Z","shell.execute_reply.started":"2025-04-17T15:57:04.22849Z","shell.execute_reply":"2025-04-17T15:57:04.444956Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_mask=np.array(Image.open(\"/kaggle/input/wordcloud-mask-collection/batman.png\"))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:04.446951Z","iopub.execute_input":"2025-04-17T15:57:04.447229Z","iopub.status.idle":"2025-04-17T15:57:04.476172Z","shell.execute_reply.started":"2025-04-17T15:57:04.447204Z","shell.execute_reply":"2025-04-17T15:57:04.475288Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"wordcloud_text=\" \".join(train_data[\"comment_text\"].tolist())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:04.477256Z","iopub.execute_input":"2025-04-17T15:57:04.477533Z","iopub.status.idle":"2025-04-17T15:57:04.502641Z","shell.execute_reply.started":"2025-04-17T15:57:04.477508Z","shell.execute_reply":"2025-04-17T15:57:04.501765Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"wordcloud=WordCloud(width=1920,height=1080,mask=test_mask,background_color =\"black\").generate(wordcloud_text)\nfig=plt.figure(figsize=(8,8))\nplt.imshow(wordcloud)\nplt.axis(\"off\")\nplt.tight_layout(pad=0)\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:04.503616Z","iopub.execute_input":"2025-04-17T15:57:04.503947Z","iopub.status.idle":"2025-04-17T15:57:09.781627Z","shell.execute_reply.started":"2025-04-17T15:57:04.50389Z","shell.execute_reply":"2025-04-17T15:57:09.78069Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data['comment_text'].apply(lambda x:len(str(x).split())).max()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:09.782581Z","iopub.execute_input":"2025-04-17T15:57:09.782827Z","iopub.status.idle":"2025-04-17T15:57:09.848232Z","shell.execute_reply.started":"2025-04-17T15:57:09.782804Z","shell.execute_reply":"2025-04-17T15:57:09.847456Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data.sample(5)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:09.849223Z","iopub.execute_input":"2025-04-17T15:57:09.849586Z","iopub.status.idle":"2025-04-17T15:57:09.860207Z","shell.execute_reply.started":"2025-04-17T15:57:09.849559Z","shell.execute_reply":"2025-04-17T15:57:09.859428Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data.comment_text[0]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:09.861188Z","iopub.execute_input":"2025-04-17T15:57:09.861493Z","iopub.status.idle":"2025-04-17T15:57:09.872127Z","shell.execute_reply.started":"2025-04-17T15:57:09.861469Z","shell.execute_reply":"2025-04-17T15:57:09.87147Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data_label=train_data[\"toxic\"].values","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:09.873225Z","iopub.execute_input":"2025-04-17T15:57:09.873805Z","iopub.status.idle":"2025-04-17T15:57:09.884804Z","shell.execute_reply.started":"2025-04-17T15:57:09.873761Z","shell.execute_reply":"2025-04-17T15:57:09.884077Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data_text=[d.split() for d in train_data[\"comment_text\"].tolist()]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:09.885685Z","iopub.execute_input":"2025-04-17T15:57:09.885959Z","iopub.status.idle":"2025-04-17T15:57:09.994964Z","shell.execute_reply.started":"2025-04-17T15:57:09.885894Z","shell.execute_reply":"2025-04-17T15:57:09.993835Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"embedding_dim=100\nw2v_model=gensim.models.Word2Vec(sentences=data_text,vector_size=embedding_dim,window=10,min_count=1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:09.996264Z","iopub.execute_input":"2025-04-17T15:57:09.996865Z","iopub.status.idle":"2025-04-17T15:57:16.426391Z","shell.execute_reply.started":"2025-04-17T15:57:09.996821Z","shell.execute_reply":"2025-04-17T15:57:16.425708Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"len(w2v_model.wv.key_to_index)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:16.427402Z","iopub.execute_input":"2025-04-17T15:57:16.427656Z","iopub.status.idle":"2025-04-17T15:57:16.432984Z","shell.execute_reply.started":"2025-04-17T15:57:16.427632Z","shell.execute_reply":"2025-04-17T15:57:16.43214Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"w2v_model.wv.most_similar(\"stupid\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:16.434097Z","iopub.execute_input":"2025-04-17T15:57:16.434888Z","iopub.status.idle":"2025-04-17T15:57:16.474493Z","shell.execute_reply.started":"2025-04-17T15:57:16.43485Z","shell.execute_reply":"2025-04-17T15:57:16.473345Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"tokenizer=Tokenizer()\ntokenizer.fit_on_texts(data_text)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:16.475792Z","iopub.execute_input":"2025-04-17T15:57:16.476266Z","iopub.status.idle":"2025-04-17T15:57:17.234148Z","shell.execute_reply.started":"2025-04-17T15:57:16.476227Z","shell.execute_reply":"2025-04-17T15:57:17.233462Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data_text=tokenizer.texts_to_sequences(data_text)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:17.235264Z","iopub.execute_input":"2025-04-17T15:57:17.235547Z","iopub.status.idle":"2025-04-17T15:57:17.563429Z","shell.execute_reply.started":"2025-04-17T15:57:17.235522Z","shell.execute_reply":"2025-04-17T15:57:17.562489Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"maxlen=1000\ndata_text=pad_sequences(data_text,maxlen=maxlen)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:17.568795Z","iopub.execute_input":"2025-04-17T15:57:17.569144Z","iopub.status.idle":"2025-04-17T15:57:17.658038Z","shell.execute_reply.started":"2025-04-17T15:57:17.569116Z","shell.execute_reply":"2025-04-17T15:57:17.657092Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"word_index=tokenizer.word_index\nvocab_size=len(tokenizer.word_index)+1\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:17.659021Z","iopub.execute_input":"2025-04-17T15:57:17.659284Z","iopub.status.idle":"2025-04-17T15:57:17.663241Z","shell.execute_reply.started":"2025-04-17T15:57:17.659259Z","shell.execute_reply":"2025-04-17T15:57:17.662303Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"embedding_matrix = np.zeros((vocab_size + 1, embedding_dim))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:17.664224Z","iopub.execute_input":"2025-04-17T15:57:17.66449Z","iopub.status.idle":"2025-04-17T15:57:17.673552Z","shell.execute_reply.started":"2025-04-17T15:57:17.66446Z","shell.execute_reply":"2025-04-17T15:57:17.672926Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for word, i in word_index.items():\n  try:\n      embedding_vector = word_vecs[word]\n  except:\n    embedding_vector = None\n    \n    if embedding_vector is not None:\n        embedding_matrix[i] = embedding_vector\n\n  \nprint(\"Embeddings done\")\nvocab_size = len(embedding_matrix)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:17.674395Z","iopub.execute_input":"2025-04-17T15:57:17.674666Z","iopub.status.idle":"2025-04-17T15:57:17.740814Z","shell.execute_reply.started":"2025-04-17T15:57:17.674639Z","shell.execute_reply":"2025-04-17T15:57:17.740089Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model=Sequential()\nmodel.add(Embedding(vocab_size,output_dim=embedding_dim,weights=[embedding_matrix],input_length=maxlen,trainable=True))\nmodel.add(LSTM(units=128))\nmodel.add(Dense(1,activation=\"sigmoid\"))\nmodel.compile(optimizer=\"adam\",loss=\"binary_crossentropy\",metrics=[\"accuracy\"])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:17.741616Z","iopub.execute_input":"2025-04-17T15:57:17.74186Z","iopub.status.idle":"2025-04-17T15:57:18.675762Z","shell.execute_reply.started":"2025-04-17T15:57:17.741837Z","shell.execute_reply":"2025-04-17T15:57:18.674767Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train,X_test,Y_train,Y_test=train_test_split(data_text,data_label,test_size=0.3,random_state=42)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:18.677602Z","iopub.execute_input":"2025-04-17T15:57:18.67797Z","iopub.status.idle":"2025-04-17T15:57:18.705778Z","shell.execute_reply.started":"2025-04-17T15:57:18.677933Z","shell.execute_reply":"2025-04-17T15:57:18.70476Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"history=model.fit(X_train,Y_train,validation_data=(X_test,Y_test), epochs=10, batch_size=10)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T15:57:18.707034Z","iopub.execute_input":"2025-04-17T15:57:18.707372Z","iopub.status.idle":"2025-04-17T16:03:46.138291Z","shell.execute_reply.started":"2025-04-17T15:57:18.70733Z","shell.execute_reply":"2025-04-17T16:03:46.137388Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.plot(history.history['accuracy'])\nplt.plot(history.history['val_accuracy'])\nplt.title('model accuracy')\nplt.ylabel('accuracy')\nplt.xlabel('epoch')\nplt.legend(['train', 'test'], loc='upper left')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T16:03:46.140027Z","iopub.execute_input":"2025-04-17T16:03:46.140373Z","iopub.status.idle":"2025-04-17T16:03:46.320935Z","shell.execute_reply.started":"2025-04-17T16:03:46.140337Z","shell.execute_reply":"2025-04-17T16:03:46.320207Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.plot(history.history['loss'])\nplt.plot(history.history['val_loss'])\nplt.title('model loss')\nplt.ylabel('loss')\nplt.xlabel('epoch')\nplt.legend(['train', 'test'], loc='upper left')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T16:03:46.322233Z","iopub.execute_input":"2025-04-17T16:03:46.32259Z","iopub.status.idle":"2025-04-17T16:03:46.489214Z","shell.execute_reply.started":"2025-04-17T16:03:46.322548Z","shell.execute_reply":"2025-04-17T16:03:46.488323Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_pred=(model.predict(X_test) >=0.5).astype(int)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T16:03:46.490302Z","iopub.execute_input":"2025-04-17T16:03:46.490579Z","iopub.status.idle":"2025-04-17T16:03:49.710882Z","shell.execute_reply.started":"2025-04-17T16:03:46.490552Z","shell.execute_reply":"2025-04-17T16:03:49.71017Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"accuracy_score(Y_test,y_pred)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T16:03:49.712084Z","iopub.execute_input":"2025-04-17T16:03:49.712395Z","iopub.status.idle":"2025-04-17T16:03:49.719706Z","shell.execute_reply.started":"2025-04-17T16:03:49.712354Z","shell.execute_reply":"2025-04-17T16:03:49.718953Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"cm = confusion_matrix(Y_test, y_pred, labels=[0, 1])\ndf_cm = pd.DataFrame(cm, range(2), range(2))\nsn.set(font_scale=1)\nsn.heatmap(df_cm, annot=True, annot_kws={'size':14}, fmt='d').set_title('Confusion Matrix')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T16:03:49.720666Z","iopub.execute_input":"2025-04-17T16:03:49.721108Z","iopub.status.idle":"2025-04-17T16:03:50.001711Z","shell.execute_reply.started":"2025-04-17T16:03:49.72108Z","shell.execute_reply":"2025-04-17T16:03:50.000842Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(classification_report(Y_test,y_pred))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T16:03:50.002789Z","iopub.execute_input":"2025-04-17T16:03:50.003178Z","iopub.status.idle":"2025-04-17T16:03:50.024339Z","shell.execute_reply.started":"2025-04-17T16:03:50.003137Z","shell.execute_reply":"2025-04-17T16:03:50.023559Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from deep_translator import GoogleTranslator\n\ntranslated = GoogleTranslator(source='ru', target='en')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T16:09:19.612112Z","iopub.execute_input":"2025-04-17T16:09:19.613047Z","iopub.status.idle":"2025-04-17T16:09:19.80362Z","shell.execute_reply.started":"2025-04-17T16:09:19.612995Z","shell.execute_reply":"2025-04-17T16:09:19.802961Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"x = [translated.translate('ты лох')]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T16:09:19.804582Z","iopub.execute_input":"2025-04-17T16:09:19.806013Z","iopub.status.idle":"2025-04-17T16:09:19.915961Z","shell.execute_reply.started":"2025-04-17T16:09:19.805981Z","shell.execute_reply":"2025-04-17T16:09:19.915061Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#x=[\"Explanation\\nWhy the edits made under my username Hardcore Metallica Fan were reverted? They weren't vandalisms, just closure on some GAs after I voted at New York Dolls FAC. And please don't remove the template from the talk page since ты тупой\"]\nx=tokenizer.texts_to_sequences(x)\nx=pad_sequences(x,maxlen=maxlen)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T16:09:19.917653Z","iopub.execute_input":"2025-04-17T16:09:19.917955Z","iopub.status.idle":"2025-04-17T16:09:19.922819Z","shell.execute_reply.started":"2025-04-17T16:09:19.917894Z","shell.execute_reply":"2025-04-17T16:09:19.921799Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"prediction=(model.predict(x) >=0.5).astype(int)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T16:09:20.051724Z","iopub.execute_input":"2025-04-17T16:09:20.052081Z","iopub.status.idle":"2025-04-17T16:09:20.141092Z","shell.execute_reply.started":"2025-04-17T16:09:20.052052Z","shell.execute_reply":"2025-04-17T16:09:20.140038Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"if(prediction==1):\n  print(\"toxic\")\nelse:\n  print(\"non toxic\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T16:09:21.037142Z","iopub.execute_input":"2025-04-17T16:09:21.03747Z","iopub.status.idle":"2025-04-17T16:09:21.042307Z","shell.execute_reply.started":"2025-04-17T16:09:21.037441Z","shell.execute_reply":"2025-04-17T16:09:21.041463Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.save(\"model.h5\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-17T16:09:22.522949Z","iopub.execute_input":"2025-04-17T16:09:22.523738Z","iopub.status.idle":"2025-04-17T16:09:22.792099Z","shell.execute_reply.started":"2025-04-17T16:09:22.523698Z","shell.execute_reply":"2025-04-17T16:09:22.791174Z"}},"outputs":[],"execution_count":null}]}