<jupyter_start><jupyter_text><jupyter_code>import torch
import numpy as np
from torch import nn

class LineNetwork(nn.Module):
  # Inicialização
  def __init__(self):
    super().__init__()
    self.layers = nn.Sequential( #Sequential ira segur a ordem das camadas
        nn.linear(1,1)
    )

  #O que a rede ira executar com o dado de entrada
  def foward(self,x):
    return self.layers(x)
from torch.utils.data import Dataset, DataLoader
import torch.distributions.uniform as urand
class AlgebraicDataset(Dataset):
  def __init__(self, f, interval, nsamples):
    X = urand.Uniform(interval[0], interval[1]).sample([nsamples])
    self.data = [(x, f(x)) for x in X]

  def __len__(self):
    return len(self.data)

  def __getitem__(self, idx):
    return self.data[idx]
line = lambda x: 2*x + 3
interval = (-10, 10)
train_nsamples = 1000
test_nsamples = 100
train_dataset = AlgebraicDataset(line, interval, train_nsamples)
test_dataset = AlgebraicDataset(line, interval, test_nsamples)

train_dataloader = DataLoader(train_dataset, batch_size=train_nsamples, shuffle=True)
test_dataloader = DataLoader(test_dataset, batch_size=test_nsamples, shuffle=True)
device = "cuda" if torch.cuda.is_available() else "cpu"
print(f"Rodando na {device}")<jupyter_output>Rodando na cpu
{'fraction_non_alphanumeric': 0.10884886452623337, 'fraction_numerical': 0.01331245105716523, 'mean_word_length': 5.173913043478261, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '95792', 'license': 'Apache-2.0', 'n_tokens_mistral': 460, 'n_tokens_neox': 440, 'n_words': 115, 'path': 'DeepLearning00.ipynb', 'repo_name': 'Jenkidamaa/DeepLearning-Estudos', 'size': '1277'}