INNER CODE UNIT · Python

train_model

yya518/FinBERT · archive/train_bert.py:16

def train_model(model, model_type, path, criterion, optimizer, scheduler, device, num_epochs=100, early_stopping = 7):
    model.to(device)
    log_file =  os.path.join(path, "{}_log.txt".format(model_type))
    model_path = os.path.join(path, "{}.pth".format(model_type))
    wo= open(log_file, 'w')
    
    since = time.time()
    print('starting')
    wo.write('starting \n')
    best_loss = 100
    best_accuracy = 0 
    best_f1 = 0
    early_stopping_count = 0
    
    for epoch in range(num_epochs):
        if (early_stopping_count >= early_stopping):
            break 
        

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…