Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dgl
Commits
1f0f57b3
Commit
1f0f57b3
authored
Oct 04, 2018
by
Minjie Wang
Browse files
fix bug in treelstm
parent
cdf7334c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
5 deletions
+5
-5
examples/pytorch/tree_lstm/train.py
examples/pytorch/tree_lstm/train.py
+1
-1
examples/pytorch/tree_lstm/tree_lstm.py
examples/pytorch/tree_lstm/tree_lstm.py
+4
-4
No files found.
examples/pytorch/tree_lstm/train.py
View file @
1f0f57b3
...
...
@@ -91,7 +91,7 @@ def main(args):
mean_dur
=
np
.
mean
(
dur
)
print
(
"Epoch {:05d} | Step {:05d} | Loss {:.4f} | "
"Acc {:.4f} | Time(s) {:.4f} | Trees/s {:.4f}"
.
format
(
epoch
,
step
,
loss
.
item
(),
acc
.
item
()
/
args
.
batch_size
,
epoch
,
step
,
loss
.
item
(),
acc
.
item
()
/
len
(
label
)
,
mean_dur
,
args
.
batch_size
/
mean_dur
))
print
(
"Epoch time(s):"
,
time
.
time
()
-
t_epoch
)
...
...
examples/pytorch/tree_lstm/tree_lstm.py
View file @
1f0f57b3
...
...
@@ -23,7 +23,7 @@ class ChildSumTreeLSTMCell(nn.Module):
self
.
ut
=
0.
def
message_func
(
self
,
src
,
edge
):
return
src
return
{
'h'
:
src
[
'h'
],
'c'
:
src
[
'c'
]}
def
reduce_func
(
self
,
node
,
msgs
):
# equation (2)
...
...
@@ -90,9 +90,9 @@ class TreeLSTM(nn.Module):
"""
g
=
graph
n
=
g
.
number_of_nodes
()
g
.
register_message_func
(
self
.
cell
.
message_func
,
batchable
=
True
)
g
.
register_reduce_func
(
self
.
cell
.
reduce_func
,
batchable
=
True
)
g
.
register_apply_node_func
(
self
.
cell
.
apply_func
,
batchable
=
True
)
g
.
register_message_func
(
self
.
cell
.
message_func
)
g
.
register_reduce_func
(
self
.
cell
.
reduce_func
)
g
.
register_apply_node_func
(
self
.
cell
.
apply_func
)
# feed embedding
wordid
=
g
.
pop_n_repr
(
'x'
)
mask
=
(
wordid
!=
dgl
.
data
.
SST
.
PAD_WORD
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment