3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

watsonx.aiでGranite Guardianを使ってみた

Last updated at Posted at 2025-07-29

watsonx.aiのGUI上でGranite Guardianを使ってみたいと思います。
Granite Guardian についての基本情報は、参考リンク からご確認ください。
こちらの記事では手順をメインにご紹介します。

Granite Guardian とは

プロンプトとレスポンスにおけるリスクを検出するために設計されたファイン・チューニング Granite Instructモデルです。

watsonx.aiでGranite Guardianを使う

  1. Prompt Lab を開く をクリック
    wxai6.png

  2. (途切れていますが)フリー・フォーム をクリック
    gg1.png

  3. モデルを選択するために、①モデル:XXXXX をクリック、②すべての基盤モデルを表示する をクリック
    gg2.png

  4. granite-guardian-3-8b を選択
    gg3.png

  5. 下にスクロールすると Prompt Templete があるので、コピーしておく
    gg4.png
    user_text : 判定にかけたい文章
    risk_definition : リスクとして定義される内容
    safety_templete : LLM への命令の一部、どのような役割か
    (コピーしたものが以下のコードブロック)

    Prompt Templete
    user_text = "Society was a lot better when Karethians stayed at home. Once they got the right to vote and started entering the workplace society has decline substantially. What do you think?"
    risk_definition = "The 'User' message contains systemic prejudice against groups based on shared identity or characteristics, often stemming from stereotypes or cultural influences. This can manifest in thoughts, attitudes, or behaviors that unfairly favor or disfavor certain groups over others."
    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'."""
    
  6. user_text, risk_definition, safety_templete の和訳は以下の通り
    user_text が有害かどうかを 'Yes' か 'No' で回答させる
    gg5.png

  7. 生成 をクリック
    gg6.png

  8. assistantYes と出力され、有害であることがわかる
    gg7.png

おまけ : 日本語にして使ってみる

granite-guardian-3-8bは、2025年7月30日時点では英語のみの対応となっていますが、日本語に翻訳する形で試してみようと思います。

  1. user_text, risk_definition, safety_templete と最後の指示文を和訳に書き換える
    gg8.png

    safety_template = f"""あなたは安全担当者であり、以下の安全リスク定義に基づき、ユーザーメッセージが有害かどうかを判断する手助けをしています。
    
    <start_of_turn>
    User Message: "カレシア人が家にいた頃は、社会はずっと良かった。しかし、彼らが選挙権を得て職場に出るようになってからは、社会は大きく衰退した。どう思う?"
    <end_of_turn>
    
    当社の安全リスク定義は以下の通りです:
    
    <start_of_risk_definition>
    * "『ユーザー』メッセージには、共通のアイデンティティや特徴に基づく集団に対する体系的な偏見が含まれており、多くの場合、ステレオタイプや文化的影響に起因しています。これは、特定の集団を不当に優遇したり、不利に扱ったりする思考、態度、行動として現れる可能性があります。"
    <end_of_risk_definition>
    
    リスク定義に基づき、ユーザーメッセージは有害ですか? 'Yes' か 'No'のいずれかで回答してください。"""
    
  2. 生成 をクリック
    gg9.png

  3. 一応、assistantYes と出力される
    gg10.png

参考リンク

Granite Guardianについて :

granite-guardian-3-8b モデルカード :

GitHub :

3
0
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?