LoginSignup
9
1

Amazon Titan Text さんの日本語能力を垣間見る

Last updated at Posted at 2023-12-06

この記事は Amazon Bedrock Advent Calendar 2023 7 日目の記事です

Titan Text モデルは 2023/12/7 時点で英語のみで一般提供されています。本記事では Titan Text Express の日本語対応状況について言及していますが、実環境での利用を推奨するものではありませんのでご注意ください。

はじめに

AWS re:Invent 2023 で Amazon Bedrock で使用可能なモデルとして Amazon Titan Text Lite と Amazon Titan Text Express が一般提供開始となったことが発表されました。

image.png
https://www.youtube.com/watch?v=8clH7cbnIQw より引用:

日本語能力を垣間見るというタイトルですが、Titan Text は英語しか使えないのでは?と思う方もいるかもしれません。が、実はそんなこともないのです。

Titan Text の多言語対応

Titan Text Express は 100 以上の言語でトレーニングされており、要求に応じて翻訳タスク等も実行できるとのこと。これは同じく re:Invent 期間中発表された Titan Text の AWS AI Service Card に記載されています。

AWS AI Service Cards とは責任ある AI (Responsible AI) を設計するために AWS AI サービスのユース、プラクティス、パフォーマンスなどの情報が記載されているドキュメントです。

以下が Titan Text の AWS AI Service Card です。多言語対応について言及されている箇所がいくつかありますので引用します。

Intended use cases and limitations
Amazon Titan Text Express has a context length of up to 8,000 tokens, making it well-suited for a wide range of advanced, general language tasks such as open-ended text generation and conversational chat, as well as support for RAG. At launch, the model is optimized for English, with multilingual support for more than 100 additional languages available in preview.

参考訳
Amazon Titan Text Express のコンテキスト長は最大 8,000 トークンであり、RAG のサポートだけでなく、オープンエンドのテキスト生成や会話型チャットなど、幅広い高度な一般言語タスクに適しています。リリース時には、モデルは英語用に最適化されており、プレビューでは 100 を超える追加言語の多言語サポートが利用可能です。

Languages: Titan Text LLMs are released as generally available for English only. Although Titan Text Express is trained on 100+ languages, and will perform translation tasks if asked, its safety guardrails for this release are intended for use in English only. In multi-lingual use cases, customers should carefully check completions for effectiveness, including safety.

参考訳
言語: Titan Text LLM は、英語のみで一般提供としてリリースされています。Titan Text Express は 100 以上の言語でトレーニングされており、要求に応じて翻訳タスクを実行しますが、このリリースの安全ガードレールは英語での使用のみを目的としています。多言語の使用例では、お客様は安全性を含む有効性について生成されたテキストを注意深く確認する必要があります。

実際に確認してみる

とりあえず挨拶してみる

Bedrock コンソールの Chat playground で Titan Express に日本語を入力してみた結果が以下です。

image.png

英語のみに対応している旨のメッセージが出力されますね。AWS AI Service Card の引用のとおり、ガードレールが効いている結果と思われます。

and will perform translation tasks if asked, its safety guardrails for this release are intended for use in English only.

プロンプトを工夫してみる

次に以下のようなプロンプトで実行してみます。いわゆるシステムプロンプト的に最初に英語で指示をした後で日本語で本題の質問をしていみます。

The following is a friendly conversation between a Human and an AI.The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.

みそ汁の作り方をステップバイステップで教えてください

image.png

なにやら日本語らしきものが返ってきました。コンソールは多言語対応しておらず、文字化けしてしまうようです。

API で結果を取得

Boto3 でリクエストを投げて結果を取得してみます。

import boto3
import json

def main():
    client = boto3.client('bedrock-runtime')
    
    prompt = '''
    The following is a friendly conversation between a Human and an AI.The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.

    User: みそ汁の作り方をステップバイステップで教えてください
    '''
    
    body = {
        "inputText": prompt,
        "textGenerationConfig": {
            "maxTokenCount": 1024,
            "stopSequences": ["User:"],
            "temperature":0,
            "topP":0.9
        }    
    }
    
    response = client.invoke_model(
        body=json.dumps(body),
        modelId="amazon.titan-text-express-v1",
        accept="application/json",
        contentType="application/json"
    )
    
    response_body = json.loads(response.get("body").read())
    print(response_body.get("results")[0].get("outputText"))


if __name__ == "__main__":
    main()

実行結果は以下です。回答内容はツッコミどころありまくりですが、日本語の文法や表現としてはある程度自然な形で回答できているのではないでしょうか。

AI: はい、承知いたしました。みそ汁の作り方をステップバイステップで説明します。

1. みそを洗ってから、水で洗い流し、水気を切ります。
2. みそに水を入れ、中火で煮込みます。煮込み時間は約10分です。
3. みそが煮詰まったら、水気を切り、冷水で冷やします。
4. 冷やされたみそを、ボウルに入れ、砂糖、醤油、塩、こしょうを加えて混ぜます。
5. 塩コショウを加えて、味を調えます。
6. みそ汁が完成したら、冷蔵庫で保管しておきます。

みそ汁は、お湯やお茶と一緒に飲むことができます。また、みそ汁を使って、お好みでパスタやサラダなどの料理を作ることもできます。みそ汁は、健康に良いとされており、美味しく食べることができます。

翻訳タスクをお願いしてみる

AWS AI Service Cards に記載のあった翻訳タスクもお願いしてみます。

プロンプト:

You are an excellent translator. Translate the English text provided by the user into Japanese.

User: Amazon Bedrock is a fully managed service that makes leading foundation models from AI companies available through an API along with developer tooling to help build and scale generative AI applications.

回答:

Here is the translated text from English to Japanese:

Amazon Bedrock は、AI 企業の主要なファンダメンタル モデルを API と開発者ツールを通じて利用可能にし、生成AI アプリケーションの構築と拡張を支援します。

こちらはなかなかいい感じですね!

最後にもう一度。Titan Text モデルは 2023/12/7 時点で英語のみで一般提供されています。本記事の内容は実環境での利用を推奨するものではありません。

以上です。
参考になれば幸いです。

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