Created
April 6, 2022 12:27
-
-
Save blythed/0183182140868fcd140cd9b0150053a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
class HiddenState(torch.nn.Layer): | |
def __init__(self, layer): | |
super().__init__() | |
self.layer = layer | |
def forward(self, x): | |
return self.layer(x)[0] | |
def build_classifier( | |
rnn_layer, | |
n_tokens, | |
): | |
return torch.nn.Sequential( | |
torch.nn.Embedding(n_tokens, n_embed), | |
HiddenState(rnn_layer), | |
torch.nn.ReLU(), | |
torch.nn.Linear(rnn_layer.hidden_size, 1), | |
torch.nn.Sigmoid(), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment