Skip to content

Instantly share code, notes, and snippets.

@blythed
Created April 6, 2022 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blythed/0183182140868fcd140cd9b0150053a4 to your computer and use it in GitHub Desktop.
Save blythed/0183182140868fcd140cd9b0150053a4 to your computer and use it in GitHub Desktop.
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