

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

# Neptune ML での SPARQL 推論クエリ
<a name="machine-learning-sparql-inference-queries"></a>

Neptune ML は、RDF グラフをプロパティグラフにマッピングし、ML タスクをモデル化します。現在、次のユースケースをサポートしています。
+ **オブジェクト分類** — オブジェクトのカテゴリ別特徴を予測します。
+ **オブジェクト回帰** — オブジェクトの数値プロパティを予測します。
+ **オブジェクト予測**— 対象と関係が与えられたオブジェクトを予測します。
+ **件名の予測** — オブジェクトと関係が与えられた対象を予測します。

**注記**  
Neptune ML は SPARQL での主題分類と回帰のユースケースをサポートしていません。

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

SPARQL 推論では、次の述語が使用されます。

## `neptune-ml:timeout` 述語
<a name="machine-learning-sparql-inference-predicates-timeout"></a>

リモートサーバーとの接続のタイムアウトを指定します。サーバーが要求を満たすのにかかる最大時間であるクエリ要求のタイムアウトと混同しないでください。

クエリタイムアウトが、`neptune-ml:timeout` 述語発生で指定されたサービスタイムアウトの前に発生した場合は、サービス接続もキャンセルされます。

## `neptune-ml:outputClass` 述語
<a name="machine-learning-sparql-inference-predicates-outputClass"></a>

`neptune-ml:outputClass` 述語は、オブジェクト予測の予測オブジェクトのクラスまたはサブジェクト予測の予測対象を定義するためにのみ使用されます。

## `neptune-ml:outputScore` 述語
<a name="machine-learning-sparql-inference-predicates-outputScore"></a>

`neptune-ml:outputScore` 述語は、機械学習モデルの出力が正しい可能性を表す正の数です。

## `neptune-ml:modelType` 述語
<a name="machine-learning-sparql-inference-predicates-modelType"></a>

`neptune-ml:modelType` 述語は、学習する機械学習モデルのタイプを指定します。
+ `OBJECT_CLASSIFICATION`
+ `OBJECT_REGRESSION`
+ `OBJECT_PREDICTION`
+ `SUBJECT_PREDICTION`

## `neptune-ml:input` 述語
<a name="machine-learning-sparql-inference-predicates-input"></a>

`neptune-ml:input` 述語は、Neptune ML の入力として使用される URI のリストを指します。

## `neptune-ml:output` 述語
<a name="machine-learning-sparql-inference-predicates-output"></a>

`neptune-ml:output` 述語は、Neptune ML が結果を返す結合集合のリストを指します。

## `neptune-ml:predicate` 述語
<a name="machine-learning-sparql-inference-predicates-predicate"></a>

`neptune-ml:predicate` 述語は、実行されるタスクに応じて異なる方法で使用されます。
+ **オブジェクトまたはサブジェクト予測**の場合: 述語のタイプ (エッジまたはリレーションシップタイプ) を定義します。
+ **オブジェクトの分類と回帰**の場合: 予測するリテラル (プロパティ) を定義します。

## `neptune-ml:batchSize` 述語
<a name="machine-learning-sparql-inference-predicates-batchSize"></a>

`neptune-ml:batchSize` はリモートサービスコールの入力サイズを指定します。

# SPARQL オブジェクト分類の例
<a name="machine-learning-sparql-inference-object-classification"></a>

Neptune ML での SPARQL オブジェクト分類では、モデルは述語値の 1 つに基づいてトレーニングされます。これは、その述語が特定の主語にまだ存在していない場合に便利です。

オブジェクト分類モデルを使用すると、カテゴリカル述語値のみを推論できます。

次のクエリは、`foaf:Person` タイプのすべての入力の <http://www.example.org/team> 述語値を予測しようとします。

```
SELECT * WHERE { ?input a foaf:Person .
  SERVICE neptune-ml:inference {
    neptune-ml:config neptune-ml:modelType 'OBJECT_CLASSIFICATION' ;
                      neptune-ml:input ?input ;
                      neptune-ml:predicate <http://www.example.org/team> ;
                      neptune-ml:output ?output .
  }
}
```

このクエリは、次のようにカスタマイズできます。

```
SELECT * WHERE { ?input a foaf:Person .
  SERVICE neptune-ml:inference {
    neptune-ml:config neptune-ml:endpoint 'node-prediction-account-balance-endpoint' ;
                      neptune-ml:iamRoleArn 'arn:aws:iam::0123456789:role/sagemaker-role' ;

                      neptune-ml:batchSize "40"^^xsd:integer ;
                      neptune-ml:timeout "1000"^^xsd:integer ;

                      neptune-ml:modelType 'OBJECT_CLASSIFICATION' ;
                      neptune-ml:input ?input ;
                      neptune-ml:predicate <http://www.example.org/team> ;
                      neptune-ml:output ?output .
  }
}
```

# SPARQL オブジェクト回帰の例
<a name="machine-learning-sparql-inference-object-regression"></a>

オブジェクト回帰は、各ノードの回帰モデルから推定される数値の述語値を除いて、オブジェクト分類に似ています。オブジェクト回帰には、オブジェクト分類の場合と同じ SPARQL クエリを使用できます。ただし、`the Neptune#ml.limit` および `Neptune#ml.threshold` 述語は適用されません。

次のクエリは、`foaf:Person` タイプのすべての入力の <http://www.example.org/accountbalance> 述語値を予測しようとします。

```
SELECT * WHERE { ?input a foaf:Person .
  SERVICE neptune-ml:inference {
    neptune-ml:config neptune-ml:modelType 'OBJECT_REGRESSION' ;
                      neptune-ml:input ?input ;
                      neptune-ml:predicate <http://www.example.org/accountbalance> ;
                      neptune-ml:output ?output .
  }
}
```

このクエリは、次のようにカスタマイズできます。

```
SELECT * WHERE { ?input a foaf:Person .
  SERVICE neptune-ml:inference {
    neptune-ml:config neptune-ml:endpoint 'node-prediction-account-balance-endpoint' ;
                      neptune-ml:iamRoleArn 'arn:aws:iam::0123456789:role/sagemaker-role' ;

                      neptune-ml:batchSize "40"^^xsd:integer ;
                      neptune-ml:timeout "1000"^^xsd:integer ;

                      neptune-ml:modelType 'OBJECT_REGRESSION' ;
                      neptune-ml:input ?input ;
                      neptune-ml:predicate <http://www.example.org/accountbalance> ;
                      neptune-ml:output ?output .
  }
}
```

# SPARQL オブジェクト予測の例
<a name="machine-learning-sparql-inference-object-prediction"></a>

*オブジェクト予測*は、指定されたサブジェクトと述語のオブジェクト値を予測します。

次のオブジェクト予測クエリは、タイプ `foaf:Person` の入力がどの映画を好むのかを予測します。

```
?x a foaf:Person .
?x   <http://www.example.org/likes> ?m .
?m a <http://www.example.org/movie> .

## Query
SELECT * WHERE { ?input a foaf:Person .
  SERVICE neptune-ml:inference {
    neptune-ml:config neptune-ml:modelType 'OBJECT_PREDICTION' ;
                      neptune-ml:input ?input ;
                      neptune-ml:predicate <http://www.example.org/likes> ;
                      neptune-ml:output ?output ;
                      neptune-ml:outputClass <http://www.example.org/movie> .
  }
}
```

クエリ自体は、次のようにカスタマイズできます。

```
SELECT * WHERE { ?input a foaf:Person .
  SERVICE neptune-ml:inference {
    neptune-ml:config neptune-ml:endpoint 'node-prediction-user-movie-prediction-endpoint' ;
                      neptune-ml:iamRoleArn 'arn:aws:iam::0123456789:role/sagemaker-role' ;

                      neptune-ml:limit "5"^^xsd:integer ;
                      neptune-ml:batchSize "40"^^xsd:integer ;
                      neptune-ml:threshold "0.1"^^xsd:double ;
                      neptune-ml:timeout "1000"^^xsd:integer ;
                      neptune-ml:outputScore ?score ;

                      neptune-ml:modelType 'OBJECT_PREDICTION' ;
                      neptune-ml:input ?input ;
                      neptune-ml:predicate <http://www.example.org/likes> ;
                      neptune-ml:output ?output ;
                      neptune-ml:outputClass <http://www.example.org/movie> .
  }
}
```

# SPARQL サブジェクト予測の例
<a name="machine-learning-sparql-inference-subject-prediction"></a>

*件名の予測*は、述語とオブジェクトが与えられた主語を予測します。

たとえば、次のクエリは、特定の映画を視聴するのは誰か (タイプ `foaf:User`) を予測します。

```
SELECT * WHERE { ?input (a foaf:Movie) .
    SERVICE neptune-ml:inference {
        neptune-ml:config neptune-ml:modelType 'SUBJECT_PREDICTION' ;
                          neptune-ml:input ?input ;
                          neptune-ml:predicate <http://aws.amazon.com/neptune/csv2rdf/object_Property/rated> ;
                          neptune-ml:output ?output ;
                          neptune-ml:outputClass <http://aws.amazon.com/neptune/csv2rdf/class/User> ;        }
}
```

# Neptune ML SPARQL 推論クエリの例外のリスト
<a name="machine-learning-sparql-exceptions"></a>

****
+ ** `BadRequestException`** -*メッセージ*:`The SERVICE http://aws.amazon.com/neptune/vocab/v01/services/ml#inference expects at least 1 value for the parameter (parameter name), found zero.` 。
+ ** `BadRequestException`** -*メッセージ*:`The SERVICE http://aws.amazon.com/neptune/vocab/v01/services/ml#inference expects at most 1 value for the parameter (parameter name), found (a number) values.` 。
+ ** `BadRequestException`** -*メッセージ*:`Invalid predicate (predicate name) provided for external service http://aws.amazon.com/neptune/vocab/v01/services/ml#inference query.` 。
+ **`BadRequestException`** -*メッセージ*: `The SERVICE http://aws.amazon.com/neptune/vocab/v01/services/ml#inference expects the predicate (predicate name) to be defined`。
+ ** `BadRequestException`** -*メッセージ*:`The SERVICE http://aws.amazon.com/neptune/vocab/v01/services/ml#inference expects the value of (parameter) (parameter name) to be a variable, found: (type)"` 。
+ **`BadRequestException`** -*メッセージ*: `The SERVICE http://aws.amazon.com/neptune/vocab/v01/services/ml#inference expects the input (parameter name) to be a constant, found: (type)`。
+ **`BadRequestException`** -*メッセージ*: `The SERVICE http://aws.amazon.com/neptune/vocab/v01/services/ml#inference is expected to return only 1 value`。
+ **`BadRequestException`** -*メッセージ*: `"The SERVICE http://aws.amazon.com/neptune/vocab/v01/services/ml#inference only allows StatementPatternNodes`。
+ **`BadRequestException`** -*メッセージ*: `The SERVICE http://aws.amazon.com/neptune/vocab/v01/services/ml#inference does not allow the predicate (predicate name)`。
+ **`BadRequestException`** -*メッセージ*: `The SERVICE http://aws.amazon.com/neptune/vocab/v01/services/ml#inference predicates cannot be variables, found: (type)`。
+ **`BadRequestException`** -*メッセージ*: `The SERVICE http://aws.amazon.com/neptune/vocab/v01/services/ml#inference predicates are expected to be part of the namespace (namespace name), found: (namespace name)`。