<jupyter_start><jupyter_text><jupyter_code>import torch
from sklearn.datasets import make_blobs
from matplotlib import pyplot
from numpy import where


num_features=2
num_class=3
num_samples=1000
x,yt=make_blobs(n_samples=num_samples,n_features=num_features,centers=num_class,cluster_std=1.0, random_state=1)

for class_value in range (num_class):
  row_idx=where(yt==class_value)
  pyplot.scatter(x[row_idx,0],x[row_idx,1])

pyplot.show()

x_train=torch.tensor(x[:int(0.6*num_samples),:]).float()
y_train=torch.tensor(yt[:int(0.6*num_samples)]).long()
x_valid=torch.tensor(x[int(0.6*num_samples):int(0.75*num_samples),:]).float()
y_valid=torch.tensor(yt[int(0.6*num_samples):int(0.75*num_samples)]).long()
x_test=torch.tensor(x[int(0.75*num_samples):,:]).float()
y_test=torch.tensor(yt[int(0.75*num_samples):]).long()

num_hidden=10
model=torch.nn.Sequential(torch.nn.Linear(num_features,num_hidden),
                          torch.nn.ReLU(),
                          torch.nn.Linear(num_hidden,num_class),
                          )



loss=torch.nn.CrossEntropyLoss()
optimizer=torch.optim.Adam(model.parameters(), lr=0.001)
#x=torch.FloatTensor(x)
#yt=torch.LongTensor(yt)
num_epochs=200
for epoch in range(num_epochs):
  optimizer.zero_grad()
  yp=model(x_train)
  print(yp)
  loss_value=loss(yp,y_train)
  num_corrects=torch.sum(torch.max(yp,1)[1]==y_train)
  acc_train=num_corrects.float()/num_samples.__float__()
  loss_value.backward()
  optimizer.step()

  yp=model(x_valid)
  num_corrects=torch.sum(torch.max(yp,1)[1]==y_valid)
  acc_valid=num_corrects.float()/num_samples.__float__()
  print('Epoch',epoch,'Loss:', loss_value,'accuracy_train',acc_train.item(),'accuracy_valid',acc_valid.item())

yp=model(x_test)
num_corrects=torch.sum(torch.max(yp,1)[1]==y_test)
acc_test=num_corrects.float()/num_samples.__float__()
print('Test Accuracy_valid',acc_test.item())<jupyter_output><empty_output><jupyter_text><jupyter_code>model.bias.grad<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16464646464646465, 'fraction_numerical': 0.023232323232323233, 'mean_word_length': 7.0528455284552845, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '197070', 'license': 'MIT', 'n_tokens_mistral': 813, 'n_tokens_neox': 812, 'n_words': 65, 'path': 'Untitled2.ipynb', 'repo_name': 'kazemiakk/PINNs', 'size': '1980'}