将一个.py文件重写为.ipynb,但行之有效
我需要在自动语音识别(ASR)成绩单和地面真实笔录中测量单词错误率(WER)。
搜索一个程序来帮助我满足这种需求,我发现 repo 我在github上它计算我需要的东西。
据我了解,该程序是在终端运行的,实际上这就是我尝试和工作的方式。
现在,我想为我拥有的一组文件运行该程序的逻辑,因此为了实现我在jupyter笔记本中编写了一些代码,以导入所使用的模块并计算每个夫妇的wer文件位于文件夹目录中。
我现在面临的问题是代码运行,但是我的指标错误,而我的指标有正确的指标。
有人可以帮助您了解此问题是否可能与ArgParse的工作原理有关,或者与ASR_Evalution模块如何管理变量有关。
请有关如何调试或解决此问题的一些暗示。
话虽如此,我已经并且执行了以下内容:
- 使用
的文件和文件夹目录
|-- ASR
| |--1
| |. ref_groundTruth.txt
| |. hyp_fakeASR.txt
| |
| |--2
| |. ref_groundTruth.txt
| |. hyp_groundTruth.txt
- ,因为导入的模块期望我从repo中复制/粘贴的argparse对象创建Parser(create_parser)
结果,当我在jupyter的终端与jupyter中使用该程序时,结果 终端的输出& jupyter的输出
用于ref_groundTruth.txt,hyp_groundtruth.txt,hyp_ground.txt,hyp_ground.txt.txt。
Esto es un texto de prueba para utilizar la libreria ASR, luego de validar, paso al siguiente nivel
- 用于hyp_fakeasr.txt的文本如下:
Esto es un text para test para utilizar la libreria ASR, luego de validar, paso al siguiente nivel
- 开发的代码为
# Import libraries
from asr_evaluation.asr_evaluation import *
import argparse
from os import walk
# Let's define the parse structure to invoke every time we need past to the module asr_evaluation
def create_parser():
parser = argparse.ArgumentParser(description='Evaluate an ASR transcript against a reference transcript.')
parser.add_argument('ref', type=argparse.FileType('r'), help='Reference transcript filename')
parser.add_argument('hyp', type=argparse.FileType('r'), help='ASR hypothesis filename')
print_args = parser.add_mutually_exclusive_group()
print_args.add_argument('-i', '--print-instances', action='store_true',
help='Print all individual sentences and their errors.')
print_args.add_argument('-r', '--print-errors', action='store_true',
help='Print all individual sentences that contain errors.')
parser.add_argument('--head-ids', action='store_true',
help='Hypothesis and reference files have ids in the first token? (Kaldi format)')
parser.add_argument('-id', '--tail-ids', '--has-ids', action='store_true',
help='Hypothesis and reference files have ids in the last token? (Sphinx format)')
parser.add_argument('-c', '--confusions', action='store_true', help='Print tables of which words were confused.')
parser.add_argument('-p', '--print-wer-vs-length', action='store_true',
help='Print table of average WER grouped by reference sentence length.')
parser.add_argument('-m', '--min-word-count', type=int, default=1, metavar='count',
help='Minimum word count to show a word in confusions (default 1).')
parser.add_argument('-a', '--case-insensitive', action='store_true',
help='Down-case the text before running the evaluation.')
parser.add_argument('-e', '--remove-empty-refs', action='store_true',
help='Skip over any examples where the reference is empty.')
return parser
# My path is the folder in which the transcripts ASR are and the ground truth
mypath = './ASR'
#Let's define some macro variables
cnt = 1
prefix_ref = 'ref_'
prefix_hyp = 'hyp_'
# With OS walk we are going to find all the folders related to the transcripted audio which containt \
# the ASR and ground Truth text files
for (dirpath, dirnames, filenames) in walk(mypath):
print(f'-------{cnt}------')
if len(filenames) > 1:
groundTruth = dirpath + '/' + ''.join([word for word in filenames if word.startswith(prefix_hyp)])
fakeASR = dirpath + '/' + ''.join([word for word in filenames if word.startswith(prefix_ref)])
parser = create_parser()
args = parser.parse_args([groundTruth, fakeASR])
main(args)
cnt+=1
I am in a need to measure the word error rate (WER) given an Automatic Speech Recognition (ASR) transcript and a ground truth transcript.
Searching for a program to help me with this need I found this repo on github that I tried and its calculates what I needed.
As far as I understand this program is built to run in a terminal, in fact that was how I tried and worked.
Now the thing is that I want to run the logic of this program for a group of files that I have, so in order to achieve that I wrote some code in a jupyter notebook that imports the module used and calculates the WER of each couple of files being in a directory of folders.
The problem that I facing now is that the code runs but I having wrong metrics, whereas I had the correct metrics running from the terminal.
Can someone please help understand if this problem could be related to how argparse works or if it can be related to how the asr_evalution modules manage the variables.
Please some hints on how I can debug or fix this problem.
Being that said, I have and did the following:
- Directory of files and folders used
|-- ASR
| |--1
| |. ref_groundTruth.txt
| |. hyp_fakeASR.txt
| |
| |--2
| |. ref_groundTruth.txt
| |. hyp_groundTruth.txt
Because the imported module expects an argparse object I copy/paste from the repo the lines that creates the parser (create_parser)
Results when I ran the program in the terminal vs in jupyter with the code developed
terminal's output & jupyter's outputThe text used for ref_groundTruth.txt, hyp_groundTruth.txt are the following:
Esto es un texto de prueba para utilizar la libreria ASR, luego de validar, paso al siguiente nivel
- The text used for hyp_fakeASR.txt is the following:
Esto es un text para test para utilizar la libreria ASR, luego de validar, paso al siguiente nivel
- The developed code is
# Import libraries
from asr_evaluation.asr_evaluation import *
import argparse
from os import walk
# Let's define the parse structure to invoke every time we need past to the module asr_evaluation
def create_parser():
parser = argparse.ArgumentParser(description='Evaluate an ASR transcript against a reference transcript.')
parser.add_argument('ref', type=argparse.FileType('r'), help='Reference transcript filename')
parser.add_argument('hyp', type=argparse.FileType('r'), help='ASR hypothesis filename')
print_args = parser.add_mutually_exclusive_group()
print_args.add_argument('-i', '--print-instances', action='store_true',
help='Print all individual sentences and their errors.')
print_args.add_argument('-r', '--print-errors', action='store_true',
help='Print all individual sentences that contain errors.')
parser.add_argument('--head-ids', action='store_true',
help='Hypothesis and reference files have ids in the first token? (Kaldi format)')
parser.add_argument('-id', '--tail-ids', '--has-ids', action='store_true',
help='Hypothesis and reference files have ids in the last token? (Sphinx format)')
parser.add_argument('-c', '--confusions', action='store_true', help='Print tables of which words were confused.')
parser.add_argument('-p', '--print-wer-vs-length', action='store_true',
help='Print table of average WER grouped by reference sentence length.')
parser.add_argument('-m', '--min-word-count', type=int, default=1, metavar='count',
help='Minimum word count to show a word in confusions (default 1).')
parser.add_argument('-a', '--case-insensitive', action='store_true',
help='Down-case the text before running the evaluation.')
parser.add_argument('-e', '--remove-empty-refs', action='store_true',
help='Skip over any examples where the reference is empty.')
return parser
# My path is the folder in which the transcripts ASR are and the ground truth
mypath = './ASR'
#Let's define some macro variables
cnt = 1
prefix_ref = 'ref_'
prefix_hyp = 'hyp_'
# With OS walk we are going to find all the folders related to the transcripted audio which containt \
# the ASR and ground Truth text files
for (dirpath, dirnames, filenames) in walk(mypath):
print(f'-------{cnt}------')
if len(filenames) > 1:
groundTruth = dirpath + '/' + ''.join([word for word in filenames if word.startswith(prefix_hyp)])
fakeASR = dirpath + '/' + ''.join([word for word in filenames if word.startswith(prefix_ref)])
parser = create_parser()
args = parser.parse_args([groundTruth, fakeASR])
main(args)
cnt+=1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论