Aprendizaje profundo intermedio con PyTorch
Michal Oleszak
Machine Learning Engineer


xhyh
h y y son los mismos.Tres entradas y salidas (dos estados ocultos):
h: estado a corto plazoc: estado a largo plazoTres «puertas»:
class Net(nn.Module): def __init__(self, input_size): super().__init__()self.lstm = nn.LSTM( input_size=1, hidden_size=32, num_layers=2, batch_first=True, ) self.fc = nn.Linear(32, 1)def forward(self, x): h0 = torch.zeros(2, x.size(0), 32) c0 = torch.zeros(2, x.size(0), 32)out, _ = self.lstm(x, (h0, c0))out = self.fc(out[:, -1, :]) return out
__init__():nn.RNN por nn.LSTMforward():cc y h con ceros.lstm.
class Net(nn.Module): def __init__(self, input_size): super().__init__()self.gru = nn.GRU( input_size=1, hidden_size=32, num_layers=2, batch_first=True, ) self.fc = nn.Linear(32, 1)def forward(self, x): h0 = torch.zeros(2, x.size(0), 32) out, _ = self.gru(x, h0) out = self.fc(out[:, -1, :]) return out
__init__():nn.RNN por nn.GRUforward():gru » (Ajustes globales).
Aprendizaje profundo intermedio con PyTorch