{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-01-08T05:11:22.065303Z","iopub.execute_input":"2022-01-08T05:11:22.066082Z","iopub.status.idle":"2022-01-08T05:11:22.098064Z","shell.execute_reply.started":"2022-01-08T05:11:22.065986Z","shell.execute_reply":"2022-01-08T05:11:22.097397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\n%matplotlib inline\nsns.set(color_codes=True)","metadata":{"execution":{"iopub.status.busy":"2022-01-08T05:11:22.099669Z","iopub.execute_input":"2022-01-08T05:11:22.100145Z","iopub.status.idle":"2022-01-08T05:11:24.161466Z","shell.execute_reply.started":"2022-01-08T05:11:22.100109Z","shell.execute_reply":"2022-01-08T05:11:24.160758Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\n# import helpers.data_mining_helpers as dmh\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport plotly.express as px\nimport seaborn as sns\nimport math\nimport nltk\nimport json\nimport re\nimport gensim\nimport string\n\n\nfrom gensim.test.utils import common_texts\nfrom gensim.models.doc2vec import Doc2Vec, TaggedDocument\nfrom sklearn.feature_extraction.text import CountVectorizer\nfrom sklearn.feature_extraction.text import TfidfVectorizer\nfrom sklearn.decomposition import PCA\nfrom sklearn.preprocessing import binarize\nfrom sklearn import preprocessing, metrics, decomposition, pipeline, dummy\nfrom sklearn.datasets import fetch_20newsgroups\nfrom sklearn.metrics.pairwise import cosine_similarity\nfrom sklearn.naive_bayes import MultinomialNB\nfrom sklearn.preprocessing import LabelEncoder\nfrom tensorflow import keras ","metadata":{"execution":{"iopub.status.busy":"2022-01-08T05:11:24.162909Z","iopub.execute_input":"2022-01-08T05:11:24.163158Z","iopub.status.idle":"2022-01-08T05:11:30.913049Z","shell.execute_reply.started":"2022-01-08T05:11:24.163124Z","shell.execute_reply":"2022-01-08T05:11:30.912252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_identification = pd.read_csv(\"../input/dm2021-lab2-hw2/data_identification.csv\")\nemotion = pd.read_csv('../input/dm2021-lab2-hw2/emotion.csv')\nsampleSubmission = pd.read_csv(\"../input/dm2021-lab2-hw2/sampleSubmission.csv\")\n\ntweets = []\nfor line in open('../input/dm2021-lab2-hw2/tweets_DM.json', 'r'):\n    tweets.append(json.loads(line))\n    \ndicts={}\nfor i in range(len(tweets)):\n    dicts[tweets[i]['_source']['tweet']['tweet_id']]=tweets[i]['_source']['tweet']['text']\n    \nsent_train=[]\nfor i in range(len(emotion.tweet_id)):\n    sent_train.append(dicts[emotion.tweet_id[i]])\n    \nemotion['sentence']=sent_train\ntraining=emotion\n\nd = {'id': training.tweet_id, 'sentence': training.sentence, 'emotion': training.emotion}\ntrain = pd.DataFrame(data=d)\n\ntest_id=sampleSubmission['id']\n\nsent_test=[]\nfor i in range(len(sampleSubmission.id)):\n    sent_test.append(dicts[sampleSubmission.id[i]])\n    \nsampleSubmission['sentence']=sent_test\ntest=sampleSubmission\n\nd = {'id': test.id, 'sentence': test.sentence}\ntest = pd.DataFrame(data=d)\n\ntrain.to_csv('train_data.csv', index=False) \ntest.to_csv('test_data.csv', index=False) ","metadata":{"execution":{"iopub.status.busy":"2022-01-08T05:11:30.915178Z","iopub.execute_input":"2022-01-08T05:11:30.915456Z","iopub.status.idle":"2022-01-08T05:12:36.959503Z","shell.execute_reply.started":"2022-01-08T05:11:30.915421Z","shell.execute_reply":"2022-01-08T05:12:36.958744Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_balanced = train","metadata":{"execution":{"iopub.status.busy":"2022-01-08T05:12:36.961550Z","iopub.execute_input":"2022-01-08T05:12:36.961742Z","iopub.status.idle":"2022-01-08T05:12:36.966965Z","shell.execute_reply.started":"2022-01-08T05:12:36.961719Z","shell.execute_reply":"2022-01-08T05:12:36.966175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data=train_balanced\n\ntest_data=test\n\ny_train1=train_data.emotion.values\n\ndf1 = train_data.groupby(['emotion']).count()['sentence']\n\nindex=df1.index\n\ny_train_conv=[]\n\nfor i in y_train1:\n    for j in range(8):\n        if i==index[j]:\n            y_train_conv.append(j)\n                        \ny_train=np.array(y_train_conv)","metadata":{"execution":{"iopub.status.busy":"2022-01-08T05:12:36.968626Z","iopub.execute_input":"2022-01-08T05:12:36.969328Z","iopub.status.idle":"2022-01-08T05:12:49.563750Z","shell.execute_reply.started":"2022-01-08T05:12:36.969288Z","shell.execute_reply":"2022-01-08T05:12:49.563012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"text=train_data.sentence.values\ntext_tests=test_data.sentence.values","metadata":{"execution":{"iopub.status.busy":"2022-01-08T05:12:49.565161Z","iopub.execute_input":"2022-01-08T05:12:49.565430Z","iopub.status.idle":"2022-01-08T05:12:49.570441Z","shell.execute_reply.started":"2022-01-08T05:12:49.565398Z","shell.execute_reply":"2022-01-08T05:12:49.569097Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels=y_train\nlabels","metadata":{"execution":{"iopub.status.busy":"2022-01-08T05:12:49.571859Z","iopub.execute_input":"2022-01-08T05:12:49.572314Z","iopub.status.idle":"2022-01-08T05:12:49.584643Z","shell.execute_reply.started":"2022-01-08T05:12:49.572280Z","shell.execute_reply":"2022-01-08T05:12:49.583851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from transformers import BertTokenizer,BertForSequenceClassification,AdamW","metadata":{"execution":{"iopub.status.busy":"2022-01-08T05:12:49.585571Z","iopub.execute_input":"2022-01-08T05:12:49.587933Z","iopub.status.idle":"2022-01-08T05:12:50.871648Z","shell.execute_reply.started":"2022-01-08T05:12:49.587900Z","shell.execute_reply":"2022-01-08T05:12:50.870930Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tokenizer = BertTokenizer.from_pretrained('bert-base-uncased',do_lower_case = True)","metadata":{"execution":{"iopub.status.busy":"2022-01-08T05:12:50.875126Z","iopub.execute_input":"2022-01-08T05:12:50.875397Z","iopub.status.idle":"2022-01-08T05:12:52.299023Z","shell.execute_reply.started":"2022-01-08T05:12:50.875365Z","shell.execute_reply":"2022-01-08T05:12:52.298317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"input_ids = []\nattention_mask = []\nfor i in text:\n    encoded_data = tokenizer.encode_plus(\n    i,\n    add_special_tokens=True,\n    max_length=64,\n    pad_to_max_length = True,\n    return_attention_mask= True,\n    return_tensors='pt')\n    input_ids.append(encoded_data['input_ids'])\n    attention_mask.append(encoded_data['attention_mask'])\ninput_ids = torch.cat(input_ids,dim=0)\nattention_mask = torch.cat(attention_mask,dim=0)\nlabels = torch.tensor(labels)","metadata":{"execution":{"iopub.status.busy":"2022-01-08T05:12:52.300520Z","iopub.execute_input":"2022-01-08T05:12:52.300830Z","iopub.status.idle":"2022-01-08T05:31:31.864266Z","shell.execute_reply.started":"2022-01-08T05:12:52.300793Z","shell.execute_reply":"2022-01-08T05:31:31.863451Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"input_ids_tests = []\nattention_mask_tests = []\nfor i in text_tests:\n    encoded_data = tokenizer.encode_plus(\n    i,\n    add_special_tokens=True,\n    max_length=64,\n    pad_to_max_length = True,\n    return_attention_mask= True,\n    return_tensors='pt')\n    input_ids_tests.append(encoded_data['input_ids'])\n    attention_mask_tests.append(encoded_data['attention_mask'])\ninput_ids_tests = torch.cat(input_ids_tests,dim=0)\nattention_mask_tests = torch.cat(attention_mask_tests,dim=0)","metadata":{"execution":{"iopub.status.busy":"2022-01-08T05:31:31.865571Z","iopub.execute_input":"2022-01-08T05:31:31.865818Z","iopub.status.idle":"2022-01-08T05:37:14.917448Z","shell.execute_reply.started":"2022-01-08T05:31:31.865786Z","shell.execute_reply":"2022-01-08T05:37:14.916563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from torch.utils.data import DataLoader,SequentialSampler,RandomSampler,TensorDataset,random_split","metadata":{"execution":{"iopub.status.busy":"2022-01-08T05:37:14.919158Z","iopub.execute_input":"2022-01-08T05:37:14.919432Z","iopub.status.idle":"2022-01-08T05:37:14.925576Z","shell.execute_reply.started":"2022-01-08T05:37:14.919397Z","shell.execute_reply":"2022-01-08T05:37:14.923532Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset = TensorDataset(input_ids,attention_mask,labels)\ntrain_size = int(0.8*len(dataset))\nval_size = len(dataset) - train_size\n\ntrain_dataset,val_dataset = random_split(dataset,[train_size,val_size])\n\nprint('Training Size - ',train_size)\nprint('Validation Size - ',val_size)","metadata":{"execution":{"iopub.status.busy":"2022-01-08T05:37:14.927164Z","iopub.execute_input":"2022-01-08T05:37:14.927461Z","iopub.status.idle":"2022-01-08T05:37:15.057078Z","shell.execute_reply.started":"2022-01-08T05:37:14.927422Z","shell.execute_reply":"2022-01-08T05:37:15.056287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_test = TensorDataset(input_ids_tests,attention_mask_tests)\nprint(len(dataset_test))\ntrain_test = DataLoader(dataset_test, shuffle=False,batch_size = 16)","metadata":{"execution":{"iopub.status.busy":"2022-01-08T05:37:15.058392Z","iopub.execute_input":"2022-01-08T05:37:15.059122Z","iopub.status.idle":"2022-01-08T05:37:15.065230Z","shell.execute_reply.started":"2022-01-08T05:37:15.059084Z","shell.execute_reply":"2022-01-08T05:37:15.064063Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_dl = DataLoader(train_dataset,sampler = RandomSampler(train_dataset),\n                     batch_size = 32)\nval_dl = DataLoader(val_dataset,sampler = SequentialSampler(val_dataset),\n                     batch_size = 32)","metadata":{"execution":{"iopub.status.busy":"2022-01-08T05:37:15.066586Z","iopub.execute_input":"2022-01-08T05:37:15.066934Z","iopub.status.idle":"2022-01-08T05:37:15.075028Z","shell.execute_reply.started":"2022-01-08T05:37:15.066901Z","shell.execute_reply":"2022-01-08T05:37:15.074140Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = BertForSequenceClassification.from_pretrained(\n'bert-base-uncased',\nnum_labels = 8,\noutput_attentions = False,\noutput_hidden_states = False)","metadata":{"execution":{"iopub.status.busy":"2022-01-08T05:37:15.076004Z","iopub.execute_input":"2022-01-08T05:37:15.078395Z","iopub.status.idle":"2022-01-08T05:37:30.969696Z","shell.execute_reply.started":"2022-01-08T05:37:15.078351Z","shell.execute_reply":"2022-01-08T05:37:30.968982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import random\n\nseed_val = 17\nrandom.seed(seed_val)\nnp.random.seed(seed_val)\ntorch.manual_seed(seed_val)\ntorch.cuda.manual_seed_all(seed_val)","metadata":{"execution":{"iopub.status.busy":"2022-01-08T05:37:30.971078Z","iopub.execute_input":"2022-01-08T05:37:30.971365Z","iopub.status.idle":"2022-01-08T05:37:30.981131Z","shell.execute_reply.started":"2022-01-08T05:37:30.971330Z","shell.execute_reply":"2022-01-08T05:37:30.980420Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')\nmodel.to(device)\n\nprint(device)","metadata":{"execution":{"iopub.status.busy":"2022-01-08T05:37:30.982295Z","iopub.execute_input":"2022-01-08T05:37:30.982561Z","iopub.status.idle":"2022-01-08T05:37:35.672300Z","shell.execute_reply.started":"2022-01-08T05:37:30.982525Z","shell.execute_reply":"2022-01-08T05:37:35.670682Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"optimizer = AdamW(model.parameters(),lr = 2e-5,eps=1e-8)","metadata":{"execution":{"iopub.status.busy":"2022-01-08T05:37:35.674162Z","iopub.execute_input":"2022-01-08T05:37:35.674587Z","iopub.status.idle":"2022-01-08T05:37:35.685134Z","shell.execute_reply.started":"2022-01-08T05:37:35.674552Z","shell.execute_reply":"2022-01-08T05:37:35.684399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from transformers import get_linear_schedule_with_warmup\nepochs = 1\ntotal_steps = len(train_dl)*epochs\nscheduler = get_linear_schedule_with_warmup(optimizer,num_warmup_steps=0,\n                                           num_training_steps=total_steps)","metadata":{"execution":{"iopub.status.busy":"2022-01-08T05:37:35.686644Z","iopub.execute_input":"2022-01-08T05:37:35.686942Z","iopub.status.idle":"2022-01-08T05:37:36.133339Z","shell.execute_reply.started":"2022-01-08T05:37:35.686893Z","shell.execute_reply":"2022-01-08T05:37:36.132452Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def accuracy(preds,labels):\n    pred_flat = np.argmax(preds,axis=1).flatten()\n    label_flat = labels.flatten()\n    return np.sum(pred_flat==label_flat)/len(label_flat)","metadata":{"execution":{"iopub.status.busy":"2022-01-08T05:37:36.134903Z","iopub.execute_input":"2022-01-08T05:37:36.135727Z","iopub.status.idle":"2022-01-08T05:37:36.143862Z","shell.execute_reply.started":"2022-01-08T05:37:36.135689Z","shell.execute_reply":"2022-01-08T05:37:36.143061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def evaluate(dataloader_test):\n    model.eval()\n    loss_val_total = 0\n    predictions,true_vals = [],[]\n    for batch in dataloader_test:\n        batch = tuple(b.to(device) for b in batch)\n        inputs = {\n            'input_ids':batch[0],\n            'attention_mask': batch[1],\n            'labels': batch[2]\n        }\n        with torch.no_grad():\n            outputs = model(**inputs)\n        loss = outputs[0]\n        logits = outputs[1]\n        loss_val_total += loss.item()\n        logits = logits.detach().cpu().numpy()\n        label_ids = inputs['labels'].cpu().numpy()\n        predictions.append(logits)\n        true_vals.append(label_ids)\n    loss_val_avg = loss_val_total / len(dataloader_test)\n    predictions = np.concatenate(predictions,axis=0)\n    true_vals = np.concatenate(true_vals,axis=0)\n    return loss_val_avg,predictions,true_vals","metadata":{"execution":{"iopub.status.busy":"2022-01-08T05:37:36.146601Z","iopub.execute_input":"2022-01-08T05:37:36.147117Z","iopub.status.idle":"2022-01-08T05:37:36.156881Z","shell.execute_reply.started":"2022-01-08T05:37:36.147083Z","shell.execute_reply":"2022-01-08T05:37:36.156073Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tqdm.notebook import tqdm\ntorch.cuda.empty_cache()\nfor epoch in tqdm(range(1, epochs+1)):\n    \n    model.train()\n    \n    loss_train_total = 0\n\n    progress_bar = tqdm(train_dl, desc='Epoch {:1d}'.format(epoch), leave=False, disable=False)\n    for batch in progress_bar:\n\n        model.zero_grad()\n        \n        batch = tuple(b.to(device) for b in batch)\n        \n        inputs = {'input_ids':      batch[0],\n                  'attention_mask': batch[1],\n                  'labels':         batch[2],\n                 }       \n\n        outputs = model(**inputs)\n        \n        loss = outputs[0]\n        loss_train_total += loss.item()\n        loss.backward()\n\n        torch.nn.utils.clip_grad_norm_(model.parameters(), 1.0)\n\n        optimizer.step()\n        scheduler.step()\n        \n        progress_bar.set_postfix({'training_loss': '{:.3f}'.format(loss.item()/len(batch))})\n         \n        \n    tqdm.write(f'\\nEpoch {epoch}')\n    \n    loss_train_avg = loss_train_total/len(train_dl)            \n    tqdm.write(f'Training loss: {loss_train_avg}')\n    \n    val_loss, predictions, true_vals = evaluate(val_dl)\n    val_acc = accuracy(predictions, true_vals)\n    tqdm.write(f'Validation loss: {val_loss}')\n    tqdm.write(f'Accuracy: {val_acc}')\n","metadata":{"execution":{"iopub.status.busy":"2022-01-08T05:37:36.159231Z","iopub.execute_input":"2022-01-08T05:37:36.159790Z","iopub.status.idle":"2022-01-08T07:56:19.483950Z","shell.execute_reply.started":"2022-01-08T05:37:36.159753Z","shell.execute_reply":"2022-01-08T07:56:19.483193Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"output_dir = './'\nmodel_to_save = model.module if hasattr(model, 'module') else model\nmodel_to_save.save_pretrained(output_dir)\ntokenizer.save_pretrained(output_dir)","metadata":{"execution":{"iopub.status.busy":"2022-01-08T07:56:19.485335Z","iopub.execute_input":"2022-01-08T07:56:19.486149Z","iopub.status.idle":"2022-01-08T07:56:20.162689Z","shell.execute_reply.started":"2022-01-08T07:56:19.486112Z","shell.execute_reply":"2022-01-08T07:56:20.162028Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from transformers import BertTokenizer,BertForSequenceClassification\nimport torch\n# Load the BERT tokenizer.\nprint('Loading BERT tokenizer...')\noutput_dir = './'\ntokenizer = BertTokenizer.from_pretrained(output_dir)\nmodel_loaded = BertForSequenceClassification.from_pretrained(output_dir)","metadata":{"execution":{"iopub.status.busy":"2022-01-08T07:56:20.163967Z","iopub.execute_input":"2022-01-08T07:56:20.164241Z","iopub.status.idle":"2022-01-08T07:56:21.186162Z","shell.execute_reply.started":"2022-01-08T07:56:20.164196Z","shell.execute_reply":"2022-01-08T07:56:21.185414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def Sentiment(sent):\n    output_dir = './'\n    tokenizer = BertTokenizer.from_pretrained(output_dir)\n    model_loaded = BertForSequenceClassification.from_pretrained(output_dir)\n    encoded_dict = tokenizer.encode_plus(\n                        sent, \n                        add_special_tokens = True,\n                        max_length = 64,\n                        pad_to_max_length = True,\n                        return_attention_mask = True,\n                        return_tensors = 'pt',\n                   )\n        \n    input_id = encoded_dict['input_ids']\n\n    attention_mask = encoded_dict['attention_mask']\n    input_id = torch.LongTensor(input_id)\n    attention_mask = torch.LongTensor(attention_mask)\n\n    device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n    model_loaded = model_loaded.to(device)\n    input_id = input_id.to(device)\n    attention_mask = attention_mask.to(device)\n\n    with torch.no_grad():\n        outputs = model_loaded(input_id, token_type_ids=None, attention_mask=attention_mask)\n\n    logits = outputs[0]\n    index = logits.argmax()\n    return index","metadata":{"execution":{"iopub.status.busy":"2022-01-08T07:56:21.187586Z","iopub.execute_input":"2022-01-08T07:56:21.187860Z","iopub.status.idle":"2022-01-08T07:56:21.195934Z","shell.execute_reply.started":"2022-01-08T07:56:21.187826Z","shell.execute_reply":"2022-01-08T07:56:21.194830Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Sentiment('I am happy.')","metadata":{"execution":{"iopub.status.busy":"2022-01-08T07:56:21.200397Z","iopub.execute_input":"2022-01-08T07:56:21.200695Z","iopub.status.idle":"2022-01-08T07:56:22.442964Z","shell.execute_reply.started":"2022-01-08T07:56:21.200659Z","shell.execute_reply":"2022-01-08T07:56:22.442054Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.eval()\nlogit = []\nsumms=0\nlens=len(dataset_test)/16\nfor batch in train_test:\n    batchs = tuple(b.to(device) for b in batch)\n\n    inputs = {'input_ids':      batchs[0],\n              'attention_mask': batchs[1]\n             }\n\n    outputs = model(**inputs)\n#     print(outputs)\n    logit += torch.argmax(outputs[0], dim=1).cpu()\n#     out.append(logit.item())\n    if summs%1000==0:\n        print(summs/lens)\n    summs+=1","metadata":{"execution":{"iopub.status.busy":"2022-01-08T07:56:22.444611Z","iopub.execute_input":"2022-01-08T07:56:22.444886Z","iopub.status.idle":"2022-01-08T08:10:56.734213Z","shell.execute_reply.started":"2022-01-08T07:56:22.444852Z","shell.execute_reply":"2022-01-08T08:10:56.733452Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"logit","metadata":{"execution":{"iopub.status.busy":"2022-01-08T08:10:56.735575Z","iopub.execute_input":"2022-01-08T08:10:56.735827Z","iopub.status.idle":"2022-01-08T08:10:56.796665Z","shell.execute_reply.started":"2022-01-08T08:10:56.735795Z","shell.execute_reply":"2022-01-08T08:10:56.795878Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred=[]\nfor i in logit:\n    pred.append(df1.index[i])","metadata":{"execution":{"iopub.status.busy":"2022-01-08T08:10:56.797906Z","iopub.execute_input":"2022-01-08T08:10:56.798230Z","iopub.status.idle":"2022-01-08T08:10:57.752500Z","shell.execute_reply.started":"2022-01-08T08:10:56.798178Z","shell.execute_reply":"2022-01-08T08:10:57.751754Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data['emotion']=pred","metadata":{"execution":{"iopub.status.busy":"2022-01-08T08:10:57.753799Z","iopub.execute_input":"2022-01-08T08:10:57.754045Z","iopub.status.idle":"2022-01-08T08:10:57.787527Z","shell.execute_reply.started":"2022-01-08T08:10:57.754012Z","shell.execute_reply":"2022-01-08T08:10:57.786761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sb=test_data.loc[:,['id','emotion']]\nsb","metadata":{"execution":{"iopub.status.busy":"2022-01-08T08:10:57.788797Z","iopub.execute_input":"2022-01-08T08:10:57.789055Z","iopub.status.idle":"2022-01-08T08:10:57.875796Z","shell.execute_reply.started":"2022-01-08T08:10:57.789018Z","shell.execute_reply":"2022-01-08T08:10:57.875055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sb.to_csv('submit.csv', index=False) ","metadata":{"execution":{"iopub.status.busy":"2022-01-08T08:10:57.877075Z","iopub.execute_input":"2022-01-08T08:10:57.877341Z","iopub.status.idle":"2022-01-08T08:10:58.642108Z","shell.execute_reply.started":"2022-01-08T08:10:57.877309Z","shell.execute_reply":"2022-01-08T08:10:58.641401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}