AWS Machine Learning Blog 2024年11月22日
Using responsible AI principles with Amazon Bedrock Batch Inference
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

亚马逊Bedrock是一项全托管服务,提供多种高性能基础模型,近期其批量推理功能可高效处理大量数据且成本降低。本文探讨将负责任AI防护栏纳入其工作流程的实用方法,包括伦理提示和后期处理防护栏,解决了诸多关键挑战。

亚马逊Bedrock提供多种高性能基础模型及多种功能

批量推理功能可高效处理大量数据且成本降低

探讨将负责任AI防护栏纳入工作流程的方法

包括伦理提示和后期处理防护栏两个关键元素

Amazon Bedrock is a fully managed service that offers a choice of high-performing foundation models (FMs) from leading AI companies like AI21 Labs, Anthropic, Cohere, Meta, Mistral AI, Stability AI, and Amazon through a single API, along with a broad set of capabilities to build generative AI applications with security, privacy, and responsible AI.

The recent announcement of batch inference in Amazon Bedrock enables organizations to process large volumes of data efficiently at 50% less cost compared to On-Demand pricing. It’s especially useful when the use case is not latency sensitive and you don’t need real-time inference. However, as we embrace these powerful capabilities, we must also address a critical challenge: implementing responsible AI practices in batch processing scenarios.

In this post, we explore a practical, cost-effective approach for incorporating responsible AI guardrails into Amazon Bedrock Batch Inference workflows. Although we use a call center’s transcript summarization as our primary example, the methods we discuss are broadly applicable to a variety of batch inference use cases where ethical considerations and data protection are a top priority.

Our approach combines two key elements:

This two-step process offers several advantages:

Throughout this post, we address several key challenges in responsible AI implementation for batch inference. These include safeguarding sensitive information, providing accuracy and relevance of AI-generated content, mitigating biases, maintaining transparency, and adhering to data protection regulations. By tackling these challenges, we aim to provide a comprehensive approach to ethical AI use in batch processing.

To illustrate these concepts, we provide practical step-by-step guidance on implementing this technique.

Solution overview

This solution uses Amazon Bedrock for batch inference to summarize call center transcripts, coupled with the following two-step approach to maintain responsible AI practices. The method is designed to be cost-effective, flexible, and maintain high ethical standards.

This two-step approach combines the efficiency of batch processing with robust ethical safeguards, providing a comprehensive solution for responsible AI implementation in scenarios involving sensitive data at scale.

In the following sections, we walk you through the key components of implementing responsible AI practices in batch inference workflows using Amazon Bedrock, with a focus on ethical prompting techniques and guardrails.

Prerequisites

To implement the proposed solution, make sure you have satisfied the following requirements:

Ethical prompting techniques

When setting up your batch inference job, it’s crucial to incorporate ethical guidelines into your prompts. The following is a concise example of how you might structure your prompt:

prompt = f"""Summarize the following customer service transcript:{transcript}Instructions:1. Focus on the main issue, steps taken, and resolution.2. Maintain a professional and empathetic tone.3. Do not include any personally identifiable information (PII) in the summary.4. Use gender-neutral language even if gender is explicitly mentioned.5. Reflect the emotional context accurately without exaggeration.6. Highlight actionable insights for improving customer service.7. If any part is unclear or ambiguous, indicate this in the summary.8. Replace specific identifiers with generic terms like 'the customer' or '{{MASKED}}'."""

This prompt sets the stage for ethical summarization by explicitly instructing the model to protect privacy, minimize bias, and focus on relevant information.

Set up a batch inference job

For detailed instructions on how to set up and run a batch inference job using Amazon Bedrock, refer to Enhance call center efficiency using batch inference for transcript summarization with Amazon Bedrock. It provides detailed instructions for the following steps:

By following the instructions in our previous post and incorporating the ethical prompt provided in the preceding section, you’ll be well-equipped to set up batch inference jobs.

Amazon Bedrock Guardrails

After the batch inference job has run successfully, apply Amazon Bedrock Guardrails as a postprocessing step. This provides an additional layer of protection against potential ethical violations or sensitive information disclosure. The following is a simple implementation, but you can update this based on your data volume and SLA requirements:

import boto3, os, json, time# Initialize Bedrock client and set guardrail detailsbedrock_runtime = boto3.client('bedrock-runtime')guardrail_id = "<Your Guardrail ID>"guardrail_version = "<Your Guardrail Version>"# S3 bucket and file details i.e. output of batch inference jobbucket_name = '<S3 bucket with batch inference output>'prefix = "<prefix>"filename = '<filename>'# Set up AWS session and S3 clientsession = boto3.Session(    aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID'),    aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY'),    region_name=os.environ.get('AWS_REGION'))s3 = session.client('s3')# Read and process batch inference output from S3output_data = []try:    object_key = f"{prefix}{filename}"    json_data = s3.get_object(Bucket=bucket_name, Key=object_key)['Body'].read().decode('utf-8')        for line in json_data.splitlines():        data = json.loads(line)        output_entry = {            'request_id': data['recordId'],            'output_text': data['modelOutput']['content'][0]['text']        }        output_data.append(output_entry)except Exception as e:    print(f"Error reading JSON file from S3: {e}")# Function to apply guardrails and mask PII datadef mask_pii_data(batch_output: str):    try:        pii_data = [{"text": {"text": batch_output}}]        response = bedrock_runtime.apply_guardrail(            guardrailIdentifier=guardrail_id,            guardrailVersion=guardrail_version,            source='OUTPUT',            content=pii_data        )        return response['outputs'][0]['text'] if response['action'] == 'GUARDRAIL_INTERVENED' else pii_data    except Exception as e:        print(f"An error occurred: {str(e)}")# Set up rate limiting: # 20 requests per minute, 3 seconds intervalrpm = 20interval = 3# Apply guardrails to each recordmasked_data = []for record in output_data:    iteration_start = time.time()        record['masked_data'] = mask_pii_data(record['output_text'])    masked_data.append(record)        # Implement rate limiting    time.sleep(max(0, interval - (time.time() - iteration_start)))

Key points about this implementation:

This approach allows you to benefit from the efficiency of batch processing while still maintaining strict control over the AI’s outputs and protecting sensitive information. By addressing ethical considerations at both the input (prompting) and output (guardrails) stages, you’ll have a comprehensive approach to responsible AI in batch inference workflows.

Although this example focuses on call center transcript summarization, you can adapt the principles and methods discussed in this post to various batch inference scenarios across different industries, always prioritizing ethical AI practices and data protection.

Ethical considerations for responsible AI

Although the prompt in the previous section provides a basic framework, there are many ethical considerations you can incorporate depending on your specific use case. The following is a more comprehensive list of ethical guidelines:

When implementing ethical AI practices in your batch inference workflows, consider which of these guidelines are most relevant to your specific use case. You may need to add, remove, or modify instructions based on your industry, target audience, and specific ethical considerations. Remember to regularly review and update your ethical guidelines as new challenges and considerations emerge in the field of AI ethics.

Clean up

To delete the guardrail you created, follow the steps in Delete a guardrail.

Conclusion

Implementing responsible AI practices, regardless of the specific feature or method, requires a thoughtful balance of privacy protection, cost-effectiveness, and ethical considerations. In our exploration of batch inference with Amazon Bedrock, we’ve demonstrated how these principles can be applied to create a system that not only efficiently processes large volumes of data, but does so in a manner that respects privacy, avoids bias, and provides actionable insights.

We encourage you to adopt this approach in your own generative AI implementations. Start by incorporating ethical guidelines into your prompts and applying guardrails to your outputs. Responsible AI is an ongoing commitment—continuously monitor, gather feedback, and adapt your approach to align with the highest standards of ethical AI use. By prioritizing ethics alongside technological advancement, we can create AI systems that not only meet business needs, but also contribute positively to society.


About the authors

Ishan Singh is a Generative AI Data Scientist at Amazon Web Services, where he helps customers build innovative and responsible generative AI solutions and products. With a strong background in AI/ML, Ishan specializes in building Generative AI solutions that drive business value. Outside of work, he enjoys playing volleyball, exploring local bike trails, and spending time with his wife and dog, Beau.

Yanyan Zhang is a Senior Generative AI Data Scientist at Amazon Web Services, where she has been working on cutting-edge AI/ML technologies as a Generative AI Specialist, helping customers use generative AI to achieve their desired outcomes. Yanyan graduated from Texas A&M University with a PhD in Electrical Engineering. Outside of work, she loves traveling, working out, and exploring new things.

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

亚马逊Bedrock 批量推理 负责任AI 伦理提示 防护栏
相关文章