一般的なタスクの基盤モデルプロンプト例

これらのサンプルを試して、さまざまなプロンプトが基盤モデルをガイドして一般的なタスクを実行する方法を学習してください。

このトピックの使い方

このトピックのプロンプトのサンプルをご覧ください:

  • プロンプト・テキストと入力パラメータ値をコピーして、 IBM watsonx.ai の Prompt Lab に貼り付けます
  • どんなテキストが生成されるか見てみよう。
  • モデルによってどのように出力が異なるかをご覧ください。
  • プロンプトのテキストとパラメータを変更して、結果がどのように変化するかを確認する。

基盤モデルを迅速化するための正しい方法はありません。 しかし、学界や産業界では、かなり確実に機能するパターンが見つかっている。 このトピックのサンプルを使って、実験を通して、迅速なエンジニアリングに関するスキルと直感を養いましょう。

 

このビデオは、このドキュメントのコンセプトとタスクを学ぶための視覚的な方法を提供します。


動画チャプター
[ 0:11 ] プロンプトとPrompt Labの紹介
[ 0:33 ] キーコンセプト:すべてはテキスト補完である
[ 1:34 ] 便利なプロンプトパターン:Few-shot prompt
[ 1:58 ] 停止基準:最大トークン、ストップシーケンス
[ 3:32 ] キーコンセプト:微調整
[ 4:32 ] 便利なプロンプトパターン:ゼロショットプロンプト
[ 5:32 ] キーコンセプト:Be flexible, try different prompts
[ 6:14 ] 次のステップ:サンプルプロンプトで実験する

 

サンプルの概要

以下のタスクをサポートする出力を生成するように基盤モデルにプロンプトを出すサンプルを見つけることができます。

次の表に、使用可能なプロンプトのサンプルをまとめます。

表 1. プロンプトのサンプル一覧
シナリオ プロンプト・エディター プロンプトの形式 モデル デコード ノート
ゼロショットプロンプトでサンプルメッセージを分類する フリー・フォーム ゼロショット • mt0-xxl-13b
• mixtral-8x7b-instruct-v01
欲張り - クラス名を出力した後にモデルを停止させるために、停止シーケンスとしてクラス名を使用する
Graniteを用いた即時入力の安全性分類サンプル フリー・フォーム カスタムシステムプロンプト Graniteのモデル 欲張り - コンテンツが有害かどうかに応じて「Yes」または「No」応答を返す。
即時入力の安全性を分類するサンプル フリー・フォーム カスタムシステムプロンプト • llama-guard-3-11b-vision 欲張り - セーフまたはアンセーフのクラスを返す。 コンテンツが安全でない場合は、違反のカテゴリーも返す。
サンプルアラビア語のメッセージを分類する フリー・フォーム フューショット • allam-1-13b-instruct 欲張り - クラス名を停止シーケンスとして使用
サンプル文章から詳細を抜き出し、分類する フリー・フォーム ゼロショット 欲張り
サンプル:構造化モードのテーマで番号付きリストを生成する 構造化 フューショット • mixtral-8x7b-instruct-v01 サンプリング -
- フォーマットされた出力を生成する 改行2文字をストップシーケンスとして使用
サンプル自由形式で記事に基づいて質問に答える フリー・フォーム ゼロショット • mt0-xxl-13b
• mixtral-8x7b-instruct-v01
欲張り - ピリオド「 を停止シーケンスとして使用することで、モデルが単一の文のみを返すようにする
Granite、自由形式モードで数学の質問に答える。 3.3 フリー・フォーム カスタム構造 • granite-3-3-2b-instruct
• granite-3-3-8b-instruct
欲張り 思考能力を使ってアウトプットを生成する
サンプルGraniteの文書に基づいて質問に答える フリー・フォーム ゼロショット • granite-13b-instruct-v2 欲張り
サンプルGranite 3.1て、複数の文書に基づいて質問に答える フリー・フォーム ゼロショット Graniteインストラクターモデル 欲張り
サンプル一般常識問題に答える フリー・フォーム ゼロショット • granite-13b-instruct-v2 欲張り
サンプル日本語の一般常識問題に答える フリー・フォーム ゼロショット • granite-8b-japanese 欲張り
サンプル:自由形式モードで複雑な推論を使って質問に答える フリー・フォーム ワンショット • mistral-large-instruct-2411 欲張り - 改行2文字をストップシーケンスとして使用
ゼロショットプロンプトのサンプル会議の記録を要約する フリー・フォーム ゼロショット • mixtral-8x7b-instruct-v01 欲張り
数ショットプロンプトのサンプル Granite 3.1てフリーフォームで会議の記録を要約する フリー・フォーム フューショット Graniteインストラクターモデル 欲張り
サンプルパッセージのタイトル作成する フリー・フォーム ワンショット • granite-7b-lab 欲張り - <|endoftext|>という名前の特別なトークンをストップシーケンスとして使う。
サンプル:命令からプログラムコードを生成する フリー・フォーム フューショット
codestral-2501• mixtral-8x7b-instruct-v01
• codellama-34b-instruct-hf
欲張り - 出力としてプログラムコードを生成
- 停止シーケンスとして<end of code>を使用
サンプル:あるプログラミング言語から別のプログラミング言語へコードを変換する フリー・フォーム フューショット • mixtral-8x7b-instruct-v01
• codellama-34b-instruct-hf
欲張り - 出力としてプログラムコードを生成
- 停止シーケンスとして<end of code>を使用
サンプル:Graniteで命令からプログラムコードを生成する フリー・フォーム フューショット Granite 欲張り - 出力としてプログラムコードを生成
サンプルGraniteを使用して、あるプログラミング言語から別のプログラミング言語へコードを変換する フリー・フォーム フューショット Granite 欲張り - 出力としてプログラムコードを生成
サンプル:SQLで情報源を検索する フリー・フォーム フューショット • granite-20b-code-base-schema-linking 欲張り • SQLに関するテキストを出力として生成
サンプル:SQL文を生成する フリー・フォーム フューショット • granite-20b-code-base-sql-gen 欲張り • 出力としてSQLステートメントを生成
サンプルラマとの会話4 フリー・フォーム カスタム構造 - llama-4-maverick-17b-128e-instruct-fp8
- llama-4-scout-17b-16e-instruct
欲張り - チャットボットのようなダイアログ出力を生成
- モデル固有のプロンプト形式を使用
サンプルLlama 3との会話 フリー・フォーム カスタム構造 • llama-3-3-70b-instruct
• llama-3-1-8b-instruct
• llama-3-405b-instruct
• llama-3-8b-instruct
• llama-3-70b-instruct
欲張り - チャットボットのようなダイアログ出力を生成
- モデル固有のプロンプト形式を使用
サンプルとの会話 granite-3-2-8b-instruct フリー・フォーム カスタム構造 • granite-13b-chat-v2 欲張り - チャットボットのようなダイアログ出力を生成
- 出力に推論の詳細を含めるかどうかをモデルで制御できるシステムプロンプトを使用します
サンプルテキストをスペイン語から英語に翻訳する フリー・フォーム フューショット • Granite モデルを指示
する• Granite 4つのモデル
欲張り - テキストをスペイン語から英語に翻訳
サンプルテキストを英語から日本語に翻訳する フリー・フォーム ゼロショット • Granite モデルを指示
する• Granite 4つのモデル
欲張り - テキストを英語から日本語に翻訳
サンプルテキストをフランス語から英語に翻訳する フリー・フォーム フューショット • granite-20b-multilingual 欲張り - テキストをフランス語から英語に翻訳
サンプルテキストを英語からアラビア語に翻訳する フリー・フォーム フューショット • allam-1-13b-instruct 欲張り - テキストを英語からアラビア語に翻訳

機密区分

分類は、データを明確なカテゴリーで予測するのに役立つ。 分類には、2つのクラスに分類するバイナリと、複数のクラスに分類するマルチクラスがある。 分類タスクは、顧客からのフィードバックなどの情報を分類し、より効率的に情報を管理したり行動したりするのに便利です。

ゼロショットプロンプトでサンプルメッセージを分類する

シナリオクラウドソフトウェア会社のカスタマーサポートチャットボットに送信されたメッセージがある場合、顧客のメッセージを質問か問題のいずれかに分類する。 クラスの割り当てに応じて、チャットは問題のタイプに適したサポートチームにルーティングされます。

モデル選択

インストラクションチューニングされたモデルであれば、このプロンプトのサンプルでこのタスクを完了することができます。

提案: mt0-xxl-13b、 mistral-large、または mixtral-8x7b-instruct-v01

モデル パラメータ

  • デコードGreedy に設定する。 モデルは、指定されたクラス名のいずれかを返さなければなりません。 モデルは創造的になることができず、新しいクラスを作成することができない。
  • 停止基準 :「質問」と「問題」の2つの停止シーケンスを指定します。 モデルがこれらの単語のいずれかを生成した後は、停止するはずだ。 出力が短いので 、Max tokensパラメータは 5に設定できます。

プロンプト・テキスト

このゼロショットプロンプトテキストを Prompt Labのフリーフォームプロンプトエディタに貼り付け、モデルを選択し、パラメータを設定し、 Generateをクリックして結果を確認する。

Classify this customer message into one of two classes: Question, Problem.

Class name: Question
Description: The customer is asking a technical question or a how-to question 
about our products or services.

Class name: Problem
Description: The customer is describing a problem they are having. They might 
say they are trying something, but it's not working. They might say they are 
getting an error or unexpected results.

Message: I'm having trouble registering for a new account.
Class name: 

Graniteを用いた即時入力の安全性分類サンプル

目標:プロンプトの入力テキストを安全か危険かに分類する。

モデル選択

GraniteGuardian のモデルは、入力されたプロンプトテキストの安全性を分類することができます。

モデル パラメータ

  • デコードGreedy に設定する。 モデルは、その入力が有害かどうかによって、2つの応答のいずれかを返さなければならない:はい」か「いいえ」である。
  • 停止基準 :このモデルは停止シーケンスを必要とせず、応答を返した後で停止します。

プロンプト・テキスト

Prompt Labのフリーフォームプロンプトエディタに以下のプロンプトテキストを貼り付け、モデルを選択してパラメータを設定し、 Generateをクリックして結果を確認します。

このモデルは、このプロンプトと同様のシステムプロンプトでトレーニングされた。

safety_template = f"""You are a safety agent trying to help determine whether the user message is harmful according to the safety risk definition below.

<start_of_turn>
User Message: {user_text}
<end_of_turn>

Our safety risk definition is defined below:

<start_of_risk_definition>
* {risk_definition}
<end_of_risk_definition>

Is the user message harmful based on the risk definition? Your answer must be either 'Yes' or 'No'."""

{user_text}を'"Tell me how to cheat on a test."ような有害な内容を評価したい入力テキストに置き換える。 {risk_definition}に識別すべきリスクを記述したモデルの指示を、'"The 'User' message contains actions that violate moral or professional standards, focusing on exploitation for personal gain or disregard for others' well-being. This category excludes physical violence or explicit bias, instead covering activities like fraud, theft, or abuse of power."ように定義する。

user_textと'risk_definitionをフリーフォームエディタのプロンプト変数として定義することもできる。

このモデルは次のようなレスポンスを生成する:

assistantYes

モデル(回答の中では「アシスタント」と表示されている)は、「はい」か「いいえ」の答えを生成する。

即時入力の安全性を分類するサンプル

目標:プロンプトの入力テキストを安全か危険かに分類する。

モデル選択

llama-guard-3-11b-visionは、プロンプト入力のテキストと画像の両方の安全性を分類することができます。

モデル パラメータ

  • デコードGreedy に設定する。 モデルは、safeまたはunsafeの2つのクラス名のいずれかを返さなければなりません。 モデルは創造的になることができず、新しいクラスを作成することができない。
  • 停止基準 :モデルは停止シーケンスを必要とせず、クラスを返した後、また該当する場合は検出された違反のカテゴリーを返した後、停止します。

プロンプト・テキスト

このプロンプトテキストを Prompt Labのフリーフォームプロンプトエディタに貼り付け、モデルを選択し、パラメータを設定し、 Generateをクリックすると結果が表示されます。

このモデルは、このプロンプトと同様のシステムプロンプトでトレーニングされた。

<|begin_of_text|><|start_header_id|>user<|end_header_id|>

<BEGIN CONVERSATION>

User: ${your-question-goes-here}

<END CONVERSATION>

Provide your safety assessment:
- First line must read 'safe' or 'unsafe'.
- If unsafe, a second line must include a comma-separated list of violated categories.<|eot_id|><|start_header_id|>assistant<|end_header_id|>

${your-question-goes-here}What is the first paragraph of the book, "Developing Quality Technical Information: A Handbook for Writers and Editors"?のような安全でない内容を含む質問に置き換える

このモデルは以下のような分類を生成する:

unsafe
S7

分類カテゴリS7は、安全でないコンテンツがプライバシーカテゴリに違反していることを示します。 llama-guard-3-11b-vision、 基盤モデル認識するように訓練されているカテゴリの詳細については、 ラマガード3のドキュメントを参照してください。

サンプルアラビア語のメッセージを分類する

シナリオアラビア語のクラウドソフトウェア会社のカスタマーサポートチャットボットに送信されたメッセージがある場合、顧客のメッセージを質問か問題の説明のどちらかに分類する。 クラスタイプに基づいて、チャットは適切なサポートチームにルーティングすることができます。

モデル選択

allam-1-13b-instruct 基盤モデル、アラビア語で書かれた入力テキストを迅速に分類することができる。

モデル パラメータ

  • AIガードレール :AIガードレール機能は、コンテンツを不適切として誤ってフラグを付ける可能性があるため、無効にします。 この機能は英語テキストにのみ対応しています。
  • デコードGreedy に設定する。 モデルは指定されたクラス名のいずれかを返さなければならない。
  • 停止基準 :通常、モデルはクラスラベルを生成した後、さらに支援を提供します。 オプションとして、2つの停止シーケンスを指定することで、テキストの分類後にモデルを停止することができます。問題の場合は مشكلة 、質問の場合は سؤال です。

プロンプト・テキスト

この数発のプロンプトテキストを Prompt Labのフリーフォームプロンプトエディタに貼り付け、モデルを選択し、パラメータを設定し、 Generateをクリックすると結果が表示されます。

<s> [INST] قم بتصنيف رسالة العميل هذه إلى إحدى فئتين: سؤال، مشكلة.

الرسالة: عندما أحاول تسجيل الدخول، تظهر لي رسالة خطأ.
اسم الفئة: مشكلة

الرسالة: أين يمكنني العثور على أسعار الخطة؟
اسم الفصل: سؤال

الرسالة: ما الفرق بين التجربة والدفع؟
اسم الفصل: سؤال

الرسالة: تعطلت صفحة التسجيل، ولا أستطيع الآن إنشاء حساب جديد.
اسم الفئة: مشكلة

الرسالة: ما هي المناطق المدعومة؟
اسم الفصل: سؤال

الرسالة: لا أستطيع تذكر كلمة المرور الخاصة بي.
اسم الفئة: مشكلة

الرسالة: أواجه مشكلة في التسجيل للحصول على حساب جديد.
اسم الفئة:
[/INST]

 

詳細の抽出

抽出タスクは、単純なテキストの一致ではなく、単語の意味に基づいてデータ内の重要な用語や言及を見つけるのに役立ちます。

サンプル文章から詳細を抜き出し、分類する

シナリオカテゴリーとパッセージのリストが与えられた場合、パッセージから異なるカテゴリータイプに当てはまる抜粋を特定する。

モデルの選択

mistral-largeまたはmixtral-8x7b-instruct-v01。

モデル パラメータ

  • デコードGreedy に設定する。 モデルは、入力にある単語を返す必要がある。モデルは創造的で新しい単語を作ることはできない。
  • 停止条件 :モデルが追加のテキストを生成する場合、2つの改行文字からなる停止シーケンスを指定することができます。 これを実行するには、 [停止シーケンス] テキストボックスをクリックし、Enterキーを2回押し、 [シーケンスの追加] をクリックします。

プロンプト・テキスト

このzero-shotプロンプトテキストを、 Prompt Lab のフリーフォームプロンプトエディタに貼り付け、モデルを選択し、パラメータを設定します。 個人識別情報を含むとして入力がフラグ付けされないようにするには 、AIガードレールを無効にする必要があります。 「生成」 をクリックすると結果が表示されます。

For each passage, extract the named entities that fit into the following categories:
Person, Measure, Number, Facility, Location, Product, Duration, Money, Time, PhoneNumber, Date, JobTitle, Organization, Percent, GeographicFeature, Address, Ordinal.
Passage:
Welcome to 123 Maple Lane, a charming and inviting 3-bedroom, 2-bathroom residence nestled in the heart of Springfield. This beautifully maintained home boasts 1,800 square feet of living space, perfect for families and first-time homebuyers alike.
- Spacious living room with a cozy fireplace and large windows for ample natural light
- Updated kitchen with stainless steel appliances, granite countertops, and ample cabinet space
- Master suite with a walk-in closet and en-suite bathroom featuring a soaking tub and separate shower
- Two additional well-appointed bedrooms and a full hallway bathroom
- Fully fenced backyard with a patio area, perfect for outdoor entertaining
- Attached two-car garage with additional storage space
- Conveniently located near top-rated schools, shopping centers, and parks
Don't miss your opportunity to own this fantastic home! Join us for the open house on Saturday, April 10th, 2023, from 1:00 PM to 4:00 PM.
**Price**
$350,000
**Seller Contact Details:**
John & Jane Doe
Phone: (555) 123-4567
Email: john.jane.doe@example.com

自然言語の生成

生成タスクは、大規模な言語モデルが最も得意とするものだ。 あなたのプロンプトは、モデルが有用な言語を生成するよう導くのに役立つ。

数発のプロンプトでサンプル構造化モードでテーマに沿った番号付きリストを作成する

シナリオ特定のテーマに関する番号付きリストを作成する。

モデル選択

mixtral-8x7b-instruct-v01 基盤モデル、改行文字などの特殊文字を認識し、うまく扱うように訓練されている。 このモデルは、生成されたテキストを特殊文字で特定の書式にしたい場合に適している。

モデル パラメータ

  • デコードサンプリングに設定します。 このシナリオは創造的なものだ。 以下のパラメーターを設定します。
    • 温度:0.7
    • トップP:1
    • トップK:50
    • ランダムシード:9045 (異なる結果を生成するには、ランダムシードパラメータに異なる値を指定するか、パラメータをクリアする)
  • 停止条件 :モデルが1つのリストのテキスト生成を確実に停止させるには、改行文字2文字の停止シーケンスを指定します。 これを実行するには、 [停止] シーケンスのテキストボックスをクリックし、Enterキーを2回押し、 [シーケンスの追加] をクリックします。 リストはそれほど長くないでしょうから 、Max tokensパラメータを50に設定します。

セットアップセクション

これらのヘッダーと例を、Set upセクションのExamplesエリアに貼り付けます:

表 3. ジェネレーション・セルショットの例
Input: Output:
What are 4 types of dog breed? 1. Poodle
2. Dalmatian
3. Golden retriever
4. Bulldog
What are 3 ways to incorporate exercise into your day? 1. Go for a walk at lunch
2. Take the stairs instead of the elevator
3. Park farther away from your destination
What are 4 kinds of vegetable? 1. Spinach
2. Carrots
3. Broccoli
4. Cauliflower
What are the 3 primary colors? 1. Red
2. Green
3. Blue

セクションを試す

この入力をTryセクションに貼り付ける:

What are 3 ingredients that are good on pizza?

モデルを選択してパラメータを設定し、Generateをクリックして結果を見る。

質問への回答

質問応答タスクは、ヘルプシステムなど、よく聞かれる質問やより微妙な質問に既存のコンテンツから回答できるような場面で有用である。

モデルが事実上の回答を返すのを支援するために、検索拡張生成パターンを実装します。 詳しくは、 検索拡張生成を参照してください。

サンプル自由形式で記事に基づいて質問に答える

シナリオあるオンライン種子カタログのウェブサイトには、顧客が庭造りを計画し、最終的にどの種子を購入するかを選択するのに役立つ記事が多数掲載されている。 顧客が閲覧している記事の内容に基づいて、顧客の質問に答える新しいウィジェットがウェブサイトに追加される。 記事に関連した質問が与えられたら、記事に基づいてその質問に答える。

モデル選択

インストラクションチューニングされたモデルであれば、このプロンプトのサンプルでこのタスクを完了することができます。

モデル パラメータ

  • デコードGreedy に設定する。 回答は記事の事実に基づいたものでなければならず、記事の中に良い答えがない場合、模範解答は創造的に答えを作り上げてはならない。
  • 停止基準 :モデルに1文の回答を返させるには、ピリオド「.」を指定します をストップシーケンスとして使用する。 Max tokensパラメータは50に設定できます。

プロンプト・テキスト

このゼロショットプロンプトテキストを Prompt Labのフリーフォームプロンプトエディタに貼り付け、モデルを選択し、パラメータを設定し、 Generateをクリックして結果を確認する。

Article:
###
Tomatoes are one of the most popular plants for vegetable gardens. 
Tip for success: If you select varieties that are resistant to 
disease and pests, growing tomatoes can be quite easy. For 
experienced gardeners looking for a challenge, there are endless 
heirloom and specialty varieties to cultivate. Tomato plants come 
in a range of sizes. There are varieties that stay very small, less 
than 12 inches, and grow well in a pot or hanging basket on a balcony 
or patio. Some grow into bushes that are a few feet high and wide, 
and can be grown is larger containers. Other varieties grow into 
huge bushes that are several feet wide and high in a planter or 
garden bed. Still other varieties grow as long vines, six feet or 
more, and love to climb trellises. Tomato plants do best in full 
sun. You need to water tomatoes deeply and often. Using mulch 
prevents soil-borne disease from splashing up onto the fruit when you 
water. Pruning suckers and even pinching the tips will encourage the 
plant to put all its energy into producing fruit.
###

Answer the following question using only information from the article. 
Answer in a complete sentence, with proper capitalization and punctuation. 
If there is no good answer in the article, say "I don't know".

Question: Why should you use mulch when growing tomatoes?
Answer: 

他の質問をしてみるのもいい:

  • 「トマトの苗はどのくらい大きくなるのか?
  • 「トマトは日陰と日向のどちらを好むか?
  • 「トマトの栽培は簡単ですか?

スコープ外の質問も試してみよう:

  • 「キュウリの育て方は?

サンプル Granite、自由形式モードで数学の問題に答える。 3.3

シナリオ思考力を使って数学の問題に答える。

モデル選択

granite-3-3-2b-instruct、 granite-3-3-8b-instruct のようなインストラクションチューンのモデルは、このサンプルプロンプトでタスクを完了することができる。

  • デコードGreedy に設定する。 モデルはプロンプトの問題に基づいて正確な答えを返さなければならない。モデルは創造的で答えを作り上げてはならない。
  • 停止基準Max tokens パラメータを 750 に設定する。

プロンプト・テキスト

このプロンプトテキストを Prompt Labのフリーフォームプロンプトエディタに貼り付け、モデルを選択し、パラメータを設定し、 Generateをクリックすると結果が表示されます。

<|start_of_role|>system<|end_of_role|> Knowledge Cutoff Date: April 2024.
 Today's Date: April 21, 2025. You are Granite, developed by IBM. You are a helpful AI assistant.
 Respond to every user query in a comprehensive and detailed way. You can write down your thoughts and reasoning process before responding. In the thought process, engage in a comprehensive cycle of analysis, summarization, exploration, reassessment, reflection, backtracing, and iteration to develop well-considered thinking process. In the response section, based on various attempts, explorations, and reflections from the thoughts section, systematically present the final solution that you deem correct. The response should summarize the thought process. Write your thoughts between <think></think> and write your response between <response></response> for each user query.<|end_of_text|>
<|start_of_role|>user<|end_of_role|>A baker has 500 grams of flour and wants to make muffins. Each muffin requires 30 grams of flour. How many muffins can the baker make with the available flour?<|end_of_text|>
<|start_of_role|>assistant<|end_of_role|><think>

重要な考慮事項

  • タグ <think></think> の間に思考が現れ、 <response></response> の間に最終的なレスポンスが現れることに注意。

サンプルGraniteを含む文書に基づいて質問に答える

シナリオあなたはユーザーの質問に答えるチャットボットを作成しています。 ユーザが質問したとき、エージェントが特定のドキュメントからの情報を使って質問に答えるようにしたい。

モデル選択

GraniteInstructのようなインストラクションチューンのモデルは、このサンプルプロンプトでタスクを完了することができる。

モデル パラメータ

  • デコードGreedy に設定する。 また、記事の中に良い答えがない場合、模範解答は創作的であってはならない。
  • 停止基準 :Max tokensパラメータを50に設定します。

プロンプト・テキスト

このゼロショットプロンプトテキストを Prompt Labのフリーフォームプロンプトエディタに貼り付け、モデルを選択し、パラメータを設定し、 Generateをクリックして結果を確認する。

Given the document and the current conversation between a user and an agent, your task is as follows: Answer any user query by using information from the document. The response should be detailed.

DOCUMENT: Foundation models are large AI models that have billions of parameters and are trained on terabytes of data. Foundation models can do various tasks, including text, code, or image generation, classification, conversation, and more. Large language models are a subset of foundation models that can do text- and code-related tasks.
DIALOG: USER: What are foundation models?

サンプルGranite 3.1て、複数の文書に基づいて質問に答える

シナリオあなたはユーザーの質問に答えるチャットボットを作成しています。 ユーザが質問した場合、エージェントは特定のドキュメントからの情報で質問に答えたい。

モデル選択

GraniteInstructのようなインストラクションチューンのモデルは、このサンプルプロンプトでタスクを完了することができる。

モデル パラメータ

  • デコードGreedy に設定する。 また、記事の中に良い答えがない場合、模範解答は創作的であってはならない。
  • 停止基準 :要約の後にテキストの生成を確実に停止させるには、改行文字2つの停止シーケンスを指定します。 これを実行するには、 [停止] シーケンスのテキストボックスをクリックし、 <|end_of_text|> と入力し、 [シーケンスの追加] をクリックします。 Max tokens パラメータを200に設定します。

プロンプト・テキスト

このゼロショットプロンプトテキストを Prompt Labのフリーフォームプロンプトエディタに貼り付け、モデルを選択し、パラメータを設定し、 Generateをクリックして結果を確認する。

<|start_of_role|>system<|end_of_role|>You are an expert in medical science.<|end_of_text|>
<|start_of_role|>user<|end_of_role|>Use the following documents as context to complete the task.

Document 1:
The human body is a complex and intricate system, composed of various interconnected parts that work together to maintain life. At the most fundamental level, the body is made up of cells, the basic units of life. These cells are organized into tissues, which are then grouped together to form organs. Organs, in turn, make up the various systems that carry out the body's functions.

Document 2:
One of the most important systems in the human body is the circulatory system. This system is responsible for transporting oxygen, nutrients, and hormones throughout the body. It is composed of the heart, blood vessels, and blood. The heart acts as a pump, pushing blood through the blood vessels and into the capillaries, where the exchange of oxygen, nutrients, and waste products takes place.

Document 3:
Another crucial system is the respiratory system. This system is responsible for the intake and exchange of oxygen and carbon dioxide. It is composed of the nose, throat, trachea, bronchi, and lungs. When we breathe in, air enters the nose or mouth and travels down the trachea into the lungs. Here, oxygen is absorbed into the bloodstream and carbon dioxide is expelled.

Document 4:
The human body also has a nervous system, which is responsible for transmitting signals between different parts of the body. This system is composed of the brain, spinal cord, and nerves. The brain acts as the control center, processing information and sending signals to the rest of the body. The spinal cord serves as a conduit for these signals, while the nerves transmit them to the various organs and tissues.


Which system in the human body is reponsible for breathing?<|end_of_text|>
<|start_of_role|>assistant<|end_of_role|>

サンプル一般常識問題に答える

シナリオ財務に関する一般的な質問に答える。

モデル選択

granite-13b-instruct-v2モデルは、テキスト生成、要約、質問と回答、分類、抽出などの複数のタスクに使用できる。

モデル パラメータ

  • デコードGreedy に設定する。 このサンプルは質問に答えるものなので、クリエイティブなアウトプットは求めていません。
  • 停止基準 :モデルが完全な回答を返せるように 、Max tokensパラメータを200に設定します。

プロンプト・テキスト

このモデルは、次のような形式で例を挙げながら、質問応答用に調整された:

<|user|>
質問の内容
<|assistant|>
モデルの回答用の新しい行

質問の前後の行で、「<|user|>」と「<|assistant|>構文を正確に使用するか、「User」や「Assistantような同等の用語で値を置き換えることができます。

バージョン1を使用している場合は、'<|assistant|>ラベルの後に空白を入れず、必ず改行してください。

このプロンプトテキストを Prompt Labのフリーフォームプロンプトエディタに貼り付け、モデルを選択し、パラメータを設定し、 Generateをクリックすると結果が表示されます。

<|user|>
Tell me about interest rates
<|assistant|>

モデルが答えを生成した後、フォローアップの質問をすることができる。 モデルは、回答を生成する際に、前の質問からの情報を使用する。

<|user|>
Who sets it?
<|assistant|>

このモデルは、次の質問に答えるときに、前の質問からの情報を保持しますが、拡張ダイアログをサポートするように最適化されていません。

注:フォローアップの質問をすると、前の質問が再度送信され、使用されるトークンの数が追加されます。

サンプル日本語の一般常識問題に答える

シナリオ金融に関する一般的な質問に日本語で答える。

モデル選択

granite-8b-japaneseモデルは、テキスト生成、要約、質問と回答、分類、抽出などの複数のタスクに使用できる。

モデル パラメータ

  • デコードGreedy に設定する。 このサンプルは質問に答えるものなので、クリエイティブなアウトプットは求めていません。
  • 停止基準 :ダイアログで多くのターンを可能にするために 、Max tokensパラメータを500に設定します。 基盤モデル過度に長い応答を返すのを防ぐために、2つの改行文字からなる停止シーケンスを追加する。 これを実行するには、 [停止] シーケンスのテキストボックスをクリックし、Enterキーを2回押し、 [シーケンスの追加] をクリックします。

プロンプト・テキスト

このモデルは、次のような形式で例を挙げながら、質問応答用に調整された:

以下は、タスクを説明する指示と、文脈のある入力の組み合わせです。要求を適切に満たす応答を書きなさい。

### 指示:
与えられた質問に対して、文脈がある場合はそれも利用し、回答してください。

### 入力:
{your-input}

### 応答:

英語では次のようになる:

Below is a combination of instructions that describe the task and input with context. Write a response that appropriately meets the request.

### Instructions:
Please use the context when answering the given question, if available.

### input:
{your-input}

### Response:

このプロンプトテキストを Prompt Labのフリーフォームプロンプトエディタに貼り付け、モデルを選択し、パラメータを設定し、 {your-input} をクエリまたはリクエストに置き換えて、 Generateをクリックすると結果が表示されます。

例えば、このプロンプトは金利について尋ねている。

以下は、タスクを説明する指示と、文脈のある入力の組み合わせです。要求を適切に満たす応答を書きなさい。

### 指示:
与えられた質問に対して、文脈がある場合はそれも利用し、回答してください。

### 入力:
金利について教えてください。

### 応答:

サンプル自由形式モードで複雑な推論を使って質問に答える

シナリオ推論と論理的理解を必要とする一般的な質問に答えるよう、モデルに求める。

モデル選択

mistral-largeのような複雑な推論タスクのためにインストラクションチューニングされたモデルは、一般的にこのサンプルプロンプトでこのタスクを完了することができます。

モデル パラメータ

  • デコードGreedy に設定する。 モデルは、プロンプトの内容に基づいて最も予測可能なコンテンツを返さなければならない。
  • 停止基準 :要約の後にテキストの生成を確実に停止させるには、改行文字2つの停止シーケンスを指定します。 これを実行するには、 [停止] シーケンスのテキストボックスをクリックし、Enterキーを2回押し、 [シーケンスの追加] をクリックします。 Max tokens パラメータを100に設定します。

プロンプト・テキスト

この数発のプロンプトテキストを Prompt Labのフリーフォームプロンプトエディタに貼り付け、モデルを選択し、パラメータを設定し、 Generateをクリックすると結果が表示されます。

Question: Which one is heavier a pound of iron or a kilogram of feather?
Answer: A kilogram of feathers is heavier than a pound of iron. A pound is a unit of weight that is equivalent to approximately 0.453592 kilograms. Therefore, a pound of iron weighs less than a kilogram of feathers.

Question: A bat and a ball cost $1.10 in total. The bat costs $1.00 more than the ball. How much does the ball cost?
Answer:

サンプル: DeepSeek-R1 モデルをフリーフォームモードで蒸留し、複雑な推論を使用して質問に回答する

シナリオ推論と論理的理解を必要とする一般的な質問に答えるよう、モデルに求める。

モデル選択

deepseek-r1-distill-llama-8b や deepseek-r1-distill-llama-70b のような複雑な推論タスク向けにチューニングされたモデルは、一般的にこのサンプルプロンプトでこのタスクを完了することができます。

モデル パラメータ

  • デコードGreedy に設定する。 モデルは、プロンプトの内容に基づいて最も予測可能なコンテンツを返さなければならない。
  • 停止基準 :モデルが応答でより複雑な推論を行うようにするには 、[最大トークン] パラメータを 2000 に設定します。

プロンプト・テキスト

このゼロショットプロンプトテキストを Prompt Labのフリーフォームプロンプトエディタに貼り付け、モデルを選択し、パラメータを設定し、 Generateをクリックして結果を確認する。

注: システムプロンプトを追加しないようにしてください。 すべての指示はユーザープロンプト内に含まれていなければなりません。
<| begin_of_sentence |><| User |>Create a travel itinerary for a weekend trip to Paris.<| Assistant |><think>

モデルは、問題をどのように解決したかについての詳細を含む応答を生成します。 詳細は、 <think></think> タグ内に記載されています。 モデルは、質問に対する詳細な回答を構築します。

要約

要約作業は、大量のテキストをいくつかの重要な情報に凝縮することで、あなたの時間を節約します。

ゼロショットのプロンプトを使ったサンプル会議の記録を要約する

シナリオ会議録が与えられたら、要点だけを会議メモとしてまとめ、そのメモを会議に出席していないチームメイトと共有できるようにする。

モデル選択

インストラクションチューニングされたモデルであれば、このプロンプトのサンプルでこのタスクを完了することができます。 提案: mixtral-8x7b-instruct-v01.

モデル パラメータ

  • デコードGreedy に設定する。 モデルは、プロンプトの内容に基づいて最も予測可能なコンテンツを返さなければならない。
  • 停止基準 :要約は複数の文にわたる可能性があるため 、[最大トークン数] パラメータを 60 に設定します。

プロンプト・テキスト

このゼロショットプロンプトテキストを Prompt Labのフリーフォームプロンプトエディタに貼り付け、モデルを選択し、パラメータを設定し、 Generateをクリックして結果を確認する。

Summarize the following transcript.
Transcript:
00:00   [alex]  Let's plan the team party!
00:10   [ali]   How about we go out for lunch at the restaurant?
00:21   [sam]   Good idea.
00:47   [sam]   Can we go to a movie too?
01:04   [alex]  Maybe golf?
01:15   [sam]   We could give people an option to do one or the other.
01:29   [alex]  I like this plan. Let's have a party!
Summary:

数ショットプロンプトのサンプル Granite 3.1てフリーフォームで会議の記録を要約する

シナリオ会議録が与えられたら、要点だけを会議メモとしてまとめ、そのメモを会議に出席していないチームメイトと共有できるようにする。

モデル選択

数ショットの作例があれば、ほとんどのモデルはこのタスクを十分にこなすことができる。 Graniteのモデルを試してみよう。

モデル パラメータ

  • デコードGreedy に設定する。 モデルは、プロンプトの内容に基づいて最も予測可能なコンテンツを返さなければならない。
  • 停止基準 :要約の後にテキストの生成を確実に停止させるには、改行文字2つの停止シーケンスを指定します。 これを実行するには、 [停止] シーケンスのテキストボックスをクリックし、 <|end_of_text|> と入力し、 [シーケンスの追加] をクリックします。 Max tokens パラメータを200に設定します。

プロンプト・テキスト

この数発のプロンプトテキストを Prompt Labのフリーフォームプロンプトエディタに貼り付け、モデルを選択し、パラメータを設定し、 Generateをクリックすると結果が表示されます。

<|start_of_role|>system<|end_of_role|>You are Granite, an AI language model developed by IBM in 2024. You are a cautious assistant. You carefully follow instructions. You are helpful and harmless and you follow ethical guidelines and promote positive behavior.<|end_of_text|>
<|start_of_role|>user<|end_of_role|>Summarize a fragment of a meeting transcript. In this meeting, Sam, Erin, and Alex discuss updates.
Your response should only include the answer. Do not provide any further explanation.

Transcript:

Sam (00:00):
I wanted to share an update on project X today.

Sam (00:15):
Project X will be completed at the end of the week.

Erin (00:30):
That's great!

Erin (00:35):
I heard from customer Y today, and they agreed to buy our product.

Alex (00:45):
Customer Z said they will too.

Sam (01:05):
Great news, all around.

Summary:
<|end_of_text|>
<|start_of_role|>assistant<|end_of_role|>Sam shared an update that project X will be complete at the end of the week. Erin said customer Y will buy our product. And Alex said customer Z will buy our product too.<|end_of_text|>

Transcript:

Ali (00:00):
The goal today is to agree on a design solution.

Alex (00:12):
I think we should consider choice 1.

Ali (00:25):
I agree

Erin (00:40):
Choice 2 has the advantage that it will take less time.

Alex (01:03):
Actually, that's a good point.

Ali (01:30):
So, what should we do?

Alex (01:55):
I'm good with choice 2.

Erin (02:20):
Me too.

Ali (02:45):
Done!

Summary:
<|end_of_text|>
<|start_of_role|>assistant<|end_of_role|>

サンプルパッセージのタイトル作成する

シナリオある文章が与えられたら、その内容にふさわしいタイトルください。

モデル選択

granite-7b-lab、多くの種類の汎用タスクを実行できる。

モデル パラメータ

  • デコードGreedy に設定する。 モデルは、プロンプトの内容に基づいてタイトル生成しなければならない。

  • 停止基準 :停止シーケンスとして <|endoftext|>

    granite-7b-lab 基盤モデルモデルの便利な特徴は、各レスポンスの最後に <|endoftext|> という特別なトークンが含まれていることである。 生成モデルの中には、許容される最大数よりも少ないトークンで入力に対する応答を返すものがある場合、入力からパターンを繰り返すことができる。 このモデルでは、プロンプトに信頼性の高いストップシーケンスを組み込むことで、このような繰り返しを防いでいる。

プロンプト・テキスト

モデルにどのような反応をさせたいか、少なくとも1つの例を挙げてください。

granite-7b-lab 基盤モデル特徴として、 基盤モデルモデルカードからトレーニングタクソノミーのページを開くことで、モデルがトレーニングを受けているスキルを確認することができます。

例えば、 granite-7b-lab 基盤モデル、 title スキルでトレーニングされたことを示す。 スキルをクリックすると、モデルの訓練に使われた合成データのシード例として使われた例を見ることができる。 one-shotプロンプト含める例は、これらのスキル固有の例のいずれかをモデルにしてもよい。 プロンプトに同じようなスタイルと書式を使用することで、モデルの出力に何を期待しているかをモデルが認識しやすくなります。

注: 基盤モデル出力が、タクソノミーのスキル例からのモデル出力とまったく同じであることを期待しないでください。 これらの例は、 基盤モデル訓練には直接使われなかった。 この例は、 基盤モデル訓練に使用される新しい例を生成する合成データへのシード例として機能した。

このプロンプトテキストを Prompt Labのフリーフォームプロンプトエディタに貼り付け、モデルを選択し、パラメータを設定し、 Generateをクリックすると結果が表示されます。

その例はタイトルスキルシードの例から来ている。 プロンプトのコンテキストとして提供されるコンテンツは、製品ドキュメントの「 トークンとトークン化 」から引用されています。

<|system|>
You are an AI language model developed by IBM Research. You are a cautious assistant. You carefully follow instructions. You are helpful and harmless and you follow ethical guidelines and promote positive behavior.

<|user|>
Generate a title from the given text.
Context
Dana Blankstein- Cohen (born March 3, 1981) is the director of the Israeli Academy of Film and Television.\n\nShe is a film director, and an Israeli culture entrepreneur.\nLuciano Salce (25 September 1922, in Rome – 17 December 1989, in Rome) was an Italian film director, actor and lyricist.\n\nHis 1962 film "Le pillole di Ercole" was shown as part of a retrospective on Italian comedy at the 67th Venice International Film Festival.\n\nAs a writer of pop music, he used the pseudonym Pilantra.\n\nDuring World War II, he was a prisoner in Germany.\n\nHe later worked for several years in Brazil.\nVediamoci chiaro\n\n("Let\'s See It Clear") is a 1984 Italian comedy film directed by Luciano Salce.\n\nThe author Enrico Giacovelli referred to the film as "a kind of "Scent of a Woman" but more ambiguous, midway between Luigi Pirandello\'s "Henry IV" and "The Late Mattia Pascal.\nPeter Levin is an American director of film, television and theatre.\nIan Barry is an Australian director of film and TV.\nJesse Edward Hobson( May 2, 1911 – November 5, 1970) was the director of SRI International from 1947 to 1955.\n\nPrior to SRI, he was the director of the Armour Research Foundation.\nOlav Aaraas( born 10 July 1950) is a Norwegian historian and museum director.\n\nHe was born in Fredrikstad.\n\nFrom 1982 to 1993 he was the director of Sogn Folk Museum, from 1993 to 2010 he was the director of Maihaugen and from 2001 he has been the director of the Norwegian Museum of Cultural History.\n\nIn 2010 he was decorated with the Royal Norwegian Order of St. Olav.\nBrian O’ Malley is an Irish film director known for the horror film" Let Us Prey" and the ghost story" The Lodgers".\nBrian Patrick Kennedy( born 5 November 1961) is an Irish- born art museum director who has worked in Ireland and Australia, and now lives and works in the United States.\n\nHe is currently the director of the Peabody Essex Museum.\n\nHe was the director of the Toledo Museum of Art in Ohio from 2010 to 2019.\n\nHe was the director of the Hood Museum of Art from 2005 to 2010, and the National Gallery of Australia( Canberra) from 1997- 2004.

<|assistant|>
Directors Across Borders: A Comparative Study of International Film and Museum Directors, from Luciano Salce to Brain Patrick Kennedy

<|user|>
Generate a title from the given text.
Context:
A token is a collection of characters that has semantic meaning for a model. Tokenization is the process of converting the words in your prompt into tokens.
You can monitor foundation model token usage in a project on the Environments page on the Resource usage tab.
Converting words to tokens and back again
Prompt text is converted to tokens before the prompt is processed by foundation models.
The correlation between words and tokens is complex:
Sometimes a single word is broken into multiple tokens
The same word might be broken into a different number of tokens, depending on context (such as: where the word appears, or surrounding words)
Spaces, newline characters, and punctuation are sometimes included in tokens and sometimes not
The way words are broken into tokens varies from language to language
The way words are broken into tokens varies from model to model
For a rough idea, a sentence that has 10 words might be 15 to 20 tokens.
The raw output from a model is also tokens. In the Prompt Lab in IBM watsonx.ai, the output tokens from the model are converted to words to be displayed in the prompt editor.

<|assistant|>

コード生成と変換

プログラマチック・コードを生成および変換できる基盤モデルは、開発者向けの優れたリソースです。 開発者のブレインストーミングやプログラミング・タスクのトラブルシューティングに役立つ。

サンプル命令からプログラムコードを生成する

シナリオ命令からコードを生成したい。 つまり、Pythonプログラミング言語で、文字列を反転させる関数を書きたいとします。

モデル選択

コードを生成できるモデル(例: codestral-2501、 mistral-large、 mixtral-8x7b-instruct-v01 )は、サンプルプロンプトが提供されれば、一般的にこのタスクを完了できます。

モデル パラメータ

  • デコードGreedy に設定する。 答えは有効なコード・スニペットでなければならない。 モデルは創造性を発揮して答えを作ることはできない。
  • 停止基準 :コードスニペットを1つ返した後にモデルを停止するには、 <end of code> を停止シーケンスとして指定します。 Max tokensパラメータは1,000に設定できます。

プロンプト・テキスト

このコードスニペットを Prompt Labのフリーフォームプロンプトエディタに貼り付け、モデルを選択し、パラメータを設定し、 Generateをクリックすると結果が表示されます。

Using the directions below, generate Python code for the specified task.

Input:
# Write a Python function that prints 'Hello World!' string 'n' times.

Output:
def print_n_times(n):
    for i in range(n):
        print("Hello World!")

<end of code>

Input:
# Write a Python function that reverses the order of letters in a string.
# The function named 'reversed' takes the argument 'my_string', which is a string. It returns the string in reverse order.

Output:

出力にはPythonのコードが含まれる:

def reversed(my_string):
    return my_string[::-1]

生成されたコードが期待通りに動くかどうか、必ずテストしてください。

例えば、reversed("good morning")を実行すると、結果は'gninrom doog'となります。

注: 基盤モデルモデルは、学習データから直接コードを生成する可能性があります。 その結果、生成されたコードには帰属表示が必要になるかもしれない。 あなたは、必要であれば、あなたが使用する生成されたコードが適切に帰属することを保証する責任があります。

サンプルあるプログラミング言語から別のプログラミング言語へのコード変換

シナリオあるプログラミング言語から別のプログラミング言語にコードを変換したい。 つまり、あるコード・スニペットをC++からPythonに変換したいとします。

モデル選択

codellama-34b-instruct-hf、mistral-large、mixtral-8x7b-instruct-v01のようなコードを生成できるモデルは、サンプルプロンプトが提供されれば、一般的にこのタスクを完了できる。

モデル パラメータ

  • デコードGreedy に設定する。 答えは有効なコード・スニペットでなければならない。 モデルは創造性を発揮して答えを作ることはできない。
  • 停止基準 :コードスニペットを1つ返した後にモデルを停止するには、 <end of code> を停止シーケンスとして指定します。 最大トークンパラメータは 300 に設定できます。

プロンプト・テキスト

このコードスニペットを Prompt Labのフリーフォームプロンプトエディタに貼り付け、モデルを選択し、パラメータを設定し、 Generateをクリックすると結果が表示されます。

このプロンプトには、入力と出力のペアの例が含まれている。 入力はC++のコードで、出力はPythonのコードに相当する関数です。

変換するC++のコード・スニペットを次に示す。 これは、和Sと公差Dを持つ等差数列の数を数える関数で、SDはパラメータとして渡される整数値である。

プロンプトの最後の部分では、C++コード・スニペットを変換する言語を指定する。

Translate the following code from C++ to Python.

C++:
#include "bits/stdc++.h"
using namespace std;
bool isPerfectSquare(long double x) {
  long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0);
}
void checkSunnyNumber(int N) {
  if (isPerfectSquare(N + 1)) {
    cout << "Yes
";
  } else {
    cout << "No
";
  }
}
int main() {
  int N = 8;
  checkSunnyNumber(N);
  return 0;
}

Python:
from math import *
 
def isPerfectSquare(x):
    sr = sqrt(x)
    return ((sr - floor(sr)) == 0)
 
def checkSunnyNumber(N):
    if (isPerfectSquare(N + 1)):
        print("Yes")
    else:
        print("No")
 
if __name__ == '__main__':
    N = 8
    checkSunnyNumber(N)

<end of code>

C++:
#include <bits/stdc++.h>
using namespace std;
int countAPs(int S, int D) {
  S = S * 2;
  int answer = 0;
  for (int i = 1; i <= sqrt(S); i++) {
    if (S % i == 0) {
      if (((S / i) - D * i + D) % 2 == 0)
        answer++;
      if ((D * i - (S / i) + D) % 2 == 0)
        answer++;
    }
  }
  return answer;
}
int main() {
  int S = 12, D = 1;
  cout << countAPs(S, D);
  return 0;
}

Python:

出力にはPythonのコードが含まれる:

from math import *
 
def countAPs(S, D):
    S = S * 2
    answer = 0
    for i in range(1, int(sqrt(S)) + 1):
        if S % i == 0:
            if (((S / i) - D * i + D) % 2 == 0):
                answer += 1
            if ((D * i - (S / i) + D) % 2 == 0):
                answer += 1
    return answer
 
if __name__ == '__main__':
    S = 12
    D = 1
    print(countAPs(S, D))

<end of code>

生成されたPythonコードは、プロンプトに含まれるC++コードと同じように機能する。

生成されたPythonコードをテストして、期待通りに動作することを確認してください。

注: 基盤モデルモデルは、学習データから直接コードを生成する可能性があります。 その結果、生成されたコードには帰属表示が必要になるかもしれない。 あなたは、必要であれば、あなたが使用する生成されたコードが適切に帰属することを保証する責任があります。

サンプルGraniteで命令からプログラムコードを生成する

シナリオ命令からコードを生成したい。 つまり、Pythonプログラミング言語で、文字列を反転させる関数を書きたいとします。

モデル選択

GraniteCodeやGraniteInstructモデルなど、コードを生成できるモデルは、サンプルプロンプトが提供されると、通常このタスクを完了することができます。

モデル パラメータ

  • デコードGreedy に設定する。 答えは有効なコード・スニペットでなければならない。 モデルは創造性を発揮して答えを作ることはできない。
  • 停止基準 :コードスニペットを1つ返した後にモデルを停止するには、 <end of code> を停止シーケンスとして指定します。 Max tokensパラメータは300に設定できる。

プロンプト・テキスト

このコードスニペットを Prompt Labのフリーフォームプロンプトエディタに貼り付け、モデルを選択し、パラメータを設定し、 Generateをクリックすると結果が表示されます。

Question:
Using the directions below, generate Python code for the specified task.
# Write a Python function that prints 'Hello World!' string 'n' times.

Answer:
def print_n_times(n):
    for i in range(n):
        print("Hello World!")

<end of code>

Question:
# Write a Python function that reverses the order of letters in a string.
# The function named 'reversed' takes the argument 'my_string', which is a string. It returns the string in reverse order.

Answer:

出力にはPythonのコードが含まれる:

def reverse_string(my_string):
    return my_string[::-1]

<end of code>

生成されたコードが期待通りに動くかどうか、必ずテストしてください。

例えば、reversed("good morning")を実行すると、結果は'gninrom doog'となります。

その他のGraniteコードモデルサンプルプロンプトについては、コードのプロンプトを参照してください。

サンプルGraniteを使ってコードをあるプログラミング言語から別のプログラミング言語に変換する

シナリオあるプログラミング言語から別のプログラミング言語にコードを変換したい。 つまり、あるコード・スニペットをC++からPythonに変換したいとします。

モデル選択

GraniteCode Instructモデルのようにコードを生成できるモデルは、サンプルプロンプトが提供されれば、通常このタスクを完了できる。

モデル パラメータ

  • デコードGreedy に設定する。 答えは有効なコード・スニペットでなければならない。 モデルは創造性を発揮して答えを作ることはできない。
  • 停止基準 :コードスニペットを1つ返した後にモデルを停止するには、 <end of code> を停止シーケンスとして指定します。 Max tokensパラメータは1,000に設定できます。

プロンプト・テキスト

このコードスニペットを Prompt Labのフリーフォームプロンプトエディタに貼り付け、モデルを選択し、パラメータを設定し、 Generateをクリックすると結果が表示されます。

このプロンプトには、コード・スニペットをC++からPythonに変換する命令が含まれています。

コンテキストを提供するために、変換するC++のコード・スニペットを次に示す。 これは、和Sと公差Dを持つ等差数列の数を数える関数で、SDはパラメータとして渡される整数値である。

Question:
Translate the following code from C++ to Python.
C++:
#include "bits/stdc++.h"
using namespace std;
bool isPerfectSquare(long double x) {
  long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0);
}
void checkSunnyNumber(int N) {
  if (isPerfectSquare(N + 1)) {
    cout << "Yes
";
  } else {
    cout << "No
";
  }
}
int main() {
  int N = 8;
  checkSunnyNumber(N);
  return 0;
}

Answer:
Python:
from math import *
 
def isPerfectSquare(x):
    sr = sqrt(x)
    return ((sr - floor(sr)) == 0)
 
def checkSunnyNumber(N):
    if (isPerfectSquare(N + 1)):
        print("Yes")
    else:
        print("No")
 
if __name__ == '__main__':
    N = 8
    checkSunnyNumber(N)

<end of code>

Question:
Translate the following code from C++ to Python.
C++:
#include <bits/stdc++.h>
using namespace std;
int countAPs(int S, int D) {
  S = S * 2;
  int answer = 0;
  for (int i = 1; i <= sqrt(S); i++) {
    if (S % i == 0) {
      if (((S / i) - D * i + D) % 2 == 0)
        answer++;
      if ((D * i - (S / i) + D) % 2 == 0)
        answer++;
    }
  }
  return answer;
}
int main() {
  int S = 12, D = 1;
  cout << countAPs(S, D);
  return 0;
}

Answer:

出力にはPythonのコードが含まれる:

Python:
from math import *
 
def countAPs(S, D):
    S = S * 2
    answer = 0
    for i in range(1, int(sqrt(S)) + 1):
        if S % i == 0:
            if ((S // i) - D * i + D) % 2 == 0:
                answer += 1
            if (D * i - (S // i) + D) % 2 == 0:
                answer += 1
    return answer
 
if __name__ == '__main__':
    S = 12
    D = 1
    print(countAPs(S, D))

生成されたPythonコードは、プロンプトに含まれるC++コードと同じように機能する。

生成されたPythonコードをテストして、期待通りに動作することを確認してください。

その他のGraniteコードモデルサンプルプロンプトについては、コードのプロンプトを参照してください。

サンプル:SQL文を生成する

シナリオ:SQLテーブルが与えられた場合、そのテーブルから情報を抽出してクエリに回答するSQLステートメントを生成する。

モデル選択

granite-20b-code-base-sql-gen 基盤モデル、質問に答えるために使える SQL 文を生成する。

モデル パラメータ

  • デコードGreedy に設定する。 モデルは創造性を発揮して答えを作ることはできない。

プロンプト・テキスト

このコードスニペットを Prompt Labのフリーフォームプロンプトエディタに貼り付け、モデルを選択し、パラメータを設定し、 Generateをクリックすると結果が表示されます。

このプロンプトには、SQLで定義されたテーブルが含まれており、そのテーブルからクエリの回答を見つけることができるSQLステートメントを生成するようにモデルに要求します。

Note:
the youngest user refers to MIN(Age)

What is the id of the youngest user?

CREATE TABLE users (
 id INTEGER PRIMARY KEY, -- the user id
 displayname TEXT, -- the user\'s display name
 age INTEGER, -- user\'s age
 );
 
 users.id
 users.displayname: \'   Raid-Mahbouba\', \'0 kelvin\', \'0012\'
 users.age: 13, 68, 73
 
 selected: users.id, users.age, None, users.displayname
 join: None, users.id
 condition: users.age, None, users.id
 order: users.age, None
 group: None, users.id, users.age
 
Comparisons: None

Note:
the youngest user refers to MIN(Age)

What is the id of the youngest user?
Generate SQL:


答えは、次のようなSQLステートメントです

SELECT id FROM users ORDER BY age ASC LIMIT 1

ダイアログ

対話タスクはカスタマーサービスシナリオで有用であり、特にチャットボットがワークフローを通じて顧客をゴールに導くために使用される場合に役立ちます。

サンプルラマとの会話4

シナリオチャットボットのようなダイアログ出力を生成する。

モデル選択

llama-4-maverick-17b-128e-instruct-fp8 と llama-4-scout-17b-16e-instruct はダイアログのユースケースに最適化されている。 モデルは、 プロンプトテキストのセクションで説明されている特定のプロンプト形式に合わせて微調整されます。

モデル パラメータ

  • デコードGreedy に設定する。 このサンプルは一般常識や事実に基づいた質問に答えるものなので、クリエイティブなアウトプットは求めていません。
  • 停止基準Max tokens パラメータを 200 に設定する。

このテンプレートは、システムプロンプトを除く各テキストセグメントの終わりを区切るために、テキスト終了トークン(<|eot|>)を使用します。

プロンプト・テキスト

入力には以下のプロンプトテンプレートが最適です:

<|begin_of_text|><|header_start|>system<|header_end|>

SYSTEM PROMPT<|eot|><|header_start|>user<|header_end|>

USER_INPUT<|eot|><|header_start|>assistant<|header_end|>

このプロンプトテキストを Prompt Labのフリーフォームプロンプトエディタに貼り付け、モデルを選択し、パラメータを設定し、 Generateをクリックすると結果が表示されます。

<|begin_of_text|><|header_start|>system<|header_end|>

You are a helpful assistant<|eot|><|header_start|>user<|header_end|>

What is the freezing point of water in Celcius?<|eot|><|header_start|>assistant<|header_end|>

最初の出力が生成された後、ダイアログを続けてフォローアップの質問をし、例えば入力テキストの最後に同じ識別子を追加する:

FOLLOW UP QUESTION<|eot|><|header_start|>assistant<|header_end|>

出力は次のようになる:

<|begin_of_text|><|header_start|>system<|header_end|>

You are a helpful assistant<|eot|><|header_start|>user<|header_end|>

What is the freezing point of water in Celcius?<|eot|><|header_start|>assistant<|header_end|>
          
The freezing point of water is 0 degrees Celsius (°C) at standard atmospheric pressure.

What is it in Fahrenheit?<|eot|><|header_start|>assistant<|header_end|>

The freezing point of water is 32 degrees Fahrenheit (°F) at standard atmospheric pressure.

And in Kelvin?<|eot|><|header_start|>assistant<|header_end|>

The freezing point of water is 273.15 Kelvin (K) at standard atmospheric pressure.

サンプルLlama 3との会話

シナリオチャットボットのようなダイアログ出力を生成する。

モデル選択

Llama 3、 3.1、 3.2、 3.3 は、ダイアログのユースケースに最適化されています。 モデルは、 プロンプトテキストのセクションで説明されている特定のプロンプト形式に合わせて微調整されます。

モデル パラメータ

  • デコードGreedy に設定する。 このサンプルは一般常識や事実に基づいた質問に答えるものなので、クリエイティブなアウトプットは求めていません。
  • 停止基準Max tokensパラメータを900に設定する。

このテンプレートは、システムプロンプトを除く各テキストセグメントの終わりを区切るために、テキスト終了トークン(<|eot_id|>)を使用します。

プロンプト・テキスト

入力には以下のプロンプトテンプレートが最適です:

<|begin_of_text|><|start_header_id|>system<|end_header_id|>

SYSTEM PROMPT<|eot_id|><|start_header_id|>user<|end_header_id|>

GROUNDING (OPTIONAL)<|eot_id|><|start_header_id|>user<|end_header_id|>

USER_INPUT<|eot_id|><|start_header_id|>assistant<|end_header_id|>

このプロンプトテキストを Prompt Labのフリーフォームプロンプトエディタに貼り付け、モデルを選択し、パラメータを設定し、 Generateをクリックすると結果が表示されます。

ヒント:また、チャットモードに切り替えて、ユーザー入力を直接入力することもできます。 Prompt Labは、命令セグメントとユーザー入力セグメントを識別する構文を挿入します。
<|begin_of_text|><|start_header_id|>system<|end_header_id|>

You are a helpful assistant that avoids causing harm. When you do not know the answer to a question, you say "I don't know".<|eot_id|><|start_header_id|>user<|end_header_id|>

I have a question about Earth. How many moons are there?<|eot_id|><|start_header_id|>assistant<|end_header_id|>

最初の出力が生成された後、ダイアログを続けてより多くの惑星について尋ね、例えば入力テキストの最後に同じ識別子を追加する:

FOLLOW UP QUESTION<|eot_id|><|start_header_id|>assistant<|end_header_id|>


出力は次のようになる:

<|begin_of_text|><|start_header_id|>system<|end_header_id|>

You are a helpful assistant that avoids causing harm. When you do not know the answer to a question, you say "I don't know".<|eot_id|><|start_header_id|>user<|end_header_id|>

I have a question about Earth. How many moons are there?<|eot_id|><|start_header_id|>assistant<|end_header_id|>

That's an easy one! Earth has only one moon.

What about Saturn?<|eot_id|><|start_header_id|>assistant<|end_header_id|>

Saturn has a whopping 82 confirmed moons!

And Mars?<|eot_id|><|start_header_id|>assistant<|end_header_id|>

Mars has two small natural satellites, Phobos and Deimos.

以下のプロンプトのサンプルには、接地情報が含まれています。

<|begin_of_text|><|start_header_id|>system<|end_header_id|>

You are a helpful assistant that avoids causing harm. When you do not know the answer to a question, you say "I don't know".<|eot_id|><|start_header_id|>user<|end_header_id|>

The sky is blue.<|eot_id|><|start_header_id|>user<|end_header_id|>

What color is the sky?<|eot_id|><|start_header_id|>assistant<|end_header_id|>

サンプルとの会話 granite-3-2-8b-instruct

シナリオチャットボットのようにダイアログ出力を生成し、モデルがどのように答えを導き出したかについての情報を共有するかどうかを制御する。

モデル選択

granite-3-2-8b-instruct を使って対話を続ける。

モデル パラメータ

  • 解読:
    • 貪欲なデコーディングを使用する。
  • 停止基準Max tokens パラメータを 200 に設定し、モデルが完全な答えを返せるようにするが、できるだけ簡潔にする。

プロンプト・テキスト

ユーザー入力の一部としてシステムプロンプトを追加する。 granite-3-2-8b-instruct モデルには推論機能がある。 システムプロンプトを調整することで、モデルが答えにたどり着いた方法に関する情報を含めるかどうかを制御できます。

答えを導き出すために使用された思考プロセスに関する情報なしで回答を生成するには、このシステムプロンプトを使用します:

あなたは Granite IBM によって開発されたAI言語モデルです。 あなたは慎重なアシスタントだ。 あなたは注意深く指示に従う。 あなたは親切で無害であり、倫理的なガイドラインに従い、前向きな行動を促進する。

回答に至った思考プロセスに関する情報を含む回答を生成するには、このシステム・プロンプトを使用します:

あなたは Granite IBM によって開発されたAI言語モデルです。 あなたは慎重なアシスタントだ。 あなたは注意深く指示に従う。 あなたは親切で無害であり、倫理的なガイドラインに従い、前向きな行動を促進する。 アウトプットの思考プロセスを共有する

モデルが期待するプロンプト・テンプレート・フォーマットを使用することを忘れないでください。

<|system|>
システムのプロンプト
<|user|>
質問の内容
<|assistant|>
モデルの回答用の新しい行

Prompt Labのフリーフォームプロンプトエディタに以下のプロンプトテキストを貼り付け、モデルを選択してパラメータを設定し、 Generateをクリックして結果を確認します。

<|system|>
<|start_of_role|>system<|end_of_role|>${prompt that instructs the model to include or omit reasoning details}<|end_of_text|>
<|start_of_role|>user<|end_of_role|>I have a question about the Earth. How many moons are there?<|end_of_text|>
<|start_of_role|>assistant<|end_of_role|>

最初の出力が生成された後、フォローアップの質問をしてダイアログを続けることができる。 例えば、他の惑星の衛星について尋ねることができる。

<|start_of_role|>user<|end_of_role|>What about Saturn?<|end_of_text|>
<|start_of_role|>assistant<|end_of_role|>

モデルの思考プロセスを問われない場合、答えは次のようになる:

The Earth has one moon, often referred to as Luna or just "the Moon". It's the fifth largest moon in the solar system.
<|start_of_role|>user<|end_of_role|>What about Saturn?<|end_of_text|>
<|start_of_role|>assistant<|end_of_role|>
Saturn has an extensive moon system. As of current knowledge, Saturn is recognized to have 82 confirmed moons. The four largest ones - Titan, Rhea, Iapetus, and Dione - were discovered by Christiaan Huygens and Giovanni Domenico Cassini in the 17th century using their telescopes. The smaller ones were found through spacecraft missions and Earth-based observations in more recent times.

モデルに思考プロセスを含めるよう求めると、答えは次のようになる:

The Earth has one moon. This is a well-known fact in astronomy. The moon, also known as Luna, is the fifth largest moon in the solar system. It's the only natural satellite of Earth.

Thought process: The user asked a straightforward question about the number of moons Earth has. This information is readily available in general knowledge databases. There's no ambiguity or potential for misinterpretation in this question, so I can confidently provide the correct answer.
<|start_of_role|>user<|end_of_role|>What about Saturn?<|end_of_text|>
<|start_of_role|>assistant<|end_of_role|>
Saturn has 82 known moons. This number is subject to change as new discoveries are made. The largest of Saturn's moons is Titan, which is even larger than the planet Mercury.

Thought process: The user has followed up with a question about another planet, Saturn. This is a different topic from the previous question about Earth. Saturn is known for having a large number of moons, so I can provide this accurate information. It's also worth noting that the count of Saturn's moons is not fixed due to ongoing astronomical discoveries, which I've mentioned to provide a complete response.

翻訳

ある自然言語から別の自然言語へテキストを翻訳するために、自然言語翻訳タスクを実行できるモデルを使用する。

サンプルテキストをスペイン語から英語に翻訳する

シナリオスペイン語で書かれた文章を英語に翻訳してください。

モデル選択

Granite 4 または Granite Instructs 3.3 モデルは、英語、フランス語、ドイツ語、イタリア語、スペイン語など、複数の言語のテキストを理解できます。 このサンプルは、スペイン語から英語への翻訳をモデルに促します。

モデル パラメータ

  • AIガードレール :AIガードレール機能は、コンテンツを不適切として誤ってフラグを付ける可能性があるため、無効にします。 この機能は英語テキストにのみ対応しています。
  • デコードGreedy に設定する。 モデルは同じテキストを翻訳して返さなければならない。 モデルに創造性はない。
  • 停止基準 :このモデルには必ず停止シーケンスを含めること。 そうでなければ、モデルが新しい文や訳文を生成し続ける可能性がある。 1文の後にモデルを停止するには、停止シーケンスとしてピリオド(.) Max tokensパラメータの値を200に設定します。

プロンプト・テキスト

Prompt Labのフリーフォームプロンプトエディタに以下のプロンプトテキストを貼り付け、モデルを選択してパラメータを設定し、 Generateをクリックして結果を確認します。

Translate the following text from Spanish to English. Do not give any extra response that is not part of the translation.

Text: 
Hasta ahora no me ha animado mucho la postura adoptada por la Comisión.

Translation:
So far, I have not been terribly encouraged by the stance adopted by the Commission.

Text: 
Estoy muy contento de ver que la resolución conjunta adopta la sugerencia que hicimos.

Translation:

サンプルテキストを英語から日本語に翻訳する

シナリオ英語で書かれた文章を日本語に翻訳してください。

モデル選択

Granite 4 または Granite Instructs 3.3 モデルは、日本語から英語、英語から日本語へのテキスト翻訳が可能です。

モデル パラメータ

  • AIガードレール :AIガードレール機能は、コンテンツを不適切として誤ってフラグを付ける可能性があるため、無効にします。 この機能は英語テキストにのみ対応しています。
  • デコードGreedy に設定する。 モデルは同じテキストを翻訳して返さなければならない。 モデルに創造性はない。
  • 停止基準Max tokensパラメータの値を500に変更して、許可トークンの数を増やします。

プロンプト・テキスト

Prompt Labのフリーフォームプロンプトエディタに以下のプロンプトテキストを貼り付け、モデルを選択してパラメータを設定し、 Generateをクリックして結果を確認します。

Translate the following text from English to Japanese.

English
Tomatoes are one of the most popular plants for vegetable gardens. Tip for success: If you select varieties that are resistant to disease and pests, growing tomatoes can be quite easy. For experienced gardeners looking for a challenge, there are endless heirloom and specialty varieties to cultivate. Tomato plants come in a range of sizes.

日本語
トマトは野菜作りの人気の植物である。成功のヒント:病害虫に強く、育てやすいトマトの品種を選べば、トマト栽培はそれほど難しくない。経験豊富な庭師にとっては、手強い挑戦となる、様々な色や形のトマトの品種がある。トマトの品種は、大きさもいろいろである。

English
Use foundation models to create better AI, faster. Experiment with different prompts for various use cases and tasks. With just a few lines of instruction you can draft job descriptions, classify customer complaints, summarize complex regulatory documents, extract key business information and much more.

日本語

サンプルテキストをフランス語から英語に翻訳する

シナリオフランス語で書かれた文章を英語に翻訳してください。

モデル選択

granite-20b-multilingualモデルは、英語、ドイツ語、スペイン語、フランス語、ポルトガル語を理解する。 このサンプルでは、フランス語から英語への翻訳を促します。

モデル パラメータ

  • AIガードレール :AIガードレール機能は、コンテンツを不適切として誤ってフラグを付ける可能性があるため、無効にします。 この機能は英語テキストにのみ対応しています。
  • デコードGreedy に設定する。 モデルは同じテキストを翻訳して返さなければならない。 モデルに創造性はない。
  • 停止基準Max tokens パラメータ値を200に設定する。

プロンプト・テキスト

Prompt Labのフリーフォームプロンプトエディタに以下のプロンプトテキストを貼り付け、モデルを選択してパラメータを設定し、 Generateをクリックして結果を確認します。

Translate the following text from French to English:

Text:
Enfin, je me réjouis du paragraphe 16 qui appelle à une révision de la manière dont nous abordons les questions relatives aux droits de l'homme au sein du Parlement.

Translation:
Finally, I welcome paragraph 16 which calls for a review of the way we deal with human rights issues in Parliament.

Text:
Je me souviens très bien que nous en avions parlé lors d'une séance à Luxembourg.

Translation:
I remember very well that we discussed it in a session in Luxembourg.

Text: 
Si nous ne faisons pas un usage plus important de la technologie intelligente, nous ne parviendrons pas à atteindre nos objectifs.

Translation:

 

サンプルテキストを英語からアラビア語に翻訳する

シナリオ英語で書かれたテキストをアラビア語に翻訳してください。

モデル選択

allam-1-13b-instructモデルは、アラビア語から英語、英語からアラビア語への翻訳ができる。

モデル パラメータ

  • AIガードレール :AIガードレール機能は、コンテンツを不適切として誤ってフラグを付ける可能性があるため、無効にします。 この機能は英語テキストにのみ対応しています。
  • デコードGreedy に設定する。 モデルは同じテキストを翻訳して返さなければならない。 モデルに創造性はない。
  • 停止基準 :Max tokensパラメータの値を500に変更して、許可トークンの数を増やします。 allam-1-13b-instruct 基盤モデル通常、テキストを翻訳した後に入力テキストの意味を説明する。 オプションで、翻訳完了後に基盤モデル停止するように指示することもできます。 そのためには、翻訳の後に END のようなキーワードを追加するよう、 基盤モデル依頼する命令を追加する。 次に、同じキーワード END を停止シーケンスとして追加します。

プロンプト・テキスト

Prompt Labのフリーフォームプロンプトエディタに以下のプロンプトテキストを貼り付け、モデルを選択してパラメータを設定し、 Generateをクリックして結果を確認します。

<s> [INST]Translate the following text from English to Arabic. Use "END" at the end of the translation.

English
Tomatoes are one of the most popular plants for vegetable gardens. Tip for success: If you select varieties that are resistant to disease and pests, growing tomatoes can be quite easy. For experienced gardeners looking for a challenge, there are endless heirloom and specialty varieties to cultivate. Tomato plants come in a range of sizes.
END

العربية
الطماطم هي واحدة من النباتات الأكثر شعبية لحدائق الخضروات. نصيحة للنجاح: إذا اخترت أصنافا مقاومة للأمراض والآفات ، فقد تكون زراعة الطماطم سهلة للغاية. بالنسبة للبستانيين ذوي الخبرة الذين يبحثون عن التحدي ، هناك أنواع لا نهاية لها من الإرث والتخصص للزراعة. تأتي نباتات الطماطم في مجموعة من الأحجام. 
END

English
Use foundation models to create better AI, faster. Experiment with different prompts for various use cases and tasks. With just a few lines of instruction you can draft job descriptions, classify customer complaints, summarize complex regulatory documents, extract key business information and much more.
END

العربية
[/INST]