

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# Gremlin 推論クエリで使用される Neptune ML 述語
<a name="machine-learning-gremlin-inference-query-predicates"></a>

## `Neptune#ml.deterministic`
<a name="machine-learning-gremlin-inference-neptune-ml-deterministic-predicate"></a>

この述語は、帰納的推論クエリ、つまり [`Neptune#ml.inductiveInference`](#machine-learning-gremlin-inference-neptune-ml-inductiveInference) 述語を含むクエリではオプションです。

帰納的推論を使用する場合、Neptune エンジンはトレーニング済みの GNN モデルを評価するための適切なサブグラフを作成します。このサブグラフの要件は、最終モデルのパラメータによって異なります。具体的には、`num-layer` パラメータによってターゲットノードまたはエッジからのトラバーサルホップ数が決まり、`fanouts` パラメータによって各ホップでサンプリングするネイバーの数を指定します ([HPO パラメータ](machine-learning-customizing-hyperparams.md)を参照)。

デフォルトでは、帰納的推論クエリは非決定論的モードで実行されます。このモードでは、Neptune は近傍をランダムに構築します。予測を行う場合、この通常のランダム近傍サンプリングによって予測が異なる場合があります。

帰納的推論クエリに `Neptune#ml.deterministic` を含めると、Neptune エンジンは、同じクエリを複数回呼び出しても毎回同じ結果が返されるように、決定論的な方法で近傍をサンプリングしようとします。ただし、基礎となるグラフの変更や分散システムのアーティファクトによって変動が生じる可能性があるため、結果が完全に決定的であることは保証できません。

次のように、クエリに `Neptune#ml.deterministic` 述語を含めます。

```
.with("Neptune#ml.deterministic")
```

`Neptune#ml.deterministic` 述語が `Neptune#ml.inductiveInference` も含まないクエリに含まれている場合は、単に無視されます。

## `Neptune#ml.disableInductiveInferenceMetadataCache`
<a name="machine-learning-gremlin-disableInductiveInferenceMetadataCache-predicate"></a>

この述語は、帰納的推論クエリ、つまり [`Neptune#ml.inductiveInference`](#machine-learning-gremlin-inference-neptune-ml-inductiveInference) 述語を含むクエリではオプションです。

帰納的推論クエリでは、Neptune は Amazon S3 に保存されているメタデータファイルを使用して、近傍を構築する際のホップ数とファンアウトを決定します。Neptune は通常、Amazon S3 からファイルを繰り返し取得しないように、このモデルメタデータをキャッシュします。クエリに `Neptune#ml.disableInductiveInferenceMetadataCache` 述語を含めることでキャッシュを無効にできます。Neptune が Amazon S3 から直接メタデータを取得するほうが時間がかかる場合がありますが、再トレーニングまたは変換後に SageMaker AI エンドポイントが更新され、キャッシュが古い場合に役立ちます。

次のように、クエリに `Neptune#ml.disableInductiveInferenceMetadataCache` 述語を含めます。

```
.with("Neptune#ml.disableInductiveInferenceMetadataCache")
```

Jupyter ノートブックでサンプルクエリがどのように表示されるかを次に示します。

```
%%gremlin
g.with("Neptune#ml.endpoint", "ep1")
 .with("Neptune#ml.iamRoleArn", "arn:aws:iam::123456789012:role/NeptuneMLRole")
 .with("Neptune#ml.disableInductiveInferenceMetadataCache")
 .V('101').properties("rating")
 .with("Neptune#ml.regression")
 .with("Neptune#ml.inductiveInference")
```

## `Neptune#ml.endpoint`
<a name="machine-learning-gremlin-inference-neptune-ml-endpoint-predicate"></a>

`Neptune#ml.endpoint` 述語は、必要に応じて、`with()` 手順に従い推論エンドポイントを指定するために使用します。

```
 .with("Neptune#ml.endpoint", "{{the model's SageMaker AI inference endpoint}}")
```

エンドポイントは、`id` またはその URL のいずれかで識別できます。例:

```
 .with( "Neptune#ml.endpoint", "node-classification-movie-lens-endpoint" )
```

または:

```
 .with( "Neptune#ml.endpoint", "https://runtime.sagemaker.us-east-1.amazonaws.com/endpoints/node-classification-movie-lens-endpoint/invocations" )
```

**注記**  
 Neptune DB クラスターのパラメータグループで[`neptune_ml_endpoint` パラメータを](machine-learning-cluster-setup.md#machine-learning-set-inference-endpoint-cluster-parameter)エンドポイント `id` または URL に設定すれば、各クエリの `Neptune#ml.endpoint` 述語を含む必要はありません。

## `Neptune#ml.iamRoleArn`
<a name="machine-learning-gremlin-inference-neptune-ml-iamRoleArn-predicate"></a>

必要に応じて、SageMaker AI 実行 IAM ロールの ARN を指定するために、`with()` ステップで `Neptune#ml.iamRoleArn` が使用されます。

```
 .with("Neptune#ml.iamRoleArn", "{{the ARN for the SageMaker AI execution IAM role}}")
```

SageMaker AI 実行 IAM ロールを作成する方法については、[カスタム NeptuneSageMakerIAMRole ロールを作成する](machine-learning-manual-setup.md#ml-manual-setup-sm-role) を参照してください。

**注記**  
Neptune DB クラスターのパラメータグループで SageMaker AI 実行 IAM ロールの ARN に [`neptune_ml_iam_role` パラメータを設定](machine-learning-cluster-setup.md#machine-learning-enabling-create-param-group)すれば、各クエリの `Neptune#ml.iamRoleArn` 述語を含む必要はありません。

## Neptune\#ml.inductiveInference
<a name="machine-learning-gremlin-inference-neptune-ml-inductiveInference"></a>

Gremlin では、トランスダクティブ推論はデフォルトで有効です。[リアルタイムの帰納的推論](machine-learning-overview-evolving-data.md#inductive-vs-transductive-inference)クエリを作成するには、次のように `Neptune#ml.inductiveInference` 述語を含めます。

```
.with("Neptune#ml.inductiveInference")
```

グラフが動的な場合、多くの場合、機能的推論は最善の選択ですが、グラフが静的な場合、トランスダクティブ推論の方が速くて効率的です。

## `Neptune#ml.limit`
<a name="machine-learning-gremlin-inference-neptune-ml-limit-predicate"></a>

`Neptune#ml.limit` 述語は、必要に応じてエンティティごとに返される結果の数を制限します。

```
 .with( "Neptune#ml.limit", {{2}} )
```

デフォルトでは、上限は 1 であり、設定できる最大数は 100 です。

## `Neptune#ml.threshold`
<a name="machine-learning-gremlin-inference-neptune-ml-threshold-predicate"></a>

`Neptune#ml.threshold` 述語はオプションで、結果スコアの切り捨てしきい値を設定します。

```
 .with( "Neptune#ml.threshold", {{0.5D}} )
```

これにより、指定したしきい値を下回るスコアを持つすべての結果を破棄できます。

## `Neptune#ml.classification`
<a name="machine-learning-gremlin-inference-neptune-ml-classification-predicate"></a>

`Neptune#ml.classification` 述語は、ノード分類モデルの SageMaker AI エンドポイントから取得する必要があるプロパティを確立するために `properties()` ステップに追加されています。

```
 .properties( "{{property key of the node classification model}}" ).with( "Neptune#ml.classification" )
```

## `Neptune#ml.regression`
<a name="machine-learning-gremlin-inference-neptune-ml-regression-predicate"></a>

`Neptune#ml.regression` 述語は、ノードリグレッションモデルの AI SageMaker エンドポイントから取得する必要があるプロパティを確立するために `properties()` ステップに添付されています。

```
 .properties( "{{property key of the node regression model}}" ).with( "Neptune#ml.regression" )
```

## `Neptune#ml.prediction`
<a name="machine-learning-gremlin-inference-neptune-ml-prediction-predicate"></a>

`Neptune#ml.prediction` 述語は、これがリンク予測クエリであることを確立するために `in()` および `out()` ステップに添付されています。

```
 .in("{{edge label of the link prediction model}}").with("Neptune#ml.prediction").hasLabel("{{target node label}}")
```

## `Neptune#ml.score`
<a name="machine-learning-gremlin-inference-neptune-ml-score-predicate"></a>

`Neptune#ml.score` 述語は Gremlin ノードまたはエッジ分類クエリで、機械学習の信頼スコアを取得するために使用されます。`Neptune#ml.score` 述語は、ノードまたはエッジ分類クエリの ML 信頼度スコアを取得するために、`properties()` ステップでクエリ述語とともに渡されます。

ノード分類の例については、[その他のノード分類の例](machine-learning-gremlin-vertex-classification-queries.md#machine-learning-gremlin-node-class-other-queries)で、また、[エッジ分類セクション](machine-learning-gremlin-edge-classification-queries.md)のエッジ分類の例でご確認いただけます。