Get Value of nnet3 output layer

941 views
Skip to first unread message

bruce...@mirlab.org

unread,
Mar 30, 2019, 4:16:18 AM3/30/19
to kaldi-help
Hi all
I have trained a nnet3 model already.
But I want to extract the value of the output layer, is there any program could be used?

Daniel Povey

unread,
Mar 30, 2019, 11:54:18 AM3/30/19
to kaldi-help
nnet3-compute

--
Go to http://kaldi-asr.org/forums.html find out how to join
---
You received this message because you are subscribed to the Google Groups "kaldi-help" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kaldi-help+...@googlegroups.com.
To post to this group, send email to kaldi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kaldi-help/3368c4ae-1fcc-40de-a33c-95a2f9f9ee5e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

bruce...@mirlab.org

unread,
Mar 30, 2019, 1:19:53 PM3/30/19
to kaldi-help
Thanks your reply!!
if I want to extract another output layer (not called "output" in kaldi), how could I fix the nnet3-compute program to get this goal?

Daniel Povey

unread,
Mar 30, 2019, 1:29:34 PM3/30/19
to kaldi-help
You can do it by editing the model to overwrite the output node.
For example:

nnet3-copy --nnet-config="echo output-node name=output input=prefinal-l|" exp/chain/tdnn1g_sp/final.mdl modified.mdl


You can see existing component-node names by doing nnet3-info on the model and looking for 'component-node' lines.

On Sat, Mar 30, 2019 at 1:19 PM <bruce...@mirlab.org> wrote:
Thanks your reply!!
if I want to extract another output layer (not called "output" in kaldi), how could I fix the nnet3-compute program to get this goal?

--
Go to http://kaldi-asr.org/forums.html find out how to join
---
You received this message because you are subscribed to the Google Groups "kaldi-help" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kaldi-help+...@googlegroups.com.
To post to this group, send email to kaldi...@googlegroups.com.

bruce...@mirlab.org

unread,
Mar 31, 2019, 3:45:24 AM3/31/19
to kaldi-help
Because my nnet3 is multi-tasking structure, there are four other layer called "output-attr*"
And I check my xconfig, there are something like "output-layer name=output_attr1 ... input=tdnn8 ..."
So from your example, do you mean that I should change the name=output to name=output-attr1 and input=prefinal-l| to input=tdnn8?

Kirill Katsnelson

unread,
Mar 31, 2019, 7:28:09 AM3/31/19
to kaldi-help
The xconfig is actually expanded to produce the actual network structure descriptor, which is much longer. Read http://kaldi-asr.org/doc/dnn3.html for the full exposition, it's worth it.

So you already have an output node, only not named 'output'. Check the output of nnet3-info or configs/final.config  in the model directory. This is the actual structure of the network. You'll likely see

output-node name=output-attr1 input=tdnn8.affine ...

generated from your output layer. Make a modified copy of your model as Dan explained, substituting the same exact line only with the name 'output', like

output-node name=output input=tdnn8.affine ...

Hmm, why does not our nnet3-compute has a switch to specify output node name? I was going to swear I've seen it, but apparently it's the nnet3-compute-from-egs that has it.

 -kkm

Create a copy

bruce...@mirlab.org

unread,
Mar 31, 2019, 10:57:17 PM3/31/19
to kaldi-help
It works!!
Thank you all!!

Armando

unread,
Jun 14, 2019, 6:13:37 AM6/14/19
to kaldi-help
is there a way to instead feed the network from an intermediate layer?
renaming the input much like in the output renaming is not the way to go

I would like to save the intermediate layer output and then to feed it again to the network (in principle, in a multi-task network) later (without feeding the network from the "original" input layer)


On Saturday, March 30, 2019 at 6:29:34 PM UTC+1, Dan Povey wrote:
You can do it by editing the model to overwrite the output node.
For example:

nnet3-copy --nnet-config="echo output-node name=output input=prefinal-l|" exp/chain/tdnn1g_sp/final.mdl modified.mdl


You can see existing component-node names by doing nnet3-info on the model and looking for 'component-node' lines.

On Sat, Mar 30, 2019 at 1:19 PM <bruc...@mirlab.org> wrote:
Thanks your reply!!
if I want to extract another output layer (not called "output" in kaldi), how could I fix the nnet3-compute program to get this goal?

--
Go to http://kaldi-asr.org/forums.html find out how to join
---
You received this message because you are subscribed to the Google Groups "kaldi-help" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kaldi...@googlegroups.com.

Daniel Povey

unread,
Jun 14, 2019, 10:03:43 AM6/14/19
to kaldi-help
The answer depends on precisely what it is you want to do, the way you said it is a bit ambiguous.

To unsubscribe from this group and stop receiving emails from it, send an email to kaldi-help+...@googlegroups.com.

To post to this group, send email to kaldi...@googlegroups.com.

Armando

unread,
Jun 14, 2019, 10:48:43 AM6/14/19
to kaldi-help
let's say I have trained a final.mdl (nnet3 type)

I save the output in the same way as specified in this thread
say

 echo "output-node name=output input=tdnn9.affine" > nnet_mod.config

nnet3-copy --nnet-config=nnet_mod.config final.mdl nnet_mod.raw
nnet3-compute nnet_mod.raw ark:feats.ark ark:tdnn9affine.ark


now I want to feed the residual part of the original network (from tdnn9.affine to the output) with tdnn9affine.ark
I don't know how to define the residual part of the network
rename the input does not work, like

 
echo "input-node name=tdnn9.affine dim=1280" > residual.config


Daniel Povey

unread,
Jun 14, 2019, 12:25:40 PM6/14/19
to kaldi-help
I suspect it might be easier to accomplish what you are trying to do a different way, without dumping that data to disk.  The config manipulation to do that is a little complicated.





To unsubscribe from this group and stop receiving emails from it, send an email to kaldi-help+...@googlegroups.com.

To post to this group, send email to kaldi...@googlegroups.com.

Armando

unread,
Jun 14, 2019, 12:54:25 PM6/14/19
to kaldi-help
the reason I'd like to save it is that I imagine a structure where, for example, different tasks like lid, multiple languages in speech2text share a portion of the network, each one with its own output. 
If I perform first the lid, then I'd like to send the data to the identified language output (among the senone outputs), but without re-computing the common part 

Daniel Povey

unread,
Jun 14, 2019, 1:38:03 PM6/14/19
to kaldi-help
OK.
It's not particularly natural to do that in the framework :-( but I was able to do it.
It required a small code change though, please pull the latest.

( echo "input-node name=new-input dim=768"; echo "component name=noop type=NoOpComponent dim=768"; echo "component-node name=tdnnf11.noop component=noop input=new-input" ) >config;
a09:s5: gdb --args nnet3-am-copy --nnet-config=config --edits="rename-node old-name=input new-name=old-input; rename-node old-name=new-input new-name=input; remove-orphan-nodes"  exp/chain/tdnn1g42o_sp/final.mdl  /dev/null 

You would change tdnnf11.noop to tdnn9.affine, but the "noop" component would remain unchanged.

Dan





To unsubscribe from this group and stop receiving emails from it, send an email to kaldi-help+...@googlegroups.com.

To post to this group, send email to kaldi...@googlegroups.com.

Armando

unread,
Jun 14, 2019, 7:46:59 PM6/14/19
to kaldi-help
does not seem to work

(echo "input-node name=new-input dim=1280"; echo "component name=noop type=NoOpComponent dim=1280"; echo "component-node name=tdnnf9.affine component=noop input=new-input") > config


nnet3-am-copy --nnet-config=config --edits="rename-node old-name=input new-name=old-input; rename-node old-name=new-input new-name=input; remove-orphan-nodes" exp/nnet/final.mdl -

WARNING (nnet3-am-copy[5.5.574~7-d3aff]:Check():nnet-nnet.cc:789) Node new-input is never used to compute any output.
WARNING (nnet3-am-copy[5.5.574~7-d3aff]:Check():nnet-nnet.cc:789) Node tdnnf9.affine is never used to compute any output.
LOG (nnet3-am-copy[5.5.574~7-d3aff]:RemoveOrphanNodes():nnet-nnet.cc:948) Removed 1 orphan nodes.
ERROR (nnet3-am-copy[5.5.574~7-d3aff]:SetContext():am-nnet-simple.cc:98) Class AmNnetSimple is only intended for a restricted type of nnet, and this one does not meet the conditions.

Daniel Povey

unread,
Jun 14, 2019, 7:48:49 PM6/14/19
to kaldi-help
Likely you didn't recompile after pulling the latest changes.


To unsubscribe from this group and stop receiving emails from it, send an email to kaldi-help+...@googlegroups.com.

To post to this group, send email to kaldi...@googlegroups.com.

Armando

unread,
Jun 15, 2019, 4:22:33 PM6/15/19
to kaldi-help
well, if the change is the one in the master in nnet3-am-copy,  it looks to me that I pull and recompiled

that model final.mdl does not have ivector, so that's only one input*
I see that it stops after

  if (NumInputNodes(nnet) == 1)
    return true;

in nnet-utils.cc

so it sees more than one input, but there should be only one, I guess (the new one)

Daniel Povey

unread,
Jun 15, 2019, 4:29:19 PM6/15/19
to kaldi-help
I suspect it's because tdnnf9.affine should be tdnn9.affine.
Depending on your model topology, of course.


To unsubscribe from this group and stop receiving emails from it, send an email to kaldi-help+...@googlegroups.com.

To post to this group, send email to kaldi...@googlegroups.com.

Armando

unread,
Jun 15, 2019, 4:48:57 PM6/15/19
to kaldi-help
it's a "7n" topology without i-vector
right, no "f" in the name


that's the log

(echo "input-node name=new-input dim=1280"; echo "component name=noop type=NoOpComponent dim=1280"; echo "component-node name=tdnn9.affine component=noop input=new-input") > exp/chain3/nnet/nnet_mod.tdnn9asinput.config


src/nnet3bin/nnet3-am-copy --nnet-config=exp/chain3/nnet/nnet_mod.tdnn9asinput.config '--edits=rename-node old-name=input new-name=old-input; rename-node old-name=new-input new-name=input; remove-orphan-nodes' exp/chain3/nnet/final.mdl -

LOG (nnet3-am-copy[5.5.574~7-d3aff]:IsSimpleNnet():nnet-utils.cc:74) BEFORE nnet.GetNodeIndex in IsSimpleNnet in nnet-utils.cc
LOG (nnet3-am-copy[5.5.574~7-d3aff]:IsSimpleNnet():nnet-utils.cc:74)  BEFORE nnet.GetNodeIndex in IsSimpleNnet in nnet-utils.cc
WARNING (nnet3-am-copy[5.5.574~7-d3aff]:Check():nnet-nnet.cc:779) Component tdnn9.affine is never used by any node.
WARNING (nnet3-am-copy[5.5.574~7-d3aff]:Check():nnet-nnet.cc:789) Node tdnn8.affine is never used to compute any output.
WARNING (nnet3-am-copy[5.5.574~7-d3aff]:Check():nnet-nnet.cc:789) Node tdnn8.relu is never used to compute any output.
WARNING (nnet3-am-copy[5.5.574~7-d3aff]:Check():nnet-nnet.cc:789) Node tdnn8.batchnorm is never used to compute any output.
WARNING (nnet3-am-copy[5.5.574~7-d3aff]:Check():nnet-nnet.cc:789) Node tdnn9l is never used to compute any output.
LOG (nnet3-am-copy[5.5.574~7-d3aff]:RemoveOrphanNodes():nnet-nnet.cc:948) Removed 4 orphan nodes.
LOG (nnet3-am-copy[5.5.574~7-d3aff]:IsSimpleNnet():nnet-utils.cc:74)  BEFORE nnet.GetNodeIndex in IsSimpleNnet in nnet-utils.cc
LOG (nnet3-am-copy[5.5.574~7-d3aff]:IsSimpleNnet():nnet-utils.cc:74)  BEFORE nnet.GetNodeIndex in IsSimpleNnet in nnet-utils.cc
ERROR (nnet3-am-copy[5.5.574~7-d3aff]:ComputeSimpleNnetContext():nnet-utils.cc:204) Failure in ComputeSimpleNnetContext (perhaps not a simple nnet?)

added simple statements, that's why line numbers do not correspond with the master's

Daniel Povey

unread,
Jun 15, 2019, 4:52:26 PM6/15/19
to kaldi-help
That topology has bypass connectinons, so what you are trying to do wouldn't work.

To unsubscribe from this group and stop receiving emails from it, send an email to kaldi-help+...@googlegroups.com.

To post to this group, send email to kaldi...@googlegroups.com.

Armando

unread,
Jun 15, 2019, 5:05:52 PM6/15/19
to kaldi-help
oh, right
thanks, with another topology indeed works
Reply all
Reply to author
Forward
0 new messages