MCPcopy Create free account
hub / github.com/AtlasAnalyticsLab/AdaFisher / forward

Method forward

Language_Model/GPT1.py:339–367  ·  view source on GitHub ↗

Mini GPT-1. This is a small version of OpenAI's GPT-1 transformer for (causal) language modeling. This module returns for each position in the sequence the log-probabilities of the next token. Parameters ---------- inputs (`torch.LongTensor` of shape

(self, inputs)

Source from the content-addressed store, hash-verified

337 return embeddings
338
339 def forward(self, inputs):
340 """Mini GPT-1.
341
342 This is a small version of OpenAI's GPT-1 transformer for (causal)
343 language modeling. This module returns for each position in the
344 sequence the log-probabilities of the next token.
345
346 Parameters
347 ----------
348 inputs (`torch.LongTensor` of shape `(batch_size, sequence_length)`)
349 The input tensor containing the token sequences.
350
351 Returns
352 -------
353 log_probas (`torch.FloatTensor` of shape `(batch_size, sequence_length, vocabulary_size)`)
354 A tensor containing the log-probabilities of the next token for
355 all positions in each sequence of the batch. For example, `log_probas[0, 3, 6]`
356 corresponds to log p(x_{5} = token_{7} | x_{0:4}) (x_{5} for the word
357 after x_{4} at index 3, and token_{7} for index 6) for the 1st sequence
358 of the batch (index 0).
359 """
360
361 # ==========================
362 x = self.get_embeddings(inputs)
363 for layer in self.layers:
364 x = layer(x)
365 outputs = nn.LogSoftmax(dim=-1)(self.classifier(x))
366 # ==========================
367 return outputs
368
369 def loss(self, log_probas, targets, mask):
370 """Loss function.

Callers

nothing calls this directly

Calls 1

get_embeddingsMethod · 0.95

Tested by

no test coverage detected