> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-feature-automate-reference-docs-generation.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Weave local scorers

<a target="_blank" href="https://colab.research.google.com/github/wandb/examples/blob/master/weave/docs/scorers_local_weave_scorers.ipynb">
  <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" />
</a>

Weaveのローカルスコアラーは、最小限のレイテンシーでマシン上でローカルに実行される小型言語モデルのスイートです。これらのモデルは、AIシステムの入力、コンテキスト、出力の安全性と品質を評価します。

これらのモデルの一部はWeights & Biasによって微調整されていますが、他はコミュニティによってトレーニングされた最先端のオープンソースモデルです。トレーニングと評価にはWeights & Biases（W\&B）レポートが使用されました。詳細は以下の[W\&Bレポートのリスト](https://wandb.ai/c-metrics/weave-scorers/reports/Weave-Scorers-v1--VmlldzoxMDQ0MDE1OA)。

モデルの重みはW\&B Artifactsで公開されており、スコアラークラスをインスタンス化すると自動的にダウンロードされます。自分でダウンロードしたい場合は、アーティファクトパスはこちらで確認できます：`weave.scorers.default_models`

これらのスコアラーによって返されるオブジェクトには`passed`入力テキストが安全または高品質であるかどうかを示すブール属性と、`metadata`モデルからの生のスコアなどの詳細情報を含む属性があります。

<Tip>
  ローカルスコアラーはCPUとGPUで実行できますが、最高のパフォーマンスを得るにはGPUを使用してください。
</Tip>

<Tabs>
  <Tab title="Python">
    ## 前提条件

    Weaveローカルスコアラーを使用する前に、追加の依存関係をインストールしてください：

    ```bash
    pip install weave[scorers]
    ```

    ## スコアラーを選択

    以下のローカルスコアラーが利用可能です。ユースケースに基づいてスコアラーを選択してください。

    | スコアラー                                                           | シナリオ                                                                 |
    | --------------------------------------------------------------- | -------------------------------------------------------------------- |
    | [WeaveToxicityScorerV1](#weavetoxicityscorerv1)                 | AIシステムの入力と出力に含まれる有害なコンテンツ（ヘイトスピーチや脅迫など）を特定します。                       |
    | [WeaveBiasScorerV1](#weavebiasscorerv1)                         | AIシステムの入力と出力における偏見やステレオタイプのコンテンツを検出します。生成されたテキストの有害な偏見を減らすのに理想的です。   |
    | [WeaveHallucinationScorerV1](#weavehallucinationscorerv1)       | RAGシステムが提供された入力とコンテキストに基づいて出力で幻覚を生成しているかどうかを識別します。                   |
    | [WeaveContextRelevanceScorerV1](#weavecontextrelevancescorerv1) | AIシステムの出力が提供された入力とコンテキストに関連しているかどうかを測定します。                           |
    | [WeaveCoherenceScorerV1](#weavecoherencescorerv1)               | AIシステムの出力の一貫性と論理構造を評価します。                                            |
    | [WeaveFluencyScorerV1](#weavefluencyscorerv1)                   | AIシステムの出力が流暢かどうかを測定します。                                              |
    | [WeaveTrustScorerV1](#weavetrustscorerv1)                       | 毒性、幻覚、コンテキスト関連性、流暢さ、一貫性のスコアラーを活用する集約スコアラーです。                         |
    | [PresidioScorer](#presidioscorer)                               | MicrosoftのPresidioライブラリを使用して、AIシステムの入力と出力に含まれる個人を特定できる情報（PII）を検出します。 |

    ## `WeaveBiasScorerV1`

    このスコアラーは、ジェンダーと人種/出身地のバイアスを2つの次元で評価します：

    * 人種と出身地：人種差別、出身国や地域、移民の地位、民族性などに対するバイアス。
    * ジェンダーとセクシュアリティ：性差別、女性蔑視、同性愛嫌悪、トランスフォビア、セクシャルハラスメントなど。

    `WeaveBiasScorerV1`は微調整された[deberta-small-long-nli](https://huggingface.co/tasksource/deberta-small-long-nli)モデルを使用しています。モデル、データセット、キャリブレーションプロセスの詳細については、[WeaveBiasScorerV1 W\&B Report](https://wandb.ai/c-metrics/bias-benchmark/reports/Bias-Scorer--VmlldzoxMDM2MTgzNw)をご覧ください。

    ### 使用上の注意

    * この`score`メソッドは、`output`パラメータに文字列を渡すことを想定しています。
    * スコアが高いほど、テキスト内のバイアスの予測が強くなります。
    * この`threshold`パラメータは設定されていますが、初期化時にオーバーライドすることもできます。

    ### 使用例

    ```python
    import weave
    from weave.scorers import WeaveBiasScorerV1

    bias_scorer = WeaveBiasScorerV1()
    result = bias_scorer.score(output="Martian men are terrible at cleaning")

    print(f"The text is biased: {not result.passed}")
    print(result)
    ```

    ***

    ## `WeaveToxicityScorerV1`

    このスコアラーは、入力テキストの毒性を5つの次元で評価します：

    * 人種と出身地：人種差別、出身国や地域、移民の地位、民族性などに対するバイアス。
    * ジェンダーとセクシュアリティ：性差別、女性蔑視、同性愛嫌悪、トランスフォビア、セクシャルハラスメントなど。
    * Religious: Bias or stereotypes against someone's religion.
    * Ability: Bias related to someone's physical, mental, or intellectual ability or disability.
    * 暴力と虐待：暴力の過度に詳細な描写、暴力の脅威、または暴力の扇動。

    この`WeaveToxicityScorerV1`はオープンソースの[Celadon](https://huggingface.co/PleIAs/celadon)モデル（PleIAsから）を使用しています。詳細については、[WeaveToxicityScorerV1 W\&B Report](https://wandb.ai/c-metrics/toxicity-benchmark/reports/Toxicity-Scorer--VmlldzoxMDMyNjc0NQ)をご覧ください。

    ### 使用上の注意

    * この`score`メソッドは、`output`パラメータに文字列を渡すことを想定しています。
    * モデルは`0`から`3`までの5つの異なるカテゴリにわたるスコアを返します：
      * これらのスコアの合計が`total_threshold`（デフォルト値`5`）を超える場合、入力は有毒としてフラグが立てられます。
      * 単一のカテゴリのスコアが`category_threshold`（デフォルト`2`）より高い場合、入力は有毒としてフラグが立てられます。
    * フィルタリングをより積極的にするには、初期化時に`category_threshold`または`total_threshold`をオーバーライドしてください。

    ### 使用例

    ```python
    import weave
    from weave.scorers import WeaveToxicityScorerV1

    toxicity_scorer = WeaveToxicityScorerV1()
    result = toxicity_scorer.score(output="people from the south pole of Mars are the worst")

    print(f"Input is toxic: {not result.passed}")
    print(result)
    ```

    ***

    ## `WeaveHallucinationScorerV1`

    このスコアラーは、AIシステムの出力に入力データに基づいた幻覚が含まれているかどうかをチェックします。

    この`WeaveHallucinationScorerV1`はオープンソースの[HHEM 2.1 model](https://huggingface.co/vectara/hallucination_evaluation_model)（Vectaraから）を使用しています。詳細については、[WeaveHallucinationScorerV1 W\&B Report](https://wandb.ai/c-metrics/hallucination/reports/Hallucination-Scorer--VmlldzoxMDM3NDA3MA)をご覧ください。

    ### 使用上の注意

    * この`score`メソッドは、`query`と`output`パラメータに値を渡すことを想定しています。
    * コンテキストは`output`パラメータに渡す必要があります（文字列または文字列のリストとして）。
    * 出力スコアが高いほど、出力における幻覚の予測が強くなります。
    * この`threshold`パラメータは設定されていますが、初期化時にオーバーライドできます。

    ### 使用例

    ```python
    import weave
    from weave.scorers import WeaveHallucinationScorerV1

    hallucination_scorer = WeaveHallucinationScorerV1()

    result = hallucination_scorer.score(
        query="What is the capital of Antarctica?",
        context="People in Antarctica love the penguins.",
        output="While Antarctica is known for its sea life, penguins aren't liked there."
    )

    print(f"Output is hallucinated: {not result.passed}")
    print(result)
    ```

    ***

    ## `WeaveContextRelevanceScorerV1`

    このスコアラーはRAGシステムを評価する際に使用するように設計されています。クエリに対するコンテキストの関連性をスコアリングします。

    この`WeaveContextRelevanceScorerV1`は微調整された[deberta-small-long-nli](https://huggingface.co/tasksource/deberta-small-long-nli)モデル（tasksourceから）を使用しています。詳細については、[WeaveContextRelevanceScorerV1 W\&B Report](https://wandb.ai/c-metrics/context-relevance-scorer/reports/Context-Relevance-Scorer--VmlldzoxMDYxNjEyNA)をご覧ください。

    ### 使用上の注意

    * この`score`メソッドは`query`と`output`の値を想定しています。
    * コンテキストは`output`パラメータに渡す必要があります（文字列または文字列のリスト）。
    * スコアが高いほど、コンテキストがクエリに関連しているという予測が強くなります。
    * `verbose=True`を`score`メソッドに渡して、チャンクごとのスコアを取得できます。

    ### 使用例

    ```python
    import weave
    from weave.scorers import WeaveContextRelevanceScorerV1

    context_relevance_scorer = WeaveContextRelevanceScorerV1()

    result = context_relevance_scorer.score(
        query="What is the capital of Antarctica?",
        output="The Antarctic has the happiest penguins."  # context is passed to the output parameter
    )

    print(f"Output is relevant: {result.passed}")
    print(result)
    ```

    ## `WeaveCoherenceScorerV1`

    このスコアラーは、入力テキストが一貫しているかどうかをチェックします。

    この`WeaveCoherenceScorerV1`は微調整された[deberta-small-long-nli](https://huggingface.co/tasksource/deberta-small-long-nli)モデル（tasksourceから）を使用しています。詳細については、[WeaveCoherenceScorerV1 W\&B Report](https://wandb.ai/c-metrics/coherence_scorer/reports/Coherence-Scorer--VmlldzoxMDI5MjA1MA).

    ### 使用上の注意

    * The `score` メソッドはテキストを `query` および `output` パラメータに渡すことを想定しています。
    * 出力スコアが高いほど、一貫性の予測が強いことを意味します。

    ### 使用例

    ```python
    import weave
    from weave.scorers import WeaveCoherenceScorerV1

    coherence_scorer = WeaveCoherenceScorerV1()

    result = coherence_scorer.score(
        query="What is the capital of Antarctica?",
        output="but why not monkey up day"
    )

    print(f"Output is coherent: {result.passed}")
    print(result)
    ```

    ***

    ## `WeaveFluencyScorerV1`

    このスコアラーは、入力テキストが流暢であるか—つまり、読みやすく理解しやすく、自然な人間の言語に似ているかをチェックします。文法、構文、全体的な読みやすさを評価します。

    The `WeaveFluencyScorerV1` は微調整された [ModernBERT-base](https://huggingface.co/answerdotai/ModernBERT-base) モデルをAnswerDotAIから使用しています。詳細については、[WeaveFluencyScorerV1 W\&B Report](https://wandb.ai/c-metrics/fluency-eval/reports/Fluency-Scorer--VmlldzoxMTA3NzE2Ng).

    ### 使用上の注意

    * The `score` メソッドはテキストを `output` パラメータに渡すことを想定しています。
    * 出力スコアが高いほど、流暢性が高いことを示します。

    ### 使用例

    ```python
    import weave
    from weave.scorers import WeaveFluencyScorerV1

    fluency_scorer = WeaveFluencyScorerV1()

    result = fluency_scorer.score(
        output="The cat did stretching lazily into warmth of sunlight."
    )

    print(f"Output is fluent: {result.passed}")
    print(result)
    ```

    ***

    ## `WeaveTrustScorerV1`

    The `WeaveTrustScorerV1` はRAGシステム用の複合スコアラーで、他のスコアラーを重要（Critical）と勧告（Advisory）の2つのカテゴリーにグループ化することで、モデル出力の信頼性を評価します。複合スコアに基づいて、次の信頼レベルを返します：

    * `high`: 問題は検出されていません
    * `medium`: 勧告（Advisory）の問題のみ検出されました
    * `low`: 重要（Critical）な問題が検出されたか、入力が空です

    重要（Critical）なスコアラーに失敗した入力は `low` 信頼レベルになります。勧告（Advisory）スコアラーに失敗すると `medium`.

    * **Critical:**
      * `WeaveToxicityScorerV1`
      * `WeaveHallucinationScorerV1`
      * `WeaveContextRelevanceScorerV1`

    * **Advisory:**
      * `WeaveFluencyScorerV1`
      * `WeaveCoherenceScorerV1`

    ### 使用上の注意

    * このスコアラーはRAGパイプラインの評価用に設計されています。
    * 正確なスコアリングには `query`, `context`, および `output` キーが必要です。

    ### 使用例

    ```python
    import weave
    from weave.scorers import WeaveTrustScorerV1

    trust_scorer = WeaveTrustScorerV1()

    def print_trust_scorer_result(result):
        print()
        print(f"Output is trustworthy: {result.passed}")
        print(f"Trust level: {result.metadata['trust_level']}")
        if not result.passed:
            print("Triggered scorers:")
            for scorer_name, scorer_data in result.metadata['raw_outputs'].items():
                if not scorer_data.passed:
                    print(f"  - {scorer_name} did not pass")
        print()
        print(f"WeaveToxicityScorerV1 scores: {result.metadata['scores']['WeaveToxicityScorerV1']}")
        print(f"WeaveHallucinationScorerV1 scores: {result.metadata['scores']['WeaveHallucinationScorerV1']}")
        print(f"WeaveContextRelevanceScorerV1 score: {result.metadata['scores']['WeaveContextRelevanceScorerV1']}")
        print(f"WeaveCoherenceScorerV1 score: {result.metadata['scores']['WeaveCoherenceScorerV1']}")
        print(f"WeaveFluencyScorerV1: {result.metadata['scores']['WeaveFluencyScorerV1']}")
        print()

    result = trust_scorer.score(
        query="What is the capital of Antarctica?",
        context="People in Antarctica love the penguins.",
        output="The cat stretched lazily in the warm sunlight."
    )

    print_trust_scorer_result(result)
    print(result)
    ```

    ***

    ## `PresidioScorer`

    このスコアラーは [Presidio library](https://github.com/microsoft/presidio) を使用して、AIシステムの入力と出力における個人を特定できる情報（PII）を検出します。

    ### 使用上の注意

    * メールアドレスや電話番号などの特定のエンティティタイプを指定するには、Presidioエンティティのリストを `selected_entities` パラメータに渡します。そうしない場合、Presidioはデフォルトのエンティティリストにあるすべてのエンティティタイプを検出します。
    * メールアドレスや電話番号などの特定のエンティティタイプを検出するには、リストを `selected_entities` パラメータに渡します。
    * カスタム認識器は `custom_recognizers` パラメータを通じて `presidio.EntityRecognizer` インスタンスのリストとして渡すことができます。
    * 英語以外の入力を処理するには、`language` パラメータを使用して言語を指定します。

    ### 使用例

    ```python
    import weave
    from weave.scorers import PresidioScorer

    presidio_scorer = PresidioScorer()

    result = presidio_scorer.score(
        output="Mary Jane is a software engineer at XYZ company and her email is mary.jane@xyz.com."
    )

    print(f"Output contains PII: {not result.passed}")
    print(result)
    ```
  </Tab>

  <Tab title="TypeScript">
    WeaveローカルスコアラーはまだTypeScriptでは利用できません。お待ちください！

    TypeScriptでWeaveスコアラーを使用するには、[function-based scorers](scorers#function-based-scorers).
  </Tab>
</Tabs>
