{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":115439,"databundleVersionId":13800781,"sourceType":"competition"}],"dockerImageVersionId":31193,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"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# 5cfcb5e8ef8458be6e85d57c45c7573477e2ad6a\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport warnings\nwarnings.filterwarnings(\"ignore\")\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\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","trusted":true,"execution":{"iopub.status.busy":"2025-11-30T12:49:53.932436Z","iopub.execute_input":"2025-11-30T12:49:53.932711Z","iopub.status.idle":"2025-11-30T12:49:54.191663Z","shell.execute_reply.started":"2025-11-30T12:49:53.932689Z","shell.execute_reply":"2025-11-30T12:49:54.191110Z"}},"outputs":[],"execution_count":1},{"cell_type":"code","source":"df = pd.read_csv(\"/kaggle/input/2025-sep-dl-gen-ai-project/train.csv\") #training set\ndt = pd.read_csv(\"/kaggle/input/2025-sep-dl-gen-ai-project/test.csv\") #test set","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-30T12:49:59.407441Z","iopub.execute_input":"2025-11-30T12:49:59.408246Z","iopub.status.idle":"2025-11-30T12:49:59.452200Z","shell.execute_reply.started":"2025-11-30T12:49:59.408221Z","shell.execute_reply":"2025-11-30T12:49:59.451673Z"}},"outputs":[],"execution_count":2},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\nlabel_cols = ['anger','fear','joy','sadness','surprise']\n\nxtrain, xval, ytrain, yval = train_test_split(\n df['text'],\n df[label_cols].values,\n test_size=0.2,\n random_state=42,\n shuffle=True\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-30T12:50:03.196291Z","iopub.execute_input":"2025-11-30T12:50:03.197029Z","iopub.status.idle":"2025-11-30T12:50:03.758590Z","shell.execute_reply.started":"2025-11-30T12:50:03.197008Z","shell.execute_reply":"2025-11-30T12:50:03.758016Z"}},"outputs":[],"execution_count":3},{"cell_type":"code","source":"# from kaggle_secrets import UserSecretsClient\n# user_secrets = UserSecretsClient()\n# wdb_t = user_secrets.get_secret(\"WB_TOKEN\")\n# import wandb\n# wandb.login(key=wdb_t)\n# # wandb.init(project=\"22f3001086-t32025\", name = \"BERT+Classifier head\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-30T12:50:10.868444Z","iopub.execute_input":"2025-11-30T12:50:10.869350Z","iopub.status.idle":"2025-11-30T12:50:20.674529Z","shell.execute_reply.started":"2025-11-30T12:50:10.869325Z","shell.execute_reply":"2025-11-30T12:50:20.673984Z"}},"outputs":[{"name":"stderr","text":"\u001b[34m\u001b[1mwandb\u001b[0m: \u001b[33mWARNING\u001b[0m If you're specifying your api key in code, ensure this code is not shared publicly.\n\u001b[34m\u001b[1mwandb\u001b[0m: \u001b[33mWARNING\u001b[0m Consider setting the WANDB_API_KEY environment variable, or running `wandb login` from the command line.\n\u001b[34m\u001b[1mwandb\u001b[0m: No netrc file found, creating one.\n\u001b[34m\u001b[1mwandb\u001b[0m: Appending key for api.wandb.ai to your netrc file: /root/.netrc\n\u001b[34m\u001b[1mwandb\u001b[0m: Currently logged in as: \u001b[33mvaishnavib\u001b[0m (\u001b[33mvaishnavib-iitm-jntuh-\u001b[0m) to \u001b[32mhttps://api.wandb.ai\u001b[0m. Use \u001b[1m`wandb login --relogin`\u001b[0m to force relogin\n","output_type":"stream"},{"execution_count":4,"output_type":"execute_result","data":{"text/plain":"True"},"metadata":{}}],"execution_count":4},{"cell_type":"code","source":"# !pip install nlpaug","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-30T12:50:52.590392Z","iopub.execute_input":"2025-11-30T12:50:52.590867Z","iopub.status.idle":"2025-11-30T12:50:57.089514Z","shell.execute_reply.started":"2025-11-30T12:50:52.590831Z","shell.execute_reply":"2025-11-30T12:50:57.088765Z"}},"outputs":[{"name":"stdout","text":"Collecting nlpaug\n Downloading nlpaug-1.1.11-py3-none-any.whl.metadata (14 kB)\nRequirement already satisfied: numpy>=1.16.2 in /usr/local/lib/python3.11/dist-packages (from nlpaug) (1.26.4)\nRequirement already satisfied: pandas>=1.2.0 in /usr/local/lib/python3.11/dist-packages (from nlpaug) (2.2.3)\nRequirement already satisfied: requests>=2.22.0 in /usr/local/lib/python3.11/dist-packages (from nlpaug) (2.32.5)\nRequirement already satisfied: gdown>=4.0.0 in /usr/local/lib/python3.11/dist-packages (from nlpaug) (5.2.0)\nRequirement already satisfied: beautifulsoup4 in /usr/local/lib/python3.11/dist-packages (from gdown>=4.0.0->nlpaug) (4.13.4)\nRequirement already satisfied: filelock in /usr/local/lib/python3.11/dist-packages (from gdown>=4.0.0->nlpaug) (3.20.0)\nRequirement already satisfied: tqdm in /usr/local/lib/python3.11/dist-packages (from gdown>=4.0.0->nlpaug) (4.67.1)\nRequirement already satisfied: mkl_fft in /usr/local/lib/python3.11/dist-packages (from numpy>=1.16.2->nlpaug) (1.3.8)\nRequirement already satisfied: mkl_random in /usr/local/lib/python3.11/dist-packages (from numpy>=1.16.2->nlpaug) (1.2.4)\nRequirement already satisfied: mkl_umath in /usr/local/lib/python3.11/dist-packages (from numpy>=1.16.2->nlpaug) (0.1.1)\nRequirement already satisfied: mkl in /usr/local/lib/python3.11/dist-packages (from numpy>=1.16.2->nlpaug) (2025.3.0)\nRequirement already satisfied: tbb4py in /usr/local/lib/python3.11/dist-packages (from numpy>=1.16.2->nlpaug) (2022.3.0)\nRequirement already satisfied: mkl-service in /usr/local/lib/python3.11/dist-packages (from numpy>=1.16.2->nlpaug) (2.4.1)\nRequirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.11/dist-packages (from pandas>=1.2.0->nlpaug) (2.9.0.post0)\nRequirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.11/dist-packages (from pandas>=1.2.0->nlpaug) (2025.2)\nRequirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.11/dist-packages (from pandas>=1.2.0->nlpaug) (2025.2)\nRequirement already satisfied: charset_normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests>=2.22.0->nlpaug) (3.4.4)\nRequirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/dist-packages (from requests>=2.22.0->nlpaug) (3.11)\nRequirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.11/dist-packages (from requests>=2.22.0->nlpaug) (2.5.0)\nRequirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.11/dist-packages (from requests>=2.22.0->nlpaug) (2025.10.5)\nRequirement already satisfied: six>=1.5 in /usr/local/lib/python3.11/dist-packages (from python-dateutil>=2.8.2->pandas>=1.2.0->nlpaug) (1.17.0)\nRequirement already satisfied: soupsieve>1.2 in /usr/local/lib/python3.11/dist-packages (from beautifulsoup4->gdown>=4.0.0->nlpaug) (2.7)\nRequirement already satisfied: typing-extensions>=4.0.0 in /usr/local/lib/python3.11/dist-packages (from beautifulsoup4->gdown>=4.0.0->nlpaug) (4.15.0)\nRequirement already satisfied: onemkl-license==2025.3.0 in /usr/local/lib/python3.11/dist-packages (from mkl->numpy>=1.16.2->nlpaug) (2025.3.0)\nRequirement already satisfied: intel-openmp<2026,>=2024 in /usr/local/lib/python3.11/dist-packages (from mkl->numpy>=1.16.2->nlpaug) (2024.2.0)\nRequirement already satisfied: tbb==2022.* in /usr/local/lib/python3.11/dist-packages (from mkl->numpy>=1.16.2->nlpaug) (2022.3.0)\nRequirement already satisfied: tcmlib==1.* in /usr/local/lib/python3.11/dist-packages (from tbb==2022.*->mkl->numpy>=1.16.2->nlpaug) (1.4.0)\nRequirement already satisfied: intel-cmplr-lib-rt in /usr/local/lib/python3.11/dist-packages (from mkl_umath->numpy>=1.16.2->nlpaug) (2024.2.0)\nRequirement already satisfied: PySocks!=1.5.7,>=1.5.6 in /usr/local/lib/python3.11/dist-packages (from requests[socks]->gdown>=4.0.0->nlpaug) (1.7.1)\nRequirement already satisfied: intel-cmplr-lib-ur==2024.2.0 in /usr/local/lib/python3.11/dist-packages (from intel-openmp<2026,>=2024->mkl->numpy>=1.16.2->nlpaug) (2024.2.0)\nDownloading nlpaug-1.1.11-py3-none-any.whl (410 kB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m410.5/410.5 kB\u001b[0m \u001b[31m10.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m\n\u001b[?25hInstalling collected packages: nlpaug\nSuccessfully installed nlpaug-1.1.11\n","output_type":"stream"}],"execution_count":5},{"cell_type":"code","source":"# --- Imports and Setup ---\n\nimport torch\nimport torch.nn as nn\nfrom torch.utils.data import Dataset, DataLoader\nfrom sklearn.metrics import f1_score\nfrom transformers import AutoTokenizer, AutoModel, get_linear_schedule_with_warmup\nfrom torch.optim import AdamW\nfrom tqdm.auto import tqdm\nimport nlpaug.augmenter.word as naw\nimport nltk\nimport pandas as pd\nimport numpy as np\nimport wandb\n\nnltk.download('averaged_perceptron_tagger')\n\nDEVICE = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\nprint(f\"Using device: {DEVICE}\")\n\nclass Config:\n MODELNAME = \"j-hartmann/emotion-english-distilroberta-base\"\n LEARNINGRATE = 2e-5\n BATCHSIZE = 32\n EPOCHS = 6\n MAXLEN = 128\n RANDOMSEED = 42\n DROPOUT = 0.1\n WEIGHTDECAY = 0.01\n WARMUPRATIO = 0.1\n OUTPUTDIM = 5 # Number of labels\n LABELCOLS = [\"anger\", \"fear\", \"joy\", \"sadness\", \"surprise\"]\n\nCONFIG = Config()\n\ntorch.manual_seed(CONFIG.RANDOMSEED)\nnp.random.seed(CONFIG.RANDOMSEED)\n\n# --- Data Loading and Splitting ---\n\ndf = pd.read_csv(\"/kaggle/input/2025-sep-dl-gen-ai-project/train.csv\")\ndf_test = pd.read_csv(\"/kaggle/input/2025-sep-dl-gen-ai-project/test.csv\")\n\nfrom sklearn.model_selection import train_test_split\n\nX_train, X_val, y_train, y_val = train_test_split(\n df[\"text\"], df[CONFIG.LABELCOLS].values,\n test_size=0.2,\n random_state=CONFIG.RANDOMSEED,\n shuffle=True\n)\n\ndf_train = pd.DataFrame({\"text\": X_train})\ndf_train[CONFIG.LABELCOLS] = y_train\n\ndf_val = pd.DataFrame({\"text\": X_val})\ndf_val[CONFIG.LABELCOLS] = y_val\n\nprint(f\"Training samples: {len(df_train)}\")\nprint(f\"Validation samples: {len(df_val)}\")\n\n# --- NLP Augmentation ---\n\nsyn_aug = naw.SynonymAug(aug_max=1, stopwords=[\"i\", \"am\", \"the\", \"a\", \"to\", \"is\"])\n\ndef augment_sample(row, aug_count=1):\n new_rows = []\n text = row['text']\n for _ in range(aug_count):\n aug_text = syn_aug.augment(text)\n new_row = row.copy()\n new_row['text'] = aug_text\n new_rows.append(new_row)\n return pd.DataFrame(new_rows)\n\nanger_samples = df_train[df_train[\"anger\"] == 1]\njoy_samples = df_train[df_train[\"joy\"] == 1]\n\naugmented_parts = []\nfor _, row in anger_samples.iterrows():\n augmented_parts.append(augment_sample(row, aug_count=2))\nfor _, row in joy_samples.iterrows():\n augmented_parts.append(augment_sample(row, aug_count=1))\n\nif augmented_parts:\n df_aug = pd.concat(augmented_parts, ignore_index=True)\n df_train_aug = pd.concat([df_train, df_aug], ignore_index=True)\nelse:\n df_train_aug = df_train.copy()\n\nprint(f\"Training size after augmentation: {len(df_train_aug)}\")\n\n# --- Positive Class Weights for BCE ---\n\n# These class counts should correspond to training augmented set stats if possible\nclass_counts = {\n \"anger\": 808,\n \"fear\": 3860,\n \"joy\": 1660,\n \"sadness\": 2171,\n \"surprise\": 1999\n}\n\nn_train = len(df_train_aug)\npos_weights = []\nfor label in CONFIG.LABELCOLS:\n count = class_counts.get(label, 1)\n weight = max(1, int((n_train - count) * 0.8 / count)) # heuristic weighting\n pos_weights.append(weight)\n\nPOS_WEIGHTS = torch.tensor(pos_weights, dtype=torch.float).to(DEVICE)\nprint(f\"Positive class weights for BCE: {POS_WEIGHTS.tolist()}\")\n\n# --- Dataset Class ---\n\nclass EmotionDataset(Dataset):\n def __init__(self, df, tokenizer, maxlen):\n self.texts = df[\"text\"].values\n self.labels = df[CONFIG.LABELCOLS].values\n self.tokenizer = tokenizer\n self.maxlen = maxlen\n \n def __len__(self):\n return len(self.texts)\n\n def __getitem__(self, idx):\n text = str(self.texts[idx])\n labels = torch.tensor(self.labels[idx], dtype=torch.float)\n encoding = self.tokenizer.encode_plus(\n text,\n add_special_tokens=True,\n max_length=self.maxlen,\n padding='max_length',\n truncation=True,\n return_attention_mask=True,\n return_tensors=\"pt\"\n )\n return {\n 'input_ids': encoding['input_ids'].squeeze(0),\n 'attention_mask': encoding['attention_mask'].squeeze(0),\n 'labels': labels\n }\n\ntokenizer = AutoTokenizer.from_pretrained(CONFIG.MODELNAME)\ntrain_dataset = EmotionDataset(df_train_aug, tokenizer, CONFIG.MAXLEN)\nval_dataset = EmotionDataset(df_val, tokenizer, CONFIG.MAXLEN)\ntrain_loader = DataLoader(train_dataset, batch_size=CONFIG.BATCHSIZE, shuffle=True, num_workers=2)\nval_loader = DataLoader(val_dataset, batch_size=CONFIG.BATCHSIZE, shuffle=False, num_workers=2)\n\n# --- Model Definition ---\n\nclass EmotionClassifier(nn.Module):\n def __init__(self, nclasses, modelname, dropout):\n super(EmotionClassifier, self).__init__()\n self.backbone = AutoModel.from_pretrained(modelname)\n self.drop = nn.Dropout(dropout)\n self.classifier = nn.Linear(self.backbone.config.hidden_size, nclasses)\n\n def forward(self, input_ids, attention_mask):\n outputs = self.backbone(input_ids=input_ids, attention_mask=attention_mask)\n pooled_output = outputs.last_hidden_state[:, 0, :]\n dropped = self.drop(pooled_output)\n logits = self.classifier(dropped)\n return logits\n\nmodel = EmotionClassifier(CONFIG.OUTPUTDIM, CONFIG.MODELNAME, CONFIG.DROPOUT).to(DEVICE)\n\n# --- Threshold Utility Functions ---\n\ndef find_optimal_thresholds(y_true, y_probs, label_cols, num_thresholds=100):\n thresholds = {}\n for i, label in enumerate(label_cols):\n best_f1 = 0.0\n best_t = 0.5\n for t in np.linspace(0.0, 1.0, num_thresholds):\n y_pred = (y_probs[:, i] >= t).astype(int)\n f1 = f1_score(y_true[:, i], y_pred, zero_division=0)\n if f1 > best_f1:\n best_f1 = f1\n best_t = t\n thresholds[label] = best_t\n return thresholds\n\ndef calculate_macro_f1(y_true, y_probs, thresholds, label_cols):\n y_pred = np.zeros_like(y_true)\n for i, label in enumerate(label_cols):\n t = thresholds.get(label, 0.5)\n y_pred[:, i] = (y_probs[:, i] >= t).astype(int)\n return f1_score(y_true, y_pred, average='macro', zero_division=0)\n\n# --- Training Loop with WandB Tracking ---\n\nwandb.init(project=\"22f3001086-t32025\", name = \"roberta-emotional\", config=CONFIG.__dict__)\n\nloss_fn = nn.BCEWithLogitsLoss(pos_weight=POS_WEIGHTS)\noptimizer = AdamW(model.parameters(), lr=CONFIG.LEARNINGRATE, weight_decay=CONFIG.WEIGHTDECAY)\ntotal_steps = len(train_loader) * CONFIG.EPOCHS\nscheduler = get_linear_schedule_with_warmup(optimizer,\n num_warmup_steps=int(total_steps*CONFIG.WARMUPRATIO),\n num_training_steps=total_steps)\n\nbest_macro_f1 = 0.0\n\nfor epoch in range(CONFIG.EPOCHS):\n model.train()\n total_loss = 0.0\n for batch in tqdm(train_loader, desc=f\"Epoch {epoch+1} Training\"):\n optimizer.zero_grad()\n input_ids = batch['input_ids'].to(DEVICE)\n attention_mask = batch['attention_mask'].to(DEVICE)\n labels = batch['labels'].to(DEVICE)\n\n logits = model(input_ids, attention_mask)\n loss = loss_fn(logits, labels)\n loss.backward()\n torch.nn.utils.clip_grad_norm_(model.parameters(), max_norm=1.0)\n optimizer.step()\n scheduler.step()\n\n total_loss += loss.item()\n\n avg_train_loss = total_loss / len(train_loader)\n\n model.eval()\n all_labels = []\n all_probs = []\n with torch.no_grad():\n for batch in val_loader:\n input_ids = batch['input_ids'].to(DEVICE)\n attention_mask = batch['attention_mask'].to(DEVICE)\n labels = batch['labels'].cpu().numpy()\n\n logits = model(input_ids, attention_mask)\n probs = torch.sigmoid(logits).cpu().numpy()\n\n all_labels.append(labels)\n all_probs.append(probs)\n\n y_true = np.vstack(all_labels)\n y_probs = np.vstack(all_probs)\n optimal_thresholds = find_optimal_thresholds(y_true, y_probs, CONFIG.LABELCOLS)\n val_macro_f1 = calculate_macro_f1(y_true, y_probs, optimal_thresholds, CONFIG.LABELCOLS)\n\n print(f\"Epoch {epoch+1} | Train Loss: {avg_train_loss:.4f} | Val Macro F1: {val_macro_f1:.4f}\")\n wandb.log({\n \"epoch\": epoch + 1,\n \"train_loss\": avg_train_loss,\n \"val_macro_f1\": val_macro_f1,\n \"learning_rate\": scheduler.get_last_lr()[0],\n **{f\"threshold_{label}\": thr for label, thr in optimal_thresholds.items()}\n })\n\n if val_macro_f1 > best_macro_f1:\n best_macro_f1 = val_macro_f1\n torch.save(model.state_dict(), \"best_emotion_model.pt\")\n print(f\"Saved best model with Macro F1: {best_macro_f1:.4f}\")\n\nwandb.finish()\nprint(\"Training complete.\")\n\n# --- Inference Code ---\n\nclass EmotionTestDataset(Dataset):\n def __init__(self, texts, tokenizer, maxlen):\n self.texts = list(texts)\n self.tokenizer = tokenizer\n self.maxlen = maxlen\n \n def __len__(self):\n return len(self.texts)\n \n def __getitem__(self, idx):\n text = str(self.texts[idx])\n encoding = self.tokenizer.encode_plus(\n text,\n add_special_tokens=True,\n max_length=self.maxlen,\n padding='max_length',\n truncation=True,\n return_attention_mask=True,\n return_tensors='pt'\n )\n return {\n 'input_ids': encoding['input_ids'].squeeze(0),\n 'attention_mask': encoding['attention_mask'].squeeze(0),\n }\n\ndef predict(model_path, test_texts, batch_size=64):\n tokenizer = AutoTokenizer.from_pretrained(CONFIG.MODELNAME)\n model = EmotionClassifier(CONFIG.OUTPUTDIM, CONFIG.MODELNAME, CONFIG.DROPOUT)\n model.load_state_dict(torch.load(model_path, map_location=DEVICE))\n model.to(DEVICE)\n model.eval()\n\n test_dataset = EmotionTestDataset(test_texts, tokenizer, CONFIG.MAXLEN)\n test_loader = DataLoader(test_dataset, batch_size=batch_size, shuffle=False, num_workers=2)\n\n all_probs = []\n with torch.no_grad():\n for batch in tqdm(test_loader, desc=\"Generating Test Predictions\"):\n input_ids = batch['input_ids'].to(DEVICE)\n attention_mask = batch['attention_mask'].to(DEVICE)\n logits = model(input_ids, attention_mask)\n probs = torch.sigmoid(logits).cpu().numpy()\n all_probs.append(probs)\n\n all_probs = np.vstack(all_probs)\n return all_probs\n\n# Example usage:\n# test_probs = predict(\"best_emotion_model.pt\", df_test[\"text\"])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-30T12:57:20.862103Z","iopub.execute_input":"2025-11-30T12:57:20.862709Z","iopub.status.idle":"2025-11-30T13:03:25.066860Z","shell.execute_reply.started":"2025-11-30T12:57:20.862685Z","shell.execute_reply":"2025-11-30T13:03:25.065896Z"}},"outputs":[{"name":"stderr","text":"[nltk_data] Downloading package averaged_perceptron_tagger to\n[nltk_data] /usr/share/nltk_data...\n[nltk_data] Package averaged_perceptron_tagger is already up-to-\n[nltk_data] date!\n","output_type":"stream"},{"name":"stdout","text":"Using device: cuda\nTraining samples: 5461\nValidation samples: 1366\nTraining size after augmentation: 8094\nPositive class weights for BCE: [7.0, 1.0, 3.0, 2.0, 2.0]\n","output_type":"stream"},{"output_type":"display_data","data":{"text/plain":"pytorch_model.bin: 0%| | 0.00/329M [00:00","text/html":"Tracking run with wandb version 0.21.0"},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"","text/html":"Run data is saved locally in /kaggle/working/wandb/run-20251130_125728-tj5esri5"},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"","text/html":"Syncing run roberta-emotional to Weights & Biases (docs)
"},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"","text/html":" View project at https://wandb.ai/vaishnavib-iitm-jntuh-/22f3001086-t32025"},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"","text/html":" View run at https://wandb.ai/vaishnavib-iitm-jntuh-/22f3001086-t32025/runs/tj5esri5"},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"Epoch 1 Training: 0%| | 0/253 [00:00\nTraceback (most recent call last):\n File \"/usr/local/lib/python3.11/dist-packages/torch/utils/data/dataloader.py\", line 1618, in __del__\n self._shutdown_workers()\n File \"/usr/local/lib/python3.11/dist-packages/torch/utils/data/dataloader.py\", line 1601, in _shutdown_workers\n if w.is_alive():\n Exception ignored in: \n Traceback (most recent call last):\n File \"/usr/local/lib/python3.11/dist-packages/torch/utils/data/dataloader.py\", line 1618, in __del__\n ^self._shutdown_workers()^\n^ File \"/usr/local/lib/python3.11/dist-packages/torch/utils/data/dataloader.py\", line 1601, in _shutdown_workers\n^ ^^if w.is_alive():\n^^ ^ ^ ^ ^ File \"/usr/lib/python3.11/multiprocessing/process.py\", line 160, in is_alive\n\n ^ assert self._parent_pid == os.getpid(), 'can only test a child process'^\n ^ ^ ^ ^ ^^ ^^ ^^ \n File \"/usr/lib/python3.11/multiprocessing/process.py\", line 160, in is_alive\n^ assert self._parent_pid == os.getpid(), 'can only test a child process'^\n^ ^ ^ ^ ^ ^^ ^ ^ ^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n^AssertionError^^^: ^can only test a child process^\n^Exception ignored in: ^^\n^Traceback (most recent call last):\n^ File \"/usr/local/lib/python3.11/dist-packages/torch/utils/data/dataloader.py\", line 1618, in __del__\n^ self._shutdown_workers()^\n File \"/usr/local/lib/python3.11/dist-packages/torch/utils/data/dataloader.py\", line 1601, in _shutdown_workers\n^ \nif w.is_alive():AssertionError\n: can only test a child process \n Exception ignored in: ^^\n^^^Traceback (most recent call last):\n File \"/usr/local/lib/python3.11/dist-packages/torch/utils/data/dataloader.py\", line 1618, in __del__\n^ ^self._shutdown_workers()^\n File \"/usr/local/lib/python3.11/dist-packages/torch/utils/data/dataloader.py\", line 1601, in _shutdown_workers\n^^ if w.is_alive():^^\n\n File \"/usr/lib/python3.11/multiprocessing/process.py\", line 160, in is_alive\n assert self._parent_pid == os.getpid(), 'can only test a child process' \n ^ ^^ ^^^ ^ ^ ^ ^ ^^^^^^\n^ File \"/usr/lib/python3.11/multiprocessing/process.py\", line 160, in is_alive\n^^ assert self._parent_pid == os.getpid(), 'can only test a child process'^\n^ ^^^ ^^ ^^ ^ ^ ^ ^^ ^^^^^^^^^^^^^^^^\nAssertionError^: ^can only test a child process^\n^^^^^^^^^^^^^^^^^^^^^^\nAssertionError: can only test a child process\n","output_type":"stream"},{"name":"stdout","text":"Epoch 3 | Train Loss: 0.4007 | Val Macro F1: 0.7712\nSaved best model with Macro F1: 0.7712\n","output_type":"stream"},{"output_type":"display_data","data":{"text/plain":"Epoch 4 Training: 0%| | 0/253 [00:00","text/html":""},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"","text/html":"

Run history:


epoch▁▂▄▅▇█
learning_rate█▇▅▄▂▁
threshold_anger▁▅▄▆█▆
threshold_fear▅▆▂█▁▃
threshold_joy█▁▅▁▂▂
threshold_sadness▆▇▁▁▆█
threshold_surprise▅▂▆▁▅█
train_loss█▅▃▂▁▁
val_macro_f1▁▄▆███

Run summary:


epoch6
learning_rate0
threshold_anger0.78788
threshold_fear0.42424
threshold_joy0.58586
threshold_sadness0.56566
threshold_surprise0.65657
train_loss0.24659
val_macro_f10.79567

"},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"","text/html":" View run roberta-emotional at: https://wandb.ai/vaishnavib-iitm-jntuh-/22f3001086-t32025/runs/tj5esri5
View project at: https://wandb.ai/vaishnavib-iitm-jntuh-/22f3001086-t32025
Synced 5 W&B file(s), 0 media file(s), 0 artifact file(s) and 0 other file(s)"},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"","text/html":"Find logs at: ./wandb/run-20251130_125728-tj5esri5/logs"},"metadata":{}},{"name":"stdout","text":"Training complete.\n","output_type":"stream"}],"execution_count":13}]}