

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

# データキャプチャ
<a name="model-monitor-data-capture"></a>

エンドポイントへの入力とデプロイされたモデルからの推論出力を Amazon S3 に記録するには、「データキャプチャ」と呼ばれる機能を有効にできます。**「データキャプチャ」は通常、トレーニング、デバッグ、モニタリングに使用できる情報を記録するために使用されます。**Amazon SageMaker Model Monitor は、このキャプチャされたデータを自動的に解析し、そのデータのメトリクスをモデル用に作成したベースラインと比較します。Model Monitor の詳細については、「[Amazon SageMaker Model Monitor を使用したデータとモデルの品質モニタリング](model-monitor.md)」を参照してください。

 AWS SDK for Python (Boto) または SageMaker Python SDK を使用して、リアルタイムモードとバッチモデルモニターモードの両方*のデータキャプチャ*を実装できます。リアルタイムエンドポイントの場合は、エンドポイントの作成時に「データキャプチャ」設定を指定します。**リアルタイムエンドポイントは永続的であるため、特定の時間にデータキャプチャをオンまたはオフにしたり、サンプリング頻度を変更したりするための追加オプションを設定できます。推論データを暗号化することもできます。

バッチ変換ジョブでは、予定どおりにモデルのモニタリングを実行したり、定期的に行われるバッチ変換ジョブのモデルのモニタリングを継続的に実行したりする場合、「データキャプチャ」を有効にできます。**「データキャプチャ」設定は、バッチ変換ジョブを作成するときに指定します。**この設定では、暗号化を有効にするか、出力で推論 ID を生成することができます。これにより、キャプチャしたデータを Ground Truth データと一致させることができます。

# リアルタイムエンドポイントからデータをキャプチャする
<a name="model-monitor-data-capture-endpoint"></a>

**注記**  
推論リクエストへの影響を防ぐため、ディスク使用率のレベルが高くなると、データキャプチャはリクエストのキャプチャを停止します。データキャプチャがリクエストのキャプチャを続行できるように、ディスク使用率を 75% 未満に抑えることをお勧めします。

リアルタイムエンドポイントのデータをキャプチャするには、SageMaker AI ホスティングサービスを使用してモデルをデプロイする必要があります。これには、SageMaker AI モデルを作成し、エンドポイント設定を定義して、HTTPS エンドポイントを作成する必要があります。

データキャプチャを有効にするために必要な手順は、 AWS SDK for Python (Boto) と SageMaker Python SDK のどちらを使用する場合でも同様です。 AWS SDK を使用する場合は、[CreateEndpointConfig](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateEndpointConfig.html) メソッド内で [DataCaptureConfig](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DataCaptureConfig.html) ディクショナリと必須フィールドを定義して、データキャプチャを有効にします。SageMaker Python SDK を使用する場合は、[DataCaptureConfig](https://sagemaker.readthedocs.io/en/stable/api/inference/model_monitor.html#sagemaker.model_monitor.data_capture_config.DataCaptureConfig) クラスをインポートし、このクラスからインスタンスを初期化します。次に、このオブジェクトを `sagemaker.model.Model.deploy()` メソッドの `DataCaptureConfig` パラメータに渡します。

上のコードスニペットを使用するには、コード例の*イタリック体のプレースホルダーテキスト*を独自の情報に置き換えます。

## データキャプチャを有効にする方法
<a name="model-monitor-data-capture-defing.title"></a>

データキャプチャ設定を指定します。この設定では、要求ペイロード、応答ペイロード、またはその両方をキャプチャできます。前述のコードスニペットは、 AWS SDK for Python (Boto) と SageMaker AI Python SDK を使用してデータキャプチャを有効にする方法を示しています。

**注記**  
Model Monitor を使用してリクエストまたはレスポンスペイロードをキャプチャする必要はありません。

------
#### [ AWS SDK for Python (Boto) ]

`CreateEndpointConfig` メソッドを使用してエンドポイントを作成するときに、[DataCaptureConfig](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DataCaptureConfig.html) ディクショナリでキャプチャするデータを設定します。`EnableCapture` をブール値 True に設定します。また、以下の必須パラメータを指定します。
+ `EndpointConfigName`: エンドポイント設定の名前。この名前は、`CreateEndpoint` リクエストを行うときに使用します。
+ `ProductionVariants`: このエンドポイントでホストするモデルのリスト。モデルごとにディクショナリデータ型を定義します。
+ `DataCaptureConfig`: サンプリングするデータの初期パーセンテージ (`InitialSamplingPercentage`) に対応する整数値、キャプチャしたデータを保存する Amazon S3 URI、キャプチャオプション (`CaptureOptions`) リストを指定するディクショナリデータ型。`CaptureOptions` リスト内の `CaptureMode` に `Input` または `Output` のいずれかを指定します。

key-value ペアの引数を `CaptureContentTypeHeader` ディクショナリに渡すことで、SageMaker AI がキャプチャしたデータをどのようにエンコードするかを任意で指定できます。

```
# Create an endpoint config name.
endpoint_config_name = '<endpoint-config-name>'

# The name of the production variant.
variant_name = '<name-of-production-variant>'                   
  
# The name of the model that you want to host. 
# This is the name that you specified when creating the model.
model_name = '<The_name_of_your_model>'

instance_type = '<instance-type>'
#instance_type='ml.m5.xlarge' # Example    

# Number of instances to launch initially.
initial_instance_count = <integer>

# Sampling percentage. Choose an integer value between 0 and 100
initial_sampling_percentage = <integer>                                                                                                                                                                                                                        

# The S3 URI containing the captured data
s3_capture_upload_path = 's3://<bucket-name>/<data_capture_s3_key>'

# Specify either Input, Output, or both
capture_modes = [ "Input",  "Output" ] 
#capture_mode = [ "Input"] # Example - If you want to capture input only
                            
endpoint_config_response = sagemaker_client.create_endpoint_config(
    EndpointConfigName=endpoint_config_name, 
    # List of ProductionVariant objects, one for each model that you want to host at this endpoint.
    ProductionVariants=[
        {
            "VariantName": variant_name, 
            "ModelName": model_name, 
            "InstanceType": instance_type, # Specify the compute instance type.
            "InitialInstanceCount": initial_instance_count # Number of instances to launch initially.
        }
    ],
    DataCaptureConfig= {
        'EnableCapture': True, # Whether data should be captured or not.
        'InitialSamplingPercentage' : initial_sampling_percentage,
        'DestinationS3Uri': s3_capture_upload_path,
        'CaptureOptions': [{"CaptureMode" : capture_mode} for capture_mode in capture_modes] # Example - Use list comprehension to capture both Input and Output
    }
)
```

その他のエンドポイント設定オプションの詳細については、「[Amazon SageMaker AI サービス API リファレンスガイド](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_Operations_Amazon_SageMaker_Service.html)」の「[CreateEndpointConfig](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateEndpointConfig.html)」API を参照してください。

------
#### [ SageMaker Python SDK ]

[sagemaker.model\$1monitor](https://sagemaker.readthedocs.io/en/stable/api/inference/model_monitor.html) モジュールから `DataCaptureConfig` クラスをインポートします。 `EnableCapture` ブール値 `True` に設定してデータキャプチャを有効にします。

オプションで、以下のパラメータに引数を指定します。
+ `SamplingPercentage`: サンプリングするデータのパーセンテージに対応する整数値。サンプリング率を指定しない場合、SageMaker AI はデフォルトで 20 (20%) のデータをサンプリングします。
+ `DestinationS3Uri`: SageMaker AI がキャプチャしたデータを保存するために使用する Amazon S3 URI。指定しない場合、SageMaker AI はキャプチャしたデータを `"s3://<default-session-bucket>/ model-monitor/data-capture"` に保存します。

```
from sagemaker.model_monitor import DataCaptureConfig

# Set to True to enable data capture
enable_capture = True

# Optional - Sampling percentage. Choose an integer value between 0 and 100
sampling_percentage = <int> 
# sampling_percentage = 30 # Example 30%

# Optional - The S3 URI of stored captured-data location
s3_capture_upload_path = 's3://<bucket-name>/<data_capture_s3_key>'

# Specify either Input, Output or both. 
capture_modes = ['REQUEST','RESPONSE'] # In this example, we specify both
# capture_mode = ['REQUEST'] # Example - If you want to only capture input.

# Configuration object passed in when deploying Models to SM endpoints
data_capture_config = DataCaptureConfig(
    enable_capture = enable_capture, 
    sampling_percentage = sampling_percentage, # Optional
    destination_s3_uri = s3_capture_upload_path, # Optional
    capture_options = ["REQUEST", "RESPONSE"],
)
```

------

## モデルをデプロイする
<a name="model-monitor-data-capture-deploy"></a>

モデルをデプロイし、`DataCapture` を有効にして HTTPS エンドポイントを作成します。

------
#### [ AWS SDK for Python (Boto3) ]

SageMaker AI にエンドポイント設定を提供します。このサービスは、ML コンピューティングインスタンスを起動し、設定で指定された 1 つ以上のモデルをデプロイします。

モデルとエンドポイントの設定が完了したら、[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateEndpoint.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateEndpoint.html) API を使用してエンドポイントを作成します。エンドポイント名は、 AWS アカウントの AWS リージョン内で一意である必要があります。

次が、リクエストで指定されたエンドポイント設定を使用してエンドポイントを作成します。Amazon SageMaker AI は、エンドポイントを使用してリソースをプロビジョンし、モデルをデプロイします。

```
# The name of the endpoint. The name must be unique within an AWS Region in your AWS account.
endpoint_name = '<endpoint-name>' 

# The name of the endpoint configuration associated with this endpoint.
endpoint_config_name='<endpoint-config-name>'

create_endpoint_response = sagemaker_client.create_endpoint(
                                            EndpointName=endpoint_name, 
                                            EndpointConfigName=endpoint_config_name)
```

詳細については、[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateEndpoint.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateEndpoint.html) API を参照してください。

------
#### [ SageMaker Python SDK ]

エンドポイントの名前を定義します。この手順は省略可能です。指定しない場合、SageMaker AI は一意の名前を作成します。

```
from datetime import datetime

endpoint_name = f"DEMO-{datetime.utcnow():%Y-%m-%d-%H%M}"
print("EndpointName =", endpoint_name)
```

Model オブジェクトに組み込まれている `deploy()` メソッドを使用して、モデルをリアルタイム HTTPS エンドポイントにデプロイします。このモデルをデプロイする Amazon EC2 インスタンスタイプの名前を `instance_type` フィールドに、エンドポイントを実行するインスタンスの初期数を `initial_instance_count` フィールドに指定します。

```
initial_instance_count=<integer>
# initial_instance_count=1 # Example

instance_type='<instance-type>'
# instance_type='ml.m4.xlarge' # Example

# Uncomment if you did not define this variable in the previous step
#data_capture_config = <name-of-data-capture-configuration>

model.deploy(
    initial_instance_count=initial_instance_count,
    instance_type=instance_type,
    endpoint_name=endpoint_name,
    data_capture_config=data_capture_config
)
```

------

## キャプチャしたデータを表示する
<a name="model-monitor-data-capture-view"></a>

SageMaker Python SDK の[予測子](https://sagemaker.readthedocs.io/en/stable/api/inference/predictors.html)クラスから予測子オブジェクトを作成します。`Predictor` クラスによって返されたオブジェクトを使用して、後のステップでエンドポイントを呼び出します。エンドポイントの名前 (以前に `endpoint_name` と定義) と、シリアライザのシリアライザオブジェクトとデシリアライザのデシリアライザオブジェクトを指定します。シリアライザタイプの詳細については、「[SageMaker Python SDK](https://sagemaker.readthedocs.io/en/stable/index.html)」の「[Serializers](https://sagemaker.readthedocs.io/en/stable/api/inference/serializers.html)」クラスを参照してください。

```
from sagemaker.predictor import Predictor
from sagemaker.serializers import <Serializer>
from sagemaker.deserializers import <Deserializers>

predictor = Predictor(endpoint_name=endpoint_name,
                      serializer = <Serializer_Class>,
                      deserializer = <Deserializer_Class>)

# Example
#from sagemaker.predictor import Predictor
#from sagemaker.serializers import CSVSerializer
#from sagemaker.deserializers import JSONDeserializer

#predictor = Predictor(endpoint_name=endpoint_name,
#                      serializer=CSVSerializer(),
#                      deserializer=JSONDeserializer())
```

このコード例のシナリオでは、`validation_with_predictions` という名前の CSV ファイルにローカルに保存したサンプル検証データを使用してエンドポイントを呼び出します。サンプル検証セットには、各入力のラベルが含まれています。

with ステートメントの最初の数行では、まず検証セットの CSV ファイルを開き、次にファイル内の各行をカンマ文字 `","` で分割し、返された 2 つのオブジェクトを label 変数と input\$1cols 変数に格納します。行ごとに、入力 (`input_cols`) が予測子変数の (`predictor`) オブジェクトの組み込みメソッド `Predictor.predict()` に渡されます。

モデルが確率を返すと仮定します。確率の範囲は 0 から 1.0 までの整数値です。モデルから返される確率が 80% (0.8) を超える場合は、予測に 1 の整数値ラベルを割り当てます。それ以外の場合は、予測に 0 の整数値ラベルを割り当てます。

```
from time import sleep

validate_dataset = "validation_with_predictions.csv"

# Cut off threshold of 80%
cutoff = 0.8

limit = 200  # Need at least 200 samples to compute standard deviations
i = 0
with open(f"test_data/{validate_dataset}", "w") as validation_file:
    validation_file.write("probability,prediction,label\n")  # CSV header
    with open("test_data/validation.csv", "r") as f:
        for row in f:
            (label, input_cols) = row.split(",", 1)
            probability = float(predictor.predict(input_cols))
            prediction = "1" if probability > cutoff else "0"
            baseline_file.write(f"{probability},{prediction},{label}\n")
            i += 1
            if i > limit:
                break
            print(".", end="", flush=True)
            sleep(0.5)
print()
print("Done!")
```

前のステップでデータキャプチャを有効にしたことにより、要求ペイロードと応答ペイロードは、追加のメタデータと共に、`DataCaptureConfig` で指定した Amazon S3 の場所に保存されます。キャプチャデータの Amazon S3 への配信には数分かかる場合があります。

Amazon S3 に保存されたデータキャプチャファイルを一覧表示して、キャプチャされたデータを表示します。Amazon S3 のパス形式は次のとおりです。`s3:///{endpoint-name}/{variant-name}/yyyy/mm/dd/hh/filename.jsonl`

呼び出しが発生した時間に基づいて編成された、異なる期間の異なるファイルが表示されます。以下を実行して 1 つのキャプチャファイルの内容を出力します。

```
print("\n".join(capture_file[-3:-1]))
```

これにより、SageMaker AI 固有の JSON 行形式のファイルが返されます。以下は、`csv/text` データを使用して呼び出したリアルタイムエンドポイントから取得した応答サンプルです。

```
{"captureData":{"endpointInput":{"observedContentType":"text/csv","mode":"INPUT",
"data":"69,0,153.7,109,194.0,105,256.1,114,14.1,6,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0\n",
"encoding":"CSV"},"endpointOutput":{"observedContentType":"text/csv; charset=utf-8","mode":"OUTPUT","data":"0.0254181120544672","encoding":"CSV"}},
"eventMetadata":{"eventId":"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee","inferenceTime":"2022-02-14T17:25:49Z"},"eventVersion":"0"}
{"captureData":{"endpointInput":{"observedContentType":"text/csv","mode":"INPUT",
"data":"94,23,197.1,125,214.5,136,282.2,103,9.5,5,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,1\n",
"encoding":"CSV"},"endpointOutput":{"observedContentType":"text/csv; charset=utf-8","mode":"OUTPUT","data":"0.07675473392009735","encoding":"CSV"}},
"eventMetadata":{"eventId":"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee","inferenceTime":"2022-02-14T17:25:49Z"},"eventVersion":"0"}
```

上の例では、`capture_file` オブジェクトはリストタイプです。リストの最初の要素にインデックスを付けると、1 つの推論リクエストが表示されます。

```
# The capture_file object is a list. Index the first element to view a single inference request  
print(json.dumps(json.loads(capture_file[0]), indent=2))
```

これにより次のような応答が返されます。返される値は、エンドポイント設定、SageMaker AI モデル、キャプチャされたデータによって異なります。

```
{
  "captureData": {
    "endpointInput": {
      "observedContentType": "text/csv", # data MIME type
      "mode": "INPUT",
      "data": "50,0,188.9,94,203.9,104,151.8,124,11.6,8,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,1,0,1,0\n",
      "encoding": "CSV"
    },
    "endpointOutput": {
      "observedContentType": "text/csv; charset=character-encoding",
      "mode": "OUTPUT",
      "data": "0.023190177977085114",
      "encoding": "CSV"
    }
  },
  "eventMetadata": {
    "eventId": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
    "inferenceTime": "2022-02-14T17:25:06Z"
  },
  "eventVersion": "0"
}
```

# バッチ変換ジョブからデータをキャプチャする
<a name="model-monitor-data-capture-batch"></a>

 バッチ変換ジョブのデータキャプチャを有効にするために必要な手順は、 AWS SDK for Python (Boto) と SageMaker Python SDK のどちらを使用する場合でも似ています。 AWS SDK を使用する場合は、[DataCaptureConfig](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DataCaptureConfig.html) ディクショナリと必須フィールドを `CreateTransformJob`メソッド内で定義して、データキャプチャを有効にします。SageMaker AI Python SDK を使用する場合は、`BatchDataCaptureConfig` クラスをインポートし、このクラスからインスタンスを初期化します。次に、このオブジェクトを変換ジョブインスタンスの `batch_data_capture_config` パラメータに渡します。

 次のコードスニペットを使用するには、コード例の*イタリック体のプレースホルダーテキスト*を独自の情報に置き換えます。

## データキャプチャを有効にする方法
<a name="data-capture-batch-enable"></a>

 変換ジョブを起動するときに、データキャプチャ設定を指定します。を使用するか SageMaker AWS SDK for Python (Boto3) Python SDK を使用するかにかかわらず、 `DestinationS3Uri`引数を指定する必要があります。これは、変換ジョブでキャプチャされたデータをログに記録するディレクトリです。オプションで次のパラメータを指定することもできます。
+  `KmsKeyId`: キャプチャされたデータの暗号化に使用される AWS KMS キー。
+  `GenerateInferenceId`: データをキャプチャするときに、変換ジョブで推論 ID と時間を出力に追加するかどうかを示すブール型フラグ。これは、Ground Truth データを取り込む必要があるモデル品質モニタリングに役立ちます。推論 ID と時間は、キャプチャしたデータを Ground Truth データと一致させるのに役立ちます。

------
#### [ AWS SDK for Python (Boto3) ]

 `CreateTransformJob` メソッドを使用して変換ジョブを作成するときに、[DataCaptureConfig](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DataCaptureConfig.html) ディクショナリでキャプチャするデータを設定します。

```
input_data_s3_uri = "s3://input_S3_uri"
output_data_s3_uri = "s3://output_S3_uri"
data_capture_destination = "s3://captured_data_S3_uri"

model_name = "model_name"

sm_client.create_transform_job(
    TransformJobName="transform_job_name",
    MaxConcurrentTransforms=2,
    ModelName=model_name,
    TransformInput={
        "DataSource": {
            "S3DataSource": {
                "S3DataType": "S3Prefix",
                "S3Uri": input_data_s3_uri,
            }
        },
        "ContentType": "text/csv",
        "CompressionType": "None",
        "SplitType": "Line",
    },
    TransformOutput={
        "S3OutputPath": output_data_s3_uri,
        "Accept": "text/csv",
        "AssembleWith": "Line",
    },
    TransformResources={
        "InstanceType": "ml.m4.xlarge",
        "InstanceCount": 1,
    },
    DataCaptureConfig={
       "DestinationS3Uri": data_capture_destination,
       "KmsKeyId": "kms_key",
       "GenerateInferenceId": True,
    }
    )
```

------
#### [ SageMaker Python SDK ]

 [sagemaker.model\$1monitor](https://sagemaker.readthedocs.io/en/stable/api/inference/model_monitor.html) モジュールから `BatchDataCaptureConfig` クラスをインポートします。

```
from sagemaker.transformer import Transformer
from sagemaker.inputs import BatchDataCaptureConfig

# Optional - The S3 URI of where to store captured data in S3
data_capture_destination = "s3://captured_data_S3_uri"

model_name = "model_name"

transformer = Transformer(model_name=model_name, ...)
transform_arg = transformer.transform(
    batch_data_capture_config=BatchDataCaptureConfig(
        destination_s3_uri=data_capture_destination,
        kms_key_id="kms_key",
        generate_inference_id=True,
    ),
    ...
)
```

------

## キャプチャされたデータを表示する方法
<a name="data-capture-batch-view"></a>

 変換ジョブが完了すると、キャプチャされたデータは、データ キャプチャ設定で指定した `DestinationS3Uri` の下に記録されます。`DestinationS3Uri` の下には `/input` と `/output` という 2 つのサブディレクトリがあります。`DestinationS3Uri` が `s3://my-data-capture` の場合、変換ジョブは次のディレクトリを作成します。
+  `s3://my-data-capture/input`: 変換ジョブのキャプチャされた入力データ。
+  `s3://my-data-capture/output`: 変換ジョブのキャプチャされた出力データ。

 データの重複を避けるため、前の 2 つのディレクトリにあるキャプチャされたデータはマニフェストです。各マニフェストは、ソースオブジェクトの Amazon S3 ロケーションを含む JSONL ファイルです。マニフェストファイルの例として、以下のようなものがあります。

```
# under "/input" directory
[
    {"prefix":"s3://input_S3_uri/"},
    "dummy_0.csv",
    "dummy_1.csv",
    "dummy_2.csv",
    ...
]

# under "/output" directory
[
    {"prefix":"s3://output_S3_uri/"},
    "dummy_0.csv.out",
    "dummy_1.csv.out",
    "dummy_2.csv.out",
    ...
]
```

 変換ジョブは、これらのマニフェストを整理し、キャプチャされた日時を示す *yyyy/mm/dd/hh* S3 プレフィックスを使ってラベル付けします。これにより、モデルモニターは分析するデータの適切な部分を判断しやすくなります。例えば、2022 年 8 月 26 日 13 時 (UTC) に変換ジョブを開始すると、キャプチャされたデータにはプレフィックス文字列 `2022/08/26/13/` のラベルが付けられます。

## 推論 ID の生成
<a name="data-capture-batch-inferenceid"></a>

 変換ジョブの `DataCaptureConfig` を設定するときに、ブール型フラグ `GenerateInferenceId` をオンにできます。これは、ユーザーが取り込んだ Ground Truth データが必要となる、モデル品質やモデルバイアスのモニタリングジョブを実行しなければならない場合に特に便利です。モデルモニターは、推論 ID を使用してキャプチャされたデータと Ground Truth データを照合します。Ground Truth 取り込みに関する詳細については、「[Ground Truth ラベルを取り込んで予測とマージする](model-monitor-model-quality-merge.md)」を参照してください。`GenerateInferenceId` をオンにすると、変換出力には、推論 ID (ランダムな UUID) と変換ジョブの開始時刻 (UTC) がレコードごとに追加されます。モデル品質とモデルバイアスのモニタリングを実行するには、これら 2 つの値が必要です。Ground Truth データを作成するときは、出力データと一致するように同じ推論 ID を指定する必要があります。現在、この機能は CSV、JSON、JSONL 形式の変換出力をサポートしています。

 変換出力が CSV 形式の場合、出力ファイルは次の例のようになります。

```
0, 1f1d57b1-2e6f-488c-8c30-db4e6d757861,2022-08-30T00:49:15Z
1, 22445434-0c67-45e9-bb4d-bd1bf26561e6,2022-08-30T00:49:15Z
...
```

 最後の 2 つの列は推論 ID と変換ジョブの開始時刻です。これらは変更しないでください。残りの列は変換ジョブの出力です。

 変換出力が JSON または JSONL 形式の場合、出力ファイルは次の例のようになります。

```
{"output": 0, "SageMakerInferenceId": "1f1d57b1-2e6f-488c-8c30-db4e6d757861", "SageMakerInferenceTime": "2022-08-30T00:49:15Z"}
{"output": 1, "SageMakerInferenceId": "22445434-0c67-45e9-bb4d-bd1bf26561e6", "SageMakerInferenceTime": "2022-08-30T00:49:15Z"}
...
```

 `SageMakerInferenceId` と `SageMakerInferenceTime` の 2 つのフィールドが追加されています。これらのフィールドは、マージジョブに必要であるため、モデル品質モニタリングやモデルバイアスモニタリングを実行する必要がある場合は変更しないでください。