mxnet icon indicating copy to clipboard operation
mxnet copied to clipboard

How to load ARK files in mxnet

Open venkateshappea opened this issue 9 years ago • 8 comments

Hi, I'm attempting to load some ARK files into mxnet, but I'm not exactly sure on how to go about it. I did go over the speech-demo example, but in there, there are custom io files that is loading sequences in certain format for LSTMs. I'm trying to simply load an ark file for an acoustic model, I was wondering if you could point to me exactly what files I can use in the speech-demo or a work around on how to go about it. -Venkatesh

@yzhang87

venkateshappea avatar Feb 06 '17 19:02 venkateshappea

Firstly you need to load ark data type to numpy array, you can try some parsing tools, the following one is a quite good

https://github.com/vesis84/kaldi-io-for-python

After converting the data into numpy arrays, then you can write your own data iterator to manage the data loading process

wsstriving avatar Feb 07 '17 13:02 wsstriving

Thank you, this helped me out a lot!

venkateshappea avatar Feb 09 '17 00:02 venkateshappea

I am trying to create a slider in my data. Essentially, after my ARK files are processed I want to train its features such that each row of features being trained will have its surrounding context. For example, if I am training row 3 in a feature matrix - [f2], with target [t2], I want to have a slider that will provide that provide f2 with its surrounding context so it should be [f1 f2 f3] with target [t2] where the surrounding context can be a variable so a right context and a left context. Is that available in Mxnet?

venkateshappea avatar Feb 09 '17 23:02 venkateshappea

For loading ark in speech demo, you can take a look the io_function. It actually call the Kaldi ".so" file directly. You can load a chunk of ark file by calling def load_next_block in https://github.com/dmlc/mxnet/blob/master/example/speech-demo/io_func/feat_io.py

For adding sliding window, you can do it on Kaldi side by using nnet1 feature transform if you familiar with Kaldi. Something like, 440 40 [-5 -4 -3 -2 -1 0 1 2 3 4 5]

Then when you call load_next_block, the feature has add context. You can check the transform section in: https://github.com/dmlc/mxnet/blob/master/example/speech-demo/README.md

yzhang87 avatar Feb 10 '17 03:02 yzhang87

I think if you use Karen's https://github.com/vesis84/kaldi-io-for-python Kaldi reader, you need add some python code to do the sliding window.

yzhang87 avatar Feb 10 '17 03:02 yzhang87

Actually, you can pass a kaldi respecifier to the kaldi-io, and do the feature transformation in the kaldi part:

For example, you can first add deltas to the features, apply cmvn operations, and then do the feature extension (sliding). The following script will get inputs of 13 dimension, and return outputs of (13+13+13) * (5+1+5) = 429 dimensions

rsp = """ark,s,cs:add-deltas --delta-window=3 --delta-order=2 scp:test.scp ark:- |
        apply-cmvn-sliding --norm-vars=false --center=true --cmn-window=300 ark:- ark:- |
        splice-feats --left-context=5 --right-context=5 ark:- ark:-|"""
kaldi_io.read_mat_ark(rsp)

wsstriving avatar Feb 10 '17 05:02 wsstriving

Okay, I tried out what @wsstriving suggested and seems to do trick. Thanks!

venkateshappea avatar Feb 10 '17 19:02 venkateshappea

Is there an option for me to train with multiple different files? Currently I only see that I can train with one file with its corresponding labels file.

venkateshappea avatar Feb 14 '17 22:02 venkateshappea