python代码优化工具,python - 优化WER(字错误率)代码?

我正在尝试计算WER来评估ASR系统,但是分数的计算却要花费很多时间(因为我想对其进行一些引导以获取置信区间以更可靠地评估系统)。

这是我到目前为止提出的代码,有没有人看到一种更有效的方法(更快,并且如果您有提高内存效率的想法,那也将受到欢迎)。def modify_text(text):

"""

Function to modify a clean text to add some errors in it.

"""

modified_text = []

for word in true_text:

action = np.random.choice(['deletion','addition','subsitution','nothing'],

p = [0.1,0.1,0.1,0.7])

if action in ['addition','substitution']:

modified_text.append(random.choice(voca))

if action in ['addition','nothing']:

modified_text.append(word)

return modified_text

def wer(s1,s2):

d = np.zeros([len(s1)+1,len(s2)+1])

d[:,0] = np.arange(len(s1)+1)

d[0,:] = np.arange(len(s2)+1)

for j in range(1,len(s2)+1):

for i in range(1,len(s1)+1):

if s1[i-1] == s2[j-1]:

d[i,j] = d[i-1,j-1]

else:

d[i,j] = min(d[i-1,j]+1, d[i,j-1]+1, d[i-1,j-1]+1)

return d[-1,-1]/len(s1)

text = """I am happy to join with you today in what will go down in history as

the greatest demonstration for freedom in the history of our nation.

Five score years ago, a great American, in whose symbolic shadow

we stand today, signed the Emancipation Proclamation. This momentous

decree came as a great beacon light of hope to millions of Negro slaves

who had been seared in the flames of withering injustice. It came as a

joyous daybreak to end the long night of their captivity. """

true_text = list(tokenize(text))

modified_text = modify_text(true_text)

%timeit wer(true_text,modified_text)

输出:

7.04 ms ± 49.4 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

好的,这似乎还不错,但是我有数以万计的文本需要使用引导程序进行评估,并且文本的长度更长。因此,我想找到一种更快的方法来执行wer功能。任何的想法?

最佳答案

大多数语音识别评估首先将语音分为句子或话语。然后,通过对齐每个发音来计算WER。因为WER计算为O(n ^ 2),所以可以大大提高速度。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值