(self, vocab_size, embedding_dim, hidden_dim, num_class)
| 4 | |
| 5 | class MLP(nn.Module): |
| 6 | def __init__(self, vocab_size, embedding_dim, hidden_dim, num_class): |
| 7 | super(MLP, self).__init__() |
| 8 | # 词嵌入层 |
| 9 | self.embedding = nn.Embedding(vocab_size, embedding_dim) |
| 10 | # 线性变换:词嵌入层->隐含层 |
| 11 | self.linear1 = nn.Linear(embedding_dim, hidden_dim) |
| 12 | # 使用ReLU激活函数 |
| 13 | self.activate = F.relu |
| 14 | # 线性变换:激活层->输出层 |
| 15 | self.linear2 = nn.Linear(hidden_dim, num_class) |
| 16 | |
| 17 | def forward(self, inputs): |
| 18 | embeddings = self.embedding(inputs) |
nothing calls this directly
no outgoing calls
no test coverage detected