Spaces:
Sleeping

File size: 771 Bytes
9d39afd
 
 
 
f16843d
9d39afd
f16843d
 
 
 
 
104752c
f16843d
9d39afd
104752c
9d39afd
 
104752c
9d39afd
f16843d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import torch.nn as nn

class LSTMClassifier(nn.Module):
    def __init__(self, vocab_size, embed_dim, hidden_dim, output_dim, n_layers, dropout):
        super().__init__()
        self.embedding = nn.Embedding(vocab_size, embed_dim)
        self.lstm = nn.LSTM(
            embed_dim, 
            hidden_dim,
            num_layers=n_layers,
            batch_first=True,
            dropout=dropout if n_layers > 1 else 0
        )
        self.fc = nn.Linear(hidden_dim, output_dim)
        self.dropout_layer = nn.Dropout(dropout)  # Renamed to avoid conflict

    def forward(self, x):
        embedded = self.dropout_layer(self.embedding(x))  # Use the renamed attribute
        output, (hidden, cell) = self.lstm(embedded)
        return self.fc(output[:, -1, :])