psunlpgroup / CONTaiNER

Code for ACL 2022 paper "CONTaiNER: Few-Shot Named Entity Recognition via Contrastive Learning"
MIT License
112 stars 18 forks source link

Sorry, why I did not seen the relevant code about function (6) in the training progress, as you said the algorithm 1 in your paper? #14

Closed ToneLi closed 1 year ago

ToneLi commented 1 year ago

model.train() batch = tuple(t.to(args.device) for t in batch) inputs = {"input_ids": batch[0], "attention_mask": batch[1], "token_type_ids": batch[2], "labels": batch[3],"loss_type":args.training_loss, "consider_mutual_O": args.consider_mutual_O}

        outputs = model(**inputs)
        loss = outputs[0]

        loss.backward()
        training_loss += loss.item()
        torch.nn.utils.clip_grad_norm_(model.parameters(), args.max_grad_norm)
        optimizer.step()
        model.zero_grad()
        global_step += 1
            # TODO remove args.save_steps
return global_step, training_loss / global_step if global_step > 0 else 0
Yiiiiie commented 1 year ago

same question

Sarathismg commented 1 year ago

Hi, sorry I have not been tracking this repository for quite some time. Although it's been a while, I remember that this outputs[0] is the result from the training loss function after all the calculations. You can find the calculation of the loss and everything else in utils.py. I hope carefully going through that file should resolve your query.

Yiiiiie commented 1 year ago

Thanks, mate! Now it's all making sense.