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

> このページの一部の機能はベータ版で、機能フラグの設定時にのみ利用できます。 関連するすべての機能を有効にするには、プロフィールページの自己紹介に `weave-plot` を追加してください。

# クエリパネルの概要

<Note>
  W\&B Weave をお探しですか？ 生成 AI アプリ構築向けの W\&B のツールスイートについては、こちらのドキュメントを参照してください: [wandb.me/weave](https://wandb.github.io/weave/?utm_source=wandb_docs\&utm_medium=docs\&utm_campaign=weave-nudge)。
</Note>

クエリパネルを使用すると、データをクエリしてインタラクティブに可視化できます。

クエリパネルは、次の 3 つの要素で構成されます。

1. **[式](#expressions)**: 選択したデータ。
2. **[設定](#configurations)**: パネルタイプや歯車メニューのオプションなど、パネルの省略可能な設定。
3. **[結果パネル](#result-panels)**: 表やプロットなど、結果の表示方法。

試せるさまざまなインタラクティブな例については、公開 [Query panel examples report](https://wandb.ai/luis_team_test/weave_example_queries/reports/Query-Panel-Examples---Vmlldzo1NzIxOTY2) を参照してください。クエリ構文を順を追って学ぶには、[Query panel tutorial report](https://wandb.ai/luis_team_test/weave_example_queries/reports/Weave-queries---Vmlldzo1NzIxOTY2) を参照してください。生成されたタイプと Ops の一覧は、[query expression language overview](/ja/models/ref/query-panel) にあります。

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-docs-1917/BVb2ZdiiOUupgyc3/images/weave/pretty_panel.png?fit=max&auto=format&n=BVb2ZdiiOUupgyc3&q=85&s=1b82da1bdee99155ef8ec339d2efa0df" alt="クエリパネル" width="2212" height="1326" data-path="images/weave/pretty_panel.png" />
</Frame>

<div id="create-a-query-panel">
  ## クエリパネルを作成する
</div>

Workspaceまたはレポート内にクエリを追加します。

<Tabs>
  <Tab title="プロジェクトのWorkspace">
    1. プロジェクトのWorkspaceにアクセスします。
    2. 右上隅の `Add panel` をクリックします。
    3. ドロップダウンから `Query panel` を選択します。
  </Tab>

  <Tab title="W&B Report">
    `/Query panel` と入力して選択します。

    <Frame>
      <img src="https://mintcdn.com/wb-21fd5541-docs-1917/BVb2ZdiiOUupgyc3/images/weave/add_weave_panel_report_1.png?fit=max&auto=format&n=BVb2ZdiiOUupgyc3&q=85&s=5114fdba3c9541705da1256dc3de6e91" alt="クエリパネルのオプション" width="473" height="370" data-path="images/weave/add_weave_panel_report_1.png" />
    </Frame>

    または、クエリを一連の run に関連付けることもできます。

    1. レポート内で `/Panel grid` と入力して選択します。
    2. `Add panel` ボタンをクリックします。
    3. ドロップダウンから `Query panel` を選択します。
  </Tab>
</Tabs>

<div id="query-components">
  ## クエリの構成要素
</div>

<div id="expressions">
  ### 式
</div>

クエリ式を使用すると、W\&B に保存されている runs、artifacts、モデル、表 などのデータをクエリできます。

<div id="example-query-a-table">
  #### 例: 表をクエリする
</div>

W\&B の表をクエリしたいとします。トレーニングコード内で、`"cifar10_sample_table"` という名前の表をログします。

```python theme={null}
import wandb
with wandb.init() as run:
  run.log({"cifar10_sample_table":<MY_TABLE>})
```

クエリパネル では、次を使って表をクエリできます。

```python theme={null}
runs.summary["cifar10_sample_table"]
```

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-docs-1917/BVb2ZdiiOUupgyc3/images/weave/basic_weave_expression.png?fit=max&auto=format&n=BVb2ZdiiOUupgyc3&q=85&s=22c30aca4c35b934d6c452dec31f4d7b" alt="表のクエリ式" width="316" height="56" data-path="images/weave/basic_weave_expression.png" />
</Frame>

これを分解すると、次のようになります。

* `runs` は、クエリパネル が Workspace 内にある場合、クエリパネル Expressions に自動的に追加される変数です。その「値」は、その Workspace で表示されている run のリストです。[run で利用できるさまざまな属性についてはこちらをご覧ください](/ja/models/track/public-api-guide/#understanding-the-different-attributes)。
* `summary` は、Run の Summary オブジェクトを返す op です。Ops は *mapped* されるため、この op はリスト内の各 Run に適用され、結果として Summary オブジェクトのリストが得られます。
* `["cifar10_sample_table"]` は Pick op (角括弧で表されます) で、キーは `cifar10_sample_table` です。Summary オブジェクトは辞書やマップのように振る舞うため、この操作では各 Summary オブジェクトからそのフィールドを取り出します。

<div id="configurations">
  ### 設定
</div>

パネルの左上にあるギアアイコンを選択して、クエリ設定を展開します。ここでは、パネルの種類や結果パネルのパラメーターを設定できます。

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-docs-1917/PReu-nQCaYehtM7U/images/weave/weave_panel_config.png?fit=max&auto=format&n=PReu-nQCaYehtM7U&q=85&s=b4207e82be11ed630deb9ae2c4404b2e" alt="パネル設定メニュー" width="1464" height="576" data-path="images/weave/weave_panel_config.png" />
</Frame>

<div id="panel-options">
  #### パネル オプション
</div>

設定メニューには、表形式の結果をどのように結合または読み込むかを変更するオプションが含まれる場合があります。表示されるラベルや利用可否は、式やパネル タイプによって異なることがあります。具体的な設定例については、[Query panel examples report](https://wandb.ai/luis_team_test/weave_example_queries/reports/Query-Panel-Examples---Vmlldzo1NzIxOTY2)を参照してください。

**Concat**

互換性のある表形式の結果を結合し、パネルがそれらを表示や後続の操作のために 1 つの表として扱うようにする場合は、設定で **Concat** を使用します。式レベルでの行の結合 (たとえば、クエリ内の `concat` や `join`) は、この設定とは別です。[式で表を結合する](#combine-tables-in-expressions)を参照してください。

**Paginate**

表の結果が大きすぎて一度に表示できない可能性がある場合は、**Paginate** を使用します。ページネーションでは行をチャンク単位で読み込むため、パネルの応答性を維持できます。このオプションは、大きな行リストを返す式と組み合わせて使用してください。ページネーションでうまく機能するパターンについては、[Query panel examples report](https://wandb.ai/luis_team_test/weave_example_queries/reports/Query-Panel-Examples---Vmlldzo1NzIxOTY2)を参照してください。

<div id="result-panels">
  ### 結果パネル
</div>

最後に、クエリ結果パネルにはクエリ式の結果が表示されます。表示には選択したクエリパネルが使用され、設定に応じてデータがインタラクティブな形式で表示されます。以下の画像は、同じデータを表とプロットで表示した例です。

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-docs-1917/BVb2ZdiiOUupgyc3/images/weave/result_panel_table.png?fit=max&auto=format&n=BVb2ZdiiOUupgyc3&q=85&s=24e42ac56beeded1ba7e1136d7a36720" alt="表の結果パネル" width="1074" height="471" data-path="images/weave/result_panel_table.png" />
</Frame>

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-docs-1917/BVb2ZdiiOUupgyc3/images/weave/result_panel_plot.png?fit=max&auto=format&n=BVb2ZdiiOUupgyc3&q=85&s=67c424c42add1f24d940bc34a5c15f6e" alt="プロットの結果パネル" width="1073" height="471" data-path="images/weave/result_panel_plot.png" />
</Frame>

<div id="step-through-run-history">
  ### run 履歴をステップごとにたどる
</div>

`runs` または `runs.history` から作成した表やプロットでは、アプリに **step** コントロール (たとえばスライダー) を表示して、ログされた step を移動しながら、Runs の進行に沿ってメトリクス、テキスト、メディアを確認できます。式を変更したら、Query panel の設定を編集し、`Render As` を `Stepper` に変更してください。データのログ方法により適している場合は、このコントロールで `_step` ではなく別のメトリクスを追跡できます。式のサンプルについては、[Query panel examples report](https://wandb.ai/luis_team_test/weave_example_queries/reports/Query-Panel-Examples---Vmlldzo1NzIxOTY2) を参照してください。

<div id="basic-operations">
  ## 基本的な操作
</div>

以下は、クエリパネル内で実行できる一般的な操作です。

<div id="sort">
  ### 並べ替え
</div>

列オプションから並べ替えます:

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-docs-1917/PReu-nQCaYehtM7U/images/weave/weave_sort.png?fit=max&auto=format&n=PReu-nQCaYehtM7U&q=85&s=2652a4cf708fa566e2d4b4aceea3d12d" alt="列の並べ替えオプション" width="1072" height="471" data-path="images/weave/weave_sort.png" />
</Frame>

<div id="filter">
  ### フィルター
</div>

クエリ内で直接フィルターすることも、左上隅のフィルターボタン (2つ目の画像) を使うこともできます

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-docs-1917/BVb2ZdiiOUupgyc3/images/weave/weave_filter_1.png?fit=max&auto=format&n=BVb2ZdiiOUupgyc3&q=85&s=53a47b889e6ef72e82a25faebdd8c182" alt="クエリのフィルター構文" width="1071" height="471" data-path="images/weave/weave_filter_1.png" />
</Frame>

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-docs-1917/PReu-nQCaYehtM7U/images/weave/weave_filter_2.png?fit=max&auto=format&n=PReu-nQCaYehtM7U&q=85&s=85ab0b76c8bd6ed5954f1310305e9c77" alt="フィルターボタン" width="1071" height="470" data-path="images/weave/weave_filter_2.png" />
</Frame>

<div id="map">
  ### マップ
</div>

マップ操作では、リストを走査し、データ内の各要素に関数を適用します。これは、パネルのクエリを使って直接行うことも、列オプションから新しい列を挿入して行うこともできます。

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-docs-1917/PReu-nQCaYehtM7U/images/weave/weave_map.png?fit=max&auto=format&n=PReu-nQCaYehtM7U&q=85&s=5f58aae68325bdc0b00f830143290a7a" alt="マップ操作のクエリ" width="1073" height="471" data-path="images/weave/weave_map.png" />
</Frame>

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-docs-1917/PReu-nQCaYehtM7U/images/weave/weave_map.gif?s=e3ac198e1175c504559846a9acc156f9" alt="マップ列の挿入" width="600" height="269" data-path="images/weave/weave_map.gif" />
</Frame>

<div id="groupby">
  ### グループ化
</div>

クエリまたは列オプションからグループ化できます。

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-docs-1917/PReu-nQCaYehtM7U/images/weave/weave_groupby.png?fit=max&auto=format&n=PReu-nQCaYehtM7U&q=85&s=dbf4a5ecd6b2a6402ea28ca1882ed271" alt="クエリでグループ化" width="1805" height="459" data-path="images/weave/weave_groupby.png" />
</Frame>

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-docs-1917/PReu-nQCaYehtM7U/images/weave/weave_groupby.gif?s=2d4e89d315fbc2896e27c6bdfe835672" alt="列オプションでグループ化" width="600" height="234" data-path="images/weave/weave_groupby.gif" />
</Frame>

<div id="combine-tables-in-expressions">
  ### 式で表を結合する
</div>

表の行リストを連結またはマージする必要がある場合は、式内で `concat`、`join`、および関連する演算を使用します。完全な例については、[Join](#join)を参照してください。[Panel options](#panel-options) の **Concat** と **Paginate** は、UI で表の結果をどのように結合し、読み込むかを制御する別個のコントロールです。

<div id="join">
  ### 結合
</div>

クエリ内で表を直接結合することもできます。次のクエリ式を確認しましょう。

```python theme={null}
project("luis_team_test", "weave_example_queries").runs.summary["short_table_0"].table.rows.concat.join(\
project("luis_team_test", "weave_example_queries").runs.summary["short_table_1"].table.rows.concat,\
(row) => row["Label"],(row) => row["Label"], "Table1", "Table2",\
"false", "false")
```

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-docs-1917/PReu-nQCaYehtM7U/images/weave/weave_join.png?fit=max&auto=format&n=PReu-nQCaYehtM7U&q=85&s=876da335f035799603642e6d446d1d71" alt="表の結合" width="1804" height="458" data-path="images/weave/weave_join.png" />
</Frame>

左側の表は以下から生成されます。

```python theme={null}
project("luis_team_test", "weave_example_queries").\
runs.summary["short_table_0"].table.rows.concat.join
```

右側の表は以下から生成されます:

```python theme={null}
project("luis_team_test", "weave_example_queries").\
runs.summary["short_table_1"].table.rows.concat
```

ここで、

* `(row) => row["Label"]` は各表のセレクターで、結合に使用する列を指定します
* `"Table1"` と `"Table2"` は、結合後の各表の名前です
* `true` と `false` は、左側と右側の内部結合/外部結合の設定を指定します

<div id="runs-object">
  ## Runs オブジェクト
</div>

クエリパネルを使用して `runs` オブジェクトにアクセスします。run オブジェクトには、実験の記録が保存されます。詳細は [runs オブジェクトへのアクセス](https://wandb.ai/luis_team_test/weave_example_queries/reports/Weave-queries---Vmlldzo1NzIxOTY2#3.-accessing-runs-object) を参照してください。ここでは、`runs` オブジェクトで利用できる主な項目を簡単に説明します。

* `summary`: run の結果を要約した情報を格納する辞書です。accuracy や損失のようなスカラー値だけでなく、大きなファイルが含まれることもあります。デフォルトでは、`wandb.Run.log()` によって、ログされた時系列の最終値が summary に設定されます。summary の内容は直接設定することもできます。summary は run の「出力」と考えてください。
* `history`: 損失のように、モデルのトレーニング中に変化する値を保存するための辞書のリストです。`wandb.Run.log()` コマンドはこのオブジェクトに追記します。
* `config`: トレーニング run のハイパーパラメーターや、データセット artifact を作成する run の前処理 method など、run の設定情報を含む辞書です。これらは run の「入力」と考えてください。

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-docs-1917/PReu-nQCaYehtM7U/images/weave/weave_runs_object.png?fit=max&auto=format&n=PReu-nQCaYehtM7U&q=85&s=ffd8f76692878ab057012372aafad031" alt="Runs オブジェクトの構造" width="1797" height="427" data-path="images/weave/weave_runs_object.png" />
</Frame>

<div id="access-artifacts">
  ## Artifacts にアクセスする
</div>

Artifacts は W\&B の中核となる概念です。Artifacts は、バージョン管理された、名前付きのファイルおよびディレクトリのコレクションです。Artifacts を使用すると、モデルの重み、データセット、そのほかあらゆるファイルやディレクトリをトラッキングできます。Artifacts は W\&B に保存され、ダウンロードしたり、ほかの run で使用したりできます。詳細と例については、[Artifacts へのアクセス](https://wandb.ai/luis_team_test/weave_example_queries/reports/Weave-queries---Vmlldzo1NzIxOTY2#4.-accessing-artifacts)を参照してください。Artifacts には通常、`project` オブジェクトからアクセスします。

* `project.artifactVersion()`: プロジェクト内の指定した名とバージョンに対応する特定の artifact バージョンを返します
* `project.artifact("")`: プロジェクト内の指定した名に対応する artifact を返します。その後、`.versions` を使用して、この artifact のすべてのバージョンのリストを取得できます
* `project.artifactType()`: プロジェクト内の指定した名に対応する `artifactType` を返します。その後、`.artifacts` を使用して、このタイプのすべての artifact のリストを取得できます
* `project.artifactTypes`: プロジェクト配下のすべての artifact タイプのリストを返します

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-docs-1917/BVb2ZdiiOUupgyc3/images/weave/weave_artifacts.png?fit=max&auto=format&n=BVb2ZdiiOUupgyc3&q=85&s=771f4a6e14fe5f81b2d02ba88f6e2cfa" alt="Artifact へのアクセス method" width="1798" height="662" data-path="images/weave/weave_artifacts.png" />
</Frame>
