

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 `dataprocessing` 命令進行資料處理
<a name="machine-learning-api-dataprocessing"></a>

您可以使用 Neptune ML `dataprocessing` 命令來建立資料處理工作、檢查其狀態、停止該工作，或列出所有作用中的資料處理工作。

## 使用 Neptune ML `dataprocessing` 命令建立資料處理工作
<a name="machine-learning-api-dataprocessing-create-job"></a>

用於建立新工作的典型 Neptune ML `dataprocessing` 命令如下所示：

------
#### [ AWS CLI ]

```
aws neptunedata start-ml-data-processing-job \
  --endpoint-url https://your-neptune-endpoint:port \
  --input-data-s3-location "s3://(S3 bucket name)/(path to your input folder)" \
  --id "(a job ID for the new job)" \
  --processed-data-s3-location "s3://(S3 bucket name)/(path to your output folder)"
```

如需詳細資訊，請參閱《 AWS CLI 命令參考》中的 [start-ml-data-processing-job](https://docs.aws.amazon.com/cli/latest/reference/neptunedata/start-ml-data-processing-job.html)。

------
#### [ SDK ]

```
import boto3
from botocore.config import Config

client = boto3.client(
    'neptunedata',
    endpoint_url='https://your-neptune-endpoint:port',
    config=Config(read_timeout=None, retries={'total_max_attempts': 1})
)

response = client.start_ml_data_processing_job(
    inputDataS3Location='s3://(S3 bucket name)/(path to your input folder)',
    id='(a job ID for the new job)',
    processedDataS3Location='s3://(S3 bucket name)/(path to your output folder)'
)

print(response)
```

------
#### [ awscurl ]

```
awscurl https://your-neptune-endpoint:port/ml/dataprocessing \
  --region us-east-1 \
  --service neptune-db \
  -X POST \
  -H 'Content-Type: application/json' \
  -d '{
        "inputDataS3Location" : "s3://(S3 bucket name)/(path to your input folder)",
        "id" : "(a job ID for the new job)",
        "processedDataS3Location" : "s3://(S3 bucket name)/(path to your output folder)"
      }'
```

**注意**  
此範例假設您的 AWS 登入資料已在您的環境中設定。將 *us-east-1* 取代為 Neptune 叢集的區域。

------
#### [ curl ]

```
curl \
  -X POST https://your-neptune-endpoint:port/ml/dataprocessing \
  -H 'Content-Type: application/json' \
  -d '{
        "inputDataS3Location" : "s3://(S3 bucket name)/(path to your input folder)",
        "id" : "(a job ID for the new job)",
        "processedDataS3Location" : "s3://(S3 bucket name)/(path to your output folder)"
      }'
```

------

要啟動增量重新處理的命令如下所示：

------
#### [ AWS CLI ]

```
aws neptunedata start-ml-data-processing-job \
  --endpoint-url https://your-neptune-endpoint:port \
  --input-data-s3-location "s3://(S3 bucket name)/(path to your input folder)" \
  --id "(a job ID for this job)" \
  --processed-data-s3-location "s3://(S3 bucket name)/(path to your output folder)" \
  --previous-data-processing-job-id "(the job ID of a previously completed job to update)"
```

如需詳細資訊，請參閱《 AWS CLI 命令參考》中的 [start-ml-data-processing-job](https://docs.aws.amazon.com/cli/latest/reference/neptunedata/start-ml-data-processing-job.html)。

------
#### [ SDK ]

```
import boto3
from botocore.config import Config

client = boto3.client(
    'neptunedata',
    endpoint_url='https://your-neptune-endpoint:port',
    config=Config(read_timeout=None, retries={'total_max_attempts': 1})
)

response = client.start_ml_data_processing_job(
    inputDataS3Location='s3://(S3 bucket name)/(path to your input folder)',
    id='(a job ID for this job)',
    processedDataS3Location='s3://(S3 bucket name)/(path to your output folder)',
    previousDataProcessingJobId='(the job ID of a previously completed job to update)'
)

print(response)
```

------
#### [ awscurl ]

```
awscurl https://your-neptune-endpoint:port/ml/dataprocessing \
  --region us-east-1 \
  --service neptune-db \
  -X POST \
  -H 'Content-Type: application/json' \
  -d '{
        "inputDataS3Location" : "s3://(S3 bucket name)/(path to your input folder)",
        "id" : "(a job ID for this job)",
        "processedDataS3Location" : "s3://(S3 bucket name)/(path to your output folder)",
        "previousDataProcessingJobId" : "(the job ID of a previously completed job to update)"
      }'
```

**注意**  
此範例假設您的 AWS 登入資料已在您的環境中設定。將 *us-east-1* 取代為 Neptune 叢集的區域。

------
#### [ curl ]

```
curl \
  -X POST https://your-neptune-endpoint:port/ml/dataprocessing \
  -H 'Content-Type: application/json' \
  -d '{
        "inputDataS3Location" : "s3://(S3 bucket name)/(path to your input folder)",
        "id" : "(a job ID for this job)",
        "processedDataS3Location" : "s3://(S3 bucket name)/(path to your output folder)",
        "previousDataProcessingJobId" : "(the job ID of a previously completed job to update)"
      }'
```

------

**用於建立 `dataprocessing` 工作的參數**
+ **`id`** – (*選用*) 新工作的唯一識別符。

  *類型*：字串 *預設值*：自動產生的 UUID。
+ **`previousDataProcessingJobId`** – (*選用*) 在舊版資料上執行且已完成之資料處理工作的工作 ID。

  *類型*：字串 *預設值*：*none*。

  *注意*：使用此項進行增量資料處理，以在圖形資料變更時更新模型 (但在資料已遭刪除時不適用)。
+ **`inputDataS3Location`**   – (*必要*) 您希望 SageMaker AI 下載執行資料處理任務所需資料之 Amazon S3 位置的 URI。

  *類型*：字串
+ **`processedDataS3Location`**   – (*必要*) 您希望 SageMaker AI 儲存資料處理任務結果的 Amazon S3 位置的 URI。

  *類型*：字串
+ **`sagemakerIamRoleArn`**   – (*選用*) SageMaker AI 執行的 IAM 角色 ARN。

  *類型*：字串 *注意*：這必須列示在您的資料庫叢集參數群組中，否則會發生錯誤。
+ **`neptuneIamRoleArn`**   – (*選用*) SageMaker AI 可擔任以代表您執行任務之 IAM 角色的 Amazon Resource Name (ARN)。

  *類型*：字串 *注意*：這必須列示在您的資料庫叢集參數群組中，否則會發生錯誤。
+ **`processingInstanceType`** – (*選用*) 資料處理期間所使用的 ML 執行個體類型。它的記憶體應該大到足以保留處理後的資料集。

  *類型*：字串 *預設值*：最小的 `ml.r5` 類型，其記憶體十倍於磁碟上所匯出圖形資料的大小。

  *注意*：Neptune ML 可以自動選取執行個體類型。請參閱 [選取執行個體進行資料處理](machine-learning-on-graphs-instance-selection.md#machine-learning-on-graphs-processing-instance-size)。
+ **`processingInstanceVolumeSizeInGB`** – (*選用*) 處理執行個體的磁碟區大小。輸入資料和處理後的資料都會儲存在磁碟上，因此磁碟區大小必須大到足以保留這兩個資料集。

  *類型*：整數。*預設*︰`0`。

  *注意*：如果未指定或指定 0，Neptune ML 會根據資料大小自動選擇磁碟區大小。
+ **`processingTimeOutInSeconds`** – (*選用*) 資料處理工作的逾時 (以秒為單位)。

  *類型*：整數。*預設值*：`86,400` (1 天)。
+ **`modelType`** – (*選用*) Neptune ML 目前支援的兩種模型類型之一：異質圖形模型 (`heterogeneous`) 和知識圖譜 (`kge`)。

  *類型*：字串 *預設值*：*none*。

  *注意*：如果未指定，Neptune ML 會根據資料自動選擇模型類型。
+ **`configFileName`** – (*選用*) 描述如何載入所匯出圖形資料進行訓練的資料規格檔案。Neptune 匯出工具組會自動產生此檔案。

  *類型*：字串 *預設*︰`training-data-configuration.json`。
+ **`subnets`** – (*選用*) Neptune VPC 中子網路的 ID。

  *類型*：字串清單。*預設值*：*none*。
+ **`securityGroupIds`** – (*選用*) VPC 安全群組 ID。

  *類型*：字串清單。*預設值*：*none*。
+ **`volumeEncryptionKMSKey`**   – (*選用*) SageMaker AI 用來加密連接至執行處理任務之 ML 運算執行個體之儲存磁碟區上的資料之 AWS Key Management Service (AWS KMS) 金鑰。

  *類型*：字串 *預設值*：*none*。
+ **`enableInterContainerTrafficEncryption`** – (*選用*) 在訓練或超參數調校工作中啟用或停用容器間流量加密。

  *類型*：布林值。*預設值*：*true*。
**注意**  
`enableInterContainerTrafficEncryption` 參數僅適用於[引擎版本 1.2.0.2.R3](engine-releases-1.2.0.2.R3.md)。
+ **`s3OutputEncryptionKMSKey`**   – (*選用*) SageMaker AI 用來加密訓練任務輸出的 AWS Key Management Service (AWS KMS) 金鑰。

  *類型*：字串 *預設值*：*none*。

## 使用 Neptune ML `dataprocessing` 命令取得資料處理工作的狀態
<a name="machine-learning-api-dataprocessing-get-job-status"></a>

工作狀態的範例 Neptune ML `dataprocessing` 命令如下所示：

------
#### [ AWS CLI ]

```
aws neptunedata get-ml-data-processing-job \
  --endpoint-url https://your-neptune-endpoint:port \
  --id "(the job ID)"
```

如需詳細資訊，請參閱《 AWS CLI 命令參考》中的 [get-ml-data-processing-job](https://docs.aws.amazon.com/cli/latest/reference/neptunedata/get-ml-data-processing-job.html)。

------
#### [ SDK ]

```
import boto3
from botocore.config import Config

client = boto3.client(
    'neptunedata',
    endpoint_url='https://your-neptune-endpoint:port',
    config=Config(read_timeout=None, retries={'total_max_attempts': 1})
)

response = client.get_ml_data_processing_job(
    id='(the job ID)'
)

print(response)
```

------
#### [ awscurl ]

```
awscurl https://your-neptune-endpoint:port/ml/dataprocessing/(the job ID) \
  --region us-east-1 \
  --service neptune-db \
  -X GET
```

**注意**  
此範例假設您的 AWS 登入資料已在您的環境中設定。將 *us-east-1* 取代為 Neptune 叢集的區域。

------
#### [ curl ]

```
curl -s \
  "https://your-neptune-endpoint:port/ml/dataprocessing/(the job ID)" \
  | python -m json.tool
```

------

**`dataprocessing` 工作狀態的參數**
+ **`id`** – (*必要*) 資料處理工作的唯一識別符。

  *類型*：字串
+ **`neptuneIamRoleArn`**   – (*選用*) IAM 角色的 ARN，提供對 SageMaker AI 和 Amazon S3 資源的 Neptune 存取權。

  *類型*：字串 *注意*：這必須列示在您的資料庫叢集參數群組中，否則會發生錯誤。

## 使用 Neptune ML `dataprocessing` 命令停止資料處理工作
<a name="machine-learning-api-dataprocessing-stop-job"></a>

用於停止工作的範例 Neptune ML `dataprocessing` 命令如下所示：

------
#### [ AWS CLI ]

```
aws neptunedata cancel-ml-data-processing-job \
  --endpoint-url https://your-neptune-endpoint:port \
  --id "(the job ID)"
```

若要同時清除 Amazon S3 成品：

```
aws neptunedata cancel-ml-data-processing-job \
  --endpoint-url https://your-neptune-endpoint:port \
  --id "(the job ID)" \
  --clean
```

如需詳細資訊，請參閱《 AWS CLI 命令參考》中的 [cancel-ml-data-processing-job](https://docs.aws.amazon.com/cli/latest/reference/neptunedata/cancel-ml-data-processing-job.html)。

------
#### [ SDK ]

```
import boto3
from botocore.config import Config

client = boto3.client(
    'neptunedata',
    endpoint_url='https://your-neptune-endpoint:port',
    config=Config(read_timeout=None, retries={'total_max_attempts': 1})
)

response = client.cancel_ml_data_processing_job(
    id='(the job ID)',
    clean=True
)

print(response)
```

------
#### [ awscurl ]

```
awscurl https://your-neptune-endpoint:port/ml/dataprocessing/(the job ID) \
  --region us-east-1 \
  --service neptune-db \
  -X DELETE
```

若要同時清除 Amazon S3 成品：

```
awscurl "https://your-neptune-endpoint:port/ml/dataprocessing/(the job ID)?clean=true" \
  --region us-east-1 \
  --service neptune-db \
  -X DELETE
```

**注意**  
此範例假設您的 AWS 登入資料已在您的環境中設定。將 *us-east-1* 取代為 Neptune 叢集的區域。

------
#### [ curl ]

```
curl -s \
  -X DELETE "https://your-neptune-endpoint:port/ml/dataprocessing/(the job ID)"
```

或如下所示：

```
curl -s \
  -X DELETE "https://your-neptune-endpoint:port/ml/dataprocessing/(the job ID)?clean=true"
```

------

**`dataprocessing` 停止工作的參數**
+ **`id`** – (*必要*) 資料處理工作的唯一識別符。

  *類型*：字串
+ **`neptuneIamRoleArn`**   – (*選用*) IAM 角色的 ARN，提供對 SageMaker AI 和 Amazon S3 資源的 Neptune 存取權。

  *類型*：字串 *注意*：這必須列示在您的資料庫叢集參數群組中，否則會發生錯誤。
+ **`clean`** – (*選用*) 此旗標指定在工作停止時應刪除所有 Amazon S3 成品。

  *類型*：布林值。*預設*︰`FALSE`。

## 使用 Neptune ML `dataprocessing` 命令列出作用中的資料處理工作
<a name="machine-learning-api-dataprocessing-list-jobs"></a>

用於列出作用中工作的範例 Neptune ML `dataprocessing` 命令如下所示：

------
#### [ AWS CLI ]

```
aws neptunedata list-ml-data-processing-jobs \
  --endpoint-url https://your-neptune-endpoint:port
```

若要限制結果數量：

```
aws neptunedata list-ml-data-processing-jobs \
  --endpoint-url https://your-neptune-endpoint:port \
  --max-items 3
```

如需詳細資訊，請參閱《 AWS CLI 命令參考》中的 [list-ml-data-processing-jobs](https://docs.aws.amazon.com/cli/latest/reference/neptunedata/list-ml-data-processing-jobs.html)。

------
#### [ SDK ]

```
import boto3
from botocore.config import Config

client = boto3.client(
    'neptunedata',
    endpoint_url='https://your-neptune-endpoint:port',
    config=Config(read_timeout=None, retries={'total_max_attempts': 1})
)

response = client.list_ml_data_processing_jobs(
    maxItems=3
)

print(response)
```

------
#### [ awscurl ]

```
awscurl https://your-neptune-endpoint:port/ml/dataprocessing \
  --region us-east-1 \
  --service neptune-db \
  -X GET
```

若要限制結果數量：

```
awscurl "https://your-neptune-endpoint:port/ml/dataprocessing?maxItems=3" \
  --region us-east-1 \
  --service neptune-db \
  -X GET
```

**注意**  
此範例假設您的 AWS 登入資料已在您的環境中設定。將 *us-east-1* 取代為 Neptune 叢集的區域。

------
#### [ curl ]

```
curl -s "https://your-neptune-endpoint:port/ml/dataprocessing"
```

或如下所示：

```
curl -s "https://your-neptune-endpoint:port/ml/dataprocessing?maxItems=3"
```

------

**`dataprocessing` 列出工作的參數**
+ **`maxItems`** – (*選用*) 要傳回的項目數上限。

  *類型*：整數。*預設*︰`10`。*允許的最大值*：`1024`。
+ **`neptuneIamRoleArn`**   – (*選用*) IAM 角色的 ARN，提供對 SageMaker AI 和 Amazon S3 資源的 Neptune 存取權。

  *類型*：字串 *注意*：這必須列示在您的資料庫叢集參數群組中，否則會發生錯誤。