openfst 学习笔记

系统学习一下openfst的操作

  • tutorial

从最基本的 fst 图说起

从图中可以大致了解到 fst 包含的几个元素: 起始状态,终止状态(终止状态含有权重),转移边,边上有输入符号,输出符号,边权重

于是,对于输入串 ac, fst 会输出 xz 权重和为 6.5

对于 bc ,输出 yz, 权重和为 7.5

  • creating fst

创建fst的方式有两种,一是通过c++接口,二是通过shell脚本

本文以shell脚本方式为主

首先通过如下指令创建 text.fst

cat >text.fst <<EOF
0 1 a x .5
0 1 b y 1.5
1 2 c z 2.5
2 3.5
EOF

text.fst 内容为:

在openfst 里面 边的输入输出都用数字来代替,所以我们还必须给 abc,xyz 提供到数字的字典映射

isyms.txt :

cat >isyms.txt <<EOF
<eps> 0
a 1
b 2
c 3
EOF

osyms.txt:

cat >osyms.txt <<EOF
<eps> 0
x 1
y 2
z 3
EOF

关于输入输出标签及其数字映射有如下规定:

可以使用任何string作为 label,可以使用任何非负数字作为 映射的label ID

当输入输出为空时,我们用 eps 来表示,对应点 label ID 为 0

先将文本 fst 编译为 二进制文件

fstcompile --isymbols=isyms.txt --osymbols=osyms.txt text.fst binary.fst

下面指令有同样的功能,并额外地具有将符号表排序

fstcompile --isymbols=isyms.txt --osymbols=osyms.txt --keep_isymbols --keep_osymbols text.fst binary.fst

经过映射后,二进制fst里保存的是上面的 fst内容

  • accessing fst

创建完一个fst后,我们就需要去访问这个fst里面的元素了

Printing, Drawing and Summarizing FSTs from the Shell

fstprint --isymbols=isyms.txt --osymbols=osyms.txt binary.fst text.fst

上面的指令可以将二进制fst转化为 text.fst ,实现和 fstcompile 相反的功能

fstdraw --isymbols=isyms.txt --osymbols=osyms.txt binary.fst | dot -Tps > binary.ps

fstdraw 可以将fst 画出来,先生成 *.ps 文件,然后可以通过 GSView 等软件进行查看

下载链接:

Ghostscript: GSView​artifex.com

 

fstinfo 指令,列出关于fst的一些相关信息

fstinfo binary.fst
  • FST Operations
    • Calling FST Operations
# The FSTs must be sorted along the dimensions they will be joined.
# In fact, only one needs to be so sorted.
# This could have instead been done for "model.fst" when it was created. 
$ fstarcsort --sort_type=olabel input.fst input_sorted.fst
$ fstarcsort --sort_type=ilabel model.fst model_sorted.fst

# Creates the composed FST. 
$ fstcompose input_sorted.fst model_sorted.fst comp.fst

# Just keeps the output label 
$ fstproject --project_output comp.fst result.fst

# Do it all in a single command line. 
$ fstarcsort --sort_type=ilabel model.fst | fstcompose input.fst - | fstproject --project_output result.fst

最重要的操作就是 compose

fst 的 weight 有两种运算:

plux(x,y) 和 time(x,y)

  • openfst advanced usage

arc iterators

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值