LUIS - 我可以在同一个应用程序中使用两种语言(中文和英文),并且仍然有好的结果吗?
LUIS - Can I have 2 languages (Chinese and English) in same App, and still have good result?
我目前正在为 Chatbot 使用 MS LUIS。
我们国家通常用英语和汉语两种语言交谈和聊天。
但是,在 LUIS 中我只能定义一种文化。
因此,当我的文化设置为英文时,当我导入中文文本时,置信度非常低(例如英文 - 0.88,中文 - 0.1)。反之亦然。
即使我使用 JieBa 或 THULAC 等库对中文文本进行标记后,情况也是一样的。
所以我做测试的时候,通常很容易陷入不相关的意图。
我想让 LUIS 轻松识别英文和中文。有什么办法可以解决这个问题吗?
非常感谢您的帮助。
I would like to make LUIS recognize both English AND Chinese easily. Are there any way to solve this problem?
是的,方法是将你的LUIS分开apps/projects,每种语言1个,在调用LUIS之前使用语言检测。
这是 LUIS 文档的官方方法(参见 here):
If you need a multi-language LUIS client application such as a chat
bot, you have a few options. If LUIS supports all the languages, you
develop a LUIS app for each language. Each LUIS app has a unique app
ID, and endpoint log. If you need to provide language understanding
for a language LUIS does not support, you can use Microsoft Translator
API to translate the utterance into a supported language, submit the
utterance to the LUIS endpoint, and receive the resulting scores.
对于语言检测,您可以使用 Microsoft Cognitive Services 中的 Text Analytics API
来获取文本语言,然后使用此结果查询正确的 LUIS 应用程序。
如何使用?
正如 Nicolas 上面提到的,您可以将 Multilanguage chat application 与针对每种文化的单独 LUIS 应用一起使用。
为了拥有单个 LUIS 应用程序,您可以使用 Translator Text API 在将所有传入消息发送到 LUIS 之前对其进行翻译。在这种情况下,您需要在调用 LUIS 识别器之前使用中间件来处理翻译。您还可以使用中间件来翻译您的机器人的响应,这样您就不必在机器人内部使用额外的本地化
Tokenizing LUIS 中的每种语言都不同。
在zh-cn culture中,LUIS需要简体中文字符集而不是繁体字符集。
这里还有一个 sample,您可以在其中 select 机器人的一种语言并根据需要继续对话。
经过调查和多次测试,我想我找到了正确执行此操作的方法:
首先,我目前正在使用 MS BotFramework - NodeJS (3.14.0) 版本来创建我的机器人。
并且在 botbuilder
class 中,您有一个名为 IntentDialog
的函数,它接受 a list of recognizers。所以我写了这样的东西:
在luis.js
const builder = require("botbuilder")
// Setting for LUIS.ai
// Universal API key for both apps
let luisAPIKey = process.env.LuisAPIKey;
// First assign variables for Chinese LUIS app
let luisAppId_Chi = process.env.LuisAppId_Chi;
let luisAPIHostName_Chi = process.env.LuisAPIHostName_Chi || 'westus.api.cognitive.microsoft.com';
let LuisModelUrl_Chi = 'https://' + luisAPIHostName_Chi + '/luis/v2.0/apps/' + luisAppId_Chi + '?subscription-key=' + luisAPIKey + '&verbose=true';
// Then assign variables for English LUIS app
let luisAppId_Eng = process.env.LuisAppId_Eng;
let luisAPIHostName_Eng = process.env.LuisAPIHostName_Eng || 'westus.api.cognitive.microsoft.com';
let LuisModelUrl_Eng = 'https://' + luisAPIHostName_Eng + '/luis/v2.0/apps/' + luisAppId_Eng + '?subscription-key=' + luisAPIKey + '&verbose=true';
// Return an object with 2 attributes: Chi for Chinese LUIS and Eng for English LUIS
let luis = {};
luis.chi = new builder.LuisRecognizer(LuisModelUrl_Chi);
luis.eng = new builder.LuisRecognizer(LuisModelUrl_Eng);
module.exports = luis;
在app.js
const luis = require("./luis")
builder.IntentDialog({ recognizers: [luis.chi, luis.eng] });
而且我在botEmulator中测试的时候,好像会先检查LUIS Chi app,然后再去LUIS Eng app。
我不知道这个识别器用来控制是否跳转到另一个应用程序的criteria/threshold是什么。但目前它在一定程度上对我有用。至少一个好的(?)开始是不准确的。 :D
不需要 MS 文本翻译API。
顺便说一句,如果我能在 session
变量中获得 topIntent
和 LUIS 路径,代码会更好看。
希望对大家有所帮助。
我目前正在为 Chatbot 使用 MS LUIS。
我们国家通常用英语和汉语两种语言交谈和聊天。
但是,在 LUIS 中我只能定义一种文化。
因此,当我的文化设置为英文时,当我导入中文文本时,置信度非常低(例如英文 - 0.88,中文 - 0.1)。反之亦然。
即使我使用 JieBa 或 THULAC 等库对中文文本进行标记后,情况也是一样的。
所以我做测试的时候,通常很容易陷入不相关的意图。
我想让 LUIS 轻松识别英文和中文。有什么办法可以解决这个问题吗?
非常感谢您的帮助。
I would like to make LUIS recognize both English AND Chinese easily. Are there any way to solve this problem?
是的,方法是将你的LUIS分开apps/projects,每种语言1个,在调用LUIS之前使用语言检测。
这是 LUIS 文档的官方方法(参见 here):
If you need a multi-language LUIS client application such as a chat bot, you have a few options. If LUIS supports all the languages, you develop a LUIS app for each language. Each LUIS app has a unique app ID, and endpoint log. If you need to provide language understanding for a language LUIS does not support, you can use Microsoft Translator API to translate the utterance into a supported language, submit the utterance to the LUIS endpoint, and receive the resulting scores.
对于语言检测,您可以使用 Microsoft Cognitive Services 中的 Text Analytics API
来获取文本语言,然后使用此结果查询正确的 LUIS 应用程序。
如何使用?
正如 Nicolas 上面提到的,您可以将 Multilanguage chat application 与针对每种文化的单独 LUIS 应用一起使用。 为了拥有单个 LUIS 应用程序,您可以使用 Translator Text API 在将所有传入消息发送到 LUIS 之前对其进行翻译。在这种情况下,您需要在调用 LUIS 识别器之前使用中间件来处理翻译。您还可以使用中间件来翻译您的机器人的响应,这样您就不必在机器人内部使用额外的本地化
Tokenizing LUIS 中的每种语言都不同。
在zh-cn culture中,LUIS需要简体中文字符集而不是繁体字符集。
这里还有一个 sample,您可以在其中 select 机器人的一种语言并根据需要继续对话。
经过调查和多次测试,我想我找到了正确执行此操作的方法:
首先,我目前正在使用 MS BotFramework - NodeJS (3.14.0) 版本来创建我的机器人。
并且在 botbuilder
class 中,您有一个名为 IntentDialog
的函数,它接受 a list of recognizers。所以我写了这样的东西:
在luis.js
const builder = require("botbuilder")
// Setting for LUIS.ai
// Universal API key for both apps
let luisAPIKey = process.env.LuisAPIKey;
// First assign variables for Chinese LUIS app
let luisAppId_Chi = process.env.LuisAppId_Chi;
let luisAPIHostName_Chi = process.env.LuisAPIHostName_Chi || 'westus.api.cognitive.microsoft.com';
let LuisModelUrl_Chi = 'https://' + luisAPIHostName_Chi + '/luis/v2.0/apps/' + luisAppId_Chi + '?subscription-key=' + luisAPIKey + '&verbose=true';
// Then assign variables for English LUIS app
let luisAppId_Eng = process.env.LuisAppId_Eng;
let luisAPIHostName_Eng = process.env.LuisAPIHostName_Eng || 'westus.api.cognitive.microsoft.com';
let LuisModelUrl_Eng = 'https://' + luisAPIHostName_Eng + '/luis/v2.0/apps/' + luisAppId_Eng + '?subscription-key=' + luisAPIKey + '&verbose=true';
// Return an object with 2 attributes: Chi for Chinese LUIS and Eng for English LUIS
let luis = {};
luis.chi = new builder.LuisRecognizer(LuisModelUrl_Chi);
luis.eng = new builder.LuisRecognizer(LuisModelUrl_Eng);
module.exports = luis;
在app.js
const luis = require("./luis")
builder.IntentDialog({ recognizers: [luis.chi, luis.eng] });
而且我在botEmulator中测试的时候,好像会先检查LUIS Chi app,然后再去LUIS Eng app。
我不知道这个识别器用来控制是否跳转到另一个应用程序的criteria/threshold是什么。但目前它在一定程度上对我有用。至少一个好的(?)开始是不准确的。 :D
不需要 MS 文本翻译API。
顺便说一句,如果我能在 session
变量中获得 topIntent
和 LUIS 路径,代码会更好看。
希望对大家有所帮助。