Upload 15_150_negs_22's state dict
Browse files- .gitattributes +1 -0
- 15_150_negs_22/15_150_negs_22.py +1583 -0
- 15_150_negs_22/lasts/15_150_negs_22_s26092004_f0_last_ema.pth +3 -0
- 15_150_negs_22/lasts/15_150_negs_22_s26092004_f1_last_ema.pth +3 -0
- 15_150_negs_22/lasts/15_150_negs_22_s26092004_f2_last_ema.pth +3 -0
- 15_150_negs_22/lasts/15_150_negs_22_s26092004_f3_last_ema.pth +3 -0
- 15_150_negs_22/lasts/15_150_negs_22_s26092004_f4_last_ema.pth +3 -0
- 15_150_negs_22/logs/15_150_negs_22_log_plot.jpg +3 -0
- 15_150_negs_22/logs/15_150_negs_22_s26092004_f0_logging.json +1 -0
- 15_150_negs_22/logs/15_150_negs_22_s26092004_f1_logging.json +1 -0
- 15_150_negs_22/logs/15_150_negs_22_s26092004_f2_logging.json +1 -0
- 15_150_negs_22/logs/15_150_negs_22_s26092004_f3_logging.json +1 -0
- 15_150_negs_22/logs/15_150_negs_22_s26092004_f4_logging.json +1 -0
- 15_150_negs_22/r1s/15_150_negs_22_s26092004_f0_r1_vs0.84997_ema.pth +3 -0
- 15_150_negs_22/r1s/15_150_negs_22_s26092004_f1_r1_vs0.84638_ema.pth +3 -0
- 15_150_negs_22/r1s/15_150_negs_22_s26092004_f2_r1_vs0.85324_ema.pth +3 -0
- 15_150_negs_22/r1s/15_150_negs_22_s26092004_f3_r1_vs0.84804_ema.pth +3 -0
- 15_150_negs_22/r1s/15_150_negs_22_s26092004_f4_r1_vs0.84691_ema.pth +3 -0
- 15_150_negs_22/results/15_150_negs_22_test.json +176 -0
- 15_150_negs_22/results/15_150_negs_22_test_df.xlsx +0 -0
- 15_150_negs_22/results/15_150_negs_22_test_df_best.xlsx +0 -0
.gitattributes
CHANGED
|
@@ -43,3 +43,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 43 |
15_40_negs_19/logs/15_40_negs_19_log_plot.jpg filter=lfs diff=lfs merge=lfs -text
|
| 44 |
15_50_negs_20/logs/15_50_negs_20_log_plot.jpg filter=lfs diff=lfs merge=lfs -text
|
| 45 |
15_25_negs_18/logs/15_25_negs_18_log_plot.jpg filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 43 |
15_40_negs_19/logs/15_40_negs_19_log_plot.jpg filter=lfs diff=lfs merge=lfs -text
|
| 44 |
15_50_negs_20/logs/15_50_negs_20_log_plot.jpg filter=lfs diff=lfs merge=lfs -text
|
| 45 |
15_25_negs_18/logs/15_25_negs_18_log_plot.jpg filter=lfs diff=lfs merge=lfs -text
|
| 46 |
+
15_150_negs_22/logs/15_150_negs_22_log_plot.jpg filter=lfs diff=lfs merge=lfs -text
|
15_150_negs_22/15_150_negs_22.py
ADDED
|
@@ -0,0 +1,1583 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# %% [code]
|
| 2 |
+
get_ipython().system('pip install evaluate seqeval underthesea positional-encodings[pytorch]')
|
| 3 |
+
|
| 4 |
+
# %% [code]
|
| 5 |
+
import warnings
|
| 6 |
+
warnings.filterwarnings('ignore')
|
| 7 |
+
|
| 8 |
+
import torch
|
| 9 |
+
import torch.nn as nn
|
| 10 |
+
import torch.optim as optim
|
| 11 |
+
from torch.utils.data import Dataset, TensorDataset, DataLoader
|
| 12 |
+
import torch.nn.functional as F
|
| 13 |
+
import albumentations as albu
|
| 14 |
+
from transformers import AutoTokenizer, AutoModel
|
| 15 |
+
import torch.distributed as dist
|
| 16 |
+
from torch.nn.parallel import DistributedDataParallel as DDP
|
| 17 |
+
from positional_encodings.torch_encodings import PositionalEncoding1D
|
| 18 |
+
|
| 19 |
+
from sklearn.metrics import f1_score
|
| 20 |
+
from sklearn.preprocessing import MinMaxScaler, StandardScaler
|
| 21 |
+
from scipy.spatial.transform import Rotation as R
|
| 22 |
+
from sklearn.model_selection import KFold, StratifiedGroupKFold, GroupKFold, StratifiedKFold
|
| 23 |
+
from sklearn.metrics import precision_recall_fscore_support
|
| 24 |
+
from timm.utils import ModelEmaV3
|
| 25 |
+
import timm
|
| 26 |
+
|
| 27 |
+
import os
|
| 28 |
+
import gc
|
| 29 |
+
import json
|
| 30 |
+
from pathlib import Path
|
| 31 |
+
import pickle
|
| 32 |
+
from tqdm.auto import tqdm
|
| 33 |
+
import copy
|
| 34 |
+
import numpy as np
|
| 35 |
+
import pandas as pd
|
| 36 |
+
import polars as pl
|
| 37 |
+
from PIL import Image
|
| 38 |
+
import time
|
| 39 |
+
from tqdm import tqdm
|
| 40 |
+
from matplotlib import pyplot as plt
|
| 41 |
+
import seaborn as sns
|
| 42 |
+
from multiprocessing import Manager as MemoryManager
|
| 43 |
+
from functools import lru_cache
|
| 44 |
+
import shutil
|
| 45 |
+
import glob
|
| 46 |
+
import cv2
|
| 47 |
+
import random
|
| 48 |
+
import re
|
| 49 |
+
import joblib
|
| 50 |
+
import math
|
| 51 |
+
from huggingface_hub import HfApi, snapshot_download
|
| 52 |
+
import evaluate
|
| 53 |
+
from underthesea import word_tokenize as vi_tokenize_tool
|
| 54 |
+
import spacy
|
| 55 |
+
en_tokenize_tool = spacy.load("en_core_web_sm")
|
| 56 |
+
from collections import defaultdict, Counter
|
| 57 |
+
|
| 58 |
+
# %% [code]
|
| 59 |
+
file_path = "/kaggle/input/notebooks/sambui22022517/kltn-lr-bm25/bm25_scores.npy"
|
| 60 |
+
|
| 61 |
+
bm25_scores = np.load(file_path, allow_pickle=True)
|
| 62 |
+
print(bm25_scores.shape)
|
| 63 |
+
|
| 64 |
+
# %% [code]
|
| 65 |
+
# Global config
|
| 66 |
+
SEEDS = [26092004]
|
| 67 |
+
topk = 1
|
| 68 |
+
nfolds = 5
|
| 69 |
+
only_fold_idx = None
|
| 70 |
+
test_only = 0
|
| 71 |
+
debug_only = 0
|
| 72 |
+
|
| 73 |
+
# Config thư mục
|
| 74 |
+
dataset = 'kltn/raw' # vhe, bkee, casie, kltn/only_issues, kltn/only_actions, kltn/raw
|
| 75 |
+
root_dir = f'/kaggle/input/notebooks/sambui22022517/kltn-data/{dataset}' ## Thư mục chứa file train, val, test
|
| 76 |
+
train_dir = f'{root_dir}'
|
| 77 |
+
# val_dir = f'{root_dir}/val'
|
| 78 |
+
test_dir = f'{root_dir}'
|
| 79 |
+
|
| 80 |
+
# Config checkpoints
|
| 81 |
+
|
| 82 |
+
# Config training
|
| 83 |
+
epochs = 18 if not debug_only else 2
|
| 84 |
+
batch_size = 32
|
| 85 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 86 |
+
# # Thêm biến toàn cục nào đó vào đây
|
| 87 |
+
repo_name = 'SS3M/kltn-lr-experiments'
|
| 88 |
+
state_dict_save_name = "15_150_negs_22"
|
| 89 |
+
checkpoints_dir = state_dict_save_name
|
| 90 |
+
pretrained_dir = "/kaggle/working"
|
| 91 |
+
os.makedirs(f'{checkpoints_dir}', exist_ok=True)
|
| 92 |
+
|
| 93 |
+
backbone_model_name = "bert-base-uncased" if dataset == "casie" else "vinai/phobert-base"
|
| 94 |
+
word_tokenize = lambda text: [token.text for token in en_tokenize_tool(text)] if dataset == "casie" else vi_tokenize_tool(text)
|
| 95 |
+
max_len_dict = {
|
| 96 |
+
'kltn/raw': 256,
|
| 97 |
+
'kltn/only_issues': 52,
|
| 98 |
+
'kltn/only_actions': 69,
|
| 99 |
+
'vhe': 51,
|
| 100 |
+
'bkee': 62,
|
| 101 |
+
'casie': 40,
|
| 102 |
+
}
|
| 103 |
+
zero_events_rate_dict = {
|
| 104 |
+
'kltn/raw': 1000,
|
| 105 |
+
'kltn/only_issues': 0,
|
| 106 |
+
'kltn/only_actions': 0.2,
|
| 107 |
+
'vhe': 1000, # mean keep all zero-events samples
|
| 108 |
+
'bkee': 1000,
|
| 109 |
+
'casie': 1000,
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
max_len = max_len_dict[dataset]
|
| 113 |
+
max_n_parts = 2
|
| 114 |
+
max_span_len = 14
|
| 115 |
+
n_negs = 5 * 30
|
| 116 |
+
zero_events_rate = zero_events_rate_dict[dataset]
|
| 117 |
+
|
| 118 |
+
# Trainer
|
| 119 |
+
trainer_params = {
|
| 120 |
+
"training_time": "00:11:30:00",
|
| 121 |
+
"eval_mode": "max",
|
| 122 |
+
"topk": topk,
|
| 123 |
+
"save_name": state_dict_save_name,
|
| 124 |
+
"save_best": True,
|
| 125 |
+
"save_last": True,
|
| 126 |
+
"device": device,
|
| 127 |
+
"logging": True,
|
| 128 |
+
"logging_file": True,
|
| 129 |
+
"checkpoints_dir": checkpoints_dir,
|
| 130 |
+
"early_stopping": 30,
|
| 131 |
+
"eval_from_ratio": 0.4,
|
| 132 |
+
"eval_every": 1,
|
| 133 |
+
"schedule_in_step": False,
|
| 134 |
+
"use_ema": True,
|
| 135 |
+
"ema_from_ratio": 0.3,
|
| 136 |
+
"ema_decay": 0.9995,
|
| 137 |
+
"max_grad_norm": 200.0,
|
| 138 |
+
"return_best": True,
|
| 139 |
+
"return_last": True,
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
# Memory
|
| 143 |
+
train_memory_params = {
|
| 144 |
+
'max_len': max_len,
|
| 145 |
+
'max_n_parts': max_n_parts,
|
| 146 |
+
'n_negs': n_negs,
|
| 147 |
+
}
|
| 148 |
+
val_memory_params = {
|
| 149 |
+
'max_len': max_len,
|
| 150 |
+
'max_n_parts': max_n_parts,
|
| 151 |
+
'n_negs': n_negs,
|
| 152 |
+
}
|
| 153 |
+
corpus_memory_params = {
|
| 154 |
+
'max_len': max_len,
|
| 155 |
+
'max_n_parts': max_n_parts,
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
# Data Loader
|
| 159 |
+
def seed_worker(worker_id):
|
| 160 |
+
worker_seed = torch.initial_seed() % 2**32
|
| 161 |
+
np.random.seed(worker_seed)
|
| 162 |
+
random.seed(worker_seed)
|
| 163 |
+
|
| 164 |
+
train_loader_params = {
|
| 165 |
+
'batch_size': batch_size,
|
| 166 |
+
'shuffle': True,
|
| 167 |
+
'pin_memory':True,
|
| 168 |
+
'num_workers': 2,
|
| 169 |
+
'drop_last': False,
|
| 170 |
+
'worker_init_fn': seed_worker,
|
| 171 |
+
'persistent_workers': False,
|
| 172 |
+
}
|
| 173 |
+
val_loader_params = {
|
| 174 |
+
'batch_size': batch_size,
|
| 175 |
+
'shuffle': False,
|
| 176 |
+
'pin_memory':True,
|
| 177 |
+
'num_workers': 1,
|
| 178 |
+
'drop_last': False,
|
| 179 |
+
'worker_init_fn': seed_worker,
|
| 180 |
+
'persistent_workers': False,
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
# Model
|
| 184 |
+
model_params = {
|
| 185 |
+
'backbone_name': backbone_model_name,
|
| 186 |
+
'projection_dim': 256,
|
| 187 |
+
'normalize': True,
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
# Loss Func
|
| 191 |
+
loss_func_params = {
|
| 192 |
+
'lambda_contrastive': 1.0,
|
| 193 |
+
'lambda_triplet': 0.5,
|
| 194 |
+
}
|
| 195 |
+
eval_func_params = {}
|
| 196 |
+
|
| 197 |
+
# Optim
|
| 198 |
+
optim_params = {
|
| 199 |
+
'name': 'AdamW',
|
| 200 |
+
'lr': 1e-4,
|
| 201 |
+
'weight_decay': 1e-4,
|
| 202 |
+
}
|
| 203 |
+
scheduler_params = {
|
| 204 |
+
'name': 'CosineAnnealingLR',
|
| 205 |
+
'T_max': 20, # Số epoch để hoàn thành một chu kỳ giảm LR
|
| 206 |
+
'eta_min': 1e-6 # Learning rate nhỏ nhất trong chu kỳ
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
# %% [code]
|
| 210 |
+
def set_seed(seed=42):
|
| 211 |
+
random.seed(seed)
|
| 212 |
+
np.random.seed(seed)
|
| 213 |
+
torch.manual_seed(seed)
|
| 214 |
+
torch.cuda.manual_seed(seed)
|
| 215 |
+
torch.cuda.manual_seed_all(seed) # if using multi-GPU
|
| 216 |
+
torch.use_deterministic_algorithms(False)
|
| 217 |
+
torch.backends.cudnn.deterministic = True
|
| 218 |
+
torch.backends.cudnn.benchmark = False
|
| 219 |
+
os.environ['PYTHONHASHSEED'] = str(seed)
|
| 220 |
+
|
| 221 |
+
# %% [code]
|
| 222 |
+
class CustomLoss(nn.Module):
|
| 223 |
+
def __init__(
|
| 224 |
+
self,
|
| 225 |
+
temperature=0.05,
|
| 226 |
+
margin=0.2,
|
| 227 |
+
lambda_contrastive=1.0,
|
| 228 |
+
lambda_triplet=0.5,
|
| 229 |
+
):
|
| 230 |
+
super().__init__()
|
| 231 |
+
|
| 232 |
+
self.temperature = temperature
|
| 233 |
+
self.margin = margin
|
| 234 |
+
|
| 235 |
+
self.lambda_contrastive = lambda_contrastive
|
| 236 |
+
self.lambda_triplet = lambda_triplet
|
| 237 |
+
|
| 238 |
+
def forward(
|
| 239 |
+
self,
|
| 240 |
+
encoded_text,
|
| 241 |
+
encoded_pos,
|
| 242 |
+
encoded_neg,
|
| 243 |
+
pos_mask
|
| 244 |
+
):
|
| 245 |
+
loss_contrastive = self.multi_pos_contrastive_loss(encoded_text, encoded_pos, encoded_neg, pos_mask)
|
| 246 |
+
loss_triplet = self.hardest_triplet_loss(encoded_text, encoded_pos, encoded_neg, pos_mask)
|
| 247 |
+
|
| 248 |
+
total_loss = (
|
| 249 |
+
self.lambda_contrastive * loss_contrastive +
|
| 250 |
+
self.lambda_triplet * loss_triplet
|
| 251 |
+
)
|
| 252 |
+
|
| 253 |
+
return {
|
| 254 |
+
"total": total_loss,
|
| 255 |
+
"contrastive_loss": loss_contrastive,
|
| 256 |
+
"triplet_loss": loss_triplet,
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
def multi_pos_contrastive_loss(self, q, pos, neg, pos_mask):
|
| 260 |
+
B, P, D = pos.shape
|
| 261 |
+
N = neg.shape[1]
|
| 262 |
+
|
| 263 |
+
# ===== concat docs =====
|
| 264 |
+
docs = torch.cat([pos, neg], dim=1) # [B, P+N, D]
|
| 265 |
+
|
| 266 |
+
# ===== similarity =====
|
| 267 |
+
logits = torch.matmul(q.unsqueeze(1), docs.transpose(1, 2)).squeeze(1)
|
| 268 |
+
logits = logits / self.temperature # [B, P+N]
|
| 269 |
+
|
| 270 |
+
# ===== labels =====
|
| 271 |
+
labels = torch.zeros_like(logits)
|
| 272 |
+
labels[:, :P] = pos_mask # chỉ pos hợp lệ
|
| 273 |
+
|
| 274 |
+
# ===== log-softmax =====
|
| 275 |
+
log_prob = logits - torch.logsumexp(logits, dim=1, keepdim=True)
|
| 276 |
+
|
| 277 |
+
# ===== normalize theo số pos thật =====
|
| 278 |
+
pos_count = pos_mask.sum(dim=1).clamp(min=1)
|
| 279 |
+
|
| 280 |
+
loss = -(labels * log_prob).sum(dim=1) / pos_count
|
| 281 |
+
|
| 282 |
+
return loss.mean()
|
| 283 |
+
|
| 284 |
+
def hardest_triplet_loss(self, q, pos, neg, pos_mask):
|
| 285 |
+
# ===== similarity =====
|
| 286 |
+
pos_sim = torch.matmul(q.unsqueeze(1), pos.transpose(1, 2)).squeeze(1) # [B, P]
|
| 287 |
+
neg_sim = torch.matmul(q.unsqueeze(1), neg.transpose(1, 2)).squeeze(1) # [B, N]
|
| 288 |
+
|
| 289 |
+
# ===== mask pos =====
|
| 290 |
+
pos_sim_masked = pos_sim.clone()
|
| 291 |
+
pos_sim_masked[pos_mask == 0] = float('inf') # loại pad
|
| 292 |
+
|
| 293 |
+
# ===== hardest =====
|
| 294 |
+
hardest_pos = pos_sim_masked.min(dim=1).values
|
| 295 |
+
hardest_neg = neg_sim.max(dim=1).values
|
| 296 |
+
|
| 297 |
+
# ===== loss =====
|
| 298 |
+
loss = F.relu(self.margin + hardest_neg - hardest_pos)
|
| 299 |
+
|
| 300 |
+
return loss.mean()
|
| 301 |
+
|
| 302 |
+
# %% [code]
|
| 303 |
+
class CustomEvalFn(nn.Module):
|
| 304 |
+
def __init__(self):
|
| 305 |
+
super().__init__()
|
| 306 |
+
|
| 307 |
+
def forward(self, pred_topk, real_topk):
|
| 308 |
+
"""
|
| 309 |
+
pred_topk: List[List[int]] shape [B, K]
|
| 310 |
+
real_topk: List[List[int]] shape [B, Ki]
|
| 311 |
+
"""
|
| 312 |
+
|
| 313 |
+
B = len(pred_topk)
|
| 314 |
+
|
| 315 |
+
total_recall = 0.0
|
| 316 |
+
total_map = 0.0
|
| 317 |
+
total_mrp = 0.0
|
| 318 |
+
|
| 319 |
+
for i in range(B):
|
| 320 |
+
preds = pred_topk[i]
|
| 321 |
+
gts = set(real_topk[i])
|
| 322 |
+
|
| 323 |
+
# ===== Recall@K =====
|
| 324 |
+
hit = any(p in gts for p in preds)
|
| 325 |
+
total_recall += 1.0 if hit else 0.0
|
| 326 |
+
|
| 327 |
+
# ===== AP =====
|
| 328 |
+
num_hits = 0
|
| 329 |
+
ap = 0.0
|
| 330 |
+
|
| 331 |
+
for rank, p in enumerate(preds, start=1):
|
| 332 |
+
if p in gts:
|
| 333 |
+
num_hits += 1
|
| 334 |
+
precision_at_rank = num_hits / rank
|
| 335 |
+
ap += precision_at_rank
|
| 336 |
+
|
| 337 |
+
if len(gts) > 0:
|
| 338 |
+
ap /= len(gts)
|
| 339 |
+
|
| 340 |
+
total_map += ap
|
| 341 |
+
|
| 342 |
+
# ===== R-Precision =====
|
| 343 |
+
r = len(gts)
|
| 344 |
+
|
| 345 |
+
if r > 0:
|
| 346 |
+
top_r = preds[:r]
|
| 347 |
+
|
| 348 |
+
tp_r = sum(p in gts for p in top_r)
|
| 349 |
+
|
| 350 |
+
rp = tp_r / r
|
| 351 |
+
else:
|
| 352 |
+
rp = 0.0
|
| 353 |
+
|
| 354 |
+
total_mrp += rp
|
| 355 |
+
|
| 356 |
+
recall = total_recall / B
|
| 357 |
+
mAP = total_map / B
|
| 358 |
+
mRP = total_mrp / B
|
| 359 |
+
|
| 360 |
+
return {
|
| 361 |
+
"recall": recall,
|
| 362 |
+
"mAP": mAP,
|
| 363 |
+
"mRP": mRP,
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
# %% [code]
|
| 367 |
+
class EncodeModel(nn.Module):
|
| 368 |
+
def __init__(
|
| 369 |
+
self,
|
| 370 |
+
backbone_name,
|
| 371 |
+
projection_dim,
|
| 372 |
+
normalize=True,
|
| 373 |
+
dropout=0.1
|
| 374 |
+
):
|
| 375 |
+
super().__init__()
|
| 376 |
+
|
| 377 |
+
self.encoder = AutoModel.from_pretrained(backbone_name)
|
| 378 |
+
|
| 379 |
+
hidden_size = self.encoder.config.hidden_size
|
| 380 |
+
|
| 381 |
+
# mạnh hơn single linear
|
| 382 |
+
self.proj = nn.Sequential(
|
| 383 |
+
nn.Linear(hidden_size, hidden_size),
|
| 384 |
+
nn.GELU(),
|
| 385 |
+
nn.Dropout(dropout),
|
| 386 |
+
nn.Linear(hidden_size, projection_dim)
|
| 387 |
+
)
|
| 388 |
+
|
| 389 |
+
# residual projection
|
| 390 |
+
self.residual_proj = (
|
| 391 |
+
nn.Identity()
|
| 392 |
+
if hidden_size == projection_dim
|
| 393 |
+
else nn.Linear(hidden_size, projection_dim)
|
| 394 |
+
)
|
| 395 |
+
|
| 396 |
+
self.normalize = normalize
|
| 397 |
+
|
| 398 |
+
def mean_pooling(self, hidden, attention_mask):
|
| 399 |
+
mask = attention_mask.unsqueeze(-1).float() # [N, L, 1]
|
| 400 |
+
pooled = (hidden * mask).sum(dim=1) / mask.sum(dim=1).clamp(min=1e-6)
|
| 401 |
+
|
| 402 |
+
return pooled
|
| 403 |
+
|
| 404 |
+
def forward(self, input_ids, attention_mask, is_query=True):
|
| 405 |
+
|
| 406 |
+
if is_query:
|
| 407 |
+
# [B, n_parts, L]
|
| 408 |
+
B, n_parts, L = input_ids.shape
|
| 409 |
+
|
| 410 |
+
input_ids = input_ids.view(-1, L)
|
| 411 |
+
attention_mask = attention_mask.view(-1, L)
|
| 412 |
+
|
| 413 |
+
outputs = self.encoder(
|
| 414 |
+
input_ids=input_ids,
|
| 415 |
+
attention_mask=attention_mask
|
| 416 |
+
)
|
| 417 |
+
|
| 418 |
+
hidden = outputs.last_hidden_state # [B*n_parts, L, H]
|
| 419 |
+
|
| 420 |
+
chunk_repr = self.mean_pooling(hidden, attention_mask) # [B*n_parts, H]
|
| 421 |
+
chunk_repr = chunk_repr.view(B, n_parts, -1) # [B, n_parts, H]
|
| 422 |
+
pooled = chunk_repr.mean(dim=1)
|
| 423 |
+
# [B, H]
|
| 424 |
+
|
| 425 |
+
else:
|
| 426 |
+
# [B, K, n_parts, L]
|
| 427 |
+
B, K, n_parts, L = input_ids.shape
|
| 428 |
+
|
| 429 |
+
input_ids = input_ids.view(-1, L)
|
| 430 |
+
attention_mask = attention_mask.view(-1, L)
|
| 431 |
+
|
| 432 |
+
outputs = self.encoder(
|
| 433 |
+
input_ids=input_ids,
|
| 434 |
+
attention_mask=attention_mask
|
| 435 |
+
)
|
| 436 |
+
|
| 437 |
+
hidden = outputs.last_hidden_state
|
| 438 |
+
|
| 439 |
+
chunk_repr = self.mean_pooling(hidden, attention_mask) # [B*K*n_parts, H]
|
| 440 |
+
chunk_repr = chunk_repr.view(B, K, n_parts, -1) # [B, K, n_parts, H]
|
| 441 |
+
pooled = chunk_repr.mean(dim=2) # [B, K, H]
|
| 442 |
+
|
| 443 |
+
# residual MLP projection
|
| 444 |
+
emb = self.proj(pooled) + self.residual_proj(pooled)
|
| 445 |
+
|
| 446 |
+
if self.normalize:
|
| 447 |
+
emb = F.normalize(emb, dim=-1)
|
| 448 |
+
|
| 449 |
+
return emb
|
| 450 |
+
|
| 451 |
+
def test_model():
|
| 452 |
+
model = nn.DataParallel(EncodeModel('vinai/phobert-base', 256, True)).to(device)
|
| 453 |
+
model.eval()
|
| 454 |
+
|
| 455 |
+
bz = 32
|
| 456 |
+
vocab_size = 1000
|
| 457 |
+
qi = torch.randint(0, vocab_size, (bz, 1, 256)).to(device)
|
| 458 |
+
qa = torch.ones(bz, 1, 256).to(device)
|
| 459 |
+
di = torch.randint(0, vocab_size, (bz, 5, 2, 256)).to(device)
|
| 460 |
+
da = torch.ones(bz, 5, 2, 256).to(device)
|
| 461 |
+
|
| 462 |
+
st = time.time()
|
| 463 |
+
with torch.no_grad():
|
| 464 |
+
encoded_text = model(qi, qa, is_query=True)
|
| 465 |
+
encoded_pos = model(di, da, is_query=False)
|
| 466 |
+
encoded_neg = model(di, da, is_query=False)
|
| 467 |
+
print(encoded_text.shape, encoded_pos.shape, encoded_neg.shape)
|
| 468 |
+
print(time.time() - st)
|
| 469 |
+
|
| 470 |
+
del model, qi, qa, di, da, encoded_text, encoded_pos, encoded_neg
|
| 471 |
+
torch.cuda.empty_cache()
|
| 472 |
+
gc.collect()
|
| 473 |
+
test_model()
|
| 474 |
+
|
| 475 |
+
# %% [code]
|
| 476 |
+
def configure_optimizers(network, optim_params, scheduler_params):
|
| 477 |
+
try:
|
| 478 |
+
optim_params = copy.copy(optim_params)
|
| 479 |
+
scheduler_params = copy.copy(scheduler_params)
|
| 480 |
+
|
| 481 |
+
optim_name = optim_params.pop('name')
|
| 482 |
+
scheduler_name = scheduler_params.pop('name')
|
| 483 |
+
|
| 484 |
+
optimizer_cls = globals().get(optim_name) or getattr(optim, optim_name, None)
|
| 485 |
+
scheduler_cls = globals().get(scheduler_name) or getattr(optim.lr_scheduler, scheduler_name, None)
|
| 486 |
+
|
| 487 |
+
if optimizer_cls is None:
|
| 488 |
+
raise ValueError(f"Optimizer '{optim_name}' is not available!")
|
| 489 |
+
|
| 490 |
+
optimizer = optimizer_cls(network.parameters(), **optim_params)
|
| 491 |
+
|
| 492 |
+
scheduler = None
|
| 493 |
+
if scheduler_params and scheduler_cls: # Chỉ tạo scheduler nếu có tham số
|
| 494 |
+
scheduler = scheduler_cls(optimizer, **scheduler_params)
|
| 495 |
+
|
| 496 |
+
return optimizer, scheduler
|
| 497 |
+
|
| 498 |
+
except KeyError as e:
|
| 499 |
+
raise ValueError(f"Missing {e} in config!!")
|
| 500 |
+
|
| 501 |
+
def freeze(self, model):
|
| 502 |
+
model.eval()
|
| 503 |
+
for param in model.parameters():
|
| 504 |
+
param.requires_grad = False
|
| 505 |
+
|
| 506 |
+
def unfreeze(self, model):
|
| 507 |
+
model.train()
|
| 508 |
+
for param in model.parameters():
|
| 509 |
+
param.requires_grad = True
|
| 510 |
+
|
| 511 |
+
def reduce_batch_size(loader, ratio=0.5):
|
| 512 |
+
new_bs = max(1, int(loader.batch_size * ratio))
|
| 513 |
+
|
| 514 |
+
shuffle = isinstance(loader.sampler, RandomSampler)
|
| 515 |
+
|
| 516 |
+
new_loader = DataLoader(
|
| 517 |
+
dataset=loader.dataset,
|
| 518 |
+
batch_size=new_bs,
|
| 519 |
+
shuffle=shuffle,
|
| 520 |
+
sampler=None if shuffle else loader.sampler,
|
| 521 |
+
num_workers=loader.num_workers,
|
| 522 |
+
collate_fn=loader.collate_fn,
|
| 523 |
+
pin_memory=loader.pin_memory,
|
| 524 |
+
drop_last=loader.drop_last,
|
| 525 |
+
timeout=loader.timeout,
|
| 526 |
+
worker_init_fn=loader.worker_init_fn,
|
| 527 |
+
multiprocessing_context=loader.multiprocessing_context,
|
| 528 |
+
generator=loader.generator,
|
| 529 |
+
prefetch_factor=loader.prefetch_factor if loader.num_workers > 0 else None,
|
| 530 |
+
persistent_workers=loader.persistent_workers,
|
| 531 |
+
pin_memory_device=loader.pin_memory_device
|
| 532 |
+
)
|
| 533 |
+
|
| 534 |
+
return new_loader
|
| 535 |
+
|
| 536 |
+
def list_to_tuple(x):
|
| 537 |
+
if isinstance(x, (list, tuple)):
|
| 538 |
+
return tuple(list_to_tuple(i) for i in x)
|
| 539 |
+
return x
|
| 540 |
+
|
| 541 |
+
def fmt(x):
|
| 542 |
+
if isinstance(x, float):
|
| 543 |
+
return round(x, 5)
|
| 544 |
+
if isinstance(x, dict):
|
| 545 |
+
return {k: fmt(v) for k, v in x.items()}
|
| 546 |
+
if isinstance(x, list):
|
| 547 |
+
return [fmt(v) for v in x]
|
| 548 |
+
return x
|
| 549 |
+
|
| 550 |
+
class ModelEmaV3Proxy(ModelEmaV3):
|
| 551 |
+
def __getattr__(self, name):
|
| 552 |
+
try:
|
| 553 |
+
return super().__getattr__(name)
|
| 554 |
+
except AttributeError:
|
| 555 |
+
return getattr(self.module, name)
|
| 556 |
+
|
| 557 |
+
class DataParallelProxy(nn.DataParallel):
|
| 558 |
+
def __getattr__(self, name):
|
| 559 |
+
try:
|
| 560 |
+
return super().__getattr__(name)
|
| 561 |
+
except AttributeError:
|
| 562 |
+
attr = getattr(self.module, name)
|
| 563 |
+
|
| 564 |
+
if callable(attr):
|
| 565 |
+
def wrapper(*args, **kwargs):
|
| 566 |
+
return self._parallel_apply_method(name, *args, **kwargs)
|
| 567 |
+
return wrapper
|
| 568 |
+
|
| 569 |
+
return attr
|
| 570 |
+
|
| 571 |
+
def _parallel_apply_method(self, method_name, *inputs, **kwargs):
|
| 572 |
+
if not self.device_ids:
|
| 573 |
+
return getattr(self.module, method_name)(*inputs, **kwargs)
|
| 574 |
+
|
| 575 |
+
inputs_scattered, kwargs_scattered = self.scatter(inputs, kwargs, self.device_ids)
|
| 576 |
+
|
| 577 |
+
replicas = self.replicate(self.module, self.device_ids)
|
| 578 |
+
|
| 579 |
+
outputs = self.parallel_apply(
|
| 580 |
+
[getattr(replica, method_name) for replica in replicas],
|
| 581 |
+
inputs_scattered,
|
| 582 |
+
kwargs_scattered
|
| 583 |
+
)
|
| 584 |
+
|
| 585 |
+
return self.gather(outputs, self.output_device)
|
| 586 |
+
|
| 587 |
+
class Trainer:
|
| 588 |
+
def __init__(
|
| 589 |
+
self, training_time="00:11:30:00", eval_mode="max", topk=1, save_name="network", save_best=True, save_last=False, max_grad_norm=200.0,
|
| 590 |
+
logging=0, logging_file=False, checkpoints_dir="", early_stopping=False, eval_from_ratio=-1, eval_every=1, device='cpu',
|
| 591 |
+
schedule_in_step=True, use_ema=True, ema_from_ratio=-1, ema_decay=0.999, return_best=True, return_last=True
|
| 592 |
+
):
|
| 593 |
+
self.ema_net = None
|
| 594 |
+
|
| 595 |
+
self.training_time = self._time_str_to_seconds(training_time)
|
| 596 |
+
self.mode = eval_mode
|
| 597 |
+
self.topk = topk
|
| 598 |
+
self.device = device
|
| 599 |
+
self.logging = logging if logging < epochs else 1
|
| 600 |
+
self.logging_file = logging_file
|
| 601 |
+
self.checkpoints_dir = checkpoints_dir
|
| 602 |
+
self.early_stopping = early_stopping
|
| 603 |
+
self.eval_from_ratio = eval_from_ratio
|
| 604 |
+
self.eval_every = eval_every
|
| 605 |
+
self.save_name = save_name
|
| 606 |
+
self.save_best = save_best
|
| 607 |
+
self.save_last = save_last
|
| 608 |
+
self.return_best = return_best
|
| 609 |
+
self.return_last = return_last
|
| 610 |
+
self.max_grad_norm = max_grad_norm
|
| 611 |
+
self.schedule_in_step = schedule_in_step
|
| 612 |
+
self.use_ema = use_ema
|
| 613 |
+
self.ema_from_ratio = ema_from_ratio
|
| 614 |
+
self.ema_decay = ema_decay
|
| 615 |
+
|
| 616 |
+
self.best_stage = [[float('-inf') if self.mode == 'max' else float('inf'), None, None]]
|
| 617 |
+
self.grad_scaler = torch.amp.GradScaler(self.device, init_scale=1024.0)
|
| 618 |
+
|
| 619 |
+
def fit(self, network, optimizer, scheduler, loss_fn, epochs, train_loader, val_loader=None, corpus_loader=None, eval_fn=None, start_epoch=1, start_training_time=None, refresh_every=3):
|
| 620 |
+
if eval_fn is None:
|
| 621 |
+
if self.mode == "max":
|
| 622 |
+
eval_fn = lambda *x: -loss_fn(*x)
|
| 623 |
+
else:
|
| 624 |
+
eval_fn = lambda *x: loss_fn(*x)
|
| 625 |
+
|
| 626 |
+
if torch.cuda.device_count() > 1:
|
| 627 |
+
network = DataParallelProxy(network)
|
| 628 |
+
network = network.to(self.device)
|
| 629 |
+
|
| 630 |
+
if not start_training_time:
|
| 631 |
+
start_training_time = time.time()
|
| 632 |
+
|
| 633 |
+
start_ema = int(epochs * self.ema_from_ratio)
|
| 634 |
+
start_eval = int(epochs * self.eval_from_ratio)
|
| 635 |
+
|
| 636 |
+
if val_loader is None:
|
| 637 |
+
print(f'[Trainer CallBack] 📢 Không có Val Set, không thể đánh giá và Early Stopping!')
|
| 638 |
+
else:
|
| 639 |
+
model_to_use_str = 'mô hình EMA' if self.use_ema else 'mô hình gốc'
|
| 640 |
+
start_model_update_str = f'Bắt đầu cập nhật EMA từ epoch {start_epoch + start_ema}!' if self.use_ema else ''
|
| 641 |
+
print(f'[Trainer CallBack] 📢 Đánh giá bằng {model_to_use_str} từ epoch {start_epoch + start_eval}!', start_model_update_str)
|
| 642 |
+
|
| 643 |
+
training_log = {}
|
| 644 |
+
for epoch in range(start_epoch, epochs+start_epoch):
|
| 645 |
+
if self.use_ema and self.ema_net is None and epoch - start_epoch >= start_ema:
|
| 646 |
+
self.ema_net = ModelEmaV3Proxy(network, self.ema_decay, device=self.device)
|
| 647 |
+
|
| 648 |
+
try:
|
| 649 |
+
eval_net = self.ema_net if (self.use_ema and self.ema_net is not None) else network
|
| 650 |
+
if (epoch - start_epoch) % refresh_every == 0:
|
| 651 |
+
encoded_docs = self._get_encoded_docs(eval_net, corpus_loader)
|
| 652 |
+
print(f"[Trainer CallBack] 📢 Epoch {epoch}/{epochs}: Refresh Encoded Doc (refresh_every={refresh_every})!")
|
| 653 |
+
|
| 654 |
+
train_loss_epoch, train_loss_epoch_dict = self._train_epoch(network, train_loader, optimizer, scheduler, loss_fn, encoded_docs)
|
| 655 |
+
logging_dict = {'lr': [group['lr'] for group in optimizer.param_groups], 'train_loss': train_loss_epoch}
|
| 656 |
+
logging_dict.update(train_loss_epoch_dict)
|
| 657 |
+
|
| 658 |
+
if val_loader is not None and epoch - start_epoch >= start_eval and (epoch - start_epoch - start_eval) % self.eval_every == 0:
|
| 659 |
+
val_score, val_score_dict, _ = self._eval_epoch(eval_net, val_loader, eval_fn, encoded_docs)
|
| 660 |
+
update = self._update_best_network(eval_net, val_score, epoch)
|
| 661 |
+
logging_dict.update({'val_score': val_score, 'best_score': self.best_stage[0][0], 'new_best_model': update})
|
| 662 |
+
logging_dict.update(val_score_dict)
|
| 663 |
+
if not self.schedule_in_step and scheduler:
|
| 664 |
+
scheduler.step()
|
| 665 |
+
|
| 666 |
+
except RuntimeError as e:
|
| 667 |
+
if "out of memory" in str(e).lower():
|
| 668 |
+
print(f"[Trainer CallBack] ⚠️ Epoch {epoch}/{epochs}: CUDA Out of Memory! Clearing GPU cache...")
|
| 669 |
+
torch.cuda.empty_cache()
|
| 670 |
+
gc.collect()
|
| 671 |
+
if torch.cuda.is_available():
|
| 672 |
+
torch.cuda.synchronize()
|
| 673 |
+
print(f"[Trainer CallBack] ✅ Epoch {epoch}/{epochs}: GPU memory cleared")
|
| 674 |
+
|
| 675 |
+
train_loader = reduce_batch_size(train_loader, ratio=0.5)
|
| 676 |
+
if val_loader is not None:
|
| 677 |
+
val_loader = reduce_batch_size(val_loader, ratio=0.5)
|
| 678 |
+
|
| 679 |
+
logging_dict = {'lr': [group['lr'] for group in optimizer.param_groups], 'train_loss': float('inf')}
|
| 680 |
+
else:
|
| 681 |
+
raise
|
| 682 |
+
|
| 683 |
+
training_log[epoch] = logging_dict
|
| 684 |
+
if self.is_early_stopping(epoch):
|
| 685 |
+
print(f'[Trainer CallBack] 📢 Epoch {epoch}/{epochs}: Detect Overfitting! Breaking Training Process...')
|
| 686 |
+
break
|
| 687 |
+
if self.logging:
|
| 688 |
+
if epoch % self.logging == 0:
|
| 689 |
+
print(f'[Trainer CallBack] 📢 Epoch {epoch}/{epochs}:', fmt(logging_dict))
|
| 690 |
+
else:
|
| 691 |
+
print(f'{epoch}...', end=' ')
|
| 692 |
+
|
| 693 |
+
if self._at_time_limit(start_training_time):
|
| 694 |
+
print(f'[Trainer CallBack] ⚠️ Epoch {epoch}/{epochs}: Thời gian training giới hạn là {self.training_time}, hết giờ tại epoch {epoch}/{epochs}')
|
| 695 |
+
break
|
| 696 |
+
|
| 697 |
+
if self.logging_file:
|
| 698 |
+
os.makedirs(f'{self.checkpoints_dir}/logs', exist_ok=True)
|
| 699 |
+
with open(f"{self.checkpoints_dir}/logs/{self.save_name}_logging.json", "a", encoding="utf-8") as f:
|
| 700 |
+
f.write(json.dumps(training_log))
|
| 701 |
+
|
| 702 |
+
if self.use_ema and self.ema_net is not None:
|
| 703 |
+
self._save_state_dict(self.ema_net.module)
|
| 704 |
+
else:
|
| 705 |
+
self._save_state_dict(network)
|
| 706 |
+
print(f'[Trainer CallBack] 📢 Kết thúc training.\n')
|
| 707 |
+
|
| 708 |
+
best_model, last_model = None, None
|
| 709 |
+
eval_net = self.ema_net.module if (self.use_ema and self.ema_net is not None) else network
|
| 710 |
+
if self.return_best :
|
| 711 |
+
best_model = self.best_stage[0][2] if self.best_stage[0][2] is not None else eval_net.state_dict()
|
| 712 |
+
best_model = {k.replace("module.", ""): v.detach().cpu().clone() for k, v in best_model.items()}
|
| 713 |
+
if self.return_last:
|
| 714 |
+
last_model = eval_net.state_dict()
|
| 715 |
+
last_model = {k.replace("module.", ""): v.detach().cpu().clone() for k, v in last_model.items()}
|
| 716 |
+
|
| 717 |
+
del network
|
| 718 |
+
torch.cuda.empty_cache()
|
| 719 |
+
gc.collect()
|
| 720 |
+
return training_log, best_model, last_model
|
| 721 |
+
|
| 722 |
+
def _time_str_to_seconds(self, time_str):
|
| 723 |
+
days, hours, minutes, seconds = map(int, time_str.split(":"))
|
| 724 |
+
return days * 86400 + hours * 3600 + minutes * 60 + seconds
|
| 725 |
+
|
| 726 |
+
def _update_best_network(self, network, val_score, epoch):
|
| 727 |
+
topk = max(1, self.topk)
|
| 728 |
+
self.best_stage.append([val_score, epoch, {k: v.detach().cpu().clone() for k, v in network.state_dict().items()}])
|
| 729 |
+
self.best_stage = sorted(self.best_stage, reverse=(self.mode == 'max'), key=lambda x: x[0])[:topk]
|
| 730 |
+
if val_score in [x[0] for x in self.best_stage]:
|
| 731 |
+
return True
|
| 732 |
+
return False
|
| 733 |
+
|
| 734 |
+
def is_early_stopping(self, epoch):
|
| 735 |
+
if self.best_stage[0][1] is None:
|
| 736 |
+
return False
|
| 737 |
+
if not self.early_stopping:
|
| 738 |
+
return False
|
| 739 |
+
return epoch - self.best_stage[0][1] >= self.early_stopping
|
| 740 |
+
|
| 741 |
+
def _at_time_limit(self, start_training_time):
|
| 742 |
+
return time.time() - start_training_time >= self.training_time
|
| 743 |
+
|
| 744 |
+
def _save_state_dict(self, network):
|
| 745 |
+
if self.topk <= 0:
|
| 746 |
+
return
|
| 747 |
+
|
| 748 |
+
if self.save_best:
|
| 749 |
+
for r in range(self.topk):
|
| 750 |
+
os.makedirs(f'{self.checkpoints_dir}/r{r+1}s', exist_ok=True)
|
| 751 |
+
|
| 752 |
+
for rank, (score, epoch, state_dict) in enumerate(self.best_stage):
|
| 753 |
+
if state_dict is None:
|
| 754 |
+
continue
|
| 755 |
+
state_dict = {k.replace("module.", ""): v.detach().cpu().clone() for k, v in state_dict.items()}
|
| 756 |
+
torch.save(state_dict, f'{self.checkpoints_dir}/r{rank+1}s/{self.save_name}_r{rank+1}_vs{score:.5f}_{"ema" if self.ema_net is not None else ""}.pth')
|
| 757 |
+
if self.save_last:
|
| 758 |
+
os.makedirs(f'{self.checkpoints_dir}/lasts', exist_ok=True)
|
| 759 |
+
state_dict = {k.replace("module.", ""): v.detach().cpu().clone() for k, v in network.state_dict().items()}
|
| 760 |
+
torch.save(state_dict, f'{self.checkpoints_dir}/lasts/{self.save_name}_last_{"ema" if self.ema_net is not None else ""}.pth')
|
| 761 |
+
|
| 762 |
+
def _train_epoch(self, network, train_loader, optimizer, scheduler, loss_fn, encoded_docs):
|
| 763 |
+
network.train()
|
| 764 |
+
total_loss = 0
|
| 765 |
+
total_loss_dict = {}
|
| 766 |
+
for batch_idx, batch in enumerate(train_loader):
|
| 767 |
+
optimizer.zero_grad()
|
| 768 |
+
with torch.autocast(device_type=self.device, dtype=torch.float16):
|
| 769 |
+
loss, loss_dict = self._cal_loss(network, batch, batch_idx, loss_fn, encoded_docs)
|
| 770 |
+
|
| 771 |
+
for k, v in loss_dict.items():
|
| 772 |
+
t = total_loss_dict.get(k, 0)
|
| 773 |
+
total_loss_dict[k] = t + v
|
| 774 |
+
self.grad_scaler.scale(loss).backward()
|
| 775 |
+
self.grad_scaler.unscale_(optimizer)
|
| 776 |
+
grad_norm = nn.utils.clip_grad_norm_(network.parameters(), self.max_grad_norm)
|
| 777 |
+
# print(grad_norm) # Bỏ cmt dòng này để biết nên chọn max_grad_norm bằng bao nhiêu...
|
| 778 |
+
self.grad_scaler.step(optimizer)
|
| 779 |
+
self.grad_scaler.update()
|
| 780 |
+
if self.schedule_in_step and scheduler:
|
| 781 |
+
scheduler.step()
|
| 782 |
+
if self.use_ema and self.ema_net is not None:
|
| 783 |
+
self.ema_net.update(network)
|
| 784 |
+
total_loss += loss
|
| 785 |
+
return (total_loss / len(train_loader)).item(), {k: v.item() / len(train_loader) for k, v in total_loss_dict.items()}
|
| 786 |
+
|
| 787 |
+
def _eval_epoch(self, network, val_loader, eval_fn, encoded_docs):
|
| 788 |
+
network.eval()
|
| 789 |
+
total_score = 0.0
|
| 790 |
+
total_score_dict = {}
|
| 791 |
+
object_lists = None # sẽ init sau
|
| 792 |
+
|
| 793 |
+
with torch.no_grad():
|
| 794 |
+
for batch_idx, batch in enumerate(val_loader):
|
| 795 |
+
score, score_dict, objects = self._cal_val_score(network, batch, batch_idx, eval_fn, encoded_docs)
|
| 796 |
+
total_score += score
|
| 797 |
+
|
| 798 |
+
for k, v in score_dict.items():
|
| 799 |
+
t = total_score_dict.get(k, 0)
|
| 800 |
+
total_score_dict[k] = t + v
|
| 801 |
+
|
| 802 |
+
if objects:
|
| 803 |
+
if object_lists is None:
|
| 804 |
+
object_lists = [[] for _ in range(len(objects))]
|
| 805 |
+
|
| 806 |
+
for i, obj in enumerate(objects):
|
| 807 |
+
object_lists[i].append(obj.detach())
|
| 808 |
+
|
| 809 |
+
if object_lists is not None:
|
| 810 |
+
object_arrays = [
|
| 811 |
+
torch.concat(obj_list, dim=0).cpu().numpy()
|
| 812 |
+
for obj_list in object_lists
|
| 813 |
+
]
|
| 814 |
+
else:
|
| 815 |
+
object_arrays = []
|
| 816 |
+
|
| 817 |
+
return total_score / len(val_loader), {k: v / len(val_loader) for k, v in total_score_dict.items()}, object_arrays
|
| 818 |
+
|
| 819 |
+
def _get_encoded_docs(self, network, corpus_loader):
|
| 820 |
+
network.eval()
|
| 821 |
+
with torch.no_grad():
|
| 822 |
+
encoded_docs = []
|
| 823 |
+
for batch_idx, batch in enumerate(corpus_loader):
|
| 824 |
+
input_ids = batch['input_ids'].to(self.device)
|
| 825 |
+
attn_mask = batch['attn_mask'].to(self.device)
|
| 826 |
+
encoded_doc = network(input_ids, attn_mask, is_query=False)
|
| 827 |
+
encoded_docs.append(encoded_doc)
|
| 828 |
+
encoded_docs = torch.concat(encoded_docs, dim=0).squeeze(1)
|
| 829 |
+
return encoded_docs
|
| 830 |
+
|
| 831 |
+
def _cal_loss(self, network, batch, batch_idx, loss_fn, encoded_docs):
|
| 832 |
+
# Bạn cần override _cal_loss để tính loss
|
| 833 |
+
text_input_ids = batch['text_input_ids'].to(self.device)
|
| 834 |
+
text_attn_mask = batch['text_attn_mask'].to(self.device)
|
| 835 |
+
pos_idxes = batch['pos_idxes'].to(self.device)
|
| 836 |
+
pos_mask = batch['pos_mask'].to(self.device)
|
| 837 |
+
neg_idxes = batch['neg_idxes'].to(self.device)
|
| 838 |
+
|
| 839 |
+
encoded_text = network(text_input_ids, text_attn_mask, is_query=True)
|
| 840 |
+
encoded_pos = encoded_docs[pos_idxes]
|
| 841 |
+
encoded_neg = encoded_docs[neg_idxes]
|
| 842 |
+
|
| 843 |
+
loss_dict = loss_fn(encoded_text, encoded_pos, encoded_neg, pos_mask)
|
| 844 |
+
return loss_dict['total'], loss_dict
|
| 845 |
+
|
| 846 |
+
def _cal_val_score(self, network, batch, batch_idx, eval_fn, encoded_docs):
|
| 847 |
+
# Bạn cần override _cal_val_score để tính val score, list bên cạnh là để trả về y hay pred gì đó (nếu cần)
|
| 848 |
+
text_input_ids = batch['text_input_ids'].to(self.device)
|
| 849 |
+
text_attn_mask = batch['text_attn_mask'].to(self.device)
|
| 850 |
+
gt_pos_idxes = batch['gt_pos_idxes']
|
| 851 |
+
encoded_text = network(text_input_ids, text_attn_mask, is_query=True)
|
| 852 |
+
|
| 853 |
+
scores = torch.matmul(encoded_text, encoded_docs.T)
|
| 854 |
+
topk_scores, topk_indices = torch.topk(scores, k=10)
|
| 855 |
+
pred_topk = [
|
| 856 |
+
idx[score > 0].tolist()
|
| 857 |
+
for score, idx in zip(topk_scores, topk_indices)
|
| 858 |
+
]
|
| 859 |
+
|
| 860 |
+
pred_topk = list_to_tuple(pred_topk)
|
| 861 |
+
gt_pos_idxes = list_to_tuple(gt_pos_idxes)
|
| 862 |
+
score_dict = eval_fn(pred_topk, gt_pos_idxes)
|
| 863 |
+
return score_dict['recall'], score_dict, []
|
| 864 |
+
|
| 865 |
+
# %% [code]
|
| 866 |
+
def tokenize_to_parts(text, tokenizer, max_len, max_n_parts):
|
| 867 |
+
# Tokenize với overflow để chia thành nhiều đoạn
|
| 868 |
+
enc = tokenizer(
|
| 869 |
+
text,
|
| 870 |
+
max_length=max_len*max_n_parts,
|
| 871 |
+
truncation=True,
|
| 872 |
+
padding="max_length",
|
| 873 |
+
return_overflowing_tokens=True,
|
| 874 |
+
return_tensors="pt"
|
| 875 |
+
)
|
| 876 |
+
|
| 877 |
+
input_ids = enc["input_ids"].reshape(max_n_parts, max_len) # (n_parts, max_len)
|
| 878 |
+
attn_mask = enc["attention_mask"].reshape(max_n_parts, max_len) # (n_parts, max_len)
|
| 879 |
+
|
| 880 |
+
return input_ids, attn_mask
|
| 881 |
+
|
| 882 |
+
class LawRetrievalDataset(Dataset):
|
| 883 |
+
def __init__(self, all_data, using_idxes, corpus_dict, tokenizer, max_len, max_n_parts, n_negs):
|
| 884 |
+
super().__init__()
|
| 885 |
+
|
| 886 |
+
self.all_data = all_data
|
| 887 |
+
self.using_idxes = using_idxes
|
| 888 |
+
self.tokenizer = tokenizer
|
| 889 |
+
self.max_len = max_len
|
| 890 |
+
self.max_n_parts = max_n_parts
|
| 891 |
+
self.n_negs = n_negs
|
| 892 |
+
|
| 893 |
+
# ===== BUILD CORPUS =====
|
| 894 |
+
idx = 0
|
| 895 |
+
self.corpus_list = []
|
| 896 |
+
self.corpus_dict = {}
|
| 897 |
+
|
| 898 |
+
for doc_name, articles_dict in corpus_dict.items():
|
| 899 |
+
self.corpus_dict[doc_name] = {}
|
| 900 |
+
for article_idx, content in articles_dict.items():
|
| 901 |
+
self.corpus_list.append([doc_name, article_idx, content])
|
| 902 |
+
self.corpus_dict[doc_name][article_idx] = {
|
| 903 |
+
'content': content,
|
| 904 |
+
'idx': idx
|
| 905 |
+
}
|
| 906 |
+
idx += 1
|
| 907 |
+
|
| 908 |
+
def __len__(self):
|
| 909 |
+
return len(self.using_idxes)
|
| 910 |
+
|
| 911 |
+
# ===== ENCODE DOC =====
|
| 912 |
+
def _encode_contexts(self, idxes):
|
| 913 |
+
all_input_ids, all_attn_mask = [], []
|
| 914 |
+
|
| 915 |
+
for idx in idxes:
|
| 916 |
+
name, art, _ = self.corpus_list[idx]
|
| 917 |
+
corpus = self.corpus_dict[name][art]
|
| 918 |
+
|
| 919 |
+
if 'content_input_ids' in corpus:
|
| 920 |
+
content_input_ids = corpus['content_input_ids']
|
| 921 |
+
content_attn_mask = corpus['content_attn_mask']
|
| 922 |
+
else:
|
| 923 |
+
content = corpus['content']
|
| 924 |
+
content_input_ids, content_attn_mask = tokenize_to_parts(
|
| 925 |
+
content, self.tokenizer, self.max_len, self.max_n_parts
|
| 926 |
+
)
|
| 927 |
+
corpus['content_input_ids'] = content_input_ids
|
| 928 |
+
corpus['content_attn_mask'] = content_attn_mask
|
| 929 |
+
|
| 930 |
+
all_input_ids.append(content_input_ids)
|
| 931 |
+
all_attn_mask.append(content_attn_mask)
|
| 932 |
+
|
| 933 |
+
all_input_ids = torch.stack(all_input_ids)
|
| 934 |
+
all_attn_mask = torch.stack(all_attn_mask)
|
| 935 |
+
|
| 936 |
+
return all_input_ids, all_attn_mask
|
| 937 |
+
|
| 938 |
+
def __getitem__(self, idx):
|
| 939 |
+
ridx = self.using_idxes[idx]
|
| 940 |
+
data = self.all_data[ridx]
|
| 941 |
+
|
| 942 |
+
query_text = data['text']
|
| 943 |
+
|
| 944 |
+
text_input_ids, text_attn_mask = tokenize_to_parts(
|
| 945 |
+
query_text, self.tokenizer, self.max_len, 1
|
| 946 |
+
)
|
| 947 |
+
|
| 948 |
+
# ===== POS =====
|
| 949 |
+
gt_pos_idxes = []
|
| 950 |
+
hard_names = []
|
| 951 |
+
for law in data['relevant_law']:
|
| 952 |
+
name = law['doc']
|
| 953 |
+
art = law['art']
|
| 954 |
+
gt_pos_idxes.append(self.corpus_dict[name][art]['idx'])
|
| 955 |
+
if name not in hard_names:
|
| 956 |
+
hard_names.append(name)
|
| 957 |
+
|
| 958 |
+
pos_idxes = torch.tensor(gt_pos_idxes, dtype=torch.long)
|
| 959 |
+
pos_mask = torch.ones(len(pos_idxes))
|
| 960 |
+
|
| 961 |
+
# ===== NEG =====
|
| 962 |
+
hard_neg_idxes = []
|
| 963 |
+
for name in hard_names:
|
| 964 |
+
for content in self.corpus_dict[name].values():
|
| 965 |
+
if content['idx'] in gt_pos_idxes:
|
| 966 |
+
continue
|
| 967 |
+
hard_neg_idxes.append(content['idx'])
|
| 968 |
+
|
| 969 |
+
easy_neg_idxes = list(range(len(self.corpus_list)))
|
| 970 |
+
for i in gt_pos_idxes + hard_neg_idxes:
|
| 971 |
+
if i in easy_neg_idxes:
|
| 972 |
+
easy_neg_idxes.remove(i)
|
| 973 |
+
|
| 974 |
+
n_hards = min(len(hard_neg_idxes), self.n_negs // 2)
|
| 975 |
+
neg_idxes = random.sample(hard_neg_idxes, n_hards) + random.sample(easy_neg_idxes, self.n_negs - n_hards)
|
| 976 |
+
neg_idxes = torch.tensor(neg_idxes, dtype=torch.long)
|
| 977 |
+
|
| 978 |
+
return {
|
| 979 |
+
'text_input_ids': text_input_ids,
|
| 980 |
+
'text_attn_mask': text_attn_mask,
|
| 981 |
+
'gt_pos_idxes': gt_pos_idxes,
|
| 982 |
+
'pos_idxes': pos_idxes,
|
| 983 |
+
'pos_mask': pos_mask,
|
| 984 |
+
'neg_idxes': neg_idxes,
|
| 985 |
+
}
|
| 986 |
+
|
| 987 |
+
class CorpusDataset(Dataset):
|
| 988 |
+
def __init__(self, corpus_dict, tokenizer, max_len, max_n_parts):
|
| 989 |
+
super().__init__()
|
| 990 |
+
self.tokenizer = tokenizer
|
| 991 |
+
self.max_len = max_len
|
| 992 |
+
self.max_n_parts = max_n_parts
|
| 993 |
+
|
| 994 |
+
idx = 0
|
| 995 |
+
self.corpus_list = []
|
| 996 |
+
self.corpus_dict = {}
|
| 997 |
+
for doc_name, articles_dict in corpus_dict.items():
|
| 998 |
+
self.corpus_dict[doc_name] = {}
|
| 999 |
+
for article_idx, content in articles_dict.items():
|
| 1000 |
+
self.corpus_list.append([doc_name, article_idx, content])
|
| 1001 |
+
self.corpus_dict[doc_name][article_idx] = {'content': content, 'idx': idx}
|
| 1002 |
+
idx += 1
|
| 1003 |
+
|
| 1004 |
+
def __len__(self):
|
| 1005 |
+
return len(self.corpus_list)
|
| 1006 |
+
|
| 1007 |
+
def _encode_contexts(self, idxes):
|
| 1008 |
+
all_input_ids, all_attn_mask = [], []
|
| 1009 |
+
for idx in idxes:
|
| 1010 |
+
name = self.corpus_list[idx][0]
|
| 1011 |
+
art = self.corpus_list[idx][1]
|
| 1012 |
+
corpus = self.corpus_dict[name][art]
|
| 1013 |
+
if 'content_input_ids' in corpus and 'content_attn_mask' in corpus:
|
| 1014 |
+
content_input_ids = corpus['content_input_ids']
|
| 1015 |
+
content_attn_mask = corpus['content_attn_mask']
|
| 1016 |
+
else:
|
| 1017 |
+
content = corpus['content']
|
| 1018 |
+
content_input_ids, content_attn_mask = tokenize_to_parts(content, self.tokenizer, self.max_len, self.max_n_parts)
|
| 1019 |
+
corpus['content_input_ids'] = content_input_ids
|
| 1020 |
+
corpus['content_attn_mask'] = content_attn_mask
|
| 1021 |
+
|
| 1022 |
+
all_input_ids.append(content_input_ids)
|
| 1023 |
+
all_attn_mask.append(content_attn_mask)
|
| 1024 |
+
|
| 1025 |
+
all_input_ids = torch.stack(all_input_ids)
|
| 1026 |
+
all_attn_mask = torch.stack(all_attn_mask)
|
| 1027 |
+
return all_input_ids, all_attn_mask
|
| 1028 |
+
|
| 1029 |
+
def __getitem__(self, idx):
|
| 1030 |
+
input_ids, attn_mask = self._encode_contexts([idx])
|
| 1031 |
+
|
| 1032 |
+
return {
|
| 1033 |
+
'input_ids': input_ids,
|
| 1034 |
+
'attn_mask': attn_mask,
|
| 1035 |
+
}
|
| 1036 |
+
|
| 1037 |
+
def _pad_batch(tensor_list, pad_value=0):
|
| 1038 |
+
"""
|
| 1039 |
+
tensor_list: list of tensors, mỗi tensor shape (Nk, max_n_parts, max_len)
|
| 1040 |
+
return: tensor shape (B, max_Nk, max_n_parts, max_len)
|
| 1041 |
+
"""
|
| 1042 |
+
max_Nk = max(t.size(0) for t in tensor_list)
|
| 1043 |
+
|
| 1044 |
+
padded = []
|
| 1045 |
+
for t in tensor_list:
|
| 1046 |
+
Nk = t.size(0)
|
| 1047 |
+
|
| 1048 |
+
if Nk < max_Nk:
|
| 1049 |
+
pad_shape = (max_Nk - Nk, *t.shape[1:])
|
| 1050 |
+
pad_tensor = t.new_full(pad_shape, pad_value)
|
| 1051 |
+
t = torch.cat([t, pad_tensor], dim=0)
|
| 1052 |
+
|
| 1053 |
+
padded.append(t)
|
| 1054 |
+
|
| 1055 |
+
return torch.stack(padded) # (B, max_Nk, max_n_parts, max_len)
|
| 1056 |
+
|
| 1057 |
+
def collate_fn(batch):
|
| 1058 |
+
text_input_ids = torch.stack([b["text_input_ids"] for b in batch])
|
| 1059 |
+
text_attn_mask = torch.stack([b["text_attn_mask"] for b in batch])
|
| 1060 |
+
gt_pos_idxes = [b["gt_pos_idxes"] for b in batch]
|
| 1061 |
+
neg_idxes = torch.stack([b["neg_idxes"] for b in batch])
|
| 1062 |
+
|
| 1063 |
+
pos_idxes = [b["pos_idxes"].unsqueeze(-1).unsqueeze(-1) for b in batch]
|
| 1064 |
+
pos_mask = [b["pos_mask"].unsqueeze(-1).unsqueeze(-1) for b in batch]
|
| 1065 |
+
|
| 1066 |
+
# pad theo Nk
|
| 1067 |
+
pos_idxes = _pad_batch(pos_idxes, pad_value=0).squeeze(-1).squeeze(-1)
|
| 1068 |
+
pos_mask = _pad_batch(pos_mask, pad_value=0).squeeze(-1).squeeze(-1)
|
| 1069 |
+
|
| 1070 |
+
return {
|
| 1071 |
+
'text_input_ids': text_input_ids,
|
| 1072 |
+
'text_attn_mask': text_attn_mask,
|
| 1073 |
+
'gt_pos_idxes': gt_pos_idxes,
|
| 1074 |
+
'pos_idxes': pos_idxes,
|
| 1075 |
+
'pos_mask': pos_mask,
|
| 1076 |
+
'neg_idxes': neg_idxes,
|
| 1077 |
+
}
|
| 1078 |
+
|
| 1079 |
+
# %% [code]
|
| 1080 |
+
def encode_corpus(state_dicts, network, corpus_loader, device):
|
| 1081 |
+
if torch.cuda.device_count() > 1:
|
| 1082 |
+
network = nn.DataParallel(network)
|
| 1083 |
+
network.to(device)
|
| 1084 |
+
network.eval()
|
| 1085 |
+
|
| 1086 |
+
all_model_embs = []
|
| 1087 |
+
for i, state_dict in enumerate(state_dicts):
|
| 1088 |
+
# ===== load model =====
|
| 1089 |
+
if torch.cuda.device_count() > 1:
|
| 1090 |
+
network.module.load_state_dict(state_dict)
|
| 1091 |
+
else:
|
| 1092 |
+
network.load_state_dict(state_dict)
|
| 1093 |
+
|
| 1094 |
+
encoded_docs = []
|
| 1095 |
+
|
| 1096 |
+
with torch.no_grad():
|
| 1097 |
+
for batch in corpus_loader:
|
| 1098 |
+
input_ids = batch['input_ids'].to(device)
|
| 1099 |
+
attn_mask = batch['attn_mask'].to(device)
|
| 1100 |
+
|
| 1101 |
+
emb = network(input_ids, attn_mask, is_query=False) # [B, 1, D] hoặc [B, D]
|
| 1102 |
+
|
| 1103 |
+
encoded_docs.append(emb)
|
| 1104 |
+
|
| 1105 |
+
encoded_docs = torch.concat(encoded_docs, dim=0).squeeze(1) # [N, D]
|
| 1106 |
+
all_model_embs.append(encoded_docs)
|
| 1107 |
+
|
| 1108 |
+
# ===== ensemble =====
|
| 1109 |
+
# stack → [M, N, D]
|
| 1110 |
+
all_model_embs = torch.stack(all_model_embs, dim=0)
|
| 1111 |
+
final_embs = all_model_embs.mean(dim=0) # [N, D]
|
| 1112 |
+
|
| 1113 |
+
return final_embs
|
| 1114 |
+
|
| 1115 |
+
def test(state_dicts, network, test_loader, device, eval_fn, encoded_docs, bm25_scores, topks=[5, 10, 15]):
|
| 1116 |
+
if torch.cuda.device_count() > 1:
|
| 1117 |
+
network = nn.DataParallel(network)
|
| 1118 |
+
network.to(device)
|
| 1119 |
+
network.eval()
|
| 1120 |
+
|
| 1121 |
+
per_model_scores = []
|
| 1122 |
+
max_k = max(topks)
|
| 1123 |
+
|
| 1124 |
+
all_scores = []
|
| 1125 |
+
all_gt_pos_idxes = []
|
| 1126 |
+
with torch.no_grad():
|
| 1127 |
+
for batch in test_loader:
|
| 1128 |
+
text_input_ids = batch['text_input_ids'].to(device)
|
| 1129 |
+
text_attn_mask = batch['text_attn_mask'].to(device)
|
| 1130 |
+
gt_pos_idxes = batch['gt_pos_idxes']
|
| 1131 |
+
all_gt_pos_idxes.extend(gt_pos_idxes)
|
| 1132 |
+
|
| 1133 |
+
list_encoded_texts = []
|
| 1134 |
+
|
| 1135 |
+
for state_dict in state_dicts:
|
| 1136 |
+
# ===== load model =====
|
| 1137 |
+
if torch.cuda.device_count() > 1:
|
| 1138 |
+
network.module.load_state_dict(state_dict)
|
| 1139 |
+
else:
|
| 1140 |
+
network.load_state_dict(state_dict)
|
| 1141 |
+
|
| 1142 |
+
encoded_text = network(text_input_ids, text_attn_mask, is_query=True)
|
| 1143 |
+
list_encoded_texts.append(encoded_text)
|
| 1144 |
+
|
| 1145 |
+
ensemble_encoded_text = torch.stack(list_encoded_texts, dim=0).mean(dim=0)
|
| 1146 |
+
scores = torch.matmul(ensemble_encoded_text, encoded_docs.T) # B, M
|
| 1147 |
+
all_scores.append(scores)
|
| 1148 |
+
|
| 1149 |
+
all_scores = torch.concat(all_scores, dim=0) # (N, M)
|
| 1150 |
+
|
| 1151 |
+
bm25_scores = torch.tensor(bm25_scores).to(all_scores.device) # (N, M)
|
| 1152 |
+
bm25_scores = bm25_scores.float()
|
| 1153 |
+
|
| 1154 |
+
# min-max về [0, 1]
|
| 1155 |
+
bm25_scores = (
|
| 1156 |
+
bm25_scores - bm25_scores.min(dim=-1, keepdim=True).values
|
| 1157 |
+
) / (
|
| 1158 |
+
bm25_scores.max(dim=-1, keepdim=True).values
|
| 1159 |
+
- bm25_scores.min(dim=-1, keepdim=True).values
|
| 1160 |
+
+ 1e-8
|
| 1161 |
+
)
|
| 1162 |
+
# đổi sang [-1, 1]
|
| 1163 |
+
bm25_scores = bm25_scores * 2 - 1
|
| 1164 |
+
|
| 1165 |
+
all_gt_pos_idxes = list_to_tuple(all_gt_pos_idxes)
|
| 1166 |
+
|
| 1167 |
+
final_score = {}
|
| 1168 |
+
for weight in [0, 0.25, 0.5, 0.75, 1]:
|
| 1169 |
+
|
| 1170 |
+
# score cuối
|
| 1171 |
+
final_scores = all_scores + weight * bm25_scores
|
| 1172 |
+
|
| 1173 |
+
# topk lớn nhất
|
| 1174 |
+
topk_scores, topk_indices = torch.topk(final_scores, k=max_k)
|
| 1175 |
+
|
| 1176 |
+
pred_topk_full = [
|
| 1177 |
+
idx[score > 0].tolist()
|
| 1178 |
+
for score, idx in zip(topk_scores, topk_indices)
|
| 1179 |
+
]
|
| 1180 |
+
|
| 1181 |
+
pred_topk_full = list_to_tuple(pred_topk_full)
|
| 1182 |
+
|
| 1183 |
+
final_score[weight] = {}
|
| 1184 |
+
|
| 1185 |
+
for k in topks:
|
| 1186 |
+
pred_topk_k = [p[:k] for p in pred_topk_full]
|
| 1187 |
+
final_score[weight][k] = eval_fn(pred_topk_k, all_gt_pos_idxes)
|
| 1188 |
+
|
| 1189 |
+
return final_score
|
| 1190 |
+
|
| 1191 |
+
# %% [code]
|
| 1192 |
+
with open(f'{train_dir}/train.json', "r", encoding="utf-8") as f:
|
| 1193 |
+
data_train = json.load(f)
|
| 1194 |
+
|
| 1195 |
+
with open(f'{test_dir}/test.json', "r", encoding="utf-8") as f:
|
| 1196 |
+
data_test = json.load(f)
|
| 1197 |
+
|
| 1198 |
+
with open(f'{test_dir}/corpus.json', "r", encoding="utf-8") as f:
|
| 1199 |
+
data_corpus = json.load(f)
|
| 1200 |
+
|
| 1201 |
+
print('Train:', len(data_train))
|
| 1202 |
+
print('Test:', len(data_test))
|
| 1203 |
+
print('Corpus:', len(data_corpus))
|
| 1204 |
+
|
| 1205 |
+
# %% [code]
|
| 1206 |
+
# trigger_types = sorted(list(set([e['label'] for d in data_train + data_test for e in d['issues']]))) # NBR : Neighbor relation
|
| 1207 |
+
# bio_trigger_types = ['O'] + [f'{prefix}-{trg}' for trg in trigger_types for prefix in ['B', 'I']]
|
| 1208 |
+
# trigger_label2id = {l: i for i, l in enumerate(bio_trigger_types)}
|
| 1209 |
+
# trigger_id2label = {i: l for l, i in trigger_label2id.items()}
|
| 1210 |
+
|
| 1211 |
+
# argument_types = sorted(list(set([a['role'] for d in data_train + data_test for e in d['issues'] for a in e['arguments']])))
|
| 1212 |
+
# bio_argument_types = ['O'] + [f'{prefix}-{arg}' for arg in argument_types for prefix in ['B', 'I']]
|
| 1213 |
+
# argument_label2id = {l: i for i, l in enumerate(bio_argument_types)}
|
| 1214 |
+
# argument_id2label = {i: l for l, i in argument_label2id.items()}
|
| 1215 |
+
|
| 1216 |
+
# label2id = {
|
| 1217 |
+
# 'Trg': trigger_label2id,
|
| 1218 |
+
# 'Arg': argument_label2id,
|
| 1219 |
+
# }
|
| 1220 |
+
|
| 1221 |
+
# id2label = {
|
| 1222 |
+
# 'Trg': trigger_id2label,
|
| 1223 |
+
# 'Arg': argument_id2label,
|
| 1224 |
+
# }
|
| 1225 |
+
|
| 1226 |
+
# %% [code]
|
| 1227 |
+
# zero_events_idxes = []
|
| 1228 |
+
# for idx, d in enumerate(data_train):
|
| 1229 |
+
# if len(d['issues']) == 0:
|
| 1230 |
+
# zero_events_idxes.append(idx)
|
| 1231 |
+
|
| 1232 |
+
# n_zero_events_samples = len(zero_events_idxes)
|
| 1233 |
+
# n_has_events_samples = len(data_train) - n_zero_events_samples
|
| 1234 |
+
|
| 1235 |
+
# random.seed(42)
|
| 1236 |
+
# k = min(int(n_has_events_samples * zero_events_rate), len(zero_events_idxes))
|
| 1237 |
+
# sampled_zero_events_idxes = random.sample(zero_events_idxes, k)
|
| 1238 |
+
|
| 1239 |
+
# new_data_train = []
|
| 1240 |
+
# for idx, d in enumerate(data_train):
|
| 1241 |
+
# if len(d['issues']) == 0:
|
| 1242 |
+
# if idx in sampled_zero_events_idxes:
|
| 1243 |
+
# new_data_train.append(d)
|
| 1244 |
+
# else:
|
| 1245 |
+
# new_data_train.append(d)
|
| 1246 |
+
# data_train = new_data_train
|
| 1247 |
+
|
| 1248 |
+
# print('Train:', len(data_train))
|
| 1249 |
+
|
| 1250 |
+
# %% [code]
|
| 1251 |
+
if debug_only:
|
| 1252 |
+
data_train = data_train[:20]
|
| 1253 |
+
data_test = data_test[:20]
|
| 1254 |
+
|
| 1255 |
+
print('Train:', len(data_train))
|
| 1256 |
+
print('Test:', len(data_test))
|
| 1257 |
+
|
| 1258 |
+
# %% [code]
|
| 1259 |
+
tokenizer = AutoTokenizer.from_pretrained(backbone_model_name)
|
| 1260 |
+
|
| 1261 |
+
# %% [code]
|
| 1262 |
+
print('Experiment name:', state_dict_save_name)
|
| 1263 |
+
|
| 1264 |
+
# %% [code]
|
| 1265 |
+
if not test_only:
|
| 1266 |
+
full_idxes = np.array(range(len(data_train)))
|
| 1267 |
+
training_logs, best_models, last_models = [], [], []
|
| 1268 |
+
start_training_time = time.time()
|
| 1269 |
+
for seed in SEEDS:
|
| 1270 |
+
kf = KFold(n_splits=nfolds, shuffle=True, random_state=seed)
|
| 1271 |
+
generator = torch.Generator()
|
| 1272 |
+
generator.manual_seed(seed)
|
| 1273 |
+
|
| 1274 |
+
corpusset = CorpusDataset(data_corpus, tokenizer, **corpus_memory_params)
|
| 1275 |
+
corpus_loader = DataLoader(corpusset, generator=generator, **val_loader_params)
|
| 1276 |
+
for fold_idx, (tr_idx, va_idx) in enumerate(kf.split(full_idxes)):
|
| 1277 |
+
if only_fold_idx is not None and only_fold_idx >= 0 and only_fold_idx != fold_idx:
|
| 1278 |
+
continue
|
| 1279 |
+
set_seed(seed)
|
| 1280 |
+
|
| 1281 |
+
train_idxes, val_idxes = full_idxes[tr_idx], full_idxes[va_idx]
|
| 1282 |
+
|
| 1283 |
+
trainset = LawRetrievalDataset(data_train, train_idxes, data_corpus, tokenizer, **train_memory_params)
|
| 1284 |
+
valset = LawRetrievalDataset(data_train, val_idxes, data_corpus, tokenizer, **val_memory_params)
|
| 1285 |
+
|
| 1286 |
+
train_loader = DataLoader(trainset, generator=generator, collate_fn=collate_fn, **train_loader_params)
|
| 1287 |
+
val_loader = DataLoader(valset, generator=generator, collate_fn=collate_fn, **val_loader_params)
|
| 1288 |
+
|
| 1289 |
+
my_model = EncodeModel(
|
| 1290 |
+
**model_params
|
| 1291 |
+
)
|
| 1292 |
+
total_params = sum(p.numel() for p in my_model.parameters())
|
| 1293 |
+
print(f"Total params: {total_params:,}")
|
| 1294 |
+
|
| 1295 |
+
# optimizer, scheduler = configure_optimizers(my_model, optim_params, scheduler_params)
|
| 1296 |
+
encoder_params = set(map(id, my_model.encoder.parameters()))
|
| 1297 |
+
other_params = [
|
| 1298 |
+
p for p in my_model.parameters()
|
| 1299 |
+
if id(p) not in encoder_params
|
| 1300 |
+
]
|
| 1301 |
+
optimizer = optim.AdamW([
|
| 1302 |
+
{"params": my_model.encoder.parameters(), "lr": 2e-5},
|
| 1303 |
+
{"params": other_params}
|
| 1304 |
+
], lr=5e-4)
|
| 1305 |
+
scheduler = optim.lr_scheduler.CosineAnnealingLR(optimizer, T_max=20, eta_min=1e-6)
|
| 1306 |
+
|
| 1307 |
+
loss_fn = CustomLoss(
|
| 1308 |
+
**loss_func_params
|
| 1309 |
+
)
|
| 1310 |
+
eval_fn = CustomEvalFn(**eval_func_params)
|
| 1311 |
+
trainer_params['save_name'] = f'{state_dict_save_name}_s{seed}_f{fold_idx}'
|
| 1312 |
+
trainer = Trainer(**trainer_params)
|
| 1313 |
+
|
| 1314 |
+
print(f'Start Training Fold {fold_idx}...')
|
| 1315 |
+
training_log, best_model, last_model = trainer.fit(
|
| 1316 |
+
my_model, optimizer, scheduler, loss_fn, epochs, train_loader, val_loader, corpus_loader, eval_fn,
|
| 1317 |
+
start_epoch=1, start_training_time=start_training_time, refresh_every=2,
|
| 1318 |
+
)
|
| 1319 |
+
|
| 1320 |
+
training_logs.append(training_log)
|
| 1321 |
+
best_models.append(best_model)
|
| 1322 |
+
last_models.append(last_model)
|
| 1323 |
+
|
| 1324 |
+
# %% [code]
|
| 1325 |
+
def load_all_state_dicts(folder):
|
| 1326 |
+
files = []
|
| 1327 |
+
|
| 1328 |
+
for file in os.listdir(folder):
|
| 1329 |
+
if file.endswith(".pt") or file.endswith(".pth"):
|
| 1330 |
+
m = re.search(r"f(\d+)", file) # tìm f<số>
|
| 1331 |
+
if m:
|
| 1332 |
+
fold = int(m.group(1))
|
| 1333 |
+
files.append((fold, file))
|
| 1334 |
+
|
| 1335 |
+
# sort theo fold
|
| 1336 |
+
files.sort(key=lambda x: x[0])
|
| 1337 |
+
|
| 1338 |
+
state_dicts = []
|
| 1339 |
+
for fold, file in files:
|
| 1340 |
+
path = os.path.join(folder, file)
|
| 1341 |
+
print(f"Loading fold {fold}: {file}")
|
| 1342 |
+
state_dict = torch.load(path, map_location="cpu")
|
| 1343 |
+
state_dicts.append(state_dict)
|
| 1344 |
+
|
| 1345 |
+
return state_dicts
|
| 1346 |
+
|
| 1347 |
+
if test_only:
|
| 1348 |
+
snapshot_download(repo_id=repo_name, local_dir="", repo_type="model", allow_patterns=[f"{state_dict_save_name}/**"])
|
| 1349 |
+
get_ipython().system('rm -rf .cache .gitattributes')
|
| 1350 |
+
|
| 1351 |
+
best_models = load_all_state_dicts(f"{state_dict_save_name}/r1s")
|
| 1352 |
+
last_models = load_all_state_dicts(f"{state_dict_save_name}/lasts")
|
| 1353 |
+
|
| 1354 |
+
# %% [code]
|
| 1355 |
+
os.makedirs(f'{checkpoints_dir}/results', exist_ok=True)
|
| 1356 |
+
testset = LawRetrievalDataset(data_test, range(len(data_test)), data_corpus, tokenizer, **val_memory_params)
|
| 1357 |
+
generator = torch.Generator()
|
| 1358 |
+
test_loader = DataLoader(testset, generator=generator, collate_fn=collate_fn, **val_loader_params)
|
| 1359 |
+
eval_fn = CustomEvalFn(**eval_func_params)
|
| 1360 |
+
my_model = EncodeModel(
|
| 1361 |
+
**model_params
|
| 1362 |
+
)
|
| 1363 |
+
total_params = sum(p.numel() for p in my_model.parameters())
|
| 1364 |
+
print(f"Total params: {total_params:,}")
|
| 1365 |
+
|
| 1366 |
+
# %% [code]
|
| 1367 |
+
start_time = time.time()
|
| 1368 |
+
encoded_docs = encode_corpus(best_models, my_model, corpus_loader, device)
|
| 1369 |
+
best_score = test(best_models, my_model, test_loader, device, eval_fn, encoded_docs, bm25_scores)
|
| 1370 |
+
|
| 1371 |
+
encoded_docs = encode_corpus(last_models, my_model, corpus_loader, device)
|
| 1372 |
+
last_score = test(last_models, my_model, test_loader, device, eval_fn, encoded_docs, bm25_scores)
|
| 1373 |
+
|
| 1374 |
+
result_test = {"Best model": best_score, "Last model": last_score}
|
| 1375 |
+
|
| 1376 |
+
with open(f"{checkpoints_dir}/results/{state_dict_save_name}_test.json", "w", encoding="utf-8") as f:
|
| 1377 |
+
json.dump(result_test, f, ensure_ascii=False, indent=2)
|
| 1378 |
+
|
| 1379 |
+
print('Test:', time.time() - start_time, 's --> Done!')
|
| 1380 |
+
|
| 1381 |
+
# %% [code]
|
| 1382 |
+
def dict_to_df(data):
|
| 1383 |
+
"""
|
| 1384 |
+
data format:
|
| 1385 |
+
{
|
| 1386 |
+
model_name: {
|
| 1387 |
+
weight: {
|
| 1388 |
+
topk: {
|
| 1389 |
+
metric: value
|
| 1390 |
+
}
|
| 1391 |
+
}
|
| 1392 |
+
}
|
| 1393 |
+
}
|
| 1394 |
+
"""
|
| 1395 |
+
|
| 1396 |
+
row_tuples = []
|
| 1397 |
+
row_values = []
|
| 1398 |
+
|
| 1399 |
+
# ===== lấy model đầu tiên =====
|
| 1400 |
+
first_model = next(iter(data.values()))
|
| 1401 |
+
|
| 1402 |
+
# ===== weight keys =====
|
| 1403 |
+
weight_keys = list(first_model.keys())
|
| 1404 |
+
|
| 1405 |
+
# ===== topk keys =====
|
| 1406 |
+
first_weight = next(iter(first_model.values()))
|
| 1407 |
+
topk_keys = list(first_weight.keys())
|
| 1408 |
+
|
| 1409 |
+
# ===== metric keys =====
|
| 1410 |
+
first_topk = next(iter(first_weight.values()))
|
| 1411 |
+
metrics = list(first_topk.keys())
|
| 1412 |
+
|
| 1413 |
+
for weight in weight_keys:
|
| 1414 |
+
|
| 1415 |
+
for topk in topk_keys:
|
| 1416 |
+
|
| 1417 |
+
# ===== multi index row =====
|
| 1418 |
+
row_tuples.append((weight, topk))
|
| 1419 |
+
|
| 1420 |
+
row = {}
|
| 1421 |
+
|
| 1422 |
+
for model_name, model_data in data.items():
|
| 1423 |
+
|
| 1424 |
+
for metric in metrics:
|
| 1425 |
+
|
| 1426 |
+
row[(model_name, metric)] = (
|
| 1427 |
+
model_data[weight][topk][metric]
|
| 1428 |
+
)
|
| 1429 |
+
|
| 1430 |
+
row_values.append(row)
|
| 1431 |
+
|
| 1432 |
+
# ===== dataframe =====
|
| 1433 |
+
df = pd.DataFrame(row_values)
|
| 1434 |
+
|
| 1435 |
+
# ===== multi columns =====
|
| 1436 |
+
df.columns = pd.MultiIndex.from_tuples(
|
| 1437 |
+
df.columns,
|
| 1438 |
+
names=["model", "metric"]
|
| 1439 |
+
)
|
| 1440 |
+
|
| 1441 |
+
# ===== multi index =====
|
| 1442 |
+
df.index = pd.MultiIndex.from_tuples(
|
| 1443 |
+
row_tuples,
|
| 1444 |
+
names=["weight", "topk"]
|
| 1445 |
+
)
|
| 1446 |
+
|
| 1447 |
+
return df
|
| 1448 |
+
|
| 1449 |
+
result_test_df = dict_to_df(result_test)
|
| 1450 |
+
result_test_df.to_excel(f"{checkpoints_dir}/results/{state_dict_save_name}_test_df.xlsx")
|
| 1451 |
+
result_test_df
|
| 1452 |
+
|
| 1453 |
+
# %% [code]
|
| 1454 |
+
key = ("Best model", "recall")
|
| 1455 |
+
|
| 1456 |
+
result_test_df_best = (
|
| 1457 |
+
result_test_df
|
| 1458 |
+
.sort_values(by=key, ascending=False)
|
| 1459 |
+
.groupby(level="weight")
|
| 1460 |
+
.head(1)
|
| 1461 |
+
)
|
| 1462 |
+
result_test_df_best.to_excel(f"{checkpoints_dir}/results/{state_dict_save_name}_test_df_best.xlsx")
|
| 1463 |
+
result_test_df_best
|
| 1464 |
+
|
| 1465 |
+
# %% [code]
|
| 1466 |
+
def get_avg_best_score(logs):
|
| 1467 |
+
return float(np.mean([list(log.values())[-1]['best_score'] for log in logs]))
|
| 1468 |
+
|
| 1469 |
+
def get_avg_log(logs, epochs):
|
| 1470 |
+
avg_log = {}
|
| 1471 |
+
|
| 1472 |
+
for epoch in range(1, epochs + 1):
|
| 1473 |
+
val_score = 0.0
|
| 1474 |
+
train_loss = 0.0
|
| 1475 |
+
n_eval = 0
|
| 1476 |
+
|
| 1477 |
+
for idx in range(len(logs)):
|
| 1478 |
+
log = logs[idx].get(epoch, logs[idx].get(str(epoch)))
|
| 1479 |
+
if log is None:
|
| 1480 |
+
continue
|
| 1481 |
+
|
| 1482 |
+
val_score += log.get('val_score', 0.0)
|
| 1483 |
+
train_loss += log.get('train_loss', 0.0)
|
| 1484 |
+
n_eval += 1
|
| 1485 |
+
|
| 1486 |
+
if n_eval == 0:
|
| 1487 |
+
continue
|
| 1488 |
+
|
| 1489 |
+
avg_log[epoch] = {
|
| 1490 |
+
'train_loss': train_loss / n_eval,
|
| 1491 |
+
'val_score': val_score / n_eval if val_score != 0 else float('inf')
|
| 1492 |
+
}
|
| 1493 |
+
|
| 1494 |
+
return avg_log
|
| 1495 |
+
|
| 1496 |
+
def parse_label_key(label: str):
|
| 1497 |
+
try:
|
| 1498 |
+
first = float(label.split('_', 1)[0]) # số đầu: trước dấu _
|
| 1499 |
+
last = float(re.findall(r'_(\d+(?:\.\d+)?)$', label)[0])
|
| 1500 |
+
return first, last
|
| 1501 |
+
except:
|
| 1502 |
+
return (0, 0)
|
| 1503 |
+
|
| 1504 |
+
def plot_training_logs(logs_dict, save_path=None, figsize=(24, 10)):
|
| 1505 |
+
fig, axes = plt.subplots(1, 2, figsize=figsize)
|
| 1506 |
+
|
| 1507 |
+
# ===== Plot Train Loss =====
|
| 1508 |
+
for name, log in logs_dict.items():
|
| 1509 |
+
epochs = sorted(log.keys())
|
| 1510 |
+
train_loss = [log[e]['train_loss'] for e in epochs]
|
| 1511 |
+
axes[0].plot(epochs, train_loss, label=name)
|
| 1512 |
+
|
| 1513 |
+
axes[0].set_xlabel('Epoch')
|
| 1514 |
+
axes[0].set_ylabel('Train Loss')
|
| 1515 |
+
axes[0].set_title('Training Loss')
|
| 1516 |
+
axes[0].grid(True)
|
| 1517 |
+
|
| 1518 |
+
# ===== Plot Validation Score =====
|
| 1519 |
+
for name, log in logs_dict.items():
|
| 1520 |
+
epochs = sorted(log.keys())
|
| 1521 |
+
val_score = [log[e]['val_score'] for e in epochs]
|
| 1522 |
+
axes[1].plot(epochs, val_score, label=name)
|
| 1523 |
+
|
| 1524 |
+
axes[1].set_xlabel('Epoch')
|
| 1525 |
+
axes[1].set_ylabel('Validation Score')
|
| 1526 |
+
axes[1].set_title('Validation Score')
|
| 1527 |
+
axes[1].grid(True)
|
| 1528 |
+
|
| 1529 |
+
# ===== Shared Legend =====
|
| 1530 |
+
handles, labels = axes[0].get_legend_handles_labels()
|
| 1531 |
+
pairs = list(zip(handles, labels))
|
| 1532 |
+
pairs_sorted = sorted(
|
| 1533 |
+
pairs,
|
| 1534 |
+
key=lambda x: parse_label_key(x[1])
|
| 1535 |
+
)
|
| 1536 |
+
handles_sorted, labels_sorted = zip(*pairs_sorted)
|
| 1537 |
+
|
| 1538 |
+
axes[0].legend(
|
| 1539 |
+
handles_sorted,
|
| 1540 |
+
labels_sorted,
|
| 1541 |
+
loc='center left',
|
| 1542 |
+
bbox_to_anchor=(1.01, 0.5),
|
| 1543 |
+
borderaxespad=0.
|
| 1544 |
+
)
|
| 1545 |
+
|
| 1546 |
+
plt.tight_layout(rect=[0, 0, 1, 1])
|
| 1547 |
+
|
| 1548 |
+
if save_path is not None:
|
| 1549 |
+
os.makedirs(os.path.dirname(save_path), exist_ok=True) if os.path.dirname(save_path) else None
|
| 1550 |
+
plt.savefig(save_path, dpi=300, bbox_inches='tight')
|
| 1551 |
+
|
| 1552 |
+
plt.show()
|
| 1553 |
+
|
| 1554 |
+
# %% [code]
|
| 1555 |
+
if not test_only:
|
| 1556 |
+
snapshot_download(repo_id=repo_name, local_dir="", repo_type="model", allow_patterns=["**/*lr*.json"], ignore_patterns=[])
|
| 1557 |
+
get_ipython().system('rm -rf .cache .gitattributes')
|
| 1558 |
+
|
| 1559 |
+
# %% [code]
|
| 1560 |
+
if not test_only:
|
| 1561 |
+
experiments = {}
|
| 1562 |
+
for experiment in os.listdir(pretrained_dir):
|
| 1563 |
+
experiment_logs = []
|
| 1564 |
+
try:
|
| 1565 |
+
for seed in SEEDS:
|
| 1566 |
+
for fold_idx in range(nfolds):
|
| 1567 |
+
with open(f"{pretrained_dir}/{experiment}/logs/{experiment}_s{seed}_f{fold_idx}_logging.json", "r", encoding="utf-8") as f:
|
| 1568 |
+
experiment_log = json.load(f)
|
| 1569 |
+
experiment_logs.append(experiment_log)
|
| 1570 |
+
except:
|
| 1571 |
+
pass
|
| 1572 |
+
experiments[experiment] = get_avg_log(experiment_logs, 1000)
|
| 1573 |
+
experiments[state_dict_save_name] = get_avg_log(training_logs, 1000)
|
| 1574 |
+
|
| 1575 |
+
# %% [code]
|
| 1576 |
+
if not test_only:
|
| 1577 |
+
score = get_avg_best_score(training_logs)
|
| 1578 |
+
state_dict_save_name, score
|
| 1579 |
+
|
| 1580 |
+
# %% [code]
|
| 1581 |
+
if not test_only:
|
| 1582 |
+
plot_training_logs(experiments, save_path=f'{checkpoints_dir}/logs/{state_dict_save_name}_log_plot.jpg', figsize=(18, 7.5))
|
| 1583 |
+
|
15_150_negs_22/lasts/15_150_negs_22_s26092004_f0_last_ema.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3cc68d4f5ac666529a7f5c5dd5cc3b0c571df8380ccfc540e59394d04c0b5b96
|
| 3 |
+
size 544003532
|
15_150_negs_22/lasts/15_150_negs_22_s26092004_f1_last_ema.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fa6b33099e61cacd18fed6a432b9ed7a101ffc8f7e5b8f0ffae6707c0db0cec6
|
| 3 |
+
size 544003532
|
15_150_negs_22/lasts/15_150_negs_22_s26092004_f2_last_ema.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ae93a80ee11eb3abaaf449a4c2d60f4c6b8b542a342d5891792c7658705ba7f5
|
| 3 |
+
size 544003532
|
15_150_negs_22/lasts/15_150_negs_22_s26092004_f3_last_ema.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8ff0348d79fa89b5a366ab72aae420fbdb19f6b1352a0f7348c224372272def9
|
| 3 |
+
size 544003532
|
15_150_negs_22/lasts/15_150_negs_22_s26092004_f4_last_ema.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8e9217104f87cbc128a86507307f229576134ad4e1f2f8015ca9bbc402fd9fa3
|
| 3 |
+
size 544003532
|
15_150_negs_22/logs/15_150_negs_22_log_plot.jpg
ADDED
|
Git LFS Details
|
15_150_negs_22/logs/15_150_negs_22_s26092004_f0_logging.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"1": {"lr": [2e-05, 0.0005], "train_loss": 4.1672186851501465, "total": 4.167218772862667, "contrastive_loss": 4.023980080084657, "triplet_loss": 0.2792642140468227}, "2": {"lr": [1.988303923565381e-05, 0.0004969282409784868], "train_loss": 3.9640235900878906, "total": 3.964023551813336, "contrastive_loss": 3.823957462374582, "triplet_loss": 0.27278428093645485}, "3": {"lr": [1.9535036904803962e-05, 0.0004877886008156408], "train_loss": 3.7115278244018555, "total": 3.711527846728679, "contrastive_loss": 3.5522779381793477, "triplet_loss": 0.31584448160535117}, "4": {"lr": [1.8964561979789496e-05, 0.00047280612778499774], "train_loss": 3.450866937637329, "total": 3.4508669033497075, "contrastive_loss": 3.2993725422632734, "triplet_loss": 0.300376254180602}, "5": {"lr": [1.8185661446562005e-05, 0.00045234974009654937], "train_loss": 3.413285493850708, "total": 3.413285577576296, "contrastive_loss": 3.2624983261261495, "triplet_loss": 0.2955685618729097}, "6": {"lr": [1.7217514421272206e-05, 0.00042692314190604356], "train_loss": 3.2078170776367188, "total": 3.2078171541858276, "contrastive_loss": 3.0652610753292224, "triplet_loss": 0.27968227424749165}, "7": {"lr": [1.60839598967785e-05, 0.00039715242044697206], "train_loss": 3.18171763420105, "total": 3.181717582370924, "contrastive_loss": 3.0312304034280935, "triplet_loss": 0.29515050167224083}, "8": {"lr": [1.4812909747525698e-05, 0.00036377062968501693], "train_loss": 2.892956495285034, "total": 2.8929565837949416, "contrastive_loss": 2.7554409065374164, "triplet_loss": 0.26964882943143814, "val_score": 0.8459523809523809, "best_score": 0.8459523809523809, "new_best_model": true, "recall": 0.8459523809523809, "mAP": 0.32820077908478196, "mRP": 0.3143268849206348}, "9": {"lr": [1.3435661446562005e-05, 0.0003275997400965494], "train_loss": 2.757239580154419, "total": 2.7572395044026963, "contrastive_loss": 2.6232087508491846, "triplet_loss": 0.2648411371237458, "val_score": 0.8417857142857142, "best_score": 0.8459523809523809, "new_best_model": false, "recall": 0.8417857142857142, "mAP": 0.3268865740740742, "mRP": 0.3140223214285715}, "10": {"lr": [1.1986127417882198e-05, 0.00028953039902753766], "train_loss": 2.5553054809570312, "total": 2.5553054044079224, "contrastive_loss": 2.4303450058136495, "triplet_loss": 0.25020903010033446, "val_score": 0.8499702380952381, "best_score": 0.8499702380952381, "new_best_model": true, "recall": 0.8499702380952381, "mAP": 0.3336574432319225, "mRP": 0.32215079365079363}, "11": {"lr": [1.0500000000000003e-05, 0.0002505], "train_loss": 2.4859142303466797, "total": 2.4859143515494355, "contrastive_loss": 2.362378787037521, "triplet_loss": 0.24770066889632106, "val_score": 0.8320535714285714, "best_score": 0.8499702380952381, "new_best_model": false, "recall": 0.8320535714285714, "mAP": 0.32448590994268056, "mRP": 0.3119866071428572}, "12": {"lr": [9.013872582117811e-06, 0.00021146960097246246], "train_loss": 2.312966823577881, "total": 2.3129668474994776, "contrastive_loss": 2.198235859440322, "triplet_loss": 0.23097826086956522, "val_score": 0.8358035714285714, "best_score": 0.8499702380952381, "new_best_model": false, "recall": 0.8358035714285714, "mAP": 0.33108820330215427, "mRP": 0.3191056547619048}, "13": {"lr": [7.564338553438001e-06, 0.00017340025990345064], "train_loss": 2.2940075397491455, "total": 2.294007572441994, "contrastive_loss": 2.179044487484323, "triplet_loss": 0.23118729096989968, "val_score": 0.8189285714285713, "best_score": 0.8499702380952381, "new_best_model": false, "recall": 0.8189285714285713, "mAP": 0.3192895353048628, "mRP": 0.30643501984127}, "14": {"lr": [6.1870902524743065e-06, 0.00013722937031498307], "train_loss": 2.155339002609253, "total": 2.1553389635373117, "contrastive_loss": 2.047856665773934, "triplet_loss": 0.21467391304347827, "val_score": 0.816220238095238, "best_score": 0.8499702380952381, "new_best_model": false, "recall": 0.816220238095238, "mAP": 0.3243836663832201, "mRP": 0.3130148809523811}, "15": {"lr": [4.916040103221507e-06, 0.00010384757955302797], "train_loss": 2.186486005783081, "total": 2.1864860815348037, "contrastive_loss": 2.076355592861622, "triplet_loss": 0.22010869565217392, "val_score": 0.7985119047619047, "best_score": 0.8499702380952381, "new_best_model": false, "recall": 0.7985119047619047, "mAP": 0.3112391798154448, "mRP": 0.301764384920635}, "16": {"lr": [3.7824855787278e-06, 7.40768580939564e-05], "train_loss": 2.0758955478668213, "total": 2.0758954816837374, "contrastive_loss": 1.9720232399012332, "triplet_loss": 0.20725334448160534, "val_score": 0.7972023809523809, "best_score": 0.8499702380952381, "new_best_model": false, "recall": 0.7972023809523809, "mAP": 0.3150650628306877, "mRP": 0.30602480158730166}, "17": {"lr": [2.814338553438001e-06, 4.865025990345063e-05], "train_loss": 2.1477086544036865, "total": 2.1477087524822323, "contrastive_loss": 2.0392823490410743, "triplet_loss": 0.21676421404682275, "val_score": 0.779702380952381, "best_score": 0.8499702380952381, "new_best_model": false, "recall": 0.779702380952381, "mAP": 0.3022472070656966, "mRP": 0.2926879960317461}, "18": {"lr": [2.0354380202105066e-06, 2.8193872215002235e-05], "train_loss": 2.0790791511535645, "total": 2.0790791080946907, "contrastive_loss": 1.974573447951505, "triplet_loss": 0.2087165551839465, "val_score": 0.7786607142857143, "best_score": 0.8499702380952381, "new_best_model": false, "recall": 0.7786607142857143, "mAP": 0.30381324266975296, "mRP": 0.2939900793650796}}
|
15_150_negs_22/logs/15_150_negs_22_s26092004_f1_logging.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"1": {"lr": [2e-05, 0.0005], "train_loss": 4.137069225311279, "total": 4.137069038722826, "contrastive_loss": 3.9935608930811037, "triplet_loss": 0.2801003344481605}, "2": {"lr": [1.988303923565381e-05, 0.0004969282409784868], "train_loss": 3.9110536575317383, "total": 3.9110536096885453, "contrastive_loss": 3.771076521347199, "triplet_loss": 0.2721571906354515}, "3": {"lr": [1.9535036904803962e-05, 0.0004877886008156408], "train_loss": 3.658980131149292, "total": 3.658980047423704, "contrastive_loss": 3.5002392414820234, "triplet_loss": 0.31668060200668896}, "4": {"lr": [1.8964561979789496e-05, 0.00047280612778499774], "train_loss": 3.3781347274780273, "total": 3.378134839112145, "contrastive_loss": 3.2279865175585285, "triplet_loss": 0.2970317725752508}, "5": {"lr": [1.8185661446562005e-05, 0.00045234974009654937], "train_loss": 3.376439094543457, "total": 3.376439123249373, "contrastive_loss": 3.2249439456391094, "triplet_loss": 0.29828595317725753}, "6": {"lr": [1.7217514421272206e-05, 0.00042692314190604356], "train_loss": 3.1349034309387207, "total": 3.1349034133962164, "contrastive_loss": 2.993013617984427, "triplet_loss": 0.27801003344481606}, "7": {"lr": [1.60839598967785e-05, 0.00039715242044697206], "train_loss": 3.1019885540008545, "total": 3.101988521308006, "contrastive_loss": 2.954596171809678, "triplet_loss": 0.2903428093645485}, "8": {"lr": [1.4812909747525698e-05, 0.00036377062968501693], "train_loss": 2.8280282020568848, "total": 2.828028241926212, "contrastive_loss": 2.6930903303982023, "triplet_loss": 0.2652591973244147, "val_score": 0.8463782051282052, "best_score": 0.8463782051282052, "new_best_model": true, "recall": 0.8463782051282052, "mAP": 0.3313440531305114, "mRP": 0.3168319978632479}, "9": {"lr": [1.3435661446562005e-05, 0.0003275997400965494], "train_loss": 2.706798791885376, "total": 2.7067987448395696, "contrastive_loss": 2.574957499934678, "triplet_loss": 0.2617056856187291, "val_score": 0.8435737179487179, "best_score": 0.8463782051282052, "new_best_model": false, "recall": 0.8435737179487179, "mAP": 0.32816869138770177, "mRP": 0.3144764957264958}, "10": {"lr": [1.1986127417882198e-05, 0.00028953039902753766], "train_loss": 2.5142157077789307, "total": 2.5142156798704014, "contrastive_loss": 2.390962224341555, "triplet_loss": 0.24853678929765885, "val_score": 0.8437820512820513, "best_score": 0.8463782051282052, "new_best_model": false, "recall": 0.8437820512820513, "mAP": 0.33585737582248, "mRP": 0.3213138354700855}, "11": {"lr": [1.0500000000000003e-05, 0.0002505], "train_loss": 2.4483139514923096, "total": 2.44831404159699, "contrastive_loss": 2.3261673841189383, "triplet_loss": 0.24498327759197325, "val_score": 0.8300320512820513, "best_score": 0.8463782051282052, "new_best_model": false, "recall": 0.8300320512820513, "mAP": 0.32692176943426937, "mRP": 0.3138902243589743}, "12": {"lr": [9.013872582117811e-06, 0.00021146960097246246], "train_loss": 2.277340888977051, "total": 2.277340892166597, "contrastive_loss": 2.1642654061716136, "triplet_loss": 0.2270066889632107, "val_score": 0.8300320512820513, "best_score": 0.8463782051282052, "new_best_model": false, "recall": 0.8300320512820513, "mAP": 0.3296229998685728, "mRP": 0.31408119658119643}, "13": {"lr": [7.564338553438001e-06, 0.00017340025990345064], "train_loss": 2.2653207778930664, "total": 2.265320844873537, "contrastive_loss": 2.1514325094063547, "triplet_loss": 0.22846989966555184, "val_score": 0.8150320512820513, "best_score": 0.8463782051282052, "new_best_model": false, "recall": 0.8150320512820513, "mAP": 0.3170579228352667, "mRP": 0.30239182692307703}, "14": {"lr": [6.1870902524743065e-06, 0.00013722937031498307], "train_loss": 2.1353514194488525, "total": 2.1353514808476173, "contrastive_loss": 2.028659782282086, "triplet_loss": 0.2130016722408027, "val_score": 0.8145032051282052, "best_score": 0.8463782051282052, "new_best_model": false, "recall": 0.8145032051282052, "mAP": 0.31952567918192915, "mRP": 0.30193456196581214}, "15": {"lr": [4.916040103221507e-06, 0.00010384757955302797], "train_loss": 2.1619455814361572, "total": 2.161945661972199, "contrastive_loss": 2.053030977281041, "triplet_loss": 0.21885451505016723, "val_score": 0.7986698717948718, "best_score": 0.8463782051282052, "new_best_model": false, "recall": 0.7986698717948718, "mAP": 0.3092705610458214, "mRP": 0.29222195512820537}, "16": {"lr": [3.7824855787278e-06, 7.40768580939564e-05], "train_loss": 2.0567691326141357, "total": 2.0567692275031355, "contrastive_loss": 1.953804960218959, "triplet_loss": 0.20464046822742474, "val_score": 0.7970993589743589, "best_score": 0.8463782051282052, "new_best_model": false, "recall": 0.7970993589743589, "mAP": 0.31092193668599927, "mRP": 0.29407264957264967}, "17": {"lr": [2.814338553438001e-06, 4.865025990345063e-05], "train_loss": 2.1372835636138916, "total": 2.1372835803590093, "contrastive_loss": 2.0295201942673495, "triplet_loss": 0.21509197324414717, "val_score": 0.7734615384615385, "best_score": 0.8463782051282052, "new_best_model": false, "recall": 0.7734615384615385, "mAP": 0.29727417169057785, "mRP": 0.2803215811965813}, "18": {"lr": [2.0354380202105066e-06, 2.8193872215002235e-05], "train_loss": 2.0649266242980957, "total": 2.06492670882107, "contrastive_loss": 1.961086923860786, "triplet_loss": 0.20673076923076922, "val_score": 0.7690865384615385, "best_score": 0.8463782051282052, "new_best_model": false, "recall": 0.7690865384615385, "mAP": 0.29995192540869625, "mRP": 0.285417200854701}}
|
15_150_negs_22/logs/15_150_negs_22_s26092004_f2_logging.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"1": {"lr": [2e-05, 0.0005], "train_loss": 4.139380931854248, "total": 4.139381025945861, "contrastive_loss": 3.995925546091137, "triplet_loss": 0.2801003344481605}, "2": {"lr": [1.988303923565381e-05, 0.0004969282409784868], "train_loss": 3.9343652725219727, "total": 3.9343653650188126, "contrastive_loss": 3.7942866194607023, "triplet_loss": 0.2729933110367893}, "3": {"lr": [1.9535036904803962e-05, 0.0004877886008156408], "train_loss": 3.700861930847168, "total": 3.700862004206731, "contrastive_loss": 3.5417778499947743, "triplet_loss": 0.3168896321070234}, "4": {"lr": [1.8964561979789496e-05, 0.00047280612778499774], "train_loss": 3.4332377910614014, "total": 3.4332377456103678, "contrastive_loss": 3.282380681372805, "triplet_loss": 0.2991220735785953}, "5": {"lr": [1.8185661446562005e-05, 0.00045234974009654937], "train_loss": 3.4100091457366943, "total": 3.4100092757107023, "contrastive_loss": 3.2590760706260453, "triplet_loss": 0.2987040133779264}, "6": {"lr": [1.7217514421272206e-05, 0.00042692314190604356], "train_loss": 3.200291395187378, "total": 3.2002914581809154, "contrastive_loss": 3.057549416022157, "triplet_loss": 0.27884615384615385}, "7": {"lr": [1.60839598967785e-05, 0.00039715242044697206], "train_loss": 3.182145833969116, "total": 3.1821458491194607, "contrastive_loss": 3.0321287837714257, "triplet_loss": 0.2938963210702341}, "8": {"lr": [1.4812909747525698e-05, 0.00036377062968501693], "train_loss": 2.8848564624786377, "total": 2.8848564632760243, "contrastive_loss": 2.7477341463733276, "triplet_loss": 0.27027591973244147, "val_score": 0.8515705128205128, "best_score": 0.8515705128205128, "new_best_model": true, "recall": 0.8515705128205128, "mAP": 0.3259249765762787, "mRP": 0.3097884615384615}, "9": {"lr": [1.3435661446562005e-05, 0.0003275997400965494], "train_loss": 2.7493114471435547, "total": 2.749311466280832, "contrastive_loss": 2.6156510062839673, "triplet_loss": 0.2652591973244147, "val_score": 0.8471955128205128, "best_score": 0.8515705128205128, "new_best_model": false, "recall": 0.8471955128205128, "mAP": 0.32194838895672223, "mRP": 0.30633707264957283}, "10": {"lr": [1.1986127417882198e-05, 0.00028953039902753766], "train_loss": 2.546830177307129, "total": 2.5468302953203388, "contrastive_loss": 2.4223757332383986, "triplet_loss": 0.24937290969899664, "val_score": 0.8532371794871795, "best_score": 0.8532371794871795, "new_best_model": true, "recall": 0.8532371794871795, "mAP": 0.3309601962081128, "mRP": 0.31604540598290604}, "11": {"lr": [1.0500000000000003e-05, 0.0002505], "train_loss": 2.4813392162323, "total": 2.481339164402174, "contrastive_loss": 2.3581951230664715, "triplet_loss": 0.24749163879598662, "val_score": 0.8353205128205128, "best_score": 0.8532371794871795, "new_best_model": false, "recall": 0.8353205128205128, "mAP": 0.3218226735263194, "mRP": 0.30647061965811984}, "12": {"lr": [9.013872582117811e-06, 0.00021146960097246246], "train_loss": 2.3067893981933594, "total": 2.306789436467914, "contrastive_loss": 2.1924699764187916, "triplet_loss": 0.23014214046822742, "val_score": 0.8432371794871795, "best_score": 0.8532371794871795, "new_best_model": false, "recall": 0.8432371794871795, "mAP": 0.3274997883385904, "mRP": 0.31122248931623947}, "13": {"lr": [7.564338553438001e-06, 0.00017340025990345064], "train_loss": 2.2870254516601562, "total": 2.2870254771765257, "contrastive_loss": 2.1725394462662, "triplet_loss": 0.229933110367893, "val_score": 0.8225160256410255, "best_score": 0.8532371794871795, "new_best_model": false, "recall": 0.8225160256410255, "mAP": 0.31528606171991597, "mRP": 0.3}, "14": {"lr": [6.1870902524743065e-06, 0.00013722937031498307], "train_loss": 2.1464900970458984, "total": 2.146490090666806, "contrastive_loss": 2.0396673400266514, "triplet_loss": 0.21289715719063546, "val_score": 0.8257371794871795, "best_score": 0.8532371794871795, "new_best_model": false, "recall": 0.8257371794871795, "mAP": 0.3201805034086283, "mRP": 0.30351255341880334}, "15": {"lr": [4.916040103221507e-06, 0.00010384757955302797], "train_loss": 2.1793973445892334, "total": 2.1793974299095944, "contrastive_loss": 2.0698056428328804, "triplet_loss": 0.21906354515050167, "val_score": 0.8038621794871794, "best_score": 0.8532371794871795, "new_best_model": false, "recall": 0.8038621794871794, "mAP": 0.30611411369302016, "mRP": 0.29142013888888907}, "16": {"lr": [3.7824855787278e-06, 7.40768580939564e-05], "train_loss": 2.069427490234375, "total": 2.0694273881688963, "contrastive_loss": 1.965861342822429, "triplet_loss": 0.2061036789297659, "val_score": 0.8046955128205128, "best_score": 0.8532371794871795, "new_best_model": false, "recall": 0.8046955128205128, "mAP": 0.31059089548568725, "mRP": 0.2977986111111113}, "17": {"lr": [2.814338553438001e-06, 4.865025990345063e-05], "train_loss": 2.1502137184143066, "total": 2.150213847590928, "contrastive_loss": 2.041660066432379, "triplet_loss": 0.21739130434782608, "val_score": 0.7809615384615385, "best_score": 0.8532371794871795, "new_best_model": false, "recall": 0.7809615384615385, "mAP": 0.29559656127051953, "mRP": 0.28261965811965806}, "18": {"lr": [2.0354380202105066e-06, 2.8193872215002235e-05], "train_loss": 2.0720674991607666, "total": 2.0720674138404056, "contrastive_loss": 1.967860193156877, "triplet_loss": 0.20714882943143811, "val_score": 0.7778365384615384, "best_score": 0.8532371794871795, "new_best_model": false, "recall": 0.7778365384615384, "mAP": 0.2975259654600799, "mRP": 0.2852719017094016}}
|
15_150_negs_22/logs/15_150_negs_22_s26092004_f3_logging.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"1": {"lr": [2e-05, 0.0005], "train_loss": 4.167065143585205, "total": 4.167065266382735, "contrastive_loss": 4.023482817072534, "triplet_loss": 0.2807274247491639}, "2": {"lr": [1.988303923565381e-05, 0.0004969282409784868], "train_loss": 3.9744906425476074, "total": 3.9744905707828178, "contrastive_loss": 3.834159519361413, "triplet_loss": 0.27424749163879597}, "3": {"lr": [1.9535036904803962e-05, 0.0004877886008156408], "train_loss": 3.758497953414917, "total": 3.7584979717548075, "contrastive_loss": 3.5985972937134196, "triplet_loss": 0.3162625418060201}, "4": {"lr": [1.8964561979789496e-05, 0.00047280612778499774], "train_loss": 3.494844913482666, "total": 3.4948448768028846, "contrastive_loss": 3.342801811703073, "triplet_loss": 0.30225752508361203}, "5": {"lr": [1.8185661446562005e-05, 0.00045234974009654937], "train_loss": 3.4667093753814697, "total": 3.466709506950251, "contrastive_loss": 3.3142165372204224, "triplet_loss": 0.30183946488294316}, "6": {"lr": [1.7217514421272206e-05, 0.00042692314190604356], "train_loss": 3.2677063941955566, "total": 3.267706523372178, "contrastive_loss": 3.1228149822324416, "triplet_loss": 0.2834448160535117}, "7": {"lr": [1.60839598967785e-05, 0.00039715242044697206], "train_loss": 3.245375633239746, "total": 3.245375617292015, "contrastive_loss": 3.0942552241194607, "triplet_loss": 0.298494983277592}, "8": {"lr": [1.4812909747525698e-05, 0.00036377062968501693], "train_loss": 2.9626638889312744, "total": 2.9626638355063752, "contrastive_loss": 2.8234291714569397, "triplet_loss": 0.2738294314381271, "val_score": 0.8338782051282052, "best_score": 0.8338782051282052, "new_best_model": true, "recall": 0.8338782051282052, "mAP": 0.31477814015652555, "mRP": 0.3007975427350429}, "9": {"lr": [1.3435661446562005e-05, 0.0003275997400965494], "train_loss": 2.8341825008392334, "total": 2.8341825861595944, "contrastive_loss": 2.6976110145798495, "triplet_loss": 0.26902173913043476, "val_score": 0.8382532051282051, "best_score": 0.8382532051282051, "new_best_model": true, "recall": 0.8382532051282051, "mAP": 0.31807417614214484, "mRP": 0.3040464743589744}, "10": {"lr": [1.1986127417882198e-05, 0.00028953039902753766], "train_loss": 2.6252567768096924, "total": 2.625256796744356, "contrastive_loss": 2.4978954098296406, "triplet_loss": 0.25418060200668896, "val_score": 0.8480448717948719, "best_score": 0.8480448717948719, "new_best_model": true, "recall": 0.8480448717948719, "mAP": 0.3268762178215303, "mRP": 0.31093536324786325}, "11": {"lr": [1.0500000000000003e-05, 0.0002505], "train_loss": 2.554565668106079, "total": 2.5545656338184575, "contrastive_loss": 2.4285153800428514, "triplet_loss": 0.2514632107023411, "val_score": 0.8355448717948718, "best_score": 0.8480448717948719, "new_best_model": false, "recall": 0.8355448717948718, "mAP": 0.316984085754138, "mRP": 0.30098344017094014}, "12": {"lr": [9.013872582117811e-06, 0.00021146960097246246], "train_loss": 2.3676581382751465, "total": 2.3676582259876673, "contrastive_loss": 2.250942880892036, "triplet_loss": 0.23453177257525085, "val_score": 0.8376282051282051, "best_score": 0.8480448717948719, "new_best_model": false, "recall": 0.8376282051282051, "mAP": 0.3238103674874506, "mRP": 0.30713995726495724}, "13": {"lr": [7.564338553438001e-06, 0.00017340025990345064], "train_loss": 2.3510525226593018, "total": 2.35105258086852, "contrastive_loss": 2.2335509233251463, "triplet_loss": 0.23787625418060201, "val_score": 0.8222115384615385, "best_score": 0.8480448717948719, "new_best_model": false, "recall": 0.8222115384615385, "mAP": 0.31330954723324517, "mRP": 0.2993731303418804}, "14": {"lr": [6.1870902524743065e-06, 0.00013722937031498307], "train_loss": 2.1988182067871094, "total": 2.198818245061664, "contrastive_loss": 2.089502851301212, "triplet_loss": 0.21906354515050167, "val_score": 0.8225320512820513, "best_score": 0.8480448717948719, "new_best_model": false, "recall": 0.8225320512820513, "mAP": 0.3189929852843915, "mRP": 0.30459134615384625}, "15": {"lr": [4.916040103221507e-06, 0.00010384757955302797], "train_loss": 2.2353107929229736, "total": 2.2353107363085285, "contrastive_loss": 2.1231954823369565, "triplet_loss": 0.2253344481605351, "val_score": 0.8086698717948718, "best_score": 0.8480448717948719, "new_best_model": false, "recall": 0.8086698717948718, "mAP": 0.3053212842134716, "mRP": 0.28958787393162405}, "16": {"lr": [3.7824855787278e-06, 7.40768580939564e-05], "train_loss": 2.1198959350585938, "total": 2.1198959095422243, "contrastive_loss": 2.0140080786867682, "triplet_loss": 0.21070234113712374, "val_score": 0.8056570512820513, "best_score": 0.8480448717948719, "new_best_model": false, "recall": 0.8056570512820513, "mAP": 0.3093023741690408, "mRP": 0.29536217948717963}, "17": {"lr": [2.814338553438001e-06, 4.865025990345063e-05], "train_loss": 2.2059547901153564, "total": 2.205954867461852, "contrastive_loss": 2.0951501342365177, "triplet_loss": 0.22240802675585283, "val_score": 0.7876282051282052, "best_score": 0.8480448717948719, "new_best_model": false, "recall": 0.7876282051282052, "mAP": 0.29546059833299426, "mRP": 0.28245245726495727}, "18": {"lr": [2.0354380202105066e-06, 2.8193872215002235e-05], "train_loss": 2.127185821533203, "total": 2.127185834291388, "contrastive_loss": 2.0204437153793897, "triplet_loss": 0.212688127090301, "val_score": 0.7833653846153846, "best_score": 0.8480448717948719, "new_best_model": false, "recall": 0.7833653846153846, "mAP": 0.2982273316671753, "mRP": 0.286792735042735}}
|
15_150_negs_22/logs/15_150_negs_22_s26092004_f4_logging.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"1": {"lr": [2e-05, 0.0005], "train_loss": 4.131608009338379, "total": 4.131608127351589, "contrastive_loss": 3.9879574983016304, "triplet_loss": 0.2798913043478261}, "2": {"lr": [1.988303923565381e-05, 0.0004969282409784868], "train_loss": 3.9153566360473633, "total": 3.9153566902696486, "contrastive_loss": 3.7752718207828178, "triplet_loss": 0.2729933110367893}, "3": {"lr": [1.9535036904803962e-05, 0.0004877886008156408], "train_loss": 3.6610000133514404, "total": 3.6610001273777173, "contrastive_loss": 3.502140925480769, "triplet_loss": 0.3162625418060201}, "4": {"lr": [1.8964561979789496e-05, 0.00047280612778499774], "train_loss": 3.3706254959106445, "total": 3.370625473583821, "contrastive_loss": 3.2205002188283864, "triplet_loss": 0.2955685618729097}, "5": {"lr": [1.8185661446562005e-05, 0.00045234974009654937], "train_loss": 3.351973295211792, "total": 3.3519734156171612, "contrastive_loss": 3.2003271810984533, "triplet_loss": 0.2978678929765886}, "6": {"lr": [1.7217514421272206e-05, 0.00042692314190604356], "train_loss": 3.0937931537628174, "total": 3.0937930716320023, "contrastive_loss": 2.9527938995871654, "triplet_loss": 0.27508361204013376}, "7": {"lr": [1.60839598967785e-05, 0.00039715242044697206], "train_loss": 3.0529468059539795, "total": 3.0529468753266094, "contrastive_loss": 2.906650300807379, "triplet_loss": 0.2869983277591973}, "8": {"lr": [1.4812909747525698e-05, 0.00036377062968501693], "train_loss": 2.83054256439209, "total": 2.8305425229279892, "contrastive_loss": 2.694996301147053, "triplet_loss": 0.26734949832775917, "val_score": 0.8469070512820512, "best_score": 0.8469070512820512, "new_best_model": true, "recall": 0.8469070512820512, "mAP": 0.323982652879528, "mRP": 0.31243883547008544}, "9": {"lr": [1.3435661446562005e-05, 0.0003275997400965494], "train_loss": 2.678433418273926, "total": 2.6784335235289505, "contrastive_loss": 2.5470074809913252, "triplet_loss": 0.2612876254180602, "val_score": 0.837948717948718, "best_score": 0.8469070512820512, "new_best_model": false, "recall": 0.837948717948718, "mAP": 0.3184660349681183, "mRP": 0.30882505341880334}, "10": {"lr": [1.1986127417882198e-05, 0.00028953039902753766], "train_loss": 2.490299701690674, "total": 2.4902996969063547, "contrastive_loss": 2.367698031524352, "triplet_loss": 0.24581939799331104, "val_score": 0.841698717948718, "best_score": 0.8469070512820512, "new_best_model": false, "recall": 0.841698717948718, "mAP": 0.32499718152218166, "mRP": 0.31498397435897435}, "11": {"lr": [1.0500000000000003e-05, 0.0002505], "train_loss": 2.4390361309051514, "total": 2.4390360854541178, "contrastive_loss": 2.317084985433215, "triplet_loss": 0.24581939799331104, "val_score": 0.8262820512820513, "best_score": 0.8469070512820512, "new_best_model": false, "recall": 0.8262820512820513, "mAP": 0.3130419898292296, "mRP": 0.30155422008547017}, "12": {"lr": [9.013872582117811e-06, 0.00021146960097246246], "train_loss": 2.274397373199463, "total": 2.2743973237614967, "contrastive_loss": 2.16100380173495, "triplet_loss": 0.22784280936454848, "val_score": 0.826698717948718, "best_score": 0.8469070512820512, "new_best_model": false, "recall": 0.826698717948718, "mAP": 0.31866423621710094, "mRP": 0.3061372863247863}, "13": {"lr": [7.564338553438001e-06, 0.00017340025990345064], "train_loss": 2.261686325073242, "total": 2.26168629317778, "contrastive_loss": 2.147550959252195, "triplet_loss": 0.23097826086956522, "val_score": 0.8041025641025641, "best_score": 0.8469070512820512, "new_best_model": false, "recall": 0.8041025641025641, "mAP": 0.30618760545974094, "mRP": 0.29620352564102553}, "14": {"lr": [6.1870902524743065e-06, 0.00013722937031498307], "train_loss": 2.1376278400421143, "total": 2.1376277451531145, "contrastive_loss": 2.030436538134929, "triplet_loss": 0.2144648829431438, "val_score": 0.804823717948718, "best_score": 0.8469070512820512, "new_best_model": false, "recall": 0.804823717948718, "mAP": 0.3101814994997284, "mRP": 0.2997451923076922}, "15": {"lr": [4.916040103221507e-06, 0.00010384757955302797], "train_loss": 2.16801118850708, "total": 2.1680112092391304, "contrastive_loss": 2.0584047247334865, "triplet_loss": 0.22010869565217392, "val_score": 0.7878525641025641, "best_score": 0.8469070512820512, "new_best_model": false, "recall": 0.7878525641025641, "mAP": 0.296918110988163, "mRP": 0.2844874465811966}, "16": {"lr": [3.7824855787278e-06, 7.40768580939564e-05], "train_loss": 2.0622289180755615, "total": 2.062228914088629, "contrastive_loss": 1.958607957514632, "triplet_loss": 0.20725334448160534, "val_score": 0.7851442307692308, "best_score": 0.8469070512820512, "new_best_model": false, "recall": 0.7851442307692308, "mAP": 0.29972229005562323, "mRP": 0.2872374465811965}, "17": {"lr": [2.814338553438001e-06, 4.865025990345063e-05], "train_loss": 2.135929822921753, "total": 2.1359297838498117, "contrastive_loss": 2.0276338200904056, "triplet_loss": 0.21676421404682275, "val_score": 0.7609935897435898, "best_score": 0.8469070512820512, "new_best_model": false, "recall": 0.7609935897435898, "mAP": 0.28754447804317596, "mRP": 0.2754911858974358}, "18": {"lr": [2.0354380202105066e-06, 2.8193872215002235e-05], "train_loss": 2.065790891647339, "total": 2.065790795163566, "contrastive_loss": 1.9615635696462166, "triplet_loss": 0.207566889632107, "val_score": 0.7609935897435898, "best_score": 0.8469070512820512, "new_best_model": false, "recall": 0.7609935897435898, "mAP": 0.2907232076083641, "mRP": 0.27999786324786313}}
|
15_150_negs_22/r1s/15_150_negs_22_s26092004_f0_r1_vs0.84997_ema.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:97187ac6f20fc33cdc92b4fc2bb2c1b204acff409c8465f3dcb555f216069cc1
|
| 3 |
+
size 544005220
|
15_150_negs_22/r1s/15_150_negs_22_s26092004_f1_r1_vs0.84638_ema.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:12baccc0d45eb4214aaf7121d4890aee41fe575296d95fc037bb4fd76a78a890
|
| 3 |
+
size 544005220
|
15_150_negs_22/r1s/15_150_negs_22_s26092004_f2_r1_vs0.85324_ema.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:399284bffe020a888736926c62ea8f304d85c0a20bcd1eab7489e42363b19874
|
| 3 |
+
size 544005220
|
15_150_negs_22/r1s/15_150_negs_22_s26092004_f3_r1_vs0.84804_ema.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:be60865cd3b78278453b76fcc7f4ce88f787dbae33134c1495ee9d0380c128ba
|
| 3 |
+
size 544005220
|
15_150_negs_22/r1s/15_150_negs_22_s26092004_f4_r1_vs0.84691_ema.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b72975c1cb32e77f39288fc4b22e998142f25936d21dedef8ddc2a5276a76466
|
| 3 |
+
size 544005220
|
15_150_negs_22/results/15_150_negs_22_test.json
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
| 7 |
+
"mRP": 0.3141629016064276
|
| 8 |
+
},
|
| 9 |
+
"10": {
|
| 10 |
+
"recall": 0.8422439759036144,
|
| 11 |
+
"mAP": 0.3263469727122792,
|
| 12 |
+
"mRP": 0.3141629016064276
|
| 13 |
+
},
|
| 14 |
+
"15": {
|
| 15 |
+
"recall": 0.8772590361445783,
|
| 16 |
+
"mAP": 0.33281272081959334,
|
| 17 |
+
"mRP": 0.3141629016064276
|
| 18 |
+
}
|
| 19 |
+
},
|
| 20 |
+
"0.25": {
|
| 21 |
+
"5": {
|
| 22 |
+
"recall": 0.797816265060241,
|
| 23 |
+
"mAP": 0.32738443356760527,
|
| 24 |
+
"mRP": 0.3318084839357452
|
| 25 |
+
},
|
| 26 |
+
"10": {
|
| 27 |
+
"recall": 0.8716114457831325,
|
| 28 |
+
"mAP": 0.34332728981401883,
|
| 29 |
+
"mRP": 0.3318084839357452
|
| 30 |
+
},
|
| 31 |
+
"15": {
|
| 32 |
+
"recall": 0.9028614457831325,
|
| 33 |
+
"mAP": 0.34975876329368505,
|
| 34 |
+
"mRP": 0.3318084839357452
|
| 35 |
+
}
|
| 36 |
+
},
|
| 37 |
+
"0.5": {
|
| 38 |
+
"5": {
|
| 39 |
+
"recall": 0.7707078313253012,
|
| 40 |
+
"mAP": 0.31007279116466024,
|
| 41 |
+
"mRP": 0.31596385542168864
|
| 42 |
+
},
|
| 43 |
+
"10": {
|
| 44 |
+
"recall": 0.8467620481927711,
|
| 45 |
+
"mAP": 0.32507930780662453,
|
| 46 |
+
"mRP": 0.31596385542168864
|
| 47 |
+
},
|
| 48 |
+
"15": {
|
| 49 |
+
"recall": 0.879894578313253,
|
| 50 |
+
"mAP": 0.3310295162954246,
|
| 51 |
+
"mRP": 0.31596385542168864
|
| 52 |
+
}
|
| 53 |
+
},
|
| 54 |
+
"0.75": {
|
| 55 |
+
"5": {
|
| 56 |
+
"recall": 0.7507530120481928,
|
| 57 |
+
"mAP": 0.2967520080321294,
|
| 58 |
+
"mRP": 0.3039344879518089
|
| 59 |
+
},
|
| 60 |
+
"10": {
|
| 61 |
+
"recall": 0.8317018072289156,
|
| 62 |
+
"mAP": 0.3118434950117939,
|
| 63 |
+
"mRP": 0.3039344879518089
|
| 64 |
+
},
|
| 65 |
+
"15": {
|
| 66 |
+
"recall": 0.8618222891566265,
|
| 67 |
+
"mAP": 0.31727805783434637,
|
| 68 |
+
"mRP": 0.3039344879518089
|
| 69 |
+
}
|
| 70 |
+
},
|
| 71 |
+
"1": {
|
| 72 |
+
"5": {
|
| 73 |
+
"recall": 0.7387048192771084,
|
| 74 |
+
"mAP": 0.28923234605087095,
|
| 75 |
+
"mRP": 0.29285266064257154
|
| 76 |
+
},
|
| 77 |
+
"10": {
|
| 78 |
+
"recall": 0.8200301204819277,
|
| 79 |
+
"mAP": 0.30308913979330077,
|
| 80 |
+
"mRP": 0.29285266064257154
|
| 81 |
+
},
|
| 82 |
+
"15": {
|
| 83 |
+
"recall": 0.8546686746987951,
|
| 84 |
+
"mAP": 0.30894348416044637,
|
| 85 |
+
"mRP": 0.29285266064257154
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
},
|
| 89 |
+
"Last model": {
|
| 90 |
+
"0": {
|
| 91 |
+
"5": {
|
| 92 |
+
"recall": 0.7195030120481928,
|
| 93 |
+
"mAP": 0.29731383868808703,
|
| 94 |
+
"mRP": 0.30035768072289304
|
| 95 |
+
},
|
| 96 |
+
"10": {
|
| 97 |
+
"recall": 0.8004518072289156,
|
| 98 |
+
"mAP": 0.3110687342624477,
|
| 99 |
+
"mRP": 0.30035768072289304
|
| 100 |
+
},
|
| 101 |
+
"15": {
|
| 102 |
+
"recall": 0.8429969879518072,
|
| 103 |
+
"mAP": 0.31671555888611713,
|
| 104 |
+
"mRP": 0.30035768072289304
|
| 105 |
+
}
|
| 106 |
+
},
|
| 107 |
+
"0.25": {
|
| 108 |
+
"5": {
|
| 109 |
+
"recall": 0.7884036144578314,
|
| 110 |
+
"mAP": 0.32488631609772634,
|
| 111 |
+
"mRP": 0.3292921686747008
|
| 112 |
+
},
|
| 113 |
+
"10": {
|
| 114 |
+
"recall": 0.865210843373494,
|
| 115 |
+
"mAP": 0.3408417773275652,
|
| 116 |
+
"mRP": 0.3292921686747008
|
| 117 |
+
},
|
| 118 |
+
"15": {
|
| 119 |
+
"recall": 0.9002259036144579,
|
| 120 |
+
"mAP": 0.3476046319010374,
|
| 121 |
+
"mRP": 0.3292921686747008
|
| 122 |
+
}
|
| 123 |
+
},
|
| 124 |
+
"0.5": {
|
| 125 |
+
"5": {
|
| 126 |
+
"recall": 0.7601656626506024,
|
| 127 |
+
"mAP": 0.3061138303212866,
|
| 128 |
+
"mRP": 0.31106927710843535
|
| 129 |
+
},
|
| 130 |
+
"10": {
|
| 131 |
+
"recall": 0.8350903614457831,
|
| 132 |
+
"mAP": 0.32037025582488826,
|
| 133 |
+
"mRP": 0.31106927710843535
|
| 134 |
+
},
|
| 135 |
+
"15": {
|
| 136 |
+
"recall": 0.8674698795180723,
|
| 137 |
+
"mAP": 0.32645165110714935,
|
| 138 |
+
"mRP": 0.31106927710843535
|
| 139 |
+
}
|
| 140 |
+
},
|
| 141 |
+
"0.75": {
|
| 142 |
+
"5": {
|
| 143 |
+
"recall": 0.7387048192771084,
|
| 144 |
+
"mAP": 0.29144400518741737,
|
| 145 |
+
"mRP": 0.2967620481927723
|
| 146 |
+
},
|
| 147 |
+
"10": {
|
| 148 |
+
"recall": 0.8253012048192772,
|
| 149 |
+
"mAP": 0.30617047804312586,
|
| 150 |
+
"mRP": 0.2967620481927723
|
| 151 |
+
},
|
| 152 |
+
"15": {
|
| 153 |
+
"recall": 0.8554216867469879,
|
| 154 |
+
"mAP": 0.3118616288434638,
|
| 155 |
+
"mRP": 0.2967620481927723
|
| 156 |
+
}
|
| 157 |
+
},
|
| 158 |
+
"1": {
|
| 159 |
+
"5": {
|
| 160 |
+
"recall": 0.7270331325301205,
|
| 161 |
+
"mAP": 0.2839835383199473,
|
| 162 |
+
"mRP": 0.28960843373494094
|
| 163 |
+
},
|
| 164 |
+
"10": {
|
| 165 |
+
"recall": 0.8125,
|
| 166 |
+
"mAP": 0.29799096684356546,
|
| 167 |
+
"mRP": 0.28960843373494094
|
| 168 |
+
},
|
| 169 |
+
"15": {
|
| 170 |
+
"recall": 0.8478915662650602,
|
| 171 |
+
"mAP": 0.30365866678084397,
|
| 172 |
+
"mRP": 0.28960843373494094
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
}
|
| 176 |
+
}
|
15_150_negs_22/results/15_150_negs_22_test_df.xlsx
ADDED
|
Binary file (6.24 kB). View file
|
|
|
15_150_negs_22/results/15_150_negs_22_test_df_best.xlsx
ADDED
|
Binary file (5.54 kB). View file
|
|
|