일괄 추론 작업 (AWS SDK) 생성 - Personalize

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

일괄 추론 작업 (AWS SDK) 생성

배치 추천을 위한 입력 데이터 준비 작업을 완료했으면 CreateBatchInferenceJob 작업을 사용하여 배치 추론 작업을 생성할 준비가 된 것입니다.

배치 추론 작업 생성

다음 코드를 사용하여 배치 추론 작업을 생성할 수 있습니다. 작업 이름, 솔루션 버전의 Amazon 리소스 이름(ARN) 설정 중에 Amazon Personalize용으로 생성한 IAM 서비스 역할의 ARN을 지정합니다. 이 역할에는 입력 및 출력 Amazon S3 버킷에 대한 읽기 및 쓰기 액세스 권한이 있어야 합니다.

출력 데이터에 대한 다른 위치(폴더 또는 다른 Amazon S3 버킷)를 사용하는 것이 좋습니다. 입력 및 출력 위치에는 구문: s3://<name of your S3 bucket>/<folder name>/<input JSON file name>.jsons3://<name of your S3 bucket>/<output folder name>/을 사용합니다.

numResults의 경우, Amazon Personalize가 각 입력 데이터 라인에 대해 예측하기를 원하는 품목의 수를 지정합니다. 원하는 대로 필터 ARN을 제공하여 권장 사항을 필터링합니다. 필터가 자리표시자 파라미터를 사용하는 경우, 파라미터 값이 입력 JSON에 포함되어 있는지 확인하세요. 자세한 내용은 배치 추천 및 사용자 세그먼트(사용자 지정 리소스) 필터링 섹션을 참조하세요.

SDK for Python (Boto3)

이 예제에는 선택 가능한 사용자-개인화 레시피별 itemExplorationConfig 하이퍼파라미터: explorationWeightexplorationItemAgeCutOff 가 포함되어 있습니다. 원하는 대로 explorationWeightexplorationItemAgeCutOff 값을 포함하여 탐색을 구성합니다. 자세한 설명은 사용자-개인 맞춤 레시피 섹션을 참조하세요.

import boto3 personalize_rec = boto3.client(service_name='personalize') personalize_rec.create_batch_inference_job ( solutionVersionArn = "Solution version ARN", jobName = "Batch job name", roleArn = "IAM service role ARN", filterArn = "Filter ARN", batchInferenceJobConfig = { # optional USER_PERSONALIZATION recipe hyperparameters "itemExplorationConfig": { "explorationWeight": "0.3", "explorationItemAgeCutOff": "30" } }, jobInput = {"s3DataSource": {"path": "s3://<name of your S3 bucket>/<folder name>/<input JSON file name>.json"}}, jobOutput = {"s3DataDestination": {"path": "s3://<name of your S3 bucket>/<output folder name>/"}} )
SDK for Java 2.x

이 예제에는 선택적 사용자-개인화 레시피별 itemExplorationConfig 필드: explorationWeightexplorationItemAgeCutOff이(가) 포함되어 있습니다. 원하는 대로 explorationWeightexplorationItemAgeCutOff 값을 포함하여 탐색을 구성합니다. 자세한 설명은 사용자-개인 맞춤 레시피 섹션을 참조하세요.

public static String createPersonalizeBatchInferenceJob(PersonalizeClient personalizeClient, String solutionVersionArn, String jobName, String filterArn, String s3InputDataSourcePath, String s3DataDestinationPath, String roleArn, String explorationWeight, String explorationItemAgeCutOff) { long waitInMilliseconds = 60 * 1000; String status; String batchInferenceJobArn; try { // Set up data input and output parameters. S3DataConfig inputSource = S3DataConfig.builder() .path(s3InputDataSourcePath) .build(); S3DataConfig outputDestination = S3DataConfig.builder() .path(s3DataDestinationPath) .build(); BatchInferenceJobInput jobInput = BatchInferenceJobInput.builder() .s3DataSource(inputSource) .build(); BatchInferenceJobOutput jobOutputLocation = BatchInferenceJobOutput.builder() .s3DataDestination(outputDestination) .build(); // Optional code to build the User-Personalization specific item exploration config. HashMap<String, String> explorationConfig = new HashMap<>(); explorationConfig.put("explorationWeight", explorationWeight); explorationConfig.put("explorationItemAgeCutOff", explorationItemAgeCutOff); BatchInferenceJobConfig jobConfig = BatchInferenceJobConfig.builder() .itemExplorationConfig(explorationConfig) .build(); // End optional User-Personalization recipe specific code. CreateBatchInferenceJobRequest createBatchInferenceJobRequest = CreateBatchInferenceJobRequest.builder() .solutionVersionArn(solutionVersionArn) .jobInput(jobInput) .jobOutput(jobOutputLocation) .jobName(jobName) .filterArn(filterArn) .roleArn(roleArn) .batchInferenceJobConfig(jobConfig) // Optional .build(); batchInferenceJobArn = personalizeClient.createBatchInferenceJob(createBatchInferenceJobRequest) .batchInferenceJobArn(); DescribeBatchInferenceJobRequest describeBatchInferenceJobRequest = DescribeBatchInferenceJobRequest.builder() .batchInferenceJobArn(batchInferenceJobArn) .build(); long maxTime = Instant.now().getEpochSecond() + 3 * 60 * 60; // wait until the batch inference job is complete. while (Instant.now().getEpochSecond() < maxTime) { BatchInferenceJob batchInferenceJob = personalizeClient .describeBatchInferenceJob(describeBatchInferenceJobRequest) .batchInferenceJob(); status = batchInferenceJob.status(); System.out.println("Batch inference job status: " + status); if (status.equals("ACTIVE") || status.equals("CREATE FAILED")) { break; } try { Thread.sleep(waitInMilliseconds); } catch (InterruptedException e) { System.out.println(e.getMessage()); } } return batchInferenceJobArn; } catch (PersonalizeException e) { System.out.println(e.awsErrorDetails().errorMessage()); } return ""; }
SDK for JavaScript v3
// Get service clients module and commands using ES6 syntax. import { CreateBatchInferenceJobCommand } from "@aws-sdk/client-personalize"; import { personalizeClient } from "./libs/personalizeClients.js"; // Or, create the client here. // const personalizeClient = new PersonalizeClient({ region: "REGION"}); // Set the batch inference job's parameters. export const createBatchInferenceJobParam = { jobName: 'JOB_NAME', jobInput: { /* required */ s3DataSource: { /* required */ path: 'INPUT_PATH', /* required */ // kmsKeyArn: 'INPUT_KMS_KEY_ARN' /* optional */' } }, jobOutput: { /* required */ s3DataDestination: { /* required */ path: 'OUTPUT_PATH', /* required */ // kmsKeyArn: 'OUTPUT_KMS_KEY_ARN' /* optional */' } }, roleArn: 'ROLE_ARN', /* required */ solutionVersionArn: 'SOLUTION_VERSION_ARN', /* required */ numResults: 20 /* optional integer*/ }; export const run = async () => { try { const response = await personalizeClient.send(new CreateBatchInferenceJobCommand(createBatchInferenceJobParam)); console.log("Success", response); return response; // For unit tests. } catch (err) { console.log("Error", err); } }; run();

배치 작업을 처리하는 데 시간이 걸릴 수 있습니다. DescribeBatchInferenceJob을 호출하고 batchRecommendationsJobArn을 입력 파라미터로 전달하여 작업 상태를 확인할 수 있습니다. 또한 호출을 통해 사용자 AWS 환경의 모든 Amazon Personalize 배치 추론 작업을 나열할 수 있습니다. ListBatchInferenceJobs

테마를 생성하는 배치 추론 작업 생성

유사한 항목에 대한 테마를 생성하려면 유사-항목 레시피를 사용해야 하며, 항목 데이터 세트에는 텍스트 필드와 항목 이름 데이터 열이 있어야 합니다. 테마가 있는 추천에 대한 자세한 내용은 콘텐츠 생성기에서 테마가 있는 배치 추천 섹션을 참조하세요.

다음 코드는 테마가 있는 추천을 생성하는 배치 추론 작업을 만듭니다. batchInferenceJobMode 설정을 "THEME_GENERATION"으로 둡니다. 항목 이름 데이터를 저장하는 열의 이름으로 COLUMNN_NAME을 바꿉니다.

import boto3 personalize_rec = boto3.client(service_name='personalize') personalize_rec.create_batch_inference_job ( solutionVersionArn = "Solution version ARN", jobName = "Batch job name", roleArn = "IAM service role ARN", filterArn = "Filter ARN", batchInferenceJobMode = "THEME_GENERATION", themeGenerationConfig = { "fieldsForThemeGeneration": { "itemName": "COLUMN_NAME" } }, jobInput = {"s3DataSource": {"path": "s3://<name of your S3 bucket>/<folder name>/<input JSON file name>.json"}}, jobOutput = {"s3DataDestination": {"path": "s3://<name of your S3 bucket>/<output folder name>/"}} )