NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

import random

# training loop

# For each epoch...
for epoch_i in range(0, epochs):
# Perform one full pass over the training set.

print("")
print('======== Epoch {:} / {:} ========'.format(epoch_i + 1, epochs))
print('Training...')

# Reset the total loss for this epoch.
total_train_loss = 0

# Put the model into training mode.
model.train()

# For each batch of training data...
num_batches = int(len(train_set)/batch_size)
if int(len(train_set)/batch_size)!=len(train_set)/batch_size:
num_batches+=1

for i in range(num_batches):
end_index = min(batch_size * (i+1), len(train_set))
batch = train_set[i*batch_size:end_index]
input_id_tensors = torch.stack([data[0] for data in batch])
input_mask_tensors = torch.stack([data[1] for data in batch])
label_tensors = torch.stack([data[2] for data in batch])

# Move tensors to the GPU
b_input_ids = input_id_tensors.to(device)
b_input_mask = input_mask_tensors.to(device)
b_labels = label_tensors.to(device)

# Clear the previously calculated gradient
model.zero_grad()

# Perform a forward pass (evaluate the model on this training batch).
outputs = model(b_input_ids,
token_type_ids=None,
attention_mask=b_input_mask,
labels=b_labels)
loss = outputs.loss
logits = outputs.logits

total_train_loss += loss.item()

# Perform a backward pass to calculate the gradients.
loss.backward()

# Update parameters and take a step using the computed gradient.
optimizer.step()

# ========================================
# Validation
# ========================================
# After the completion of each training epoch, measure our performance on
# our validation set. Implement this function in the cell above.
print(f"Total loss: {total_train_loss}")
val_acc = get_validation_performance(val_set)
print(f"Validation accuracy: {val_acc}")

print("")
print("Training complete!")
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.