

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 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 객체 분류의 경우 모델은 조건자 값 중 하나를 기반으로 훈련됩니다. 이는 주어진 주제에 해당 조건자가 아직 없을 때 유용합니다.

객체 분류 모델을 사용하여 범주형 조건자 값만 유추할 수 있습니다.

다음 쿼리는 모든 `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>

객체 회귀는 각 노드의 회귀 모델에서 유추된 수치 예측 값을 제외하면 객체 분류와 유사합니다. `the Neptune#ml.limit` 및 `Neptune#ml.threshold` 조건자를 적용할 수 없다는 점을 제외하면 객체 분류의 경우와 동일한 SPARQL 쿼리를 객체 회귀에 사용할 수 있습니다.

다음 쿼리는 모든 `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)`.