Skip to Content
Deep Learning with PyTorch
book

Deep Learning with PyTorch

by Vishnu Subramanian
February 2018
Intermediate to advanced
262 pages
6h 59m
English
Packt Publishing
Content preview from Deep Learning with PyTorch

Creating a network model with embedding

We discussed word embeddings briefly earlier. In this section, we create word embeddings as part of our network architecture and train the entire model to predict the sentiment of each review. At the end of the training, we will have a sentiment classifier model and also the word embeddings for the IMDB datasets. The following code demonstrates how to create a network architecture to predict the sentiment using word embeddings:

class EmbNet(nn.Module):    def __init__(self,emb_size,hidden_size1,hidden_size2=400):        super().__init__()        self.embedding = nn.Embedding(emb_size,hidden_size1)        self.fc = nn.Linear(hidden_size2,3)            def forward(self,x):        embeds = self.embedding(x).view(x.size(0),-1) out = self.fc(embeds) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Deep Learning with PyTorch

Deep Learning with PyTorch

Eli Stevens, Thomas Viehmann, Luca Pietro Giovanni Antiga
Grokking Deep Learning

Grokking Deep Learning

Andrew W. Trask

Publisher Resources

ISBN: 9781788624336Supplemental Content