本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
超级参数和 HPO
您可以在训练之前指定超参数,以便针对您的特定使用案例优化经过训练的模型。这与模型参数相反,后者的值在训练过程中确定。
超参数是使用 algorithmHyperParameters
键指定的,该键是传递到 CreateSolution 操作的 SolutionConfig 对象的一部分。
CreateSolution
请求的精简版本如下。该示例包括 solutionConfig
对象。您使用 solutionConfig
来覆盖配方的默认参数。
{ "name": "string", "recipeArn": "string", "eventType": "string", "solutionConfig": { "optimizationObjective": { "itemAttribute": "string", "objectiveSensitivity": "string" }, "eventValueThreshold": "string", "featureTransformationParameters": { "string" : "string" }, "algorithmHyperParameters": { "string" : "string" }, "hpoConfig": { "algorithmHyperParameterRanges": { ... }, "hpoResourceConfig": { "maxNumberOfTrainingJobs": "string", "maxParallelTrainingJobs": "string" } }, }, }
使用不同超级参数的不同配方。有关可用的超级参数,请参阅选择配方中的各个配方。
启用超参数优化
超参数优化 (HPO) 或调整是针对特定学习目标选择最佳超参数的任务。最佳超级参数是通过运行使用来自指定可能性范围的不同值的很多训练任务确定的。默认情况下,Amazon Personalize 不执行 HPO。要使用 HPO,请将 performHPO
设置为 true
,并包含 hpoConfig
对象。
超参数可以是分类值、连续值或整数值。hpoConfig
对象具有与所有这些类型对应的键,您可以在其中指定超级参数及其范围。您必须在请求中提供每种类型,但是如果配方没有某个类型的参数,则您可以将其留空。例如,User-Personalization 没有连续类型的可调整超参数。因此,对于 continousHyperParameterRange
,您可以传递一个空数组。
以下代码显示了如何使用 SDK for Python (Boto3) 创建启用了 HPO 的解决方案。本示例中的解决方案使用 User-Personalization 食谱配方,并将 HPO 设置为 true
。代码为 hidden_dimension
、categoricalHyperParameterRanges
和 integerHyperParameterRanges
提供值。continousHyperParameterRange
为空,hpoResourceConfig
设置为 maxNumberOfTrainingJobs
和 maxParallelTrainingJobs
。
create_solution_response = personalize.create_solution( name = solutionName, datasetGroupArn = 'arn:aws:personalize:region:accountId:dataset-group/datasetGroupName', recipeArn = 'arn:aws:personalize:::recipe/aws-user-personalization', performHPO = True, solutionConfig = { "algorithmHyperParameters": { "hidden_dimension": "55" }, "hpoConfig": { "algorithmHyperParameterRanges": { "categoricalHyperParameterRanges": [ { "name": "recency_mask", "values": [ "true", "false"] } ], "integerHyperParameterRanges": [ { "name": "bptt", "minValue": 2, "maxValue": 22 } ], "continuousHyperParameterRanges": [ ] }, "hpoResourceConfig": { "maxNumberOfTrainingJobs": "4", "maxParallelTrainingJobs": "2" } } } )
有关 HPO 的更多信息,请参阅自动模型优化。
查看超参数
您可以通过调用 DescribeSolution 操作来查看解决方案的超参数。下面的示例显示了 DescribeSolution
输出。创建解决方案版本(训练模型)后,您还可以通过 DescribeSolutionVersion 操作查看超参数。
{ "solution": { "name": "hpo_coonfig_solution", "solutionArn": "arn:aws:personalize:region:accountId:solution/solutionName", "performHPO": true, "performAutoML": false, "recipeArn": "arn:aws:personalize:::recipe/aws-user-personalization", "datasetGroupArn": "arn:aws:personalize:region:accountId:dataset-group/datasetGroupName", "eventType": "click", "solutionConfig": { "hpoConfig": { "hpoResourceConfig": { "maxNumberOfTrainingJobs": "4", "maxParallelTrainingJobs": "2" }, "algorithmHyperParameterRanges": { "integerHyperParameterRanges": [ { "name": "training.bptt", "minValue": 2, "maxValue": 22 } ], "continuousHyperParameterRanges": [], "categoricalHyperParameterRanges": [ { "name": "data.recency_mask", "values": [ "true", "false" ] } ] } }, "algorithmHyperParameters": { "hidden_dimension": "55" } }, "status": "ACTIVE", "creationDateTime": "2022-07-08T12:12:48.565000-07:00", "lastUpdatedDateTime": "2022-07-08T12:12:48.565000-07:00" } }