Last active
December 22, 2019 17:25
-
-
Save akshay-3apr/906412d5b6de917f57fdaade85a29ce0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load BertForSequenceClassification, the pretrained BERT model with a single linear classification layer on top. | |
model = BertForSequenceClassification.from_pretrained("bert-base-uncased", num_labels=2).to(device) | |
# Parameters: | |
lr = 2e-5 | |
adam_epsilon = 1e-8 | |
# Number of training epochs (authors recommend between 2 and 4) | |
epochs = 3 | |
num_warmup_steps = 0 | |
num_training_steps = len(train_dataloader)*epochs | |
### In Transformers, optimizer and schedules are splitted and instantiated like this: | |
optimizer = AdamW(model.parameters(), lr=lr,eps=adam_epsilon,correct_bias=False) # To reproduce BertAdam specific behavior set correct_bias=False | |
scheduler = get_linear_schedule_with_warmup(optimizer, num_warmup_steps=num_warmup_steps, num_training_steps=num_training_steps) # PyTorch scheduler |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment