Skip to content

Commit

Permalink
feat: Add table parsing pipeline separately
Browse files Browse the repository at this point in the history
  • Loading branch information
shahrukhqasim committed Nov 20, 2017
1 parent 67fc1bc commit 038f332
Show file tree
Hide file tree
Showing 5 changed files with 733 additions and 0 deletions.
Empty file added python/table_parse/__init__.py
Empty file.
56 changes: 56 additions & 0 deletions python/table_parse/computation_graph_table_parse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import torch
from torch.autograd import Variable

from network.dense import Dense


class TableParse(torch.nn.Module):
def __init__(self, num_embeddings, num_positional, num_convolutional):
super(TableParse, self).__init__()

self.moduleA_embeddings = Dense(num_embeddings, config = [300, 'R', 300, 'R', 100])
self.moduleA_positional = Dense(num_positional, config = [20, 'S', 20, 'R', 100])
self.moduleA_convolutional = Dense(num_convolutional, config = [100, 'R', 100, 'R', 100])

self.moduleA_project_down = Dense(300, config=[100, 'R'])

self.moduleB = torch.nn.GRUCell(500, 100).cuda()
self.moduleBO_1 = Dense(100, config = [100, 'R', 100, 'R', 100, 'R'])
self.moduleBO_2 = Dense(100, config = [100, 'R', 100, 'R', 100, 'R'])
self.moduleC = Dense(100, config = [100,'R',100])
self.moduleD = Dense(100, config = [100, 'R', 100, 'R'])

self.iterations = 1

def set_iterations(self, iterations):
self.iterations = iterations

def concat(self, x, indices, indices_not_found, num_words):
y = Variable(torch.zeros(num_words, 100 * 5)).cuda()
y[:, 000:100] = x[indices[:, 0]]
y[:, 100:200] = x[indices[:, 1]]
y[:, 200:300] = x[indices[:, 2]]
y[:, 300:400] = x[indices[:, 3]]
y[:, 400:500] = x[indices[:, 4]]
y[indices_not_found] = 0

return y

def forward(self, indices, indices_not_found, word_embeddings, positional_features, convolutional_features, num_words):
uu_embeddings = self.moduleA_embeddings.forward(word_embeddings)
uu_positional = self.moduleA_positional.forward(positional_features)
uu_convolutional = self.moduleA_convolutional.forward(convolutional_features)

uu_combined = torch.cat((uu_embeddings, uu_positional, uu_convolutional), dim=1)
uu = self.moduleA_project_down.forward(uu_combined)

hh = Variable(torch.zeros(num_words,100)).cuda()

for i in range(self.iterations):
ww = self.concat(uu, indices, indices_not_found, num_words)
bb = self.moduleB.forward(ww, hh)
oo, hh = self.moduleBO_1.forward(bb), self.moduleBO_2.forward(bb)
ll = self.moduleC.forward(oo)
uu = self.moduleD.forward(hh)

return ll
Loading

0 comments on commit 038f332

Please sign in to comment.