翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
バッチ推論ジョブの作成 (AWS SDKs)
バッチレコメンデーション用の入力データを準備します。 を完了すると、CreateBatchInferenceJob 操作を使用してバッチ推論ジョブを作成する準備が整います。
バッチ推論ジョブの作成
次のコードを使用して、バッチ推論ジョブを作成できます。ジョブ名、ソリューションバージョンの Amazon リソースネーム (ARN)、設定中に Amazon Personalize 用に作成した IAM サービスロールの ARN を指定します。このロールには、入力および出力の Amazon S3 バケットへの読み取りおよび書き込みアクセスが必要です。
出力データには別の場所 (フォルダまたは別の Amazon S3 バケット) を使用することをお勧めします。入力および出力の場所には、s3://<name of your S3 bucket>/<folder name>/<input JSON file name>.json
および s3://<name of your S3 bucket>/<output folder name>/
の構文を使用します。
numResults
には、入力データの各行に Amazon Personalize に予測させたいアイテムの数を指定します。オプションで、レコメンデーションをフィルタリングするためのフィルター ARN を選択します。フィルターでプレースホルダーパラメータを使用する場合は、パラメータの値が入力 JSON に含まれていることを確認してください。詳細については、「バッチレコメンデーションとユーザーセグメントのフィルタリング (カスタムリソース)」を参照してください。
- SDK for Python (Boto3)
-
この例には、オプションの User-Personalization レシピ固有の itemExplorationConfig
ハイパーパラメータ (explorationWeight
および explorationItemAgeCutOff
) が含まれています。オプションで、explorationWeight
および explorationItemAgeCutOff
の値を含めて、探索を設定します。詳細については、「User-Personalization レシピ」を参照してください。
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
-
この例には、オプションの User-Personalization レシピ固有の itemExplorationConfig
フィールド (explorationWeight
および explorationItemAgeCutOff
) が含まれています。オプションで、explorationWeight
および explorationItemAgeCutOff
の値を含めて、探索を設定します。詳細については、「User-Personalization レシピ」を参照してください。
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。
テーマを生成するバッチ推論ジョブの作成
類似アイテムのテーマを生成するには、Similar-Items レシピを使用し、アイテムデータセットにテキストフィールドとアイテム名データの列が必要です。テーマ付きレコメンデーションの詳細については、「Content Generator のテーマ付きバッチレコメンデーション」を参照してください。
次のコードは、テーマ付きレコメンデーションを生成するバッチ推論ジョブを作成します。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>/
"}}
)