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

Method __init__

beginner_source/nlp/deep_learning_tutorial.py:261–274  ·  view source on GitHub ↗
(self, num_labels, vocab_size)

Source from the content-addressed store, hash-verified

259class BoWClassifier(nn.Module): # inheriting from nn.Module!
260
261 def __init__(self, num_labels, vocab_size):
262 # calls the init function of nn.Module. Dont get confused by syntax,
263 # just always do it in an nn.Module
264 super(BoWClassifier, self).__init__()
265
266 # Define the parameters that you will need. In this case, we need A and b,
267 # the parameters of the affine mapping.
268 # Torch defines nn.Linear(), which provides the affine map.
269 # Make sure you understand why the input dimension is vocab_size
270 # and the output is num_labels!
271 self.linear = nn.Linear(vocab_size, num_labels)
272
273 # NOTE! The non-linearity log softmax does not have parameters! So we don't need
274 # to worry about that here
275
276 def forward(self, bow_vec):
277 # Pass the input through the linear layer,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected