Skip to content

Instantly share code, notes, and snippets.

@tomgrek
Last active June 22, 2020 17:11
Show Gist options
  • Save tomgrek/ff22289ed4d6f78c3aa746141b4b1469 to your computer and use it in GitHub Desktop.
Save tomgrek/ff22289ed4d6f78c3aa746141b4b1469 to your computer and use it in GitHub Desktop.
A PyTorch training loop
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