說(shuō)明
NLC服務(wù)使用機(jī)器學(xué)習(xí)算法返回短文本輸入的匹配預(yù)定義類(lèi)不见。創(chuàng)建和訓(xùn)練一個(gè)分類(lèi)器,將預(yù)定義分類(lèi)與示例文本連接起來(lái)蚀腿,以便服務(wù)可以將這些分類(lèi)器可以對(duì)新的輸入進(jìn)行分類(lèi)
認(rèn)證方式
使用HTTP Basic Authentication方式認(rèn)證慢味。 即用戶(hù)名/密碼方式
創(chuàng)建一個(gè)分類(lèi)器
CURL命令
curl -u "USERNAME":"PASSWORD" ^
-F training_data=@weather_data_train.csv ^
-F training_metadata="{\"language\":\"en\",\"name\":\"atp-weather\"}" ^
"https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers"
返回值
{
"classifier_id" : "359f3fx202-nlc-223328",
"name" : "atp-weather",
"language" : "en",
"created" : "2017-07-25T03:20:16.451Z",
"url" : "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/359f3fx202-nlc-223328",
"status" : "Training",
"status_description" : "The classifier instance is in its training phase, not yet ready to accept classify requests"
}
** 注意此時(shí)分類(lèi)器的狀態(tài)為訓(xùn)練中 暫時(shí)還不能使用澈蚌。我們可以通過(guò)命令查看分類(lèi)器狀態(tài)**
查看分類(lèi)器列表
CURL命令
curl -u "USERNAME":"PASSWORD" ^
"https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers"
返回值
{
"classifiers" : [ {
"classifier_id" : "359f3fx202-nlc-223328",
"url" : "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/359f3fx202-nlc-223328",
"name" : "atp-weather",
"language" : "en",
"created" : "2017-07-25T03:20:16.451Z"
} ]
}
查看分類(lèi)器信息
CURL命令
curl -u "USERNAME":"PASSWORD" ^
"https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/359f3fx202-nlc-223328"
返回值
{
"classifier_id" : "359f3fx202-nlc-223328",
"name" : "atp-weather",
"language" : "en",
"created" : "2017-07-25T03:20:16.451Z",
"url" : "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/359f3fx202-nlc-223328",
"status" : "Available",
"status_description" : "The classifier instance is now available and is ready to take classifier requests."
}
分類(lèi)器有如下五種狀態(tài)
- 1 Non Existent : 不存在
- 2 Training : 訓(xùn)練中
- 3 Failed:失敗
- 4 Available:有效
- 5 Unavailable:無(wú)效
使用分類(lèi)器進(jìn)行分類(lèi)
CURL命令
- Get方法分類(lèi) How how will it be today?
curl -G -u "USERNAME":"PASSWORD" ^
"https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/359f3fx202-nlc-223328/classify?text=How%20hot%20will%20it%20be%20today%3F"
- Post方法分類(lèi) How how will it be today?
curl -X POST -u "USERNAME":"PASSWORD" ^
-H "Content-Type:application/json" ^
-d "{\"text\":\"How hot will it be today?\"}" ^
"https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/359f3fx202-nlc-223328/classify"
返回值
{
"classifier_id" : "359f3fx202-nlc-223328",
"url" : "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/359f3fx202-nlc-223328",
"text" : "How hot will it be today?",
"top_class" : "temperature",
"classes" : [ {
"class_name" : "temperature",
"confidence" : 0.9929586035651006
}, {
"class_name" : "conditions",
"confidence" : 0.007041396434899482
} ]
}
使用分類(lèi)器訓(xùn)練數(shù)據(jù)中未包含的詞匯(sleet 為雨夾雪)
特意使用了temperature分類(lèi)中包含的句式 how xxx it is today?
分類(lèi)器還是準(zhǔn)確將其分到condition類(lèi)中了亦镶。
curl -X POST -u "username":"password" ^
-H "Content-Type:application/json" ^
-d "{\"text\":\"How sleet will it be today?\"}" ^
"https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/359f3fx202-nlc-223328/classify"
返回值
{
"classifier_id" : "359f3fx202-nlc-223328",
"url" : "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/359f3fx202-nlc-223328",
"text" : "How sleet will it be today?",
"top_class" : "conditions",
"classes" : [ {
"class_name" : "conditions",
"confidence" : 0.89688785244637
}, {
"class_name" : "temperature",
"confidence" : 0.10311214755363002
} ]
}
使用分類(lèi)器完全無(wú)關(guān)的詞匯 it is atp's notebook?
分類(lèi)結(jié)果非常不理想 temperature類(lèi)的置信度竟然高達(dá)82%
curl -X POST -u "74e23665-dfea-4bd6-ad80-3e9b4a7f7604":"RxFKejjwlUcA" ^
-H "Content-Type:application/json" ^
-d "{\"text\":\"it is atp's notebook?\"}" ^
"https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/359f3fx202-nlc-223328/classify"
返回值
{
"classifier_id" : "359f3fx202-nlc-223328",
"url" : "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/359f3fx202-nlc-223328",
"text" : "it is atp's notebook?",
"top_class" : "temperature",
"classes" : [ {
"class_name" : "temperature",
"confidence" : 0.8255246180698945
}, {
"class_name" : "conditions",
"confidence" : 0.1744753819301055
} ]
}
刪除一個(gè)分類(lèi)器
CURL命令
curl -X DELETE -u "{username}":"{password}"
"https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/10D41B-nlc-1"
要點(diǎn)
- 置信度值表示為百分比日月,值越大表示置信度越高。響應(yīng)最多包含 10 個(gè)類(lèi)染乌。
- 如果培訓(xùn)數(shù)據(jù)中的類(lèi)少于10個(gè)山孔,那么所有置信度值的和為 100%懂讯。例如只定義了兩個(gè)類(lèi)荷憋,就只能返回兩個(gè)類(lèi)。
- 其中一個(gè)樣本問(wèn)題包含未對(duì)分類(lèi)器進(jìn)行培訓(xùn)的詞語(yǔ)(“foggy”)褐望。您無(wú)須執(zhí)行額外工作來(lái)識(shí)別這些“缺少”的詞語(yǔ)勒庄,分類(lèi)器對(duì)于這些詞語(yǔ)就能獲得不錯(cuò)的分?jǐn)?shù)。請(qǐng)嘗試使用包含培訓(xùn)數(shù)據(jù)中沒(méi)有的詞(例如瘫里,“sleet”或“storm”)的其他問(wèn)題实蔽。
課題
- 1 支持語(yǔ)言 en之外還包含?
- 2 訓(xùn)練數(shù)據(jù)文本的格式 csv固定谨读? csv的format也是固定局装?
- 3 分類(lèi)器建成以后是否可以追加training數(shù)據(jù)