25
Microsoft Cognitive Services 自自自自自 API 自自 2016-11-22( 自 ) 自 2 自 Cogbot 自自自

Microsoft Cognitive Services NLP APIs

Embed Size (px)

Citation preview

Page 1: Microsoft Cognitive Services NLP APIs

Microsoft Cognitive Services自然言語系 API 概要2016-11-22( 火 )第 2 回 Cogbot 勉強会

Page 2: Microsoft Cognitive Services NLP APIs

Cognitive Services とは?•画像認識、音声認識、自然言語処理を

REST API を通して簡単に利用できるサービス

Page 3: Microsoft Cognitive Services NLP APIs

自然言語処理 API• Cognitive Services では、

6 種類の自然言語処理 API を提供

Translator API

Language UnderstandingIntelligent Service(LUIS)

Bing Spell Check API Linguistic AnalysisAPI

Text Analytics API Web LanguageModel API

用途のアイデアが必要な API( アイデア例は後述 )

用途が分かりやすい API

Page 4: Microsoft Cognitive Services NLP APIs

Language UnderstandingIntelligent Service(LUIS)人間が入力した文章をアプリが理解できるよう支援する API• 文章の意図を判定• 場所、時刻、数、温度等のエンティティを抽出

例 )“ 目覚ましを 8 時に設定”→ 意図 : アラーム設定 エンティティ : 8 時

Page 5: Microsoft Cognitive Services NLP APIs

Bing Spell Check API文章のスペルを修正するための API( ドキュメント作成の支援向け )

(1) 誤って分割された単語を修正

(2) 誤ったスペル修正

(3) 氏名の修正

(4) 同音異義語の修正

(5) ブランド名の修正

Page 6: Microsoft Cognitive Services NLP APIs

Bing Spell Check API{ "flaggedTokens": [ { "offset": 19, "token": "micros oft", "type": "UnknownToken", "suggestions": [ { "suggestion": "Microsoft", "score": "21.1047019958496" } ] } ]}

A new servicefrom micros  oft!

入力 出力

(1) 誤って分割された単語を修正

誤ってスペースが入った単語スペースを削除した正しい単語を提案

Page 7: Microsoft Cognitive Services NLP APIs

Bing Spell Check API{ "flaggedTokens": [ { "offset": 5, "token": "gona", "type": "UnknownToken", "suggestions": [ { "suggestion": "gonna", "score": "17.034782409668" } ] } ]}

I am gona use this today!

入力 出力

(2) 誤ったスペル修正

誤ったスペルの単語正しいスペルの単語を提案

Page 8: Microsoft Cognitive Services NLP APIs

Bing Spell Check API{ "flaggedTokens": [ { "offset": 0, "token": "Stephen", "type": "UnknownToken", "suggestions": [ { "suggestion": "Steven", "score": "17.2489261627197" } ] } ]}

Director Stephen Spielberg should use this in the next AI movie

入力 出力

(3) 氏名の修正

誤った人名のスペル

正しい人名のスペルを提案

Page 9: Microsoft Cognitive Services NLP APIs

Bing Spell Check API{ "flaggedTokens": [ { "offset": 0, "token": "four", "type": "UnknownToken", "suggestions": [ { "suggestion": "for", "score": "16.9818840026855" } ] } ]}

Our engineers developed this four you!

入力 出力

(4) 同音異義語の修正

for とすべき所が同音異義語の four

正しいスペルの単語を提案

Page 10: Microsoft Cognitive Services NLP APIs

Bing Spell Check API{ "flaggedTokens": [ { "offset": 0, "token": "lyft", "type": "UnknownToken", "suggestions": [ { "suggestion": "Lyft", "score": "0" } ] } ]}

Our service is like lyft for word processing!

入力 出力

(5) ブランド名の修正

固有名詞のため、最初の英字を大文字にすべき単語正しいスペルの単語を提案

Page 11: Microsoft Cognitive Services NLP APIs

Text Analytics APIテキストから感情、キーワード、言語情報を抽出する API (1) 感情分析 テキストの内容が肯定的か、 否定的かを判定 (2) キーワード抽出 1 つの記事から話題を抽出 (3) トピック検出 複数記事から話題を抽出( 顧客のレビューやフィードバックから 問題や提案を理解するために役立つ ) (4) 言語判定テキストの記述言語を判定

Page 12: Microsoft Cognitive Services NLP APIs

Text Analytics API

{ "documents": [ { "score": 0.7293376, "id": "4513" } ]}

"It's fine weather today."

入力 出力

(1) 感情分析テキストの内容が肯定的か、否定的かを判定肯定的である程、高いスコアを出力

( 否定的な文として、“It‘s bad weather today.” を入力した時のスコアは 0.1887506)

Page 13: Microsoft Cognitive Services NLP APIs

Text Analytics API

{ "documents": [ { "keyPhrases": [ " 天気 " ], "id": "4513" } ]}

" 今日はいい天気だ。"

入力 出力

(2) キーワード抽出文章中のキーワードを抽出

Page 14: Microsoft Cognitive Services NLP APIs

Text Analytics API{ "documents": [ { "id": "4513", "detectedLanguages": [ { "name": "Japanese", "iso6391Name": "ja", "score": 1.0 } ] } ]}

“ こんにちは "

入力 出力

(4) 言語判定 言語判定結果を出力

Page 15: Microsoft Cognitive Services NLP APIs

Linguistic Analysis API自然言語処理の前処理として、テキストをパースするための API

(1) テキストを文で区切る(2) 単語の品詞判定(3) 構文解析 ( 動詞や主語、目的語が 分かるため、誰が何をする 文章なのか把握できる )

Page 16: Microsoft Cognitive Services NLP APIs

Linguistic Analysis API(1) テキストを文で区切る

- This is a pen. - It's important to Mr. Smith.

This is a pen. It's important to Mr. Smith.

入力 出力

改行のないテキスト文を区切った結果

( 単にピリオドで区切らず、Mr. は文中の単語と判定 )

Page 17: Microsoft Cognitive Services NLP APIs

Linguistic Analysis API(2) 単語の品詞判定

[ { "result": [ ["NNP",",","NNP","."], ["WRB","VBP","PRP","NN","."] ] }]

Hi, Tom!How are you today?

入力 出力

各単語の品詞を出力例 ) 名詞、名詞、文末、疑問詞、動詞、代名詞、名詞、文末

Page 18: Microsoft Cognitive Services NLP APIs

Linguistic Analysis API(3) 構文解析

[ { "result":["(TOP (S (NNP Hi) (, ,) (NNP Tom) (. !)))","(TOP (SBARQ (WHADVP (WRB How)) (SQ (VP (VBP are)) (NP (PRP you)) (NN today) (. ?))))"] }]

Hi, Tom!How are you today?

入力 出力

構文解析結果を出力( ツリー構造を 括弧で表現 )

Page 19: Microsoft Cognitive Services NLP APIs

アイデア例 (Linguistic Analysis API)

• 英会話レッスンで文法力を自動採点

英会話では定型の文法パターンしか使いこなせていない例 ) I‘m Ichiro Suzuki. I‘m from Aichi.I‘m a baseball player. I’m happy to meet you. I’m…

( 受動態や現在完了形など、知識として持っている文法パータンを英会話でも適材適所で使いこなしたい )

• 英会話の悩み

次回レッスンで改善Linguistic

Analysis APIBing

Speech APIスカイプ英会話等のレッスン 品詞列から文法パターン

( 受動態、現在完了形、文型など )を判定し自動採点

英会話で使いこなせている / いない文法パターンを自動レポート音声をテキスト化 テキストを品詞化

Page 20: Microsoft Cognitive Services NLP APIs

Web Language Model APIウェブ上での「単語の並び (N-gram) の出現確率」が格納されたデータセットを参照する API

(1) 単語の並びの出現確率を出力

(2) 特定の単語の並びの後ろに 続く単語を予測

(3) スペースが欠落している 文字列に空白を挿入 (ハッシュタグや URL などスペース が欠落している文字列から 単語を抽出する際などで活用 )

Page 21: Microsoft Cognitive Services NLP APIs

Web Language Model API{ “results”: [ { "words": "lean against", "probability": -7.127 }, { "words": "lean between", "probability": -9.412 }, { "words": "lean about", "probability": -8.078 } ]}

"lean against""lean between","lean about",

入力 出力

(1) 単語の並びの 出現確率を出力

出現確率を求める単語の並びを入力( 複数問合せ可 )

単語の並びの出現確率を出力(3 つの中では、“ lean against” がウェブ上で最もよく使われている )

Page 22: Microsoft Cognitive Services NLP APIs

Web Language Model API{ "candidates": [ { "word": "iphone", "probability": -1.194 }, { "word": "ipad", "probability": -1.471 }, { "word": "ipod", "probability": -1.701 } ]}

Apple -> ?入力

出力

(2) 特定の単語の並びの 後ろに続く単語を予測

Apple の後ろに続く単語は何?

予測した単語を出力(Apple iPhone 、

Apple iPad 、Apple iPod 等 )

Page 23: Microsoft Cognitive Services NLP APIs

Web Language Model API{ "candidates": [ { "words": "microsoft uses micro service", "probability": -16.484 }, { "words": "microsoft uses microservice", "probability": -18.079 }, { "words": "microsoft uses micro serv ice", "probability": -19.16 } ]}

microsoftusesmicroservice

入力 出力

(3) スペースが欠落 している文字列 に空白を挿入

適切に空白を挿入した文字列を出力(“Microservice” は 2 単語になり得るが、 “ Microsoft” は 1 単語のため区切られない )

空白のない文字列を入力

Page 24: Microsoft Cognitive Services NLP APIs

アイデア例 (Web Language Model API)• コロケーション (相性の良い単語の並び ) の提案

英文ドキュメント作成中

目的語が problem の時の動詞は solve が適切です。problem が目的語の時、「解決する」の英単語はsolve, settle, resolveのどれが適切?

Web LanguageModel API

solve problem,settle problem,

resolve problem の出現確率を求める

アシスタントが提案

Page 25: Microsoft Cognitive Services NLP APIs

日本語対応状況# API 英語 日本語 その他言語1 Language Understanding

Intelligent Service(LUIS) 〇 〇〇 ( フランス語、イタリア語、スペイン語、中国語 )

2 Translator API 〇 〇 〇 (58 言語 )3 Bing Spell Check API 〇 × ×( 英語方言、中国語、

スペイン語は対応予定 )4 Text Analytics API

(評判分析 ) 〇 × 〇 ( フランス語、スペイン語、ポルトガル語 )

5 Text Analytics API( キーワード抽出 ) 〇 〇 〇 ( ドイツ語、スペイン

語 )6 Text Analytics API

( 言語判定 ) 〇 〇 〇 (118 言語 )

7 Linguistic Analysis API 〇 × ×

8 Web LanguageModel API 〇 × ×