Facebook Twitter
お問い合わせ
TOPICS
更新情報
ホーム > ブログ > Oracle Cloud > OCI AIサービス:OCI Languageのデモに触れてみよう

OCI AIサービス:OCI Languageのデモに触れてみよう

ブログ
Oracle Cloud
2023.06.08

k.sasakiです。OCI AIサービスについては日本語対応しているものがほとんどないので、これを使用してサービスを作成する方は少ないでしょう。

しかし、OCIコンソールから使用できるデモがあり、無料枠あり、ドキュメントありなので、デモに触れつつ何がAIで実行できるのかを体験するには良い学習教材であると言えます。

本記事ではAIサービスの一つである”Language”についてデモに触れてみてどのような結果が得られるのかをご紹介します。ユースケースや詳細な機能については適宜リンクを記載しましたので、併せてご確認ください。

OCI AIサービスについて

OCI AIサービスについてAI Services ラインナップからサービス名と機能を抜粋します。

  • Digital Assistant: チャット・ボットの開発・運用に必要な機能を提供
  • Document Understanding: 事前学習済みのモデルを用いたドキュメント分析機能を提供
  • Language: 事前学習済みのモデルを用いた言語解析機能を提供
  • Speech: 音声や動画ファイルのトランスクリプション機能を提供
  • Vision: 事前学習済みのモデルを用いた画像分類、物体検出の機能を提供
  • Anomaly Detection: 時系列データに基づいた異常検出モデルを提供
  • Forecasting: 時系列予測と予測結果のExplainabilityを提供

各AIサービスの無料枠については13ページ目のAI Services 価格一覧(2023年1月時点)にまとめられています。無料枠は存在するのですが、FreeTierアカウントではAIサービスを使用できないことに注意が必要です。(私の個人のFreeTierアカウントで試しましたがエラーが出てアップグレードを求められました。)

OCI Languageのデモに触れてみよう

OCIコンソールで使用しているアカウントがAdministratorsグループに所属していれば、権限の追加は不要です。それ以外の場合は IAMポリシーの追加が必要です。

OCIコンソールにアクセスしたら、検索窓に”言語”と入力して"言語"のリンクから遷移するのが簡単です。

Languageでは2つ機能についてデモが用意されています

  • テキスト・アナリティクス
  • テキスト翻訳

テキスト・アナリティクスでは個人情報を抽出してマスクしたり、感情を分析することができます。日本語のテキストのインプットには現時点で対応していません。

テキスト翻訳は日本語の入力、出力ともに対応しています。今回は、GoogleのBardに以下のプロンプトを与えて感情や個人名が含まれるメッセージを作り、テキスト・アナリティクスのインプットとして与えることにします。

  • Bard インプット

わたしはアヤです。同級生のマイがタロウと結婚するので、彼女にお祝いのメッセージを書いてください。メッセージは400文字程度でお願いします。

  • Bard アウトプット

マイさん、結婚おめでとうございます!私たちが幼い頃から、あなたはいつもとても特別な存在でした。あなたはいつも明るく、前向きで、周りの人を元気づけてくれました。そして、あなたはとても優しくて思いやりのある人です。タロウさんは、あなたにぴったりのパートナーだと思います。彼はあなたをとても愛していて、いつもあなたを第一に考えています。彼はあなたを幸せにしてくれると思います。二人でこれからの人生を歩んでいく中で、きっとたくさんの幸せを味わうことができると思います。二人の末永い幸せを心からお祈りしています。おめでとうございます!

デモ:テキスト翻訳

テキスト翻訳は、API としてはBatchLanguageTranslationが動作します。

テキストを任意の言語に翻訳することができます。日本語にも対応しており、21の言語の間で翻訳をすることができます。デモでは5000文字までの制限があります。

テキスト翻訳

Bardで作成したメッセージをインプットにして英語に翻訳します。数秒待つと、以下のアウトプットを得ることができました。

Congratulations on your marriage, MY!Since we were young, you were always very special.You've always been bright, positive and cheered around.And you are a very kind and compassionate person.I think Taro is the right partner for you.He loves you very much and always thinks of you first.I think he will make you happy.I think you can enjoy a lot of happiness as you walk through your life.We sincerely pray for the long-lasting happiness of the two.Congratulations!

以下2点が気になります。

  • 人名のマイの翻訳がMYである
  • センテンス間のスペースが抜けている

同じテキストを使用してGoogle翻訳、DeepL、ChatGPT3.5、Bardで翻訳したところ、人名のマイをMYと訳したのはOCI Language とChatGPTのみでした。また、センテンス間のスペースについてはOCI Language以外は、いずれも挿入されました。各ツールで翻訳した結果は、参考情報として本記事の末尾にまとめます。

テキスト・アナリティクスでより正確な結果を得るために、人名やセンテンス間のスペースを修正した以下のデータを使用することにします。

  • テキスト・アナリティクスのインプット

    Congratulations on your marriage, Mai! Since we were young, you were always very special. You've always been bright, positive and cheered around. And you are a very kind and compassionate person. I think Taro is the right partner for you. He loves you very much and always thinks of you first. I think he will make you happy. I think you can enjoy a lot of happiness as you walk through your life. We sincerely pray for the long-lasting happiness of the two. Congratulations!

デモ:テキスト・アナリティクス

テキスト・アナリティクスのデモでは1つのインプットに対してテキスト・アナリティクスの6種類全てのAPIが動作するようになっています。デモで使用できる言語は英語とスペイン語のみです。レスポンスのJSONもデモの結果から取得できましたので、参考情報として本記事の末尾にまとめます。

テキスト・アナリティクス

言語の検出

言語の検出は、日本語にも対応しており、テキストを分析して言語を検出します。レスポンスは、検出された主要な言語1つと、信頼度スコアです。

今回のテキストは英語ですので正しく検出できました。

言語の検出

テキスト分類

テキスト分類が対応している言語は英語のみです。結果には定義済みのカテゴリ名1つと信頼度スコアが含まれます。

結果は、 "社会と国家/家族と関係"でした。結婚のお祝いなので、それらしいカテゴリが選ばれていると思います。カテゴリは階層構造になっていて、"家族と関係"の箇所がサブカテゴリとなっています。

テキスト分類

名前付きエンティティの認識

名前付きエンティティの認識は、英語とスペイン語に対応しています。例えば日時や人物、地理情報などがエンティティに当たります。結果には、抽出されたエンティティとテキスト上の位置、信頼度スコアが含まれます。

結果から、MaiやTaroが個人名、marrriageがイベントなど、複数のエンティティが識別できたことがわかります。

名前付きエンティティの認識

キーフレーズ抽出

キーフレーズ抽出は英語とスペイン語に対応しています。テキストを分析して、主要なトピックを抽出することに使用できます。結果には、主語と目的語に加えて関連した修飾語に信頼度スコアを加えたリストが含まれます。

結果では、お祝いに関係するキーワードや人名が抽出できました。抽出されたフレーズの登場回数はすべて1回なので、スコアは文脈やテキスト全体から計測されたもののようです。

キーフレーズ抽出

センチメント分析

センチメント分析 は英語とスペイン語に対応しています。テキストを分析して、その感情を読み取る機能で、文に含まれるキーワードレベルの分析(アスペクトベース)と文レベルの分析(センテンスベース)の2種類があります。結果には、好意的、否定的、中立、あるいは混合という感情の分類と、それぞれに対しての信頼度スコアが含まれます。制限事項としては皮肉は認識されないとのことです。

アスペクトベースの分析の結果としては、personとTaroという単語のみが"好意的"と判断されており、機能している様子は確認できませんでした。

センテンスベースの分析の結果としては、すべての文が"好意的"と判定されていてこちらは機能していると感じました。OCIコンソール上では"好意的"のみスコアを確認できますが、JSONのレスポンスを見ると、他のスコアも確認できます。

アスペクト・ベース センチメント分析

センテンス・ベース センチメント分析

個人情報

個人情報(正確には個人情報識別可能情報)の対応言語の情報を確認できませんでした。他のAPIの状況よりおそらく英語とスペイン語に対応しているものと思います。

テキストを分析して、人の名前や認証情報、OCIのID情報などを検出し、マスキングを行います。結果には、識別されたエンティティと信頼度スコア、マスキング済みのテキストが含まれます。

結果ではMaiやTaroという個人名は、認識できましたが、マスキングされていませんでした。"マスク構成"というメニューが結果から選択できるので、"削除"としたところ、OCIコンソール上のテキストから個人名の削除ができました。

マスキング設定

個人情報 (削除)

最後に

一通りLanguageのデモについて紹介させていただきました。日本語に対応した機能がほとんどないので仕事で使用することはなさそうですね。

強いていうなら、個人情報としてOCIDなどOCI関連のID情報のエンティティが識別できるので、ブログを作成する際などOCIDが含まれた情報を公開する際に使える。。かもしれません。

今回発生したAPIのリクエスト回数については、テキスト翻訳で1種類、テキスト・アナリティクスで6種類のAPIがコールされたので合計7回のリクエストが発生しました。Languageのリクエストは5000回まで毎月無料なので、デモを触ってみる程度では課金が発生することはないでしょう。他のAIサービスについてもデモが用意されていますので、ぜひ触れてみてください。

最後までご覧いただき、ありがとうございました。

参考情報

リンク

Language ドキュメント

Language API latest

Language ocicli latest

テキスト翻訳

インプット

マイさん、結婚おめでとうございます!私たちが幼い頃から、あなたはいつもとても特別な存在でした。あなたはいつも明るく、前向きで、周りの人を元気づけてくれました。そして、あなたはとても優しくて思いやりのある人です。タロウさんは、あなたにぴったりのパートナーだと思います。彼はあなたをとても愛していて、いつもあなたを第一に考えています。彼はあなたを幸せにしてくれると思います。二人でこれからの人生を歩んでいく中で、きっとたくさんの幸せを味わうことができると思います。二人の末永い幸せを心からお祈りしています。おめでとうございます!

Google翻訳

Mai, congratulations on your marriage! Ever since I was little, you have always been very special. You were always bright, positive, and cheered up the people around you. A caring person. I think Taro is the perfect partner for you. He loves you very much and always puts you first. I think he will make you happy. I think that you will be able to enjoy a lot of happiness as you live your life together. I sincerely pray for their eternal happiness. congratulations!

DeepL

Mai, congratulations on your marriage! Ever since we were little, you have always been very special to us. You have always been cheerful, positive and inspiring to those around you. And you are a very kind and caring person. I think Tarou is the perfect partner for you. He loves you very much and always puts you first. I believe he will make you happy. I am sure that you will experience a lot of happiness as you move forward in your life together. I wish you both a long and happy life together. Congratulations and best wishes for your future!

OCI Language

Congratulations on your marriage, MY!Since we were young, you were always very special.You've always been bright, positive and cheered around.And you are a very kind and compassionate person.I think Taro is the right partner for you.He loves you very much and always thinks of you first.I think he will make you happy.I think you can enjoy a lot of happiness as you walk through your life.We sincerely pray for the long-lasting happiness of the two.Congratulations!

ChatGPT 3.5 (プロンプトは”以下の日本語を英語に翻訳して”)

My-san, congratulations on your marriage! Since we were young, you have always been a very special presence. You have always been bright, positive, and have uplifted those around you. Moreover, you are a person who is incredibly kind and compassionate. I believe Tarou-san is the perfect partner for you. He loves you deeply and always puts you first. I think he will make you happy. As you both walk through life together from now on, I believe you will experience a lot of happiness. I sincerely pray for your everlasting happiness. Congratulations!

Bard (プロンプトは”以下の日本語を英語に翻訳して”)

Dear Mai,Congratulations on your wedding! You have always been a very special person to us since we were young. You are always cheerful, positive, and encouraging to those around you. And you are a very kind and compassionate person. I think Taro is the perfect partner for you. He loves you very much and always puts you first. I think he will make you happy. I am sure that you will be able to enjoy many happy moments in your life together. I sincerely pray for your lasting happiness. Congratulations!

テキスト・アナリティクス

言語の検出

API BatchDetectDominantLanguage
レスポンス- LanguageDetection.json

{
    "documents": [
        {
            "key": "1",
            "languages": [
                {
                    "code": "en",
                    "name": "English",
                    "score": 0.9999961585710423
                }
            ]
        }
    ],
    "errors": []
}

テキスト分類

API BatchDetectLanguageTextClassification
レスポンス

{
    "documents": [
        {
            "key": "1",
            "textClassification": [
                {
                    "label": "Society and State/Family and Relationships",
                    "score": 1
                }
            ],
            "languageCode": "en"
        }
    ],
    "errors": []
}

名前付きエンティティの認識

API BatchDetectLanguageEntities
レスポンス

{
    "documents": [
        {
            "key": "1",
            "entities": [
                {
                    "offset": 24,
                    "length": 8,
                    "text": "marriage",
                    "type": "EVENT",
                    "subType": null,
                    "score": 0.846564531326294,
                    "metaInfo": null
                },
                {
                    "offset": 34,
                    "length": 3,
                    "text": "Mai",
                    "type": "PERSON",
                    "subType": null,
                    "score": 0.9970710873603821,
                    "metaInfo": null
                },
                {
                    "offset": 204,
                    "length": 4,
                    "text": "Taro",
                    "type": "PERSON",
                    "subType": null,
                    "score": 1,
                    "metaInfo": null
                },
                {
                    "offset": 287,
                    "length": 5,
                    "text": "first",
                    "type": "QUANTITY",
                    "subType": "NUMBER",
                    "score": 0.9982279539108276,
                    "metaInfo": [
                        {
                            "offset": 287,
                            "length": 5,
                            "text": "first",
                            "subType": "UNIT",
                            "score": 0.9982279539108276
                        }
                    ]
                },
                {
                    "offset": 454,
                    "length": 3,
                    "text": "two",
                    "type": "QUANTITY",
                    "subType": "NUMBER",
                    "score": 0.957197368144989,
                    "metaInfo": [
                        {
                            "offset": 454,
                            "length": 3,
                            "text": "two",
                            "subType": "UNIT",
                            "score": 0.957197368144989
                        }
                    ]
                }
            ],
            "languageCode": "en"
        }
    ],
    "errors": []
}

キーフレーズ抽出

API BatchDetectLanguageKeyPhrases
レスポンス

{
    "documents": [
        {
            "key": "1",
            "keyPhrases": [
                {
                    "text": "congratulations",
                    "score": 0.9999994197569447
                },
                {
                    "text": "kind and compassionate person",
                    "score": 0.9998106383818767
                },
                {
                    "text": "right partner",
                    "score": 0.9998106383818767
                },
                {
                    "text": "lot of happiness",
                    "score": 0.9998106383818767
                },
                {
                    "text": "long-lasting happiness",
                    "score": 0.9998106383818767
                },
                {
                    "text": "marriage",
                    "score": 0.999238842713225
                },
                {
                    "text": "mai",
                    "score": 0.999238842713225
                },
                {
                    "text": "taro",
                    "score": 0.999238842713225
                },
                {
                    "text": "life",
                    "score": 0.9530231419717251
                }
            ],
            "languageCode": "en"
        }
    ],
    "errors": []
}

センチメント分析

API BatchDetectLanguageSentiments
レスポンス

{
    "documents": [
        {
            "key": "1",
            "documentSentiment": "Positive",
            "documentScores": {
                "Mixed": 0.03353581,
                "Neutral": 0.12370119,
                "Negative": 0.01412617,
                "Positive": 0.8286368
            },
            "sentences": [
                {
                    "offset": 0,
                    "length": 38,
                    "text": "Congratulations on your marriage, Mai!",
                    "sentiment": "Positive",
                    "scores": {
                        "Positive": 0.7525975,
                        "Mixed": 0.07706629,
                        "Neutral": 0.13676079,
                        "Negative": 0.03357542
                    }
                },
                {
                    "offset": 39,
                    "length": 50,
                    "text": "Since we were young, you were always very special.",
                    "sentiment": "Positive",
                    "scores": {
                        "Neutral": 0.24991773,
                        "Positive": 0.66626257,
                        "Mixed": 0.067840494,
                        "Negative": 0.015979186
                    }
                },
                {
                    "offset": 90,
                    "length": 55,
                    "text": "You've always been bright, positive and cheered around.",
                    "sentiment": "Positive",
                    "scores": {
                        "Neutral": 0.04168884,
                        "Mixed": 0.015272366,
                        "Negative": 0,
                        "Positive": 0.9430388
                    }
                },
                {
                    "offset": 146,
                    "length": 49,
                    "text": "And you are a very kind and compassionate person.",
                    "sentiment": "Positive",
                    "scores": {
                        "Mixed": 0,
                        "Positive": 0.9823853,
                        "Negative": 0.0029358647,
                        "Neutral": 0.014678839
                    }
                },
                {
                    "offset": 196,
                    "length": 42,
                    "text": "I think Taro is the right partner for you.",
                    "sentiment": "Positive",
                    "scores": {
                        "Negative": 0,
                        "Mixed": 0,
                        "Positive": 0.9845885,
                        "Neutral": 0.01541152
                    }
                },
                {
                    "offset": 239,
                    "length": 54,
                    "text": "He loves you very much and always thinks of you first.",
                    "sentiment": "Positive",
                    "scores": {
                        "Negative": 0.0076547656,
                        "Mixed": 0.020472221,
                        "Neutral": 0.13251877,
                        "Positive": 0.8393542
                    }
                },
                {
                    "offset": 294,
                    "length": 31,
                    "text": "I think he will make you happy.",
                    "sentiment": "Positive",
                    "scores": {
                        "Mixed": 0.02391577,
                        "Negative": 0.015761225,
                        "Neutral": 0.15475495,
                        "Positive": 0.80556804
                    }
                },
                {
                    "offset": 326,
                    "length": 71,
                    "text": "I think you can enjoy a lot of happiness as you walk through your life.",
                    "sentiment": "Positive",
                    "scores": {
                        "Neutral": 0.256231,
                        "Positive": 0.6566829,
                        "Negative": 0.033104815,
                        "Mixed": 0.05398128
                    }
                },
                {
                    "offset": 398,
                    "length": 60,
                    "text": "We sincerely pray for the long-lasting happiness of the two.",
                    "sentiment": "Positive",
                    "scores": {
                        "Negative": 0.023899734,
                        "Neutral": 0.18959033,
                        "Mixed": 0.034773055,
                        "Positive": 0.7517369
                    }
                },
                {
                    "offset": 459,
                    "length": 16,
                    "text": "Congratulations!",
                    "sentiment": "Positive",
                    "scores": {
                        "Negative": 0.008350697,
                        "Mixed": 0.042036608,
                        "Neutral": 0.045459144,
                        "Positive": 0.9041535
                    }
                }
            ],
            "aspects": [
                {
                    "offset": 188,
                    "length": 6,
                    "text": "person",
                    "sentiment": "Positive",
                    "scores": {
                        "Positive": 0.9949816635021949,
                        "Negative": 0.004458162296489943,
                        "Neutral": 0,
                        "Mixed": 0.0005601742013152134
                    }
                },
                {
                    "offset": 204,
                    "length": 4,
                    "text": "Taro",
                    "sentiment": "Positive",
                    "scores": {
                        "Positive": 0.9962341506044986,
                        "Negative": 0.0014704633301666399,
                        "Neutral": 0,
                        "Mixed": 0.0022953860653347224
                    }
                }
            ],
            "languageCode": "en"
        }
    ],
    "errors": []
}

個人情報

API BatchDetectLanguagePiEntities
レスポンス (マスキングが動作していない)

{
    "documents": [
        {
            "key": "1",
            "entities": [
                {
                    "offset": 34,
                    "length": 3,
                    "type": "PERSON",
                    "text": "Mai",
                    "score": 0.7374207377433777,
                    "isCustom": false
                },
                {
                    "offset": 204,
                    "length": 4,
                    "type": "PERSON",
                    "text": "Taro",
                    "score": 0.9801111221313477,
                    "isCustom": false
                }
            ],
            "languageCode": "en",
            "maskedText": "Congratulations on your marriage, Mai! Since we were young, you were always very special. You've always been bright, positive and cheered around. And you are a very kind and compassionate person. I think Taro is the right partner for you. He loves you very much and always thinks of you first. I think he will make you happy. I think you can enjoy a lot of happiness as you walk through your life. We sincerely pray for the long-lasting happiness of the two. Congratulations!"
        }
    ],
    "errors": []
}

この記事が気に入ったら
「いいね!」

この記事を書いた人


関連コンテンツ

CONTACT お問い合わせ

Cloudiiのサービスやプロダクトについて
興味をお持ちの方は、
お気軽にお問い合わせください。