INNER CODE UNIT · Python

train

barissayil/SentimentAnalysis · analyzer.py:89

    def train(self, train_loader, optimizer, criterion):
        # Set model to training mode.
        self.model.train()
        # Go through training set in batches.
        for input_ids, attention_mask, labels in tqdm(
            iterable=train_loader, desc="Training"
        ):
            # Reset gradient
            optimizer.zero_grad()
            # Put input IDs, attention mask, and labels to device
            input_ids, attention_mask, labels = (
                input_ids.to(self.device),
                attention_mask.to(self.device),
                labels.to(self.device),
            )
            # Get logits.
            logits = self.model(input_ids=input_ids, attention_mask=attention_mask)
            # Get loss.

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…