本文介绍如何以定量方式度量和提高基础语音转文本模型或你自己的自定义模型的准确度。 测试准确性需要音频 + 人为标记的听录内容数据。 你应该提供 30 分钟到 5 小时的代表性音频。
重要
测试时,系统将执行听录。 请务必记住,因为定价因服务套餐和订阅级别而异。 请始终参阅官方 Azure AI 服务定价 以获取最新详细信息。
创建测试
可以通过创建测试来测试自定义模型的准确性。 测试需要一组音频文件及其相应的听录。 可以将自定义模型的准确性与语音与文本基础模型或其他自定义模型进行比较。 获取测试结果后,与语音识别结果相比,评估单词错误率(WER)。
按照以下步骤创建准确性测试:
登录 Speech Studio。
选择 “自定义语音> 项目名称 >测试模型”。
选择“ 创建新测试”。
选择“下一步评估准确性>”。
选择一个音频 + 人工标记听录数据集,然后选择“ 下一步”。 如果没有任何可用的数据集,请取消设置,然后转到“语音数据集”菜单来上传数据集。
注释
选择的声学数据集必须不同于你对自己的模型使用的数据集。 此方法可以提供对模型性能更现实的感觉。
最多选择两个要评估的模型,然后选择“ 下一步”。
输入测试名称和说明,然后选择“ 下一步”。
查看测试详细信息,然后选择“ 保存并关闭”。
若要创建测试,请使用 spx csr evaluation create
命令。 根据以下说明构造请求参数:
- 将
project
属性设置为现有项目的 ID。 建议使用此属性,以便还可以在 Speech Studio 中查看测试。 可以运行spx csr project list
命令来获取可用项目。 - 将所需
model1
属性设置为要测试的模型的 ID。 - 将所需
model2
属性设置为要测试的另一个模型的 ID。 如果你不想比较两个模型,请对model1
和model2
使用相同的模型。 - 将所需
dataset
属性设置为要用于测试的数据集的 ID。 - 设置
language
属性,否则 Speech CLI 将默认设置为“en-US”。 此参数应设置为数据集内容的区域。 以后无法更改区域设置。 语音 CLIlanguage
参数对应于 JSON 请求和响应中的locale
属性。 - 设置所需的
name
属性。 此参数是在 Speech Studio 中显示的名称。 语音 CLIname
属性对应于 JSON 请求和响应中的displayName
属性。
下面是创建测试的示例语音 CLI 命令:
spx csr evaluation create --api-version v3.2 --project 0198f569-cc11-4099-a0e8-9d55bc3d0c52 --dataset 23b6554d-21f9-4df1-89cb-f84510ac8d23 --model1 ff43e922-e3e6-4bf0-8473-55c08fd68048 --model2 13fb305e-09ad-4bce-b3a1-938c9124dda3 --name "My Evaluation" --description "My Evaluation Description"
你应该会收到以下格式的响应正文:
{
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/evaluations/dda6e880-6ccd-49dc-b277-137565cbaa38",
"model1": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/models/base/13fb305e-09ad-4bce-b3a1-938c9124dda3"
},
"model2": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/models/base/13fb305e-09ad-4bce-b3a1-938c9124dda3"
},
"dataset": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/datasets/23b6554d-21f9-4df1-89cb-f84510ac8d23"
},
"transcription2": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/transcriptions/b50642a8-febf-43e1-b9d3-e0c90b82a62a"
},
"transcription1": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/transcriptions/b50642a8-febf-43e1-b9d3-e0c90b82a62a"
},
"project": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/projects/0198f569-cc11-4099-a0e8-9d55bc3d0c52"
},
"links": {
"files": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/evaluations/dda6e880-6ccd-49dc-b277-137565cbaa38/files"
},
"properties": {
"wordErrorRate1": -1.0,
"sentenceErrorRate1": -1.0,
"sentenceCount1": -1,
"wordCount1": -1,
"correctWordCount1": -1,
"wordSubstitutionCount1": -1,
"wordDeletionCount1": -1,
"wordInsertionCount1": -1,
"wordErrorRate2": -1.0,
"sentenceErrorRate2": -1.0,
"sentenceCount2": -1,
"wordCount2": -1,
"correctWordCount2": -1,
"wordSubstitutionCount2": -1,
"wordDeletionCount2": -1,
"wordInsertionCount2": -1
},
"lastActionDateTime": "2024-07-14T21:31:14Z",
"status": "NotStarted",
"createdDateTime": "2024-07-14T21:31:14Z",
"locale": "en-US",
"displayName": "My Evaluation",
"description": "My Evaluation Description",
"customProperties": {
"testingKind": "Evaluation"
}
}
响应正文中的顶级 self
属性是评估的 URI。 使用此 URI 获取有关项目和测试结果的详细信息。 还可以使用此 URI 更新或删除评估。
如需语音命令行界面的评估帮助,请运行以下命令:
spx help csr evaluation
若要创建测试,请使用语音转文本 REST API 的Evaluations_Create 操作。 根据以下说明构造请求正文:
- 将
project
属性设置为现有项目的 URI。 建议使用此属性,以便还可以在 Speech Studio 中查看测试。 可以发出 Projects_List 请求来获取可用项目。 - 将
testingKind
属性设置为Evaluation
在customProperties
. 如果未指定Evaluation
,测试将被视为质量检查测试。 无论属性testingKind
是设置为Evaluation
还是Inspection
未设置,都可以通过 API 访问准确性分数,但不能在 Speech Studio 中访问。 - 将所需
model1
属性设置为要测试的模型的 URI。 - 将所需
model2
属性设置为要测试的另一个模型的 URI。 如果不想比较两个模型,请对model1
和model2
使用相同的模型。 - 将所需
dataset
属性设置为要用于测试的数据集的 URI。 - 设置所需的
locale
属性。 此属性应该是数据集内容的区域设置。 以后无法更改区域设置。 - 设置所需的
displayName
属性。 此属性是在 Speech Studio 中显示的名称。
使用 URI 发出 HTTP POST 请求,如以下示例所示。 将 YourSubscriptionKey
替换为语音资源密钥,将 YourServiceRegion
替换为语音资源区域,并按前面所述设置请求正文属性。
curl -v -X POST -H "Ocp-Apim-Subscription-Key: YourSubscriptionKey" -H "Content-Type: application/json" -d '{
"model1": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/models/13fb305e-09ad-4bce-b3a1-938c9124dda3"
},
"model2": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/models/base/13fb305e-09ad-4bce-b3a1-938c9124dda3"
},
"dataset": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/datasets/23b6554d-21f9-4df1-89cb-f84510ac8d23"
},
"project": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/projects/0198f569-cc11-4099-a0e8-9d55bc3d0c52"
},
"displayName": "My Evaluation",
"description": "My Evaluation Description",
"customProperties": {
"testingKind": "Evaluation"
},
"locale": "en-US"
}' "https://YourServiceRegion.api.cognitive.azure.cn/speechtotext/v3.2/evaluations"
你应该会收到以下格式的响应正文:
{
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/evaluations/dda6e880-6ccd-49dc-b277-137565cbaa38",
"model1": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/models/base/13fb305e-09ad-4bce-b3a1-938c9124dda3"
},
"model2": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/models/base/13fb305e-09ad-4bce-b3a1-938c9124dda3"
},
"dataset": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/datasets/23b6554d-21f9-4df1-89cb-f84510ac8d23"
},
"transcription2": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/transcriptions/b50642a8-febf-43e1-b9d3-e0c90b82a62a"
},
"transcription1": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/transcriptions/b50642a8-febf-43e1-b9d3-e0c90b82a62a"
},
"project": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/projects/0198f569-cc11-4099-a0e8-9d55bc3d0c52"
},
"links": {
"files": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/evaluations/dda6e880-6ccd-49dc-b277-137565cbaa38/files"
},
"properties": {
"wordErrorRate1": -1.0,
"sentenceErrorRate1": -1.0,
"sentenceCount1": -1,
"wordCount1": -1,
"correctWordCount1": -1,
"wordSubstitutionCount1": -1,
"wordDeletionCount1": -1,
"wordInsertionCount1": -1,
"wordErrorRate2": -1.0,
"sentenceErrorRate2": -1.0,
"sentenceCount2": -1,
"wordCount2": -1,
"correctWordCount2": -1,
"wordSubstitutionCount2": -1,
"wordDeletionCount2": -1,
"wordInsertionCount2": -1
},
"lastActionDateTime": "2024-07-14T21:31:14Z",
"status": "NotStarted",
"createdDateTime": "2024-07-14T21:31:14Z",
"locale": "en-US",
"displayName": "My Evaluation",
"description": "My Evaluation Description",
"customProperties": {
"testingKind": "Evaluation"
}
}
响应正文中的顶级 self
属性是评估的 URI。 使用此 URI 获取 有关评估项目和测试结果的详细信息。 还可以使用此 URI 更新或删除评估。
获取测试结果
应获取测试结果以与语音识别结果相比并评估单词错误率(WER)。
按照以下步骤获取测试结果:
- 登录 Speech Studio。
- 选择 “自定义语音> 项目名称 >测试模型”。
- 按测试名称选择链接。
- 测试完成后,状态指示为 “成功” 时,您应该会看到包含每个已测试模型的 WER 编号的结果。
此页面列出了数据集中所有的语句、识别结果,以及提交的数据集中的转录文件。 可以切换各种错误类型,包括插入、删除和替换。 通过侦听音频并比较每列中的识别结果,可以确定哪个模型满足你的需求,并确定需要更多训练和改进的位置。
若要获取测试结果,请使用 spx csr evaluation status
命令。 根据以下说明构造请求参数:
- 将所需的
evaluation
属性设置为想要获取测试结果的评估的 ID。
下面是获取测试结果的示例语音 CLI 命令:
spx csr evaluation status --api-version v3.2 --evaluation 8bfe6b05-f093-4ab4-be7d-180374b751ca
响应正文中返回单词错误率和更多详细信息。
你应该会收到以下格式的响应正文:
{
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/evaluations/dda6e880-6ccd-49dc-b277-137565cbaa38",
"model1": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/models/base/13fb305e-09ad-4bce-b3a1-938c9124dda3"
},
"model2": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/models/base/13fb305e-09ad-4bce-b3a1-938c9124dda3"
},
"dataset": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/datasets/23b6554d-21f9-4df1-89cb-f84510ac8d23"
},
"transcription2": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/transcriptions/b50642a8-febf-43e1-b9d3-e0c90b82a62a"
},
"transcription1": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/transcriptions/b50642a8-febf-43e1-b9d3-e0c90b82a62a"
},
"project": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/projects/0198f569-cc11-4099-a0e8-9d55bc3d0c52"
},
"links": {
"files": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/evaluations/dda6e880-6ccd-49dc-b277-137565cbaa38/files"
},
"properties": {
"wordErrorRate1": 0.028900000000000002,
"sentenceErrorRate1": 0.667,
"tokenErrorRate1": 0.12119999999999999,
"sentenceCount1": 3,
"wordCount1": 173,
"correctWordCount1": 170,
"wordSubstitutionCount1": 2,
"wordDeletionCount1": 1,
"wordInsertionCount1": 2,
"tokenCount1": 165,
"correctTokenCount1": 145,
"tokenSubstitutionCount1": 10,
"tokenDeletionCount1": 1,
"tokenInsertionCount1": 9,
"tokenErrors1": {
"punctuation": {
"numberOfEdits": 4,
"percentageOfAllEdits": 20.0
},
"capitalization": {
"numberOfEdits": 2,
"percentageOfAllEdits": 10.0
},
"inverseTextNormalization": {
"numberOfEdits": 1,
"percentageOfAllEdits": 5.0
},
"lexical": {
"numberOfEdits": 12,
"percentageOfAllEdits": 12.0
},
"others": {
"numberOfEdits": 1,
"percentageOfAllEdits": 5.0
}
},
"wordErrorRate2": 0.028900000000000002,
"sentenceErrorRate2": 0.667,
"tokenErrorRate2": 0.12119999999999999,
"sentenceCount2": 3,
"wordCount2": 173,
"correctWordCount2": 170,
"wordSubstitutionCount2": 2,
"wordDeletionCount2": 1,
"wordInsertionCount2": 2,
"tokenCount2": 165,
"correctTokenCount2": 145,
"tokenSubstitutionCount2": 10,
"tokenDeletionCount2": 1,
"tokenInsertionCount2": 9,
"tokenErrors2": {
"punctuation": {
"numberOfEdits": 4,
"percentageOfAllEdits": 20.0
},
"capitalization": {
"numberOfEdits": 2,
"percentageOfAllEdits": 10.0
},
"inverseTextNormalization": {
"numberOfEdits": 1,
"percentageOfAllEdits": 5.0
},
"lexical": {
"numberOfEdits": 12,
"percentageOfAllEdits": 12.0
},
"others": {
"numberOfEdits": 1,
"percentageOfAllEdits": 5.0
}
}
},
"lastActionDateTime": "2024-07-14T21:31:22Z",
"status": "Succeeded",
"createdDateTime": "2024-07-14T21:31:14Z",
"locale": "en-US",
"displayName": "My Evaluation",
"description": "My Evaluation Description",
"customProperties": {
"testingKind": "Evaluation"
}
}
有关评估的语音 CLI 帮助,请运行以下命令:
spx help csr evaluation
若要获取测试结果,请首先使用语音转文本 REST API 的Evaluations_Get操作。
使用 URI 提出 HTTP GET 请求,如以下示例所示。 将 YourEvaluationId
替换为您的评估 ID,将 YourSubscriptionKey
替换为您的语音资源密钥,将 YourServiceRegion
替换为您的语音资源区域。
curl -v -X GET "https://YourServiceRegion.api.cognitive.azure.cn/speechtotext/v3.2/evaluations/YourEvaluationId" -H "Ocp-Apim-Subscription-Key: YourSubscriptionKey"
响应正文中返回单词错误率和更多详细信息。
你应该会收到以下格式的响应正文:
{
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/evaluations/dda6e880-6ccd-49dc-b277-137565cbaa38",
"model1": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/models/base/13fb305e-09ad-4bce-b3a1-938c9124dda3"
},
"model2": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/models/base/13fb305e-09ad-4bce-b3a1-938c9124dda3"
},
"dataset": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/datasets/23b6554d-21f9-4df1-89cb-f84510ac8d23"
},
"transcription2": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/transcriptions/b50642a8-febf-43e1-b9d3-e0c90b82a62a"
},
"transcription1": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/transcriptions/b50642a8-febf-43e1-b9d3-e0c90b82a62a"
},
"project": {
"self": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/projects/0198f569-cc11-4099-a0e8-9d55bc3d0c52"
},
"links": {
"files": "https://chinanorth2.api.cognitive.azure.cn/speechtotext/v3.2/evaluations/dda6e880-6ccd-49dc-b277-137565cbaa38/files"
},
"properties": {
"wordErrorRate1": 0.028900000000000002,
"sentenceErrorRate1": 0.667,
"tokenErrorRate1": 0.12119999999999999,
"sentenceCount1": 3,
"wordCount1": 173,
"correctWordCount1": 170,
"wordSubstitutionCount1": 2,
"wordDeletionCount1": 1,
"wordInsertionCount1": 2,
"tokenCount1": 165,
"correctTokenCount1": 145,
"tokenSubstitutionCount1": 10,
"tokenDeletionCount1": 1,
"tokenInsertionCount1": 9,
"tokenErrors1": {
"punctuation": {
"numberOfEdits": 4,
"percentageOfAllEdits": 20.0
},
"capitalization": {
"numberOfEdits": 2,
"percentageOfAllEdits": 10.0
},
"inverseTextNormalization": {
"numberOfEdits": 1,
"percentageOfAllEdits": 5.0
},
"lexical": {
"numberOfEdits": 12,
"percentageOfAllEdits": 12.0
},
"others": {
"numberOfEdits": 1,
"percentageOfAllEdits": 5.0
}
},
"wordErrorRate2": 0.028900000000000002,
"sentenceErrorRate2": 0.667,
"tokenErrorRate2": 0.12119999999999999,
"sentenceCount2": 3,
"wordCount2": 173,
"correctWordCount2": 170,
"wordSubstitutionCount2": 2,
"wordDeletionCount2": 1,
"wordInsertionCount2": 2,
"tokenCount2": 165,
"correctTokenCount2": 145,
"tokenSubstitutionCount2": 10,
"tokenDeletionCount2": 1,
"tokenInsertionCount2": 9,
"tokenErrors2": {
"punctuation": {
"numberOfEdits": 4,
"percentageOfAllEdits": 20.0
},
"capitalization": {
"numberOfEdits": 2,
"percentageOfAllEdits": 10.0
},
"inverseTextNormalization": {
"numberOfEdits": 1,
"percentageOfAllEdits": 5.0
},
"lexical": {
"numberOfEdits": 12,
"percentageOfAllEdits": 12.0
},
"others": {
"numberOfEdits": 1,
"percentageOfAllEdits": 5.0
}
}
},
"lastActionDateTime": "2024-07-14T21:31:22Z",
"status": "Succeeded",
"createdDateTime": "2024-07-14T21:31:14Z",
"locale": "en-US",
"displayName": "My Evaluation",
"description": "My Evaluation Description",
"customProperties": {
"testingKind": "Evaluation"
}
}
评估字词错误率 (WER)
测量模型准确性的行业标准是单词错误率(WER)。 WER 计算识别过程中识别的错误单词数,并将总和除以人工标记脚本(N)中提供的单词总数。
错误识别的单词分为三个类别:
- 插入 (I):在假设听录中错误添加的单词
- 删除(D):假设脚本中未检测到的单词
- 替换(S):引用和假设之间替换的单词
在 Speech Studio 中,商乘以 100 并以百分比显示。 Speech CLI 和 REST API 的结果不会乘以 100。
$$ WER = {{I+D+S} N}\over\times 100 $$
以下示例与人为标记的听录内容相比显示错误识别的字词:
语音识别结果出现错误,如下所示:
- 插入(I):添加了单词“a”
- 删除 (D):删除了单词“are”
- 替换(S):用“Jones”一词替换“John”
上一示例中的单词错误率为 60%。
如果要在本地复制 WER 度量,可以使用 NIST 评分工具包 (SCTK) 中的 sclite 工具。
解决错误并改进 WER
可以使用计算机识别结果中的 WER 计算来评估与应用、工具或产品一起使用的模型的质量。 WER 为 5-10% 表明质量好,可以使用。 20% 的 WER 是可以接受的,但你可能需要考虑进行更多训练。 30 个% 或更多个 WER 表示质量差,需要自定义和培训。
如何分布错误非常重要。 遇到许多删除错误时,通常是由于音频信号强度弱。 若要解决此问题,需要收集离源更近的音频数据。 插入错误意味着音频是在嘈杂环境中录制的,并且可能存在串音,从而导致识别问题。 如果以人为标记的听录内容或相关文本形式提供特定于领域的术语样本不足,则通常会遇到替换错误。
通过分析单个文件,可以确定存在哪种类型的错误,以及特定文件特有的错误。 了解文件级别的问题有助于确定改进目标。
评估令牌错误率 (TER)
除了 单词错误率,还可以使用 令牌错误率(TER) 的扩展度量来评估最终端到端显示格式的质量。 除了词法格式(That will cost $900.
而不是 that will cost nine hundred dollars
词法格式),TER 还考虑了标点、大写和 ITN 等显示格式方面。 详细了解 如何使用语音转文本显示输出格式。
TER 计算识别期间识别的错误令牌数,并将总和除以人工标记脚本(N)中提供的令牌总数。
$$ TER = {{I+D+S} N}\over\times 100 $$
TER 计算的公式也类似于 WER。 唯一的区别是基于令牌级别而不是单词级别计算 TER。
- 插入 (I):在假设听录中错误添加的令牌
- 删除 (D):在假设听录中未检测到的令牌
- 替换 (S):在引用和假设之间替换的令牌
在实际情况下,可以分析 WER 和 TER 结果以获取所需的改进。
注释
要测量 TER,需要确保音频 + 听录测试数据包含带有显示格式(例如标点符号、大写字母和 ITN)的听录。
示例方案结果
语音识别方案因音频质量和语言(词汇和说话风格)而异。 下表检查了四种常见方案:
情景 | 音频质量 | 词汇表 | 说话风格 |
---|---|---|---|
呼叫中心 | 低,8 kHz,可以是 1 个音频通道上的 2 个人,可以压缩 | 窄、对于域和产品是唯一的 | 对话式,结构松散 |
语音助理(如 Cortana 或驾车通过式窗口) | 高频率,16 kHz | 实体拥堵(歌曲名、产品、位置) | 明确陈述的字词和短语 |
听写(即时消息、备注、搜索) | 高、16 kHz | Varied | 笔记记录 |
视频隐藏式字幕 | 不同,包括各种麦克风使用、添加的音乐 | 形式各异,包括会议、背诵演讲、音乐歌词 | 读取、准备就绪或松散结构化 |
不同的方案会产生不同的质量结果。 下表检查了如何用 WER 计算这四种方案中内容的错误率。 该表显示每个方案中最常见的错误类型。 插入、替换和删除错误率有助于确定要添加哪些数据来改进模型。
情景 | 语音识别质量 | 插入错误 | 删除错误 | 替换错误 |
---|---|---|---|---|
呼叫中心 | 中等 (< 30% WER) |
低,但其他人在后台说话时除外 | 可能很高。 呼叫中心可能会干扰,重叠的扬声器可能会混淆模型 | 中等。 产品和人员的姓名可能会导致这些错误 |
语音助手 | 高 (可以是 < 10% WER) |
低 | 低 | 中,由于歌曲名、产品名称或位置 |
听写 | 高 (可以是 < 10% WER) |
低 | 低 | 高 |
视频隐藏式字幕 | 取决于视频类型(可以是 < 50% WER) | 低 | 可能由于音乐、噪音、麦克风质量而较高 | 行话可能会导致这些错误 |