INNER CODE UNIT · Python

accuracy

barissayil/SentimentAnalysis · analyzer.py:84

        accuracy = batch_accuracy_summation / num_batches
        # Return accuracy and loss.
        return accuracy.item(), loss

    # Trains analyzer for one epoch.
    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),

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…