# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# + papermill={"duration": 9.890226, "end_time": "2022-03-12T13:49:37.918069", "exception": false, "start_time": "2022-03-12T13:49:28.027843", "status": "completed"} tags=[]
from tqdm.auto import tqdm
import os

import numpy as np
import pandas as pd 

import matplotlib.pyplot as plt
import seaborn as sns 

from sklearn.metrics import roc_auc_score
from sklearn.model_selection import train_test_split , StratifiedKFold


import tensorflow as tf 
import tensorflow.keras.backend as K
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.models import Model, load_model, save_model
from tensorflow.keras.callbacks import ModelCheckpoint, EarlyStopping, ReduceLROnPlateau
from tensorflow.keras.layers import Input,Dense, LSTM, RNN, Bidirectional, GlobalAveragePooling2D , Dropout, Conv1D, Flatten
from tensorflow.keras.utils import to_categorical

from transformers import TFAutoModel , AutoTokenizer

from sklearn.metrics import classification_report

# + papermill={"duration": 0.115724, "end_time": "2022-03-12T13:49:38.051478", "exception": false, "start_time": "2022-03-12T13:49:37.935754", "status": "completed"} tags=[]
col_names = ['labels','text']
df_tamil_mine = pd.read_csv('../input/cross-verifying-results/BpHigh_tamil.tsv',sep ='\t')
df_tamil_en_mine = pd.read_csv('../input/cross-verifying-results/BpHigh_tamil-english.tsv',sep ='\t')
df_tamil_given = pd.read_csv('../input/cross-verifying-results/ta-misogyny-test.csv',names=col_names,sep ='\t')
df_tamil_en_given = pd.read_csv('../input/cross-verifying-results/ta-en-misogyny-test.csv',names=col_names,sep ='\t')


# + papermill={"duration": 0.026537, "end_time": "2022-03-12T13:49:38.095039", "exception": false, "start_time": "2022-03-12T13:49:38.068502", "status": "completed"} tags=[]
def transform_df_labels(df):
    df = df.replace({'Counter-speech':0,
                             'Homophobia':1, 
                             'Hope-Speech':2, 
                             'Misandry':3, 
                             'Misogyny':4, 
                             'None-of-the-above':5, 
                             'Transphobic':6,
                             'Xenophobia':7})
    return df


# + papermill={"duration": 0.042214, "end_time": "2022-03-12T13:49:38.155516", "exception": false, "start_time": "2022-03-12T13:49:38.113302", "status": "completed"} tags=[]
df_tamil_mine

# + papermill={"duration": 0.049215, "end_time": "2022-03-12T13:49:38.223418", "exception": false, "start_time": "2022-03-12T13:49:38.174203", "status": "completed"} tags=[]
df_tamil_given.info()

# + papermill={"duration": 0.027155, "end_time": "2022-03-12T13:49:38.269036", "exception": false, "start_time": "2022-03-12T13:49:38.241881", "status": "completed"} tags=[]
null_list = df_tamil_given[df_tamil_given['text'].isnull()].index.tolist()

# + papermill={"duration": 0.028667, "end_time": "2022-03-12T13:49:38.316317", "exception": false, "start_time": "2022-03-12T13:49:38.287650", "status": "completed"} tags=[]
df_tamil_given.dropna(how='any',axis=0,inplace=True)

# + papermill={"duration": 0.034142, "end_time": "2022-03-12T13:49:38.369477", "exception": false, "start_time": "2022-03-12T13:49:38.335335", "status": "completed"} tags=[]
df_tamil_given

# + papermill={"duration": 0.030579, "end_time": "2022-03-12T13:49:38.420013", "exception": false, "start_time": "2022-03-12T13:49:38.389434", "status": "completed"} tags=[]
df_tamil_en_given.dropna(how='any',axis=0,inplace=True)

# + papermill={"duration": 0.041736, "end_time": "2022-03-12T13:49:38.482435", "exception": false, "start_time": "2022-03-12T13:49:38.440699", "status": "completed"} tags=[]
df_tamil_mine_transformed = transform_df_labels(df_tamil_mine['label'])
df_tamil_given_transformed = transform_df_labels(df_tamil_given['labels'])
df_tamil_en_mine_transformed = transform_df_labels(df_tamil_en_mine['label'])
df_tamil_en_given_transformed = transform_df_labels(df_tamil_en_given['labels'])


# + papermill={"duration": 0.029646, "end_time": "2022-03-12T13:49:38.526321", "exception": false, "start_time": "2022-03-12T13:49:38.496675", "status": "completed"} tags=[]
target_names = ['Counter-speech',
                             'Homophobia', 
                             'Hope-Speech', 
                             'Misandry', 
                             'Misogyny', 
                             'None-of-the-above', 
                             'Transphobic',
                             'Xenophobia']
print(classification_report(df_tamil_given_transformed ,df_tamil_mine_transformed,target_names=target_names))

# + papermill={"duration": 0.034421, "end_time": "2022-03-12T13:49:38.581109", "exception": false, "start_time": "2022-03-12T13:49:38.546688", "status": "completed"} tags=[]
print(classification_report(df_tamil_en_given_transformed ,df_tamil_en_mine_transformed,target_names=target_names))

# + papermill={"duration": 0.022885, "end_time": "2022-03-12T13:49:38.625746", "exception": false, "start_time": "2022-03-12T13:49:38.602861", "status": "completed"} tags=[]


StarcoderdataJupyterScriptsDedupFiltered