Membuat pekerjaan inferensi batch (AWS SDK) - Amazon Personalize

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Membuat pekerjaan inferensi batch (AWS SDK)

Setelah selesaiMempersiapkan data input untuk rekomendasi batch, Anda siap untuk membuat pekerjaan inferensi batch dengan CreateBatchInferenceJob operasi.

Membuat pekerjaan inferensi batch

Anda dapat menggunakan kode berikut untuk membuat pekerjaan inferensi batch. Tentukan nama pekerjaan, Nama Sumber Daya Amazon (ARN) versi solusi Anda, dan ARN peran layanan IAM yang Anda buat untuk Amazon Personalisasi selama penyiapan. Peran ini harus memiliki akses baca dan tulis ke bucket Amazon S3 input dan output Anda.

Sebaiknya gunakan lokasi yang berbeda untuk data keluaran Anda (baik folder atau bucket Amazon S3 yang berbeda). Gunakan sintaks berikut untuk lokasi input dan output: s3://<name of your S3 bucket>/<folder name>/<input JSON file name>.json dans3://<name of your S3 bucket>/<output folder name>/.

UntuknumResults, tentukan jumlah item yang ingin diprediksi Amazon Personalize untuk setiap baris data input. Secara opsional menyediakan filter ARN untuk memfilter rekomendasi. Jika filter Anda menggunakan parameter placeholder, pastikan nilai untuk parameter disertakan dalam input JSON Anda. Untuk informasi selengkapnya, lihat Memfilter rekomendasi batch dan segmen pengguna (sumber daya khusus).

SDK for Python (Boto3)

Contohnya termasuk itemExplorationConfig hiperparameter khusus resep Personalisasi Pengguna opsional: dan. explorationWeight explorationItemAgeCutOff Secara opsional sertakan explorationWeight dan explorationItemAgeCutOff nilai untuk mengonfigurasi eksplorasi. Untuk informasi selengkapnya, lihat Resep Personalisasi Pengguna.

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

Contoh ini mencakup itemExplorationConfig bidang khusus resep Personalisasi Pengguna opsional: dan. explorationWeight explorationItemAgeCutOff Secara opsional sertakan explorationWeight dan explorationItemAgeCutOff nilai untuk mengonfigurasi eksplorasi. Untuk informasi selengkapnya, lihat Resep Personalisasi Pengguna.

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();

Memproses pekerjaan batch mungkin membutuhkan waktu beberapa saat untuk diselesaikan. Anda dapat memeriksa status pekerjaan dengan memanggil DescribeBatchInferenceJob dan meneruskan batchRecommendationsJobArn sebagai parameter input. Anda juga dapat mencantumkan semua pekerjaan inferensi batch Amazon Personalisasi di AWS lingkungan Anda dengan menelepon. ListBatchInferenceJobs

Membuat pekerjaan inferensi batch yang menghasilkan tema

Untuk menghasilkan tema untuk item serupa, Anda harus menggunakan resep Item Serupa dan kumpulan data Item Anda harus memiliki bidang tekstual dan kolom data nama item. Untuk informasi selengkapnya tentang rekomendasi dengan tema, lihatRekomendasi Batch dengan tema dari Content Generator.

Kode berikut membuat pekerjaan inferensi batch yang menghasilkan rekomendasi dengan tema. Biarkan batchInferenceJobMode set ke"THEME_GENERATION". Ganti COLUMNN_NAME dengan nama kolom yang menyimpan data nama item Anda.

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>/"}} )