Opensourcetechブログ

OpensourcetechによるNGINX/Kubernetes/Zabbix/Neo4j/Linuxなどオープンソース技術に関するブログです。

IBM Watson(AI)を無料で使ってみる

こんにちは、LinuCエバンジェリストこと、鯨井貴博@opensourcetechです。

 

今回は、IBMの人工知能(AI)Watsonを使ってみます。

 

 

IBM Cloudでのアカウント作成

Watsonは、IBMのクラウドサービス上で利用可能です。

また、利用にはアカウントが必要になるので、作成します。

 

以下のURLから、IBM Cloudライト・アカウントを作ります。

https://www.ibm.com/cloud-computing/jp/ja/

f:id:opensourcetech:20181222144231p:plain

IBM Cloud - Japan

 

メールアドレスなどの情報があればアカウントは作成できます。

ライト・アカウントは、いくつかの制限はありますが、

その制限の中では多くのサービスが無料で使えます。

f:id:opensourcetech:20181222144336p:plain

 

 

Watsonサービスの利用開始

アカウント作成後、ダッシュボードにある「リソースの作成」からWatsonを利用します。

f:id:opensourcetech:20181222144742p:plain

 

「リソースの作成」クリック後、

カタログの選択ができるようになるので、「Natural Language Understanding」を使用します。

※サービス名の下に「ライト」と書かれているものがライト・アカウントでも使用できるようです。

f:id:opensourcetech:20181222150105p:plain

 

Natural Language Understandingに入ると、

以下のようにサービス詳細を選択できます。

また、無料の範囲で使用する場合、ライトプランを選択して「作成」をクリックします。

f:id:opensourcetech:20181222150456p:plain

 

ダッシュボードのサービス欄に作成したものが追加されました。

f:id:opensourcetech:20181222150805p:plain

 

 

Natural Language Understandingの使用

サービス欄に追加された名前「Natural Language Understanding-pe」を」クリックすると使うことができます。

なお、Natural Language Understandingとは、

テキスト情報を読み込ませるとそれが「Positive(楽観的)」「Negative(悲観的)」「Neutral(中間)」かを判別してくれるAIサービスです。

f:id:opensourcetech:20181222151622p:plain

 

「APIリファレンス」をクリックすると、

Curl(HTTP)・Go・Java・Node・Python・Rubyで利用する方法を確認することができます。

f:id:opensourcetech:20181222152419p:plain

 

今回は、Curl(HTTP)からNatural Language Understandingを使います。

f:id:opensourcetech:20181222152849p:plain

 

まず、サンプルをそのまま使ってみます。

なお、******には、ご自身のアカウントのAPI Keyを入れてください。

label:という箇所に判定結果が出てきます。

また、入力したテキストの中で使用されている言語や単語ごとの登場回数・評価値が計算結果が表示されます。

このあたりは、AIの判断に対して企業に説明責任を求める際などに使える可能性を感じさせてくれます。

企業に説明責任を求める『AI』の基本原則 : 地域 : 読売新聞(YOMIURI ONLINE)

XYZ:~ Yoshiki$ curl -X POST -u "apikey:********************************************" -H "Content-Type: application/json" -d '{ "text": "I still have a dream. It is a dream deeply rooted in the American dream. I have a dream that one day this nation will rise up and live out the true meaning of its creed: \"We hold these truths to be self-evident, that all men are created equal.\"", "features": { "sentiment": {}, "keywords": {} }}' "https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2018-03-19"
{
"usage": {
"text_units": 1,
"text_characters": 244,
"features": 2
},
"sentiment": {
"document": {
"score": 0.882447,
"label": "positive"    <---------判定結果
}
},
"language": "en",    <---------英語と判断
"keywords": [
{
"text": "American dream",
"relevance": 0.915853,
"count": 1
},
{
"text": "true meaning",
"relevance": 0.885109,
"count": 1
},
{
"text": "dream",
"relevance": 0.759709,
"count": 3
},
{
"text": "day",
"relevance": 0.595949,
"count": 1
},
{
"text": "nation",
"relevance": 0.586388,
"count": 1
},
{
"text": "self-evident",
"relevance": 0.582448,
"count": 1
},
{
"text": "creed",
"relevance": 0.564129,
"count": 1
},
{
"text": "truths",
"relevance": 0.553062,
"count": 1
},
{
"text": "men",
"relevance": 0.53247,
"count": 1
}
]}
 

 

 当初は英語のみだけだったようですが、日本語対応もしているようなので試してみます。「ヤバい」・「まじ卍」・「そだねー」も判断してくれましたw

XYZ:~ Yoshiki$ curl -X POST -u "apikey:********************************************" -H "Content-Type: application/json" -d '{ "text": "I am happy!", "features": { "sentiment": {}, "keywords": {} }}' "https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2018-03-19"
{
"usage": {
"text_units": 1,
"text_characters": 11,
"features": 2
},
"sentiment": {
"document": {
"score": 0.988636,
"label": "positive"    <---------判定結果
}
},
"language": "en",
"keywords":

}

XYZ:~ Yoshiki$ curl -X POST -u "apikey:********************************************" -H "Content-Type: application/json" -d '{ "text": "幸せだなぁ", "features": { "sentiment": {}, "keywords": {} }}' "https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2018-03-19"
{
"usage": {
"text_units": 1,
"text_characters": 5,
"features": 2
},
"sentiment": {
"document": {
"score": 0.971503,
"label": "positive"    <---------判定結果
}
},
"language": "ja",    <---------日本語と判断
"keywords":

XYZ:~ Yoshiki$ curl -X POST -u "apikey:********************************************" -H "Content-Type: application/json" -d '{ "text": "ヤバい", "features": { "sentiment": {}, "keywords": {} }}' "https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2018-03-19"
{
"usage": {
"text_units": 1,
"text_characters": 3,
"features": 2
},
"sentiment": {
"document": {
"score": 0,
"label": "neutral"    <---------判定結果
}
},
"language": "ja",
"keywords":
}
XYZ:~ Yoshiki$ curl -X POST -u "apikey:obPpZrPG4k_rVbWfWRA4mhsMOc4qO8FN-suKRV3rb7U" -H "Content-Type: application/json" -d '{ "text": "まじ卍", "features": { "sentiment": {}, "keywords": {} }}' "https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2018-03-19"
{
"usage": {
"text_units": 1,
"text_characters": 3,
"features": 2
},
"sentiment": {
"document": {
"score": -0.658479,
"label": "negative"    <---------判定結果
}
},
"language": "ja",
"keywords": [
{
"text": "まじ卍",
"relevance": 0.999998,
"count": 1
},
{
"text": "まじ",
"relevance": 7.97e-4,
"count": 2
}
]
}
XYZ:~ Yoshiki$ curl -X POST -u "apikey:********************************************" -H "Content-Type: application/json" -d '{ "text": "そだねー", "features": { "sentiment": {}, "keywords": {} }}' "https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2018-03-19"
{
"usage": {
"text_units": 1,
"text_characters": 4,
"features": 2
},
"sentiment": {
"document": {
"score": 0,
"label": "neutral"    <---------判定結果
}
},
"language": "ja",
"keywords":

 }

 

 

 

www.slideshare.net

github.com

www.facebook.com

twitter.com

www.instagram.com

 

 

にほんブログ村 IT技術ブログ Linuxへ
Linux

にほんブログ村 IT技術ブログ オープンソースへ
オープンソース

 

 

Opensourcetech by Takahiro Kujirai