Download src/part2/ffn.py from Chechaaa09/anlp-a2-models: direct link, hf CLI and curl.
- Browser
- Download file 469 Bytes
-
https://huggingface.co/Chechaaa09/anlp-a2-models/resolve/main/src/part2/ffn.py
- Command line
-
hf download hf://Chechaaa09/anlp-a2-models/src/part2/ffn.py
-
curl -L -o ffn.py https://huggingface.co/Chechaaa09/anlp-a2-models/resolve/main/src/part2/ffn.py
469 Bytes
| import torch | |
| import torch.nn as nn | |
| import torch.nn.functional as F | |
| class PositionWiseFFN(nn.Module): | |
| def __init__(self, d_model, d_ff, dropout=0.1): | |
| super().__init__() | |
| self.linear1 = nn.Linear(d_model, d_ff) | |
| self.linear2 = nn.Linear(d_ff, d_model) | |
| self.dropout = nn.Dropout(dropout) | |
| def forward(self, x): | |
| x = self.linear1(x) | |
| x = F.relu(x) | |
| x = self.dropout(x) | |
| x = self.linear2(x) | |
| return x |