要使Amazon SageMaker Ground Truth中的主动学习起作用,您可以使用以下方法。
首先,确保您的数据集满足以下要求:
接下来,您可以按照以下步骤配置主动学习:
import boto3
sagemaker_client = boto3.client('sagemaker')
response = sagemaker_client.create_labeling_job(
LabelingJobName='my-labeling-job',
LabelAttributeName='label',
InputConfig={
'DataSource': {
'S3DataSource': {
'ManifestS3Uri': 's3://my-bucket/my-manifest.manifest'
}
},
'DataAttributes': {
'ContentClassifiers': ['FreeOfPersonallyIdentifiableInformation', 'FreeOfAdultContent']
}
},
OutputConfig={
'S3OutputPath': 's3://my-bucket/output/'
},
RoleArn='arn:aws:iam::123456789012:role/service-role/AmazonSageMaker-ExecutionRole-20201231T123456',
LabelingJobAlgorithmsConfig={
'LabelingJobAlgorithmSpecificationArn': 'arn:aws:sagemaker:us-west-2:027400017018:labeling-job-algorithm-specification/active-learning',
'InitialActiveLearningModelArn': 'arn:aws:sagemaker:us-west-2:027400017018:active-learning-model/initial-active-learning-model',
'LabelingJobResourceConfig': {
'VolumeKmsKeyId': 'arn:aws:kms:us-west-2:027400017018:key/abcd1234-a123-456b-789c-0123456789ab',
'InstanceCount': 1,
'InstanceType': 'ml.m5.large',
'VolumeSizeInGB': 100
}
}
)
print(response)
response = sagemaker_client.create_active_learning_model(
ActiveLearningModelName='initial-active-learning-model',
ModelArn='arn:aws:sagemaker:us-west-2:027400017018:model/my-model',
TrainingDataSource={
'S3DataSource': {
'ManifestS3Uri': 's3://my-bucket/initial-manifest.manifest'
}
},
RoleArn='arn:aws:iam::123456789012:role/service-role/AmazonSageMaker-ExecutionRole-20201231T123456'
)
print(response)
response = sagemaker_client.describe_labeling_job(LabelingJobName='my-labeling-job')
print(response)
response = sagemaker_client.update_active_learning_model(
ActiveLearningModelName='initial-active-learning-model',
ModelArn='arn:aws:sagemaker:us-west-2:027400017018:model/my-model',
TrainingDataSource={
'S3DataSource': {
'ManifestS3Uri': 's3://my-bucket/new-manifest.manifest'
}
}
)
print(response)
请注意,上述示例中的ARN(Amazon 资源名称)和参数值应根据您的实际情况进行替换。
希望这可以帮助您解决问题!