6
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

性格分析APIの「Personality Insights」が提供終了になるので代替APIを探してみた

Last updated at Posted at 2021-04-03

こんばんは。
去年の末くらいに性格診断APIでおなじみのIBM Watson Personality Insights の非推奨化/サービス提供終了の発表がされました。
スケジュールは以下の通りです。

サ終について

  • 2020 年11 月1 日: サービスのすべての有料ユーザーにサービス提供終了メールを通知
  • 2020 年12 月1 日: Personality Insights のサービス提供終了。**新規のインスタンス作成ができなくなります。**既存のインスタンスをお使いのお客様は、1 年間は引き続きサービスを使用可能です。
  • 2021 年12 月1 日: Personality Insights サービス終了

なお移行サービスの提供はありません。
出典:https://www.ibm.com/blogs/solutions/jp-ja/ibm-watson-personality-insights-sunset/
もう新規インスタンスも作れないのでご注意ください。
(IBMはIT企業なのにグロース株どころかここ10年間株価下がり続けているんで事業拡大とかがキツイんでしょうか?)

代替API

代替となるAPIを何個か見つけて試してみたのでご紹介します。

Watson Natural Language Understanding

画像_2021-04-03_191720.png

「Watson Natural Language Understanding」はIBMが正式に移行を推奨しているAPIです。一番期待できるやつですね。
IBMが以下のようにアナウンスしています。

Q: Personality Insights を置き換えるオファリングはありますか。
A: Personality Insights と同様のサービスオファリングはありませんが、Personality Insights で現在サポートされているユースケースを継続希望のお客様は、IBM Watson Natural Language Understanding、またはお客様固有のカスタムモデルを活用して独自のテキスト分類モデルを構築する必要があります。

文章だけでなくURLでのリクエストもOKだそうです。
以下引用↓

IBM はPersonality Insights の移行サービスは提供いたしません。
Personality Insights に類似したIBM のWatson オファリングであるIBM Watson Natural Language Understanding、またはお客様固有のカスタムモデルを開発して、独自のテキスト分類モデルを構築する必要があります。

なお、WNLUを使うにはIBM Cloudへの登録が必要です。クレジットカード等の登録も不要で試せますので簡単です。
チュートリアルやデモなどは以下の公式リファレンスガイドを見てみてください。

APIの概要と制限

このAPIでは以下のような情報及び指標を取得してくれます。

  • 感情
  • キーワード
  • エンティティ
  • カテゴリ
  • 概念
  • 構文

感情では文章のネガポジ判定や感情分析を行ってくれます。
画像_2021-04-03_211732.png
画像_2021-04-03_211804.png
文章全体を解析してカテゴリー分けをしてくれます。
画像_2021-04-03_211855.png

※但し、感情分析は日本語は非対応ですので適宜翻訳APIをかませる必要がありますのでそこらへんの正確さはなくなりそうですね。
ネガポジ判定は日本語でもしてくれます。
性格分析じゃなくね?と言われるとそうでもないような気がしますが。。。

使い方

APIガイドによると文章やurlをcURLで送りつけるだけでです。簡単ですね。
ターミナルで以下のテンプレートの沿ってcURLで送るだけで結果が帰ってきます。

terminal
curl -X POST -u "apikey:{apikey}" "{url}/v1/analyze?version=2018-11-16" --header "Content-Type: application/json" --data '{
  "url": "http://newsroom.ibm.com/Guerbet-and-IBM-Watson-Health-Announce-Strategic-Partnership-for-Artificial-Intelligence-in-Medical-Imaging-Liver",
  "features": {
    "sentiment": {},
    "categories": {},
    "concepts": {},
    "entities": {},
    "keywords": {}
  }
}'

PHPで実装してみた

cURLのコマンドをNodeやR・PHP・Python・Javaに自動で変換してくれる神サービスがあるので変換して貼り付けるだけです。

※予めRequestをComposerからInstallしましょう。

terminal
composer require rmccue/requests
<?php
include('vendor/rmccue/requests/library/Requests.php');
Requests::register_autoloader();
$txt = file_get_contents('a.txt');
$headers = array(
    'Content-Type' => 'application/json'
);
$t = '""';
$data = '{ "text": ' . $t . ', "features": { "sentiment": {}, "categories": {}, "concepts": {}, "entities": {}, "keywords": {} } }';
$options = array('auth' => array('apikey', '************************************'));
$response = Requests::post('https://api.us-south.natural-language-understanding.watson.cloud.ibm.com/instances/ad1e8e83-7ca2-495f-ae01-dd42ef082963/v1/analyze?version=2018-11-16', $headers, $data, $options);
print_r($response);

jsonで返してくれるのであとは連想配列にしてもいいですし煮るなり焼くなりなんでもできます。

結果

まずはじめに以下のツイートを読み込ませた結果です。

[Sentiment]

  • Positive 0.73

[Categories]

  • technology and computing / operating systems : 0.93
  • technology and computing / hardware / computer : 0.87
  • technology and computing / hardware / computer peripherals : 0.83

まぁそこそこちゃんとした判定を返してくれますね。

Watson Tone Analyzer

Tone Analyzerでは言語分析機能を使用して、テキストから感情と文体のトーンを検出してくれます。
さっきのNatural UnderestandingのOverall Emotionと似たようなやつなので具体的な実装方法は書きません。こちらのデモで試します。

結果

ツイートサンプルが最初から用意されてたのでそれを使います。一応以下がサンプル内容です。

I hate these new features On #ThisPhone after the update.
I hate #ThisPhoneCompany products, you'd have to torture me to get me to use #ThisPhone.
The emojis in #ThisPhone are stupid.
#ThisPhone is a useless, stupid waste of money.
#ThisPhone is the worst phone I've ever had - ever 😠.
#ThisPhone another ripoff, lost all respect SHAME.
I'm worried my #ThisPhone is going to overheat like my brother's did.
#ThisPhoneCompany really let me down... my new phone won't even turn on.

なにやら製品が不満かなんかで怒ってますね。
結果は以下のようになりました。
画像_2021-04-03_214444.png
どの文のどこら辺がどれくらい怒りを表してるのかといった度合いを色つけてオーバーレイ表示してくれます。
画像_2021-04-03_214511.png
各ステートメントごとの数値も出してくれます。
画像_2021-04-03_214727.png

まとめ

IBMの移行推奨APIとか感情分析とか試してみましたが性格分析!ってな感じではなかったですしNLUの一分機能はまだ日本語非対応だったりとまだまだ見軸な気がします。
他にもおすすめのAPIが知ってるよって方は是非コメントお願いします!Azureとかにあるかもしれんん。

WatsonのNLUに関するおすすめ記事→Watson Natural Language Understandingの感情分析触ってみた
翻訳に関する超おすすめ記事→Google翻訳APIを無料で作る方法


My Website&Blog
GitHub
Twitter:@tomox0115

6
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?