Skip to content

Commit e33b412

Browse files
committed
Add documentation
1 parent 61b0a3b commit e33b412

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

models/full_model.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55

66
class FullModel(nn.Module):
7+
"""
8+
Complete methodNaming model.
9+
"""
710
def __init__(self, encoder, decoder, device, graph_encoder=None, graph=False):
811
super().__init__()
912

@@ -30,6 +33,7 @@ def forward(self, sequence, target, adj=None, node_features=None):
3033
# output contains the hidden states for all input elements
3134
encoder_output, hidden = self.encoder(sequence)
3235

36+
# graph encoder
3337
if self.graph:
3438
# graph_hidden has shape [1, 1, hidden_size] and contains a graph representation
3539
n_nodes = adj.size(0)
@@ -47,6 +51,7 @@ def forward(self, sequence, target, adj=None, node_features=None):
4751
# first input to the decoder is the <sos> tokens
4852
input = torch.tensor([[0]], device=self.device)
4953

54+
# sequence decoder
5055
for t in range(1, max_len):
5156
output, hidden = self.decoder(input, hidden, encoder_output)
5257
outputs[t] = output

models/gat_encoder.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import torch.nn as nn
2-
import torch.nn.functional as F
32
from models.graph_convolutional_layer import GraphConvolution
43
from models.graph_attention_layer import GraphAttentionLayer
5-
import torch
64

75

86
class GATEncoder(nn.Module):
7+
"""
8+
Graph encoder using a Graph Attention Network.
9+
"""
910
def __init__(self, num_features, hidden_size, dropout=0):
1011
super(GATEncoder, self).__init__()
1112

models/gcn_encoder.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55

66
class GCNEncoder(nn.Module):
7+
"""
8+
Graph encoder using a Graph Convolutional Network.
9+
"""
710
def __init__(self, num_features, hidden_size, dropout=0):
811
super(GCNEncoder, self).__init__()
912

models/lstm_decoder.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,28 @@
44

55

66
class LSTMDecoder(nn.Module):
7-
def __init__(self, hidden_size, output_size, device, attention=False, pointer_network=False):
7+
"""
8+
Sequence decoder which makes use of a single-layer LSTM.
9+
"""
10+
def __init__(self, hidden_size, output_size, device, attention=False):
811
super(LSTMDecoder, self).__init__()
912
self.hidden_size = hidden_size
1013
self.output_size = output_size
14+
self.attention = attention
15+
self.device = device
16+
1117
self.embedding = nn.Embedding(output_size, hidden_size).to(device)
1218
self.lstm = nn.LSTM(hidden_size, hidden_size).to(device)
1319
self.out = nn.Linear(hidden_size, output_size).to(device)
1420
self.softmax = nn.LogSoftmax(dim=1)
15-
self.attention = attention
16-
self.pointer_network = pointer_network
1721
self.attention_layer = nn.Linear(hidden_size * 2, 1).to(device)
1822
self.attention_combine = nn.Linear(hidden_size * 2, hidden_size).to(device)
19-
self.device = device
2023

2124
def forward(self, input, hidden, encoder_hiddens, input_seq=None):
2225
# encoder_hiddens has shape [batch_size, seq_len, hidden_dim]
2326
output = self.embedding(input).view(1, 1, -1)
2427

28+
# Compute attention
2529
if self.attention:
2630
# Create a matrix of shape [batch_size, seq_len, 2 * hidden_dim] where the last
2731
# dimension is a concatenation of the ith encoder hidden state and the current decoder

models/lstm_encoder.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44

55
class LSTMEncoder(nn.Module):
6+
"""
7+
Sequence encoder which makes use of a single-layer LSTM.
8+
"""
69
def __init__(self, input_size, hidden_size, device):
710
super(LSTMEncoder, self).__init__()
811
self.hidden_size = hidden_size

0 commit comments

Comments
 (0)