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
688a9228
"src/git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "24563ca654f6574dae93aeece8eeef69e39097e5"
Commit
688a9228
authored
Apr 11, 2019
by
Da Zheng
Committed by
Sheng Zha
Apr 11, 2019
Browse files
fix. (#491)
parent
e2e04329
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
4 deletions
+5
-4
examples/mxnet/tree_lstm/train.py
examples/mxnet/tree_lstm/train.py
+3
-3
examples/mxnet/tree_lstm/tree_lstm.py
examples/mxnet/tree_lstm/tree_lstm.py
+2
-1
No files found.
examples/mxnet/tree_lstm/train.py
View file @
688a9228
...
@@ -122,7 +122,7 @@ def main(args):
...
@@ -122,7 +122,7 @@ def main(args):
dur
.
append
(
time
.
time
()
-
t0
)
# tok
dur
.
append
(
time
.
time
()
-
t0
)
# tok
if
step
>
0
and
step
%
args
.
log_every
==
0
:
if
step
>
0
and
step
%
args
.
log_every
==
0
:
pred
=
pred
.
argmax
(
axis
=
1
)
pred
=
pred
.
argmax
(
axis
=
1
)
.
astype
(
batch
.
label
.
dtype
)
acc
=
(
batch
.
label
==
pred
).
sum
()
acc
=
(
batch
.
label
==
pred
).
sum
()
root_ids
=
[
i
for
i
in
range
(
batch
.
graph
.
number_of_nodes
())
if
batch
.
graph
.
out_degree
(
i
)
==
0
]
root_ids
=
[
i
for
i
in
range
(
batch
.
graph
.
number_of_nodes
())
if
batch
.
graph
.
out_degree
(
i
)
==
0
]
root_acc
=
np
.
sum
(
batch
.
label
.
asnumpy
()[
root_ids
]
==
pred
.
asnumpy
()[
root_ids
])
root_acc
=
np
.
sum
(
batch
.
label
.
asnumpy
()[
root_ids
]
==
pred
.
asnumpy
()[
root_ids
])
...
@@ -139,7 +139,7 @@ def main(args):
...
@@ -139,7 +139,7 @@ def main(args):
n
=
g
.
number_of_nodes
()
n
=
g
.
number_of_nodes
()
h
=
mx
.
nd
.
zeros
((
n
,
args
.
h_size
),
ctx
=
ctx
)
h
=
mx
.
nd
.
zeros
((
n
,
args
.
h_size
),
ctx
=
ctx
)
c
=
mx
.
nd
.
zeros
((
n
,
args
.
h_size
),
ctx
=
ctx
)
c
=
mx
.
nd
.
zeros
((
n
,
args
.
h_size
),
ctx
=
ctx
)
pred
=
model
(
batch
,
h
,
c
).
argmax
(
1
)
pred
=
model
(
batch
,
h
,
c
).
argmax
(
1
)
.
astype
(
batch
.
label
.
dtype
)
acc
=
(
batch
.
label
==
pred
).
sum
().
asscalar
()
acc
=
(
batch
.
label
==
pred
).
sum
().
asscalar
()
accs
.
append
([
acc
,
len
(
batch
.
label
)])
accs
.
append
([
acc
,
len
(
batch
.
label
)])
...
@@ -175,7 +175,7 @@ def main(args):
...
@@ -175,7 +175,7 @@ def main(args):
n
=
g
.
number_of_nodes
()
n
=
g
.
number_of_nodes
()
h
=
mx
.
nd
.
zeros
((
n
,
args
.
h_size
),
ctx
=
ctx
)
h
=
mx
.
nd
.
zeros
((
n
,
args
.
h_size
),
ctx
=
ctx
)
c
=
mx
.
nd
.
zeros
((
n
,
args
.
h_size
),
ctx
=
ctx
)
c
=
mx
.
nd
.
zeros
((
n
,
args
.
h_size
),
ctx
=
ctx
)
pred
=
model
(
batch
,
h
,
c
).
argmax
(
axis
=
1
)
pred
=
model
(
batch
,
h
,
c
).
argmax
(
axis
=
1
)
.
astype
(
batch
.
label
.
dtype
)
acc
=
(
batch
.
label
==
pred
).
sum
().
asscalar
()
acc
=
(
batch
.
label
==
pred
).
sum
().
asscalar
()
accs
.
append
([
acc
,
len
(
batch
.
label
)])
accs
.
append
([
acc
,
len
(
batch
.
label
)])
...
...
examples/mxnet/tree_lstm/tree_lstm.py
View file @
688a9228
...
@@ -118,7 +118,8 @@ class TreeLSTM(gluon.nn.Block):
...
@@ -118,7 +118,8 @@ class TreeLSTM(gluon.nn.Block):
g
.
register_apply_node_func
(
self
.
cell
.
apply_node_func
)
g
.
register_apply_node_func
(
self
.
cell
.
apply_node_func
)
# feed embedding
# feed embedding
embeds
=
self
.
embedding
(
batch
.
wordid
*
batch
.
mask
)
embeds
=
self
.
embedding
(
batch
.
wordid
*
batch
.
mask
)
g
.
ndata
[
'iou'
]
=
self
.
cell
.
W_iou
(
self
.
dropout
(
embeds
))
*
batch
.
mask
.
expand_dims
(
-
1
)
wiou
=
self
.
cell
.
W_iou
(
self
.
dropout
(
embeds
))
g
.
ndata
[
'iou'
]
=
wiou
*
batch
.
mask
.
expand_dims
(
-
1
).
astype
(
wiou
.
dtype
)
g
.
ndata
[
'h'
]
=
h
g
.
ndata
[
'h'
]
=
h
g
.
ndata
[
'c'
]
=
c
g
.
ndata
[
'c'
]
=
c
# propagate
# propagate
...
...
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