CoolFace
Apppublic

FakeNewsDetector/Space1

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
0likes
models.py20 linesDownload Raw Back to root
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, :])