src.ml.pytorch_example

From: https://pytorch.org/tutorials/beginner/text_sentiment_ngrams_tutorial.html

Module Contents

Classes

TextSentiment

Base class for all neural network modules.

Functions

generate_batch(batch)

train_func(model, optimizer, criterion, scheduler, sub_train_)

test(model, criterion, data_)

main()

src.ml.pytorch_example.BATCH_SIZE = 16[source]
src.ml.pytorch_example.device[source]
class src.ml.pytorch_example.TextSentiment(vocab_size, embed_dim, num_class)[source]

Bases: torch.nn.Module

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing to nest them in a tree structure. You can assign the submodules as regular attributes:

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self):
        super(Model, self).__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

Submodules assigned in this way will be registered, and will have their parameters converted too when you call to(), etc.

init_weights(self)[source]
forward(self, text, offsets)[source]
src.ml.pytorch_example.generate_batch(batch)[source]
src.ml.pytorch_example.train_func(model, optimizer, criterion, scheduler, sub_train_)[source]
src.ml.pytorch_example.test(model, criterion, data_)[source]
src.ml.pytorch_example.main()[source]