Last active
June 22, 2020 17:11
-
-
Save tomgrek/ff22289ed4d6f78c3aa746141b4b1469 to your computer and use it in GitHub Desktop.
A PyTorch training loop
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
criterion = nn.CrossEntropyLoss() | |
optimizer = optim.SGD(m.parameters(), lr=0.01) | |
for epoch in range(0,300): | |
gen = DataGenerator([words[word.lower()] for word in ' '.join(sentences).replace('?',' <unk>').split(' ')]) | |
for x, y in gen: | |
m.zero_grad() | |
output = m(x) | |
loss = criterion(output, y) | |
loss.backward() | |
optimizer.step() | |
print(loss) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment