FakeNewsDetector/Space1
0
1import torch.nn as nn2 3class LSTMClassifier(nn.Module):4 def __init__(self, vocab_size, embed_dim, hidden_dim, output_dim, n_layers, dropout):5 super().__init__()6 self.embedding = nn.Embedding(vocab_size, embed_dim)7 self.lstm = nn.LSTM(8 embed_dim, 9 hidden_dim,10 num_layers=n_layers,11 batch_first=True,12 dropout=dropout if n_layers > 1 else 013 )14 self.fc = nn.Linear(hidden_dim, output_dim)15 self.dropout_layer = nn.Dropout(dropout) # Renamed to avoid conflict16 17 def forward(self, x):18 embedded = self.dropout_layer(self.embedding(x)) # Use the renamed attribute19 output, (hidden, cell) = self.lstm(embedded)20 return self.fc(output[:, -1, :])