

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

# Kueri inferensi SPARQL di Neptunus ML
<a name="machine-learning-sparql-inference-queries"></a>

Neptunus ML memetakan grafik RDF ke dalam grafik properti untuk memodelkan Tugas ML. Saat ini, ia mendukung kasus penggunaan berikut:
+ **Klasifikasi objek** — Memprediksi fitur kategoris suatu objek.
+ **Regresi objek** — Memprediksi properti numerik dari suatu objek.
+ **Prediksi objek** — Memprediksi objek yang diberikan subjek dan hubungan.
+ **Prediksi subjek** — Memprediksi subjek yang diberi objek dan hubungan.

**catatan**  
Neptunus ML tidak mendukung klasifikasi subjek dan kasus penggunaan regresi dengan SPARQL.

# Predikat Neptunus Neptunus yang digunakan dalam kueri inferensi SPARQL
<a name="machine-learning-sparql-inference-query-predicates"></a>

Predikat berikut digunakan dengan inferensi SPARQL:

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

Menentukan batas waktu untuk koneksi dengan server jarak jauh. Jangan bingung dengan batas waktu permintaan kueri, yang merupakan jumlah waktu maksimum yang dapat diambil server untuk memenuhi permintaan.

Perhatikan bahwa jika batas waktu kueri terjadi sebelum batas waktu layanan yang ditentukan oleh `neptune-ml:timeout` predikat terjadi, sambungan layanan juga dibatalkan.

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

`neptune-ml:outputClass`Predikat hanya digunakan untuk menentukan kelas objek yang diprediksi untuk prediksi objek atau subjek yang diprediksi untuk prediksi subect.

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

`neptune-ml:outputScore`Predikat adalah angka positif yang mewakili kemungkinan bahwa output dari model pembelajaran mesin benar.

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

`neptune-ml:modelType`Predikat menentukan jenis model pembelajaran mesin yang dilatih:
+ `OBJECT_CLASSIFICATION`
+ `OBJECT_REGRESSION`
+ `OBJECT_PREDICTION`
+ `SUBJECT_PREDICTION`

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

`neptune-ml:input`Predikat mengacu pada daftar yang URIs digunakan sebagai input untuk Neptunus ML.

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

`neptune-ml:output`Predikat mengacu pada daftar set pengikatan di mana Neptunus ML mengembalikan hasil.

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

`neptune-ml:predicate`Predikat digunakan secara berbeda tergantung pada tugas yang dilakukan:
+ Untuk **prediksi objek atau subjek**: mendefinisikan jenis predikat (tipe tepi atau hubungan).
+ Untuk **klasifikasi dan regresi objek**: mendefinisikan literal (properti) yang ingin kita prediksi.

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

`neptune-ml:batchSize`Menentukan ukuran input untuk panggilan layanan jarak jauh.

# Contoh klasifikasi objek SPARQL
<a name="machine-learning-sparql-inference-object-classification"></a>

Untuk klasifikasi objek SPARQL di Neptunus ML, model dilatih pada salah satu nilai predikat. Ini berguna di mana predikat itu belum ada dengan subjek tertentu.

Hanya nilai predikat kategoris yang dapat disimpulkan menggunakan model klasifikasi objek.

Kueri berikut berusaha untuk < http://www.example.org/team > memprediksi nilai predikat untuk semua input tipe: `foaf:Person`

```
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 .
  }
}
```

Kueri ini dapat disesuaikan sebagai berikut:

```
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 .
  }
}
```

# Contoh regresi objek SPARQL
<a name="machine-learning-sparql-inference-object-regression"></a>

Regresi objek mirip dengan klasifikasi objek, kecuali bahwa nilai predikat numerik disimpulkan dari model regresi untuk setiap node. Anda dapat menggunakan kueri SPARQL yang sama untuk regresi objek seperti untuk klasifikasi objek dengan pengecualian bahwa `the Neptune#ml.limit` dan predikat `Neptune#ml.threshold` tidak berlaku.

Kueri berikut berusaha untuk < http://www.example.org/accountbalance > memprediksi nilai predikat untuk semua input tipe: `foaf:Person`

```
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 .
  }
}
```

Kueri ini dapat disesuaikan sebagai berikut:

```
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 .
  }
}
```

# Contoh prediksi objek SPARQL
<a name="machine-learning-sparql-inference-object-prediction"></a>

*Prediksi objek* memprediksi nilai objek untuk subjek dan predikat tertentu.

Kueri prediksi objek berikut berupaya memprediksi film apa yang diinginkan oleh masukan tipe`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> .
  }
}
```

Kueri itu sendiri dapat disesuaikan sebagai berikut:

```
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> .
  }
}
```

# Contoh prediksi subjek SPARQL
<a name="machine-learning-sparql-inference-subject-prediction"></a>

*Prediksi subjek* memprediksi subjek yang diberi predikat dan objek.

Misalnya, kueri berikut memprediksi siapa (tipe`foaf:User`) yang akan menonton film tertentu:

```
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> ;        }
}
```

# Daftar pengecualian untuk kueri inferensi Neptunus ML SPARQL
<a name="machine-learning-sparql-exceptions"></a>

****
+ **`BadRequestException`**— *Pesan*: `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`**— *Pesan*: `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`**— *Pesan*: `Invalid predicate (predicate name) provided for external service http://aws.amazon.com/neptune/vocab/v01/services/ml#inference query.`
+ **`BadRequestException`**— *Pesan*:`The SERVICE http://aws.amazon.com/neptune/vocab/v01/services/ml#inference expects the predicate (predicate name) to be defined`.
+ **`BadRequestException`**— *Pesan*: `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`**— *Pesan*:`The SERVICE http://aws.amazon.com/neptune/vocab/v01/services/ml#inference expects the input (parameter name) to be a constant, found: (type)`.
+ **`BadRequestException`**— *Pesan*:`The SERVICE http://aws.amazon.com/neptune/vocab/v01/services/ml#inference is expected to return only 1 value`.
+ **`BadRequestException`**— *Pesan*:`"The SERVICE http://aws.amazon.com/neptune/vocab/v01/services/ml#inference only allows StatementPatternNodes`.
+ **`BadRequestException`**— *Pesan*:`The SERVICE http://aws.amazon.com/neptune/vocab/v01/services/ml#inference does not allow the predicate (predicate name)`.
+ **`BadRequestException`**— *Pesan*:`The SERVICE http://aws.amazon.com/neptune/vocab/v01/services/ml#inference predicates cannot be variables, found: (type)`.
+ **`BadRequestException`**— *Pesan*:`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)`.