CoolFace
Datasetpublic

ysn-rfd/text-dataset-tiny-code-script-py-format

USED of tahamajs/medicine_ds_persian for .parquet file USED of Alijafarixcs2/persian-it-llama2-2k for .parquet file USED of Abirate/english_quotes for .jsonl file NEW FILES (05/12/2025) NEW FILES (12/26/2025) NEW FILES (02/15/2026)

sourceHugging Faceapache-2.0updated 4mo agoView on Hugging Face
3likes1.7kdownloads
day1_2.py31 linesDownload Raw Back to pytorch_study
1import torch as t
2import torch.nn as nn
3
4x = t.randn(4,3)
5y = t.randn(4,2)
6
7linear = nn.Linear(3,2)
8
9print('w: ', linear.weight)
10print('b: ', linear.bias)
11
12criterion = nn.MSELoss()
13optimizer = t.optim.SGD(linear.parameters(), lr=0.01)
14
15pred = linear(x)
16
17loss = criterion(pred, y)
18print('loss: ', loss.item())
19
20loss.backward()
21
22print('dL/dw: ', linear.weight.grad)
23print('dL/db: ', linear.bias.grad)
24
25
26optimizer.step()
27
28pred = linear(x)
29loss = criterion(pred, y)
30
31print('loss after 1 step optimization', loss.item())