Lecture 13 RNN Classifier
Lecture 13 RNN Classifier
Lecturer : Hongpu Liu Lecture 13-1 PyTorch Tutorial @ SLAM Research Group
RNN Classifier – Name Classification
Name Country
Maclean English
Vajnichy Russian
Nasikovsky Russian We shall train on a few thousand
Usami Japanese surnames from 18 languages of origin,
Fionin Russian and predict which language a name is
Balagul Russian
Pakhrin Russian
Tansho Japanese
Lecturer : Hongpu Liu Lecture 13-2 PyTorch Tutorial @ SLAM Research Group
Revision
𝑜1 𝑜2 𝑜3 𝑜4 𝑜5
ℎ0 RNN Cell RNN Cell RNN Cell RNN Cell RNN Cell ℎ5
𝑥1 𝑥2 𝑥3 𝑥4 𝑥𝑁
Lecturer : Hongpu Liu Lecture 13-3 PyTorch Tutorial @ SLAM Research Group
Our Model
Linear
Layer
𝑥1 𝑥2 𝑥3 𝑥𝑁
Lecturer : Hongpu Liu Lecture 13-4 PyTorch Tutorial @ SLAM Research Group
Our Model
ℎ0
Embedding ℎ𝑁 Linear
𝒙 GRU Layer 𝑜
Layer Layer
Name Country
Maclean English
Vajnichy Russian
Nasikovsky Russian
Usami Japanese
Fionin Russian
Sharkey English
Balagul Russian
Pakhrin Russian
Tansho Japanese
Lecturer : Hongpu Liu Lecture 13-5 PyTorch Tutorial @ SLAM Research Group
Our Model
ℎ0
Embedding ℎ𝑁 Linear
𝒙 GRU Layer 𝑜
Layer Layer
Name Country
Maclean English
Vajnichy Russian
Nasikovsky Russian
Usami Japanese
Fionin Russian
Sharkey English
Balagul Russian
Pakhrin Russian
Tansho Japanese
Lecturer : Hongpu Liu Lecture 13-6 PyTorch Tutorial @ SLAM Research Group
Implementation – Main Cycle
if __name__ == '__main__':
classifier = RNNClassifier(N_CHARS, HIDDEN_SIZE, N_COUNTRY, N_LAYER)
if USE_GPU:
device = torch.device("cuda:0") Instantiate the classifier
classifier.to(device)
model.
criterion = torch.nn.CrossEntropyLoss()
optimizer = torch.optim.Adam(classifier.parameters(), lr=0.001)
start = time.time()
print("Training for %d epochs..." % N_EPOCHS)
acc_list = []
for epoch in range(1, N_EPOCHS + 1):
# Train cycle
trainModel()
acc = testModel()
acc_list.append(acc)
Lecturer : Hongpu Liu Lecture 13-7 PyTorch Tutorial @ SLAM Research Group
Implementation – Main Cycle
if __name__ == '__main__':
classifier = RNNClassifier(N_CHARS, HIDDEN_SIZE, N_COUNTRY, N_LAYER)
if USE_GPU:
device = torch.device("cuda:0")
Whether use GPU for
classifier.to(device)
training model.
criterion = torch.nn.CrossEntropyLoss()
optimizer = torch.optim.Adam(classifier.parameters(), lr=0.001)
start = time.time()
print("Training for %d epochs..." % N_EPOCHS)
acc_list = []
for epoch in range(1, N_EPOCHS + 1):
# Train cycle
trainModel()
acc = testModel()
acc_list.append(acc)
Lecturer : Hongpu Liu Lecture 13-8 PyTorch Tutorial @ SLAM Research Group
Implementation – Main Cycle
if __name__ == '__main__':
classifier = RNNClassifier(N_CHARS, HIDDEN_SIZE, N_COUNTRY, N_LAYER)
if USE_GPU:
device = torch.device("cuda:0")
classifier.to(device)
Using cross entropy loss
criterion = torch.nn.CrossEntropyLoss()
optimizer = torch.optim.Adam(classifier.parameters(), lr=0.001) as loss function.
Using Adam optimizer.
start = time.time()
print("Training for %d epochs..." % N_EPOCHS)
acc_list = []
for epoch in range(1, N_EPOCHS + 1):
# Train cycle
trainModel()
acc = testModel()
acc_list.append(acc)
Lecturer : Hongpu Liu Lecture 13-9 PyTorch Tutorial @ SLAM Research Group
Implementation – Main Cycle
if __name__ == '__main__':
classifier = RNNClassifier(N_CHARS, HIDDEN_SIZE, N_COUNTRY, N_LAYER)
if USE_GPU:
device = torch.device("cuda:0")
For printing elapsed
classifier.to(device)
time.
criterion = torch.nn.CrossEntropyLoss()
optimizer = torch.optim.Adam(classifier.parameters(), lr=0.001)
start = time.time()
print("Training for %d epochs..." % N_EPOCHS)
def time_since(since):
acc_list = []
s = time.time() - since
for epoch in range(1, N_EPOCHS + 1):
m = math.floor(s / 60)
# Train cycle
s -= m * 60
trainModel()
return '%dm %ds' % (m, s)
acc = testModel()
acc_list.append(acc)
Lecturer : Hongpu Liu Lecture 13-10 PyTorch Tutorial @ SLAM Research Group
Implementation – Main Cycle
if __name__ == '__main__':
classifier = RNNClassifier(N_CHARS, HIDDEN_SIZE, N_COUNTRY, N_LAYER)
if USE_GPU:
device = torch.device("cuda:0")
classifier.to(device)
criterion = torch.nn.CrossEntropyLoss()
optimizer = torch.optim.Adam(classifier.parameters(), lr=0.001)
start = time.time()
print("Training for %d epochs..." % N_EPOCHS)
acc_list = []
for epoch in range(1, N_EPOCHS + 1): In every epoch, training
# Train cycle and testing the model
trainModel()
acc = testModel() once.
acc_list.append(acc)
Lecturer : Hongpu Liu Lecture 13-11 PyTorch Tutorial @ SLAM Research Group
Implementation – Main Cycle
if __name__ == '__main__':
classifier = RNNClassifier(N_CHARS, HIDDEN_SIZE, N_COUNTRY, N_LAYER)
if USE_GPU:
device = torch.device("cuda:0")
Recording the accuracy
classifier.to(device)
of testing.
criterion = torch.nn.CrossEntropyLoss()
optimizer = torch.optim.Adam(classifier.parameters(), lr=0.001)
import matplotlib.pyplot as plt
start = time.time() import numpy as np
print("Training for %d epochs..." % N_EPOCHS)
acc_list = [] epoch = np.arange(1, len(acc_list) + 1, 1)
for epoch in range(1, N_EPOCHS + 1): acc_list = np.array(acc_list)
# Train cycle plt.plot(epoch, acc_list)
trainModel() plt.xlabel('Epoch')
acc = testModel() plt.ylabel('Accuracy')
acc_list.append(acc) plt.grid()
plt.show()
Lecturer : Hongpu Liu Lecture 13-12 PyTorch Tutorial @ SLAM Research Group
Implementation – Preparing Data
Maclean ['M', 'a', 'c', 'l', 'e', 'a', 'n'] [ 77 97 99 108 101 97 110]
Vajnichy ['V', 'a', 'j', 'n', 'i', 'c', 'h', 'y'] [ 86 97 106 110 105 99 104 121]
Nasikovsky ['N', 'a', 's', 'i', 'k', 'o', 'v', 's', 'k', 'y'] [ 78 97 115 105 107 111 118 115 107 121]
Fionin ['F', 'i', 'o', 'n', 'i', 'n'] [ 70 105 111 110 105 110]
Sharkey ['S', 'h', 'a', 'r', 'k', 'e', 'y'] [ 83 104 97 114 107 101 121]
Balagul ['B', 'a', 'l', 'a', 'g', 'u', 'l'] [ 66 97 108 97 103 117 108]
Pakhrin ['P', 'a', 'k', 'h', 'r', 'i', 'n'] [ 80 97 107 104 114 105 110]
Tansho ['T', 'a', 'n', 's', 'h', 'o'] [ 84 97 110 115 104 111]
Lecturer : Hongpu Liu Lecture 13-13 PyTorch Tutorial @ SLAM Research Group
Implementation – Preparing Data
[ 86 97 106 110 105 99 104 121] [ 86 97 106 110 105 99 104 121 0 0]
[ 78 97 115 105 107 111 118 115 107 121] [ 78 97 115 105 107 111 118 115 107 121]
[ 70 105 111 110 105 110] [ 70 105 111 110 105 110 0 0 0 0]
[ 83 104 97 114 107 101 121] [ 83 104 97 114 107 101 121 0 0 0]
[ 80 97 107 104 114 105 110] [ 80 97 107 104 114 105 110 0 0 0]
Lecturer : Hongpu Liu Lecture 13-14 PyTorch Tutorial @ SLAM Research Group
Implementation – Preparing Data
Lecturer : Hongpu Liu Lecture 13-15 PyTorch Tutorial @ SLAM Research Group
Implementation – Preparing Data
class NameDataset(Dataset):
def __init__(self, is_train_set=True):
filename = 'data/names_train.csv.gz' if is_train_set else 'data/names_test.csv.gz'
with gzip.open(filename, 'rt') as f:
Reading data from .gz reader = csv.reader(f)
file with package gzip rows = list(reader)
self.names = [row[0] for row in rows]
and csv. self.len = len(self.names)
self.countries = [row[1] for row in rows]
import gzip self.country_list = list(sorted(set(self.countries)))
self.country_dict = self.getCountryDict()
import csv
self.country_num = len(self.country_list)
def __len__(self):
return self.len
Lecturer : Hongpu Liu Lecture 13-16 PyTorch Tutorial @ SLAM Research Group
Implementation – Preparing Data
class NameDataset(Dataset):
def __init__(self, is_train_set=True):
filename = 'data/names_train.csv.gz' if is_train_set else 'data/names_test.csv.gz'
with gzip.open(filename, 'rt') as f:
Name Country
reader = csv.reader(f)
Maclean English
rows = list(reader)
Vajnichy Russian
self.names = [row[0] for row in rows]
Save names and Nasikovsky Russian
self.len = len(self.names)
countries in list. self.countries = [row[1] for row in rows] Usami Japanese
def __len__(self):
return self.len
Lecturer : Hongpu Liu Lecture 13-17 PyTorch Tutorial @ SLAM Research Group
Implementation – Preparing Data
self.country_list = list(sorted(set(self.countries)))
index in list and self.country_dict = self.getCountryDict()
self.country_num = len(self.country_list)
dictionary.
def __getitem__(self, index):
return self.names[index], self.country_dict[self.countries[index]]
def __len__(self):
return self.len
Lecturer : Hongpu Liu Lecture 13-18 PyTorch Tutorial @ SLAM Research Group
Implementation – Preparing Data
self.country_list = list(sorted(set(self.countries)))
self.country_dict = self.getCountryDict()
self.country_num = len(self.country_list)
Save countries and its
def __getitem__(self, index):
index in list and return self.names[index], self.country_dict[self.countries[index]]
dictionary.
def __len__(self):
return self.len
Lecturer : Hongpu Liu Lecture 13-19 PyTorch Tutorial @ SLAM Research Group
Implementation – Preparing Data
self.country_list = list(sorted(set(self.countries)))
self.country_dict = self.getCountryDict()
self.country_num = len(self.country_list)
Save countries and its
def __getitem__(self, index):
index in list and return self.names[index], self.country_dict[self.countries[index]]
dictionary.
def __len__(self):
return self.len
Lecturer : Hongpu Liu Lecture 13-20 PyTorch Tutorial @ SLAM Research Group
Implementation – Preparing Data
class NameDataset(Dataset):
def __init__(self, is_train_set=True):
filename = 'data/names_train.csv.gz' if is_train_set else 'data/names_test.csv.gz'
with gzip.open(filename, 'rt') as f:
reader = csv.reader(f)
rows = list(reader)
self.names = [row[0] for row in rows]
self.len = len(self.names)
self.countries = [row[1] for row in rows]
self.country_list = list(sorted(set(self.countries)))
self.country_dict = self.getCountryDict()
self.country_num = len(self.country_list)
Lecturer : Hongpu Liu Lecture 13-21 PyTorch Tutorial @ SLAM Research Group
Implementation – Preparing Data
def getCountriesNum(self):
return self.country_num
Lecturer : Hongpu Liu Lecture 13-22 PyTorch Tutorial @ SLAM Research Group
Implementation – Preparing Data
Lecturer : Hongpu Liu Lecture 13-23 PyTorch Tutorial @ SLAM Research Group
Implementation – Preparing Data
Lecturer : Hongpu Liu Lecture 13-24 PyTorch Tutorial @ SLAM Research Group
Implementation – Preparing Data
trainset = NameDataset(is_train_set=True)
trainloader = DataLoader(trainset, batch_size=BATCH_SIZE, shuffle=True)
testset = NameDataset(is_train_set=False)
testloader = DataLoader(testset, batch_size=BATCH_SIZE, shuffle=False)
N_COUNTRY = trainset.getCountriesNum()
Lecturer : Hongpu Liu Lecture 13-25 PyTorch Tutorial @ SLAM Research Group
Implementation – Preparing Data
trainset = NameDataset(is_train_set=True)
trainloader = DataLoader(trainset, batch_size=BATCH_SIZE, shuffle=True)
testset = NameDataset(is_train_set=False)
testloader = DataLoader(testset, batch_size=BATCH_SIZE, shuffle=False)
N_COUNTRY = trainset.getCountriesNum()
Lecturer : Hongpu Liu Lecture 13-26 PyTorch Tutorial @ SLAM Research Group
Implementation – Preparing Data
# Parameters
HIDDEN_SIZE = 100
BATCH_SIZE = 256
N_LAYER = 2
N_EPOCHS = 100
trainset = NameDataset(is_train_set=True) N_CHARS = 128
trainloader = DataLoader(trainset, batch_size=BATCH_SIZE, shuffle=True)
USE_GPU = False
testset = NameDataset(is_train_set=False)
testloader = DataLoader(testset, batch_size=BATCH_SIZE, shuffle=False)
N_COUNTRY = trainset.getCountriesNum()
Lecturer : Hongpu Liu Lecture 13-27 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
class RNNClassifier(torch.nn.Module):
def __init__(self, input_size, hidden_size, output_size, n_layers=1, bidirectional=True):
super(RNNClassifier, self).__init__()
self.hidden_size = hidden_size
self.n_layers = n_layers
self.n_directions = 2 if bidirectional else 1
Lecturer : Hongpu Liu Lecture 13-28 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
class RNNClassifier(torch.nn.Module):
def __init__(self, input_size, hidden_size, output_size, n_layers=1, bidirectional=True):
super(RNNClassifier, self).__init__()
self.hidden_size = hidden_size Parameters of GRU layer.
self.n_layers = n_layers
self.n_directions = 2 if bidirectional else 1
Lecturer : Hongpu Liu Lecture 13-29 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
Lecturer : Hongpu Liu Lecture 13-30 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
Lecturer : Hongpu Liu Lecture 13-31 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
class RNNClassifier(torch.nn.Module):
def __init__(self, input_size, hidden_size, output_size, n_layers=1, bidirectional=True):
super(RNNClassifier, self).__init__()
self.hidden_size = hidden_size
What is the Bi-Direction RNN/LSTM/GRU?
self.n_layers = n_layers
self.n_directions = 2 if bidirectional else 1
Lecturer : Hongpu Liu Lecture 13-32 PyTorch Tutorial @ SLAM Research Group
Implementation – Bi-direction RNN/LSTM/GRU
𝒇
𝒉𝟎 RNN Cell
𝒙𝟏
Lecturer : Hongpu Liu Lecture 13-33 PyTorch Tutorial @ SLAM Research Group
Implementation – Bi-direction RNN/LSTM/GRU
𝒇
𝒉𝟎 RNN Cell RNN Cell
𝒙𝟏 𝒙𝟐
Lecturer : Hongpu Liu Lecture 13-34 PyTorch Tutorial @ SLAM Research Group
Implementation – Bi-direction RNN/LSTM/GRU
𝒇
𝒉𝟎 RNN Cell RNN Cell RNN Cell
𝒙𝟏 𝒙𝟐 𝒙𝑵−𝟏
Lecturer : Hongpu Liu Lecture 13-35 PyTorch Tutorial @ SLAM Research Group
Implementation – Bi-direction RNN/LSTM/GRU
𝒇 𝒇
𝒉𝟎 RNN Cell RNN Cell RNN Cell RNN Cell 𝒉𝑵
Forward
𝒙𝟏 𝒙𝟐 𝒙𝑵−𝟏 𝒙𝑵
Lecturer : Hongpu Liu Lecture 13-36 PyTorch Tutorial @ SLAM Research Group
Implementation – Bi-direction RNN/LSTM/GRU
𝒉𝒃𝟎
𝒇 𝒇
𝒉𝟎 RNN Cell RNN Cell RNN Cell RNN Cell 𝒉𝑵
𝒙𝟏 𝒙𝟐 𝒙𝑵−𝟏 𝒙𝑵
Lecturer : Hongpu Liu Lecture 13-37 PyTorch Tutorial @ SLAM Research Group
Implementation – Bi-direction RNN/LSTM/GRU
𝒇 𝒇
𝒉𝟎 RNN Cell RNN Cell RNN Cell RNN Cell 𝒉𝑵
𝒙𝟏 𝒙𝟐 𝒙𝑵−𝟏 𝒙𝑵
Lecturer : Hongpu Liu Lecture 13-38 PyTorch Tutorial @ SLAM Research Group
Implementation – Bi-direction RNN/LSTM/GRU
𝒉𝑵
Concat
𝒇 𝒇
𝒉𝟎 RNN Cell RNN Cell RNN Cell RNN Cell 𝒉𝑵
𝒙𝟏 𝒙𝟐 𝒙𝑵−𝟏 𝒙𝑵
Lecturer : Hongpu Liu Lecture 13-39 PyTorch Tutorial @ SLAM Research Group
Implementation – Bi-direction RNN/LSTM/GRU
𝒉𝑵
Concat
𝒇 𝒇
𝒉𝟎 RNN Cell RNN Cell RNN Cell RNN Cell 𝒉𝑵
𝒙𝟏 𝒙𝟐 𝒙𝑵−𝟏 𝒙𝑵
Lecturer : Hongpu Liu Lecture 13-40 PyTorch Tutorial @ SLAM Research Group
Implementation – Bi-direction RNN/LSTM/GRU
𝒉𝑵−𝟏 𝒉𝑵
Concat Concat
𝒇 𝒇
𝒉𝟎 RNN Cell RNN Cell RNN Cell RNN Cell 𝒉𝑵
𝒙𝟏 𝒙𝟐 𝒙𝑵−𝟏 𝒙𝑵
Lecturer : Hongpu Liu Lecture 13-41 PyTorch Tutorial @ SLAM Research Group
Implementation – Bi-direction RNN/LSTM/GRU
𝒉𝑵−𝟏 𝒉𝑵
Concat Concat
𝒇 𝒇
𝒉𝟎 RNN Cell RNN Cell RNN Cell RNN Cell 𝒉𝑵
𝒙𝟏 𝒙𝟐 𝒙𝑵−𝟏 𝒙𝑵
Lecturer : Hongpu Liu Lecture 13-42 PyTorch Tutorial @ SLAM Research Group
Implementation – Bi-direction RNN/LSTM/GRU
𝒉𝑵−𝟏 𝒉𝑵
Concat Concat
𝒇 𝒇
𝒉𝟎 RNN Cell RNN Cell RNN Cell RNN Cell 𝒉𝑵
𝒙𝟏 𝒙𝟐 𝒙𝑵−𝟏 𝒙𝑵
Lecturer : Hongpu Liu Lecture 13-43 PyTorch Tutorial @ SLAM Research Group
Implementation – Bi-direction RNN/LSTM/GRU
𝒉𝟏 𝒉𝑵−𝟏 𝒉𝑵
𝒇 𝒇
𝒉𝟎 RNN Cell RNN Cell RNN Cell RNN Cell 𝒉𝑵
𝒙𝟏 𝒙𝟐 𝒙𝑵−𝟏 𝒙𝑵
Lecturer : Hongpu Liu Lecture 13-44 PyTorch Tutorial @ SLAM Research Group
Implementation – Bi-direction RNN/LSTM/GRU
𝒉𝟏 𝒉𝑵−𝟏 𝒉𝑵
𝒇 𝒇
𝒉𝟎 RNN Cell RNN Cell RNN Cell RNN Cell 𝒉𝑵
𝒙𝟏 𝒙𝟐 𝒙𝑵−𝟏 𝒙𝑵
Lecturer : Hongpu Liu Lecture 13-45 PyTorch Tutorial @ SLAM Research Group
Implementation – Bi-direction RNN/LSTM/GRU
𝒉𝟎 𝒉𝟏 𝒉𝑵−𝟏 𝒉𝑵
𝒇 𝒇
𝒉𝟎 RNN Cell RNN Cell RNN Cell RNN Cell 𝒉𝑵
𝒙𝟏 𝒙𝟐 𝒙𝑵−𝟏 𝒙𝑵
Lecturer : Hongpu Liu Lecture 13-46 PyTorch Tutorial @ SLAM Research Group
Implementation – Bi-direction RNN/LSTM/GRU
𝒉𝟎 𝒉𝟏 𝒉𝑵−𝟏 𝒉𝑵
Backward
𝒉𝒃𝑵 RNN Cell RNN Cell RNN Cell RNN Cell 𝒉𝒃𝟎
𝒇 𝒇
𝒉𝟎 RNN Cell RNN Cell RNN Cell RNN Cell 𝒉𝑵
𝒙𝟏 𝒙𝟐 𝒙𝑵−𝟏 𝒙𝑵
Lecturer : Hongpu Liu Lecture 13-47 PyTorch Tutorial @ SLAM Research Group
Implementation – Bi-direction RNN/LSTM/GRU
output 𝒉𝟎 𝒉𝟏 𝒉𝑵−𝟏 𝒉𝑵
𝒉𝒃𝑵 RNN Cell RNN Cell RNN Cell RNN Cell 𝒉𝒃𝟎
𝒇 𝒇
𝒉𝟎 RNN Cell RNN Cell RNN Cell RNN Cell 𝒉𝑵
𝒙𝟏 𝒙𝟐 𝒙𝑵−𝟏 𝒙𝑵
Lecturer : Hongpu Liu Lecture 13-48 PyTorch Tutorial @ SLAM Research Group
Implementation – Bi-direction RNN/LSTM/GRU
𝒉𝟎 𝒉𝟏 𝒉𝑵−𝟏 𝒉𝑵
𝒇 𝒃
𝒉𝒃𝑵 RNN Cell
𝒉𝒊𝒅𝒅𝒆𝒏 =
RNN Cell
𝒉𝑵 , 𝒉𝑵
RNN Cell RNN Cell 𝒉𝒃𝟎
𝒇 𝒇
𝒉𝟎 RNN Cell RNN Cell RNN Cell RNN Cell 𝒉𝑵
𝒙𝟏 𝒙𝟐 𝒙𝑵−𝟏 𝒙𝑵
Lecturer : Hongpu Liu Lecture 13-49 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
Lecturer : Hongpu Liu Lecture 13-50 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
Lecturer : Hongpu Liu Lecture 13-51 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
class RNNClassifier(torch.nn.Module):
def forward(self, input, seq_lengths):
# input shape : B x S -> S x B
input = input.t()
batch_size = input.size(1)
hidden = self._init_hidden(batch_size)
embedding = self.embedding(input)
# pack them up
gru_input = pack_padded_sequence(embedding, seq_lengths)
Lecturer : Hongpu Liu Lecture 13-52 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
class RNNClassifier(torch.nn.Module):
def forward(self, input, seq_lengths):
# input shape : B x S -> S x B
input = input.t()
batch_size = input.size(1)
hidden = self._init_hidden(batch_size)
embedding = self.embedding(input)
# pack them up
gru_input = pack_padded_sequence(embedding, seq_lengths)
Lecturer : Hongpu Liu Lecture 13-53 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
class RNNClassifier(torch.nn.Module):
def forward(self, input, seq_lengths):
# input shape : B x S -> S x B
input = input.t()
batch_size = input.size(1)
hidden = self._init_hidden(batch_size)
After padding After transpose
[ 77 97 99 embedding
108 101 97 110 = 0self.embedding(input)
0 0] 77 86 78 85 70 83 66 80 84
[ 78 # pack them up
97 115 105 107 111 118 115 107 121]
99 106 115 97 111 97 108 107 110
[ 85 115
gru_input
97 109 105 0 0
= 0pack_padded_sequence(embedding,
0 0]
seq_lengths)
108 110 105 109 110 114 97 104 115
101 105 107 105 105 107 103 114 104
[ 70 105 111 110 105 110 0 0 0 0]
[ 83
output, hidden
104 97 114 107 101 121 0 0
= self.gru(gru_input,
0]
hidden)
97 99 111 0 110 101 117 105 111
Lecturer : Hongpu Liu Lecture 13-54 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
class RNNClassifier(torch.nn.Module):
def forward(self, input, seq_lengths):
# input shape : B x S -> S x B
input = input.t()
batch_size = input.size(1) Save batch-size for make initial hidden.
hidden = self._init_hidden(batch_size)
embedding = self.embedding(input)
# pack them up
gru_input = pack_padded_sequence(embedding, seq_lengths)
Lecturer : Hongpu Liu Lecture 13-55 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
class RNNClassifier(torch.nn.Module):
def forward(self, input, seq_lengths):
# input shape : B x S -> S x B
Initial hidden with shape:
input = input.t()
batch_size = input.size(1) 𝑛𝐿𝑎𝑦𝑒𝑟 ∗ 𝑛𝐷𝑖𝑟𝑒𝑐𝑡𝑖𝑜𝑛𝑠, 𝑏𝑎𝑡𝑐ℎ𝑆𝑖𝑧𝑒, ℎ𝑖𝑑𝑑𝑒𝑛𝑆𝑖𝑧𝑒
hidden = self._init_hidden(batch_size)
embedding = self.embedding(input)
# pack them up
gru_input = pack_padded_sequence(embedding, seq_lengths)
Lecturer : Hongpu Liu Lecture 13-56 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
class RNNClassifier(torch.nn.Module):
def forward(self, input, seq_lengths):
# input shape : B x S -> S x B
input = input.t() Result of embedding with shape:
batch_size = input.size(1) 𝑠𝑒𝑞𝐿𝑒𝑛, 𝑏𝑎𝑡𝑐ℎ𝑆𝑖𝑧𝑒, ℎ𝑖𝑑𝑑𝑒𝑛𝑆𝑖𝑧𝑒
hidden = self._init_hidden(batch_size)
embedding = self.embedding(input)
# pack them up
gru_input = pack_padded_sequence(embedding, seq_lengths)
Lecturer : Hongpu Liu Lecture 13-57 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
𝒃𝒂𝒕𝒄𝒉𝑺𝒊𝒛𝒆
Lecturer : Hongpu Liu Lecture 13-58 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
𝒃𝒂𝒕𝒄𝒉𝑺𝒊𝒛𝒆
Lecturer : Hongpu Liu Lecture 13-59 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
class RNNClassifier(torch.nn.Module):
The first parameter with shape:
def forward(self, input, seq_lengths):
# input shape : B x S -> S x B 𝑠𝑒𝑞𝐿𝑒𝑛, 𝑏𝑎𝑡𝑐ℎ𝑆𝑖𝑧𝑒, ℎ𝑖𝑑𝑑𝑒𝑛𝑆𝑖𝑧𝑒
input = input.t() The second parameter is a tensor, which is a list of
batch_size = input.size(1)
sequence length of each batch element.
hidden = self._init_hidden(batch_size)
embedding = self.embedding(input)
# pack them up
gru_input = pack_padded_sequence(embedding, seq_lengths)
Lecturer : Hongpu Liu Lecture 13-60 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
class RNNClassifier(torch.nn.Module):
def forward(self, input, seq_lengths):
# input shape : B x S -> S x B
input = input.t()
batch_size = input.size(1)
hidden = self._init_hidden(batch_size)
Result of embedding with shape:
embedding = self.embedding(input)
𝑠𝑒𝑞𝐿𝑒𝑛, 𝑏𝑎𝑡𝑐ℎ𝑆𝑖𝑧𝑒, ℎ𝑖𝑑𝑑𝑒𝑛𝑆𝑖𝑧𝑒
# pack them up
gru_input = pack_padded_sequence(embedding, seq_lengths)
Lecturer : Hongpu Liu Lecture 13-61 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
class RNNClassifier(torch.nn.Module):
The first parameter with shape:
def forward(self, input, seq_lengths):
# input shape : B x S -> S x B 𝑠𝑒𝑞𝐿𝑒𝑛, 𝑏𝑎𝑡𝑐ℎ𝑆𝑖𝑧𝑒, ℎ𝑖𝑑𝑑𝑒𝑛𝑆𝑖𝑧𝑒
input = input.t()
The second parameter is a tensor, which is a list of
batch_size = input.size(1)
sequence length of each batch element.
hidden = self._init_hidden(batch_size)
embedding = self.embedding(input)
It returns a PackedSquence object.
# pack them up
gru_input = pack_padded_sequence(embedding, seq_lengths)
Lecturer : Hongpu Liu Lecture 13-62 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
Lecturer : Hongpu Liu Lecture 13-63 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
It cannot work!
7 8 10 5 6 7 7 7 6
Must be sorted by descendent
Lecturer : Hongpu Liu Lecture 13-64 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
77 86 78 85 70 83 66 80 84 78 86 77 83 66 80 70 84 85
97 97 97 115 105 104 97 97 97 97 97 97 104 97 97 105 97 115
99 106 115 97 111 97 108 107 110 115 106 99 97 108 107 111 110 97
108 110 105 109 110 114 97 104 115 105 110 108 114 97 104 110 115 109
101 105 107 105 105 107 103 114 104 107 105 101 107 103 114 105 104 105
97 99 111 0 110 101 117 105 111 111 99 97 101 117 105 110 111 0
110 104 118 0 0 121 108 110 0 118 104 110 121 108 110 0 0 0
0 101 115 0 0 0 0 0 0 115 101 0 0 0 0 0 0 0
0 0 107 0 0 0 0 0 0 107 0 0 0 0 0 0 0 0
0 0 121 0 0 0 0 0 0 121 0 0 0 0 0 0 0 0
Lecturer : Hongpu Liu Lecture 13-65 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
78 86 77 83 66 80 70 84 85 78 86 77 83 66 80 70 84 85
97 97 97 104 97 97 105 97 115 97 97 97 104 97 97 105 97 115
115 106 99 97 108 107 111 110 97 115 106 99 97 108 107 111 110 97
105 110 108 114 97 104 110 115 109 105 110 108 114 97 104 110 115 109
107 105 101 107 103 114 105 104 105 107 105 101 107 103 114 105 104 105
111 99 97 101 117 105 110 111 0
𝒔𝒆𝒒𝑳𝒆𝒏 111 99 97 101 117 105 110 111 0
118 104 110 121 108 110 0 0 0 118 104 110 121 108 110 0 0 0
115 101 0 0 0 0 0 0 0 115 101 0 0 0 0 0 0 0
107 0 0 0 0 0 0 0 0 107 0 0 0 0 0 0 0 0
121 0 0 0 0 0 0 0 0 Embedding 121 0 0 0 0 0 0 0 0
𝒃𝒂𝒕𝒄𝒉𝑺𝒊𝒛𝒆
Lecturer : Hongpu Liu Lecture 13-66 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
PackedSequence
78 86 77 83 66 80 70 84 85
97 97 97 104 97 97 105 97 115 gru_input
115 106 99 97 108 107 111 110 97
105 110 108 114 97 104 110 115 109
107 105 101 107 103 114 105 104 105
111 99 97 101 117 105 110 111 0
118 104 110 121 108 110 0 0 0 10 8 7 7 7 7 6 6 5
115 101 0 0 0 0 0 0 0 𝒃𝒂𝒕𝒄𝒉_𝒔𝒊𝒛𝒆𝒔
107 0 0 0 0 0 0 0 0
121 0 0 0 0 0 0 0 0
𝒆𝒎𝒃𝒆𝒅𝒅𝒊𝒏𝒈
10 8 7 7 7 7 6 6 5 𝒅𝒂𝒕𝒂
𝒔𝒆𝒒_𝒍𝒆𝒏𝒈𝒕𝒉
Lecturer : Hongpu Liu Lecture 13-67 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
class RNNClassifier(torch.nn.Module):
The first parameter with shape:
def forward(self, input, seq_lengths):
# input shape : B x S -> S x B 𝑠𝑒𝑞𝐿𝑒𝑛, 𝑏𝑎𝑡𝑐ℎ𝑆𝑖𝑧𝑒, ℎ𝑖𝑑𝑑𝑒𝑛𝑆𝑖𝑧𝑒
input = input.t() The second parameter is a tensor, which is a list of
batch_size = input.size(1)
sequence length of each batch element.
hidden = self._init_hidden(batch_size)
embedding = self.embedding(input)
It returns a PackedSquence object.
# pack them up
gru_input = pack_padded_sequence(embedding, seq_lengths)
Lecturer : Hongpu Liu Lecture 13-68 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
class RNNClassifier(torch.nn.Module):
The output is a PackedSequence object, actually it is a tuple.
def forward(self, input, seq_lengths):
# input shape : B x S -> S x B
input = the shape of hidden, which we concerned, with shape:
input.t()
batch_size = input.size(1)
𝑛𝐿𝑎𝑦𝑒𝑟𝑠 ∗ 𝑛𝐷𝑖𝑟𝑒𝑐𝑡𝑖𝑜𝑛, 𝑏𝑎𝑡𝑐ℎ𝑆𝑖𝑧𝑒, ℎ𝑖𝑑𝑑𝑒𝑛𝑆𝑖𝑧𝑒
hidden = self._init_hidden(batch_size)
embedding = self.embedding(input)
# pack them up
gru_input = pack_padded_sequence(embedding, seq_lengths)
Lecturer : Hongpu Liu Lecture 13-69 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
Linear
Layer
𝑥1 𝑥2 𝑥3 𝑥𝑁
Lecturer : Hongpu Liu Lecture 13-70 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
𝒉𝟎 𝒉𝟏 𝒉𝑵−𝟏 𝒉𝑵
𝒇 𝒃
𝒉𝒃𝑵 RNN Cell
𝒉𝒊𝒅𝒅𝒆𝒏 =
RNN Cell
𝒉𝑵 , 𝒉𝑵
RNN Cell RNN Cell 𝒉𝒃𝟎
𝒇 𝒇
𝒉𝟎 RNN Cell RNN Cell RNN Cell RNN Cell 𝒉𝑵
𝒙𝟏 𝒙𝟐 𝒙𝑵−𝟏 𝒙𝑵
Lecturer : Hongpu Liu Lecture 13-71 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
class RNNClassifier(torch.nn.Module):
def forward(self, input, seq_lengths):
# input shape : B x S -> S x B
input = input.t()
batch_size = input.size(1)
hidden = self._init_hidden(batch_size)
embedding = self.embedding(input)
Lecturer : Hongpu Liu Lecture 13-72 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
class RNNClassifier(torch.nn.Module):
def forward(self, input, seq_lengths):
# input shape : B x S -> S x B
input = input.t()
batch_size = input.size(1)
hidden = self._init_hidden(batch_size)
embedding = self.embedding(input)
# pack them up
gru_input = pack_padded_sequence(embedding, seq_lengths)
Lecturer : Hongpu Liu Lecture 13-73 PyTorch Tutorial @ SLAM Research Group
Implementation – Model Design
class RNNClassifier(torch.nn.Module):
def forward(self, input, seq_lengths):
# input shape : B x S -> S x B
input = input.t()
batch_size = input.size(1)
hidden = self._init_hidden(batch_size)
embedding = self.embedding(input)
# pack them up
gru_input = pack_padded_sequence(embedding, seq_lengths)
Lecturer : Hongpu Liu Lecture 13-74 PyTorch Tutorial @ SLAM Research Group
Implementation – Convert name to tensor
Name
Maclean 78 86 77 83 66 80 70 84 85
97 97 97 104 97 97 105 97 115
Vajnichy 115 106 99 97 108 107 111 110 97
105 110 108 114 97 104 110 115 109
Nasikovsky
107 105 101 107 103 114 105 104 105
Sharkey 107 0 0 0 0 0 0 0 0
121 0 0 0 0 0 0 0 0
Balagul
Pakhrin
10 8 7 7 7 7 6 6 5
Tansho
Lecturer : Hongpu Liu Lecture 13-75 PyTorch Tutorial @ SLAM Research Group
Implementation – Convert name to tensor
Maclean ['M', 'a', 'c', 'l', 'e', 'a', 'n'] [ 77 97 99 108 101 97 110]
Vajnichy ['V', 'a', 'j', 'n', 'i', 'c', 'h', 'y'] [ 86 97 106 110 105 99 104 121]
Nasikovsky ['N', 'a', 's', 'i', 'k', 'o', 'v', 's', 'k', 'y'] [ 78 97 115 105 107 111 118 115 107 121]
Fionin ['F', 'i', 'o', 'n', 'i', 'n'] [ 70 105 111 110 105 110]
Sharkey ['S', 'h', 'a', 'r', 'k', 'e', 'y'] [ 83 104 97 114 107 101 121]
Balagul ['B', 'a', 'l', 'a', 'g', 'u', 'l'] [ 66 97 108 97 103 117 108]
Pakhrin ['P', 'a', 'k', 'h', 'r', 'i', 'n'] [ 80 97 107 104 114 105 110]
Tansho ['T', 'a', 'n', 's', 'h', 'o'] [ 84 97 110 115 104 111]
Lecturer : Hongpu Liu Lecture 13-76 PyTorch Tutorial @ SLAM Research Group
Implementation – Convert name to tensor
[ 86 97 106 110 105 99 104 121] [ 86 97 106 110 105 99 104 121 0 0]
[ 78 97 115 105 107 111 118 115 107 121] [ 78 97 115 105 107 111 118 115 107 121]
[ 70 105 111 110 105 110] [ 70 105 111 110 105 110 0 0 0 0]
[ 83 104 97 114 107 101 121] [ 83 104 97 114 107 101 121 0 0 0]
[ 80 97 107 104 114 105 110] [ 80 97 107 104 114 105 110 0 0 0]
Lecturer : Hongpu Liu Lecture 13-77 PyTorch Tutorial @ SLAM Research Group
Implementation – Convert name to tensor
Lecturer : Hongpu Liu Lecture 13-78 PyTorch Tutorial @ SLAM Research Group
Implementation – Convert name to tensor
77 86 78 85 70 83 66 80 84 78 86 77 83 66 80 70 84 85
97 97 97 115 105 104 97 97 97 97 97 97 104 97 97 105 97 115
99 106 115 97 111 97 108 107 110 115 106 99 97 108 107 111 110 97
108 110 105 109 110 114 97 104 115 105 110 108 114 97 104 110 115 109
101 105 107 105 105 107 103 114 104 107 105 101 107 103 114 105 104 105
97 99 111 0 110 101 117 105 111 111 99 97 101 117 105 110 111 0
110 104 118 0 0 121 108 110 0 118 104 110 121 108 110 0 0 0
0 101 115 0 0 0 0 0 0 115 101 0 0 0 0 0 0 0
0 0 107 0 0 0 0 0 0 107 0 0 0 0 0 0 0 0
0 0 121 0 0 0 0 0 0 121 0 0 0 0 0 0 0 0
Lecturer : Hongpu Liu Lecture 13-79 PyTorch Tutorial @ SLAM Research Group
Implementation – Convert name to tensor
def make_tensors(names, countries):
sequences_and_lengths = [name2list(name) for name in names]
name_sequences = [sl[0] for sl in sequences_and_lengths]
def name2list(name):
seq_lengths = torch.LongTensor([sl[1] for sl in sequences_and_lengths])
countries = countries.long() arr = [ord(c) for c in name]
return arr, len(arr)
# make tensor of name, BatchSize x SeqLen
seq_tensor = torch.zeros(len(name_sequences), seq_lengths.max()).long()
for idx, (seq, seq_len) in enumerate(zip(name_sequences, seq_lengths), 0):
seq_tensor[idx, :seq_len] = torch.LongTensor(seq)
return create_tensor(seq_tensor), \
create_tensor(seq_lengths),\
create_tensor(countries)
Lecturer : Hongpu Liu Lecture 13-80 PyTorch Tutorial @ SLAM Research Group
Implementation – Convert name to tensor
def make_tensors(names, countries):
sequences_and_lengths = [name2list(name) for name in names]
name_sequences = [sl[0] for sl in sequences_and_lengths]
seq_lengths = torch.LongTensor([sl[1] for sl in sequences_and_lengths])
countries = countries.long() ASCII
Lecturer : Hongpu Liu Lecture 13-81 PyTorch Tutorial @ SLAM Research Group
Implementation – Convert name to tensor
def make_tensors(names, countries):
sequences_and_lengths = [name2list(name) for name in names]
name_sequences = [sl[0] for sl in sequences_and_lengths]
seq_lengths = torch.LongTensor([sl[1] for sl in sequences_and_lengths])
countries = countries.long()
return create_tensor(seq_tensor), \
create_tensor(seq_lengths),\
create_tensor(countries)
Lecturer : Hongpu Liu Lecture 13-82 PyTorch Tutorial @ SLAM Research Group
Implementation – Convert name to tensor
def make_tensors(names, countries):
sequences_and_lengths = [name2list(name) for name in names]
name_sequences = [sl[0] for sl in sequences_and_lengths]
seq_lengths = torch.LongTensor([sl[1] for sl in sequences_and_lengths])
countries = countries.long()
seq_tensor = seq_tensor[perm_idx] [ 78 97 115 105 107 111 118 115 107 121]
Lecturer : Hongpu Liu Lecture 13-83 PyTorch Tutorial @ SLAM Research Group
Implementation – Convert name to tensor
def make_tensors(names, countries):
sequences_and_lengths = [name2list(name) for name in names]
name_sequences = [sl[0] for sl in sequences_and_lengths]
seq_lengths = torch.LongTensor([sl[1] for sl in sequences_and_lengths])
countries = countries.long()
return create_tensor(seq_tensor), \
create_tensor(seq_lengths),\
create_tensor(countries)
Lecturer : Hongpu Liu Lecture 13-84 PyTorch Tutorial @ SLAM Research Group
Implementation – Convert name to tensor
After padding After padding
def make_tensors(names, countries):
[ 77 97 99 108 101 97 110 0 0 0] [ 78 97 115 105 107 111 118 115 107 121]
sequences_and_lengths = [name2list(name) for name in names]
[ 86 97 106 110 105 99 104 121 0 0] [ 86 97 106 110 105 99 104 121 0 0]
name_sequences = [sl[0] for sl in sequences_and_lengths]
seq_lengths = torch.LongTensor([sl[1] for sl in
[ 78 97 115 105 107 111 118 115 107 121]
sequences_and_lengths])
[ 83 104 97 114 107 101 121 0 0 0]
countries0 =0 countries.long()
[ 85 115 97 109 105 0 0 0] [ 66 97 108 97 103 117 108 0 0 0]
[ 70 105 111 110 105 110 0 0 0 0] [ 80 97 107 104 114 105 110 0 0 0]
[ 83 104
# 97make tensor 0 of0 name,
114 107 101 121 0]
BatchSize x SeqLen [ 77 97 99 108 101 97 110 0 0 0]
[ 66
seq_tensor
97 108
= torch.zeros(len(name_sequences),
97 103 117 108 0 0 0]
seq_lengths.max()).long()
[ 70 105 111 110 105 110 0 0 0 0]
[ 80
for idx, (seq,0 seq_len)
97 107 104 114 105 110 0 0]
in enumerate(zip(name_sequences, seq_lengths),
[ 84 97 110 115 104 111 0 0 0 0]
0):
[ 84
seq_tensor[idx, :seq_len] = torch.LongTensor(seq)
97 110 115 104 111 0 0 0 0] [ 85 115 97 109 105 0 0 0 0 0]
return create_tensor(seq_tensor), \
create_tensor(seq_lengths),\
create_tensor(countries)
Lecturer : Hongpu Liu Lecture 13-85 PyTorch Tutorial @ SLAM Research Group
Implementation – Convert name to tensor
def make_tensors(names, countries):
sequences_and_lengths = [name2list(name) for name in names]
name_sequences = [sl[0] for sl in sequences_and_lengths]
seq_lengths = torch.LongTensor([sl[1] for sl in sequences_and_lengths])
countries = countries.long()
Lecturer : Hongpu Liu Lecture 13-86 PyTorch Tutorial @ SLAM Research Group
Implementation – One Epoch Training
def trainModel():
total_loss = 0
for i, (names, countries) in enumerate(trainloader, 1):
inputs, seq_lengths, target = make_tensors(names, countries)
output = classifier(inputs, seq_lengths)
loss = criterion(output, target)
optimizer.zero_grad()
loss.backward()
optimizer.step()
1. forward – compute output of model
total_loss += loss.item()
2. forward – compute loss
if i % 10 == 0:
3. zero grad Epoch {epoch} ', end='')
print(f'[{time_since(start)}]
print(f'[{i * len(inputs)}/{len(trainset)}]
4. backward ', end='')
print(f'loss={total_loss / (i * len(inputs))}')
return total_loss 5. update
Lecturer : Hongpu Liu Lecture 13-87 PyTorch Tutorial @ SLAM Research Group
Implementation – One Epoch Training
def trainModel():
total_loss = 0
for i, (names, countries) in enumerate(trainloader, 1):
inputs, seq_lengths, target = make_tensors(names, countries)
output = classifier(inputs, seq_lengths)
loss = criterion(output, target)
optimizer.zero_grad()
loss.backward()
optimizer.step()
total_loss += loss.item()
if i % 10 == 0:
print(f'[{time_since(start)}] Epoch {epoch} ', end='')
print(f'[{i * len(inputs)}/{len(trainset)}] ', end='')
print(f'loss={total_loss / (i * len(inputs))}')
return total_loss
Lecturer : Hongpu Liu Lecture 13-88 PyTorch Tutorial @ SLAM Research Group
Implementation – Testing
def testModel():
correct = 0
total = len(testset)
print("evaluating trained model ...")
with torch.no_grad():
for i, (names, countries) in enumerate(testloader, 1):
inputs, seq_lengths, target = make_tensors(names, countries)
output = classifier(inputs, seq_lengths)
pred = output.max(dim=1, keepdim=True)[1]
correct += pred.eq(target.view_as(pred)).sum().item()
Lecturer : Hongpu Liu Lecture 13-89 PyTorch Tutorial @ SLAM Research Group
Implementation – Testing
def testModel():
correct = 0
total = len(testset)
print("evaluating trained model ...")
with torch.no_grad():
for i, (names, countries) in enumerate(testloader, 1):
inputs, seq_lengths, target = make_tensors(names, countries)
output = classifier(inputs, seq_lengths)
pred = output.max(dim=1, keepdim=True)[1]
Compute the output of the model.
correct += pred.eq(target.view_as(pred)).sum().item()
Lecturer : Hongpu Liu Lecture 13-90 PyTorch Tutorial @ SLAM Research Group
Implementation – Testing
def testModel():
correct = 0
total = len(testset)
print("evaluating trained model ...")
with torch.no_grad():
for i, (names, countries) in enumerate(testloader, 1):
inputs, seq_lengths, target = make_tensors(names, countries)
output = classifier(inputs, seq_lengths)
pred = output.max(dim=1, keepdim=True)[1]
correct += pred.eq(target.view_as(pred)).sum().item()
Lecturer : Hongpu Liu Lecture 13-91 PyTorch Tutorial @ SLAM Research Group
Implementation – Result
Lecturer : Hongpu Liu Lecture 13-92 PyTorch Tutorial @ SLAM Research Group
Exercise 13-1 Sentiment Analysis on Movie Reviews
• The Rotten Tomatoes movie review dataset is a corpus of movie reviews used for
sentiment analysis.
• dataset: https://www.kaggle.com/c/sentiment-analysis-on-movie-reviews/data
• The dataset is comprised of tab-separated files with phrases from the Rotten Tomatoes
dataset.
Lecturer : Hongpu Liu Lecture 13-93 PyTorch Tutorial @ SLAM Research Group
Exercise 13-1 Sentiment Analysis on Movie Reviews
Lecturer : Hongpu Liu Lecture 13-94 PyTorch Tutorial @ SLAM Research Group
Exercise 13-1 Sentiment Analysis on Movie Reviews
Lecturer : Hongpu Liu Lecture 13-95 PyTorch Tutorial @ SLAM Research Group
PyTorch Tutorial
13. RNN Classifier
Lecturer : Hongpu Liu Lecture 13-96 PyTorch Tutorial @ SLAM Research Group