Download Deception/Code/Multitask_Learning/base_network.py from ankurani/deception: direct link, hf CLI and curl.
- Browser
- Download file 968 Bytes
-
https://huggingface.co/datasets/ankurani/deception/resolve/refs%2Fpr%2F1/Deception/Code/Multitask_Learning/base_network.py
- Command line
-
hf download hf://datasets/ankurani/deception@refs/pr/1/Deception/Code/Multitask_Learning/base_network.py
-
curl -L -o base_network.py https://huggingface.co/datasets/ankurani/deception/resolve/refs%2Fpr%2F1/Deception/Code/Multitask_Learning/base_network.py
968 Bytes
| # Code for making a base nework that would take tokenized input and pass it through an embedding layer and then through a LSTM layer to get the output | |
| import torch | |
| import torch.nn as nn | |
| import torch.nn.functional as F | |
| import torch.optim as optim | |
| class base_network(nn.Module): | |
| def __init__(self, input_size, embedding_size, hidden_size, num_layers, dropout, bidirectional, device): | |
| super(base_network, self).__init__() | |
| self.embedding = nn.Embedding(input_size, embedding_size) | |
| self.lstm = nn.LSTM(embedding_size, hidden_size, num_layers, batch_first=True, | |
| dropout=dropout, bidirectional=bidirectional) | |
| # self.fc = nn.Linear(hidden_size, output_size) | |
| self.device = device | |
| def forward(self, x): | |
| x = x.to(self.device) | |
| x = self.embedding(x) | |
| x, (h_n, c_n) = self.lstm(x) | |
| out = torch.permute(h_n[-2:, :, :], (1, 0, 2)).reshape(x.size(0), -1) | |
| return out | |