Advertisement
Roageev

Untitled

Apr 1st, 2024
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | Fixit | 0 0
  1. import torch
  2. import torch.nn as nn
  3.  
  4.  
  5. n_in_neurons = 5
  6. n_hidden_neurons = 3
  7. n_out_neurons = 1
  8.  
  9. net = nn.Sequential(
  10.     nn.Linear(n_in_neurons, n_hidden_neurons),
  11.     nn.ReLU(),
  12.     nn.Linear(n_hidden_neurons, n_out_neurons),
  13.     nn.BCEWithLogitsLoss()
  14. )
  15.  
  16. x = torch.Tensor([-0.23, -0.2, 0.31, -0.9, 0.2])
  17. y = torch.Tensor([0,])
  18. y_hat = net.forward(x) # прогоните x через нейронную сеть
  19.  
  20. loss = nn.BCEWithLogitsLoss() # инициализируйте функцию потерь бинарной кросс-энтропии
  21.  
  22. print(loss(y_hat, y))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement