Kaldi的rnnlm训练

本文介绍如何使用Kaldi工具中的RNNLM组件训练词向量,并提供了详细的步骤及示例,包括安装配置、参数说明及运行过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境: Ubuntu 12.04, Kaldi

深度学习在NLP上的应用(具体可参考这篇文章  http://licstar.net/archives/328) 中提到一个概念:词向量 (英文为distributed representation, word representation, word embeding中任一个)。在Mikolov 的 RNNLM中有涉及到到词向量的训练,其中Kaldi中有实现示例。

1. 切换到Kaldi目录/u01/kaldi/tools,未找到rnnlm目录。 可能是版本有些旧了, 直接从网上下载这个目录

svn co https://svn.code.sf.net/p/kaldi/code/trunk/tools/rnnlm-hs-0.1b

2. 
cd rnnlm-hs-01.b
make
生成rnnlm执行文件

jerry@hq:/u01/kaldi/tools/rnnlm-hs-0.1b$ ./rnnlm
RNNLM based on WORD VECTOR estimation toolkit v 0.1b

Options:
Parameters for training:
        -train
                Use text data from to train the model
        -valid
                Use text data from to perform validation and control learning rate
        -test
                Use text data from to compute logprobs with an existing model
        -rnnlm
                Use to save the resulting language model
        -hidden
                Set size of hidden layer; default is 100
        -bptt
                Set length of BPTT unfolding; default is 3; set to 0 to disable truncation
        -bptt-block
                Set period of BPTT unfolding; default is 10; BPTT is performed each bptt+bptt_block steps
        -gen
                Sampling mode; number of sentences to sample, default is 0 (off); enter negative number for interactive mode
        -threads
                Use threads (default 1)
        -min-count
                This will discard words that appear less than times; default is 0
        -alpha
                Set the starting learning rate; default is 0.1
        -maxent-alpha
                Set the starting learning rate for maxent; default is 0.1
        -reject-threshold
                Reject nnet and reload nnet from previous epoch if the relative entropy improvement on the validation set is below this threshold (default 0.997)
        -stop
                Stop training when the relative entropy improvement on the validation set is below this threshold (default 1.003); see also -retry
        -retry
                Stop training iff N retries with halving learning rate have failed (default 2)
        -debug
                Set the debug mode (default = 2 = more info during training)
        -direct-size
                Set the size of hash for maxent parameters, in millions (default 0 = maxent off)
        -direct-order
                Set the order of n-gram features to be used in maxent (default 3)
        -beta1
                L2 regularisation parameter for RNNLM weights (default 1e-6)
        -beta2
                L2 regularisation parameter for maxent weights (default 1e-6)
        -recompute-counts
                Recompute train words counts, useful for fine-tuning (default = 0 = use counts stored in the vocab file)


Examples:
./rnnlm -train data.txt -valid valid.txt -rnnlm result.rnnlm -debug 2 -hidden 200

3.  使用kaldi中的wsj示例
下载一个包含wsj的 git clone https://github.com/foundintranslation/Kaldi.git
将其中的cp wsj/s1 /u01/kaldi/egs/wsj/ -Rf
发现其中的wsj数据源是要用dvd光盘上的,没法获得,这条路走不通。


4. 到网站http://www.fit.vutbr.cz/~imikolov/rnnlm/下载

rnnlm-0.3e 

Basic examples

这两个文件,其中有程序和示例, 解压Basic_examples,里面有数据文件data

jerry@hq:/u01/kaldi/tools/rnnlm-hs-0.1b$ ls /u01/jerry/simple-examples/data
ptb.char.test.txt  ptb.char.train.txt  ptb.char.valid.txt  ptb.test.txt  ptb.train.txt  ptb.valid.txt  README

开始训练词向量
jerry@hq:/u01/kaldi/tools/rnnlm-hs-0.1b$ ./rnnlm -train /u01/jerry/simple-examples/data/ptb.train.txt -valid /u01/jerry/simple-examples/data/ptb.valid.txt -rnnlm result.rnnlm -debug2 -hidden 100

Vocab size: 10000
Words in train file: 929589
Starting training using file /u01/jerry/simple-examples/data/ptb.train.txt
Iteration 0     Valid Entropy 9.457519
Alpha: 0.100000  ME-alpha: 0.100000  Progress: 99.11%  Words/thread/sec: 28.40k Iteration 1     Valid Entropy 8.416857
Alpha: 0.100000  ME-alpha: 0.100000  Progress: 99.11%  Words/thread/sec: 28.18k Iteration 2     Valid Entropy 8.203366
Alpha: 0.100000  ME-alpha: 0.100000  Progress: 99.11%  Words/thread/sec: 27.98k Iteration 3     Valid Entropy 8.090350
Alpha: 0.100000  ME-alpha: 0.100000  Progress: 99.11%  Words/thread/sec: 27.25k Iteration 4     Valid Entropy 8.026399
Alpha: 0.100000  ME-alpha: 0.100000  Progress: 99.11%  Words/thread/sec: 27.35k Iteration 5     Valid Entropy 7.979509
Alpha: 0.100000  ME-alpha: 0.100000  Progress: 99.11%  Words/thread/sec: 27.43k Iteration 6     Valid Entropy 7.949336
Alpha: 0.100000  ME-alpha: 0.100000  Progress: 99.11%  Words/thread/sec: 27.35k Iteration 7     Valid Entropy 7.931067  Decay started
Alpha: 0.050000  ME-alpha: 0.050000  Progress: 99.11%  Words/thread/sec: 28.55k Iteration 8     Valid Entropy 7.827513
Alpha: 0.025000  ME-alpha: 0.025000  Progress: 99.11%  Words/thread/sec: 28.37k Iteration 9     Valid Entropy 7.759574
Alpha: 0.012500  ME-alpha: 0.012500  Progress: 99.11%  Words/thread/sec: 28.45k Iteration 10    Valid Entropy 7.714383
Alpha: 0.006250  ME-alpha: 0.006250  Progress: 99.11%  Words/thread/sec: 28.51k Iteration 11    Valid Entropy 7.684731
Alpha: 0.003125  ME-alpha: 0.003125  Progress: 99.11%  Words/thread/sec: 28.64k Iteration 12    Valid Entropy 7.668839  Retry 1/2
Alpha: 0.001563  ME-alpha: 0.001563  Progress: 99.11%  Words/thread/sec: 28.25k Iteration 13    Valid Entropy 7.668437  Retry 2/2



jerry@hq:/u01/kaldi/tools/rnnlm-hs-0.1b$ ls -l
total 8184
-rw-rw-r-- 1 jerry jerry   11358 Aug 25 15:08 LICENSE
-rw-rw-r-- 1 jerry jerry     407 Aug 25 15:08 Makefile
-rw-rw-r-- 1 jerry jerry    8325 Aug 25 15:08 README.txt
-rw-rw-r-- 1 jerry jerry  109943 Aug 25 18:05 result.rnnlm
-rw-rw-r-- 1 jerry jerry 8040020 Aug 25 18:05 result.rnnlm.nnet
-rwxrwxr-x 1 jerry jerry  142501 Aug 25 15:08 rnnlm
-rw-rw-r-- 1 jerry jerry   33936 Aug 25 15:08 rnnlm.c
jerry@hq:/u01/kaldi/tools/rnnlm-hs-0.1b$

vi   result.rnnlm

42068
the 50770
45020
N 32481
of 24400
to 23638
a 21196
in 18000
and 17474
's 9784




来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/16582684/viewspace-1257524/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/16582684/viewspace-1257524/

### Kaldi结合Lhotse进行数据预处理 为了使Kaldi能够更高效地利用现代Python工具链的优势,社区开发了Lhotse库来简化和增强数据准备流程。通过Lhotse,可以更加方便地完成从原始音频文件到适合Kaldi训练的数据格式转换。 #### 安装依赖项 首先需要安装必要的软件包: ```bash pip install lhotse kaldi-native-io ``` #### 准备Manifests Lhotse的核心概念之一是manifest——一种描述音频记录及其转录的JSON文件结构。这一步骤涉及创建这些manifest文件,它们将在后续阶段被用来指导特征提取和其他预处理操作[^1]。 #### 特征提取 一旦有了manifests,就可以使用Lhotse轻松地为Kaldi生成所需的MFCC特征矩阵。下面是一个简单的例子展示如何执行此任务: ```python from pathlib import Path import lhotse from lhotse.recipes import prepare_librispeech from lhotse.features.kaldi import compute_kaldi_fbank, FbankConfig # 假设已经有一个LibriSpeech manifest位于'data/manifest.jsonl.gz' cuts = lhotse.CutSet.from_manifest_path('data/manifest.jsonl.gz') # 配置FBANK参数并计算特征 fbank_config = FbankConfig(num_mel_bins=80) features = cuts.compute_and_store_features( extractor=compute_kaldi_fbank, output_dir='data/fbank', fbank_config=fbank_config ) print(f"Features stored at {Path('data/fbank')}") ``` 这段代码会读取之前准备好的cutset对象,并基于指定配置计算滤波器组(FBANK)特性,最后保存至磁盘上供下一步使用。 #### 构建Kaldi兼容格式 为了让上述产生的特征能顺利导入给定版本的Kaldi环境中,还需要做一些额外的工作把它们转化为特定于该框架的形式。通常这意味着要编写一些脚本将Lhotse输出的结果映射成`.scp` 和 `.ark` 文件形式,这是Kaldi所期望看到的标准输入格式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值