tree_rnn
tree_rnn copied to clipboard
Some question about the code
hello , thank you very much for sharing the code. when I read the code, I meet some trouble. 1 in the function compute_tree() in file tree_rnn.py . when the tree is irregular_tree , the init_node_h is the concatenation of two leaf_h. this is the place that makes me confused if self.irregular_tree: init_node_h = T.concatenate([leaf_h, leaf_h], axis=0) else: init_node_h = leaf_h
2 in the function _recurrence in the tree_rnn.py , I am not very understand that use a the offset to get the child_h,and after remove the first embedding after a loop.
def _recurrence(cur_emb, node_info, t, node_h, last_h):
child_exists = node_info > -1
offset = num_leaves * int(self.irregular_tree) - child_exists * t #if isrregular_tree is true
child_h = node_h[node_info + offset] * child_exists.dimshuffle(0, 'x')
parent_h = self.recursive_unit(cur_emb, child_h, child_exists)
node_h = T.concatenate([node_h,
parent_h.reshape([1, self.hidden_dim])])
return node_h[1:], parent_h #means that the next loop the node_h is changed
according to my understanding, if the lead_h is [c0,c1,c2,c3] and the tree is irregular and the tree structure is [[0,1,2,-1,-1,4], [3,4,-1,-1,-1,5]] so the init_node_h is [c0,c1,c2,c3,c0,c1,c2,c3] in the first iteration, the child_exists = [true,true,true,false,false,true] offset = [4,4,4,4,4,4] .... so I feel that I don't understand the part of the project. can you kindly give me an example in the part?
thank you very much