LoginSignup
1
0

More than 3 years have passed since last update.

Text Analytics の Docker コンテナを使ってキーフレーズを抽出する

Posted at

はじめに

Azure Cognitive Service のいくつかは Docker イメージが提供されています。
ドキュメントに従って Text Analytics のキーフレーズ抽出を使ってみます。

コンテナイメージの取得

Text Analytics は2020/12月現在パブリックプレビューとなっており、誰でも試す事が出来ます。

docker pull mcr.microsoft.com/azure-cognitive-services/keyphrase

実行の準備

Cognitive Service コンテナを実行するには、Azure に接続して課金情報を送信できる必要があります。
その為、先ず Azure に Text Analytics を作成し、エンドポイントと API キーを取得します。
image.png

コンテナの起動

Eula の承認と Azure Text Analytics のエンドポイント, API キーを指定してコンテナを起動します。

docker run -it --rm -p 5000:5000 \
--mount type=bind,src=$HOME/output,target=/output \
mcr.microsoft.com/azure-cognitive-services/keyphrase:latest \
Eula=accept \
Billing=https://<your_app_name>.cognitiveservices.azure.com/ \
ApiKey=<your_api_key>

Text Analytics API の実行

http://localhost:5000/swagger/index.html にアクセスすると swagger の API 仕様を参照できます。
サンプルを参考に適当に実行します。

curl -X POST \
-H 'Content-Type: application/json' \
http://localhost:5000/text/analytics/v3.0/keyPhrases \
--data '{"documents":[{"language":"ja","id":"1","text":"今日は大晦日なので、ビールを吐くまで飲みます。"}]}'

結果。

{
  "documents": [
    {
      "id": "1",
      "keyPhrases": [
        "ビール",
        "大晦日",
        "飲み"
      ],
      "warnings": []
    }
  ],
  "errors": [],
  "modelVersion": "2019-10-01"
}

「今日は大晦日なので、ビールを吐くまで飲みます。」というフレーズから「ビール」「大晦日」「飲み」というキーワードが抽出されました。

おわりに

Text Analytics コンテナを localhost で実行しました。感情分析 API 等も同じ様に実行する事が出来ます。
コンプライアンス上の観点からパブリッククラウドにデータを送る事が出来ないケースや、パフォーマンスの点でデータの近くで処理したいケースなどで有効だと思います。

参考

1
0
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
1
0