pytorch-tree-lstm icon indicating copy to clipboard operation
pytorch-tree-lstm copied to clipboard

Implicit assumptions in code?

Open michael-hahn opened this issue 5 years ago • 4 comments

Commit 66f29a44e98c7332661b57d22501107bcb193f90 modified TreeLSTM class, specifically, regarding h_sum.

By using torch.unique_consecutive to construct h_sum on the fly seems to assume that if two edges have the same parent, they must be adjacent to each other in the list. Otherwise, when performing the following operation:

iou = self.W_iou(x) + self.U_iou(h_sum)

x and h_sum will have different 0th dimensions.

michael-hahn avatar Jun 24 '19 17:06 michael-hahn

Yes, you are correct; I changed this recently as a performance optimization but I failed to update the documentation. The adjacency_list in the current code needs to have all parent nodes adjacent in the list. I will update the documentation to reflect this.

freedryk avatar Jun 24 '19 20:06 freedryk

Thanks!

michael-hahn avatar Jun 24 '19 20:06 michael-hahn

I'm reopening this just to help me keep track of what I still have to do :)

freedryk avatar Jun 24 '19 20:06 freedryk

It can be forced inside the forward function of TreeLSTM layer.

edge_ordered_by_parent_indexes = adjacency_list[:, 0].argsort() adjacency_list = adjacency_list[edge_ordered_by_parent_indexes] edge_order = edge_order[edge_ordered_by_parent_indexes]

So that it doesn't matter if the adjacency matrix is sorted by parent_index or not After all, this constraint is there because of the way batched computations is done (torch.unique_consecutive).

SlimFrkh avatar Jan 07 '20 16:01 SlimFrkh