MCPcopy Create free account
hub / github.com/pytorch/tutorials / __init__

Method __init__

beginner_source/nlp/advanced_tutorial.py:154–179  ·  view source on GitHub ↗
(self, vocab_size, tag_to_ix, embedding_dim, hidden_dim)

Source from the content-addressed store, hash-verified

152class BiLSTM_CRF(nn.Module):
153
154 def __init__(self, vocab_size, tag_to_ix, embedding_dim, hidden_dim):
155 super(BiLSTM_CRF, self).__init__()
156 self.embedding_dim = embedding_dim
157 self.hidden_dim = hidden_dim
158 self.vocab_size = vocab_size
159 self.tag_to_ix = tag_to_ix
160 self.tagset_size = len(tag_to_ix)
161
162 self.word_embeds = nn.Embedding(vocab_size, embedding_dim)
163 self.lstm = nn.LSTM(embedding_dim, hidden_dim // 2,
164 num_layers=1, bidirectional=True)
165
166 # Maps the output of the LSTM into tag space.
167 self.hidden2tag = nn.Linear(hidden_dim, self.tagset_size)
168
169 # Matrix of transition parameters. Entry i,j is the score of
170 # transitioning *to* i *from* j.
171 self.transitions = nn.Parameter(
172 torch.randn(self.tagset_size, self.tagset_size))
173
174 # These two statements enforce the constraint that we never transfer
175 # to the start tag and we never transfer from the stop tag
176 self.transitions.data[tag_to_ix[START_TAG], :] = -10000
177 self.transitions.data[:, tag_to_ix[STOP_TAG]] = -10000
178
179 self.hidden = self.init_hidden()
180
181 def init_hidden(self):
182 return (torch.randn(2, 1, self.hidden_dim // 2),

Callers

nothing calls this directly

Calls 1

init_hiddenMethod · 0.95

Tested by

no test coverage detected