In this Cloud Lab, you’ll learn how to deploy a machine learning model with Amazon SageMaker, provide access to it with a Lambda function, and trigger the Lambda function with API Gateway.
Imagine running a global e-commerce business where your customer support team handles thousands of multilingual queries effortlessly. Marketing campaigns come to life with tailored content, product listings write themselves, and market trends turn into actionable insights at your fingertips.
What if these capabilities weren’t futuristic aspirations but solutions available today? Enter foundation models—AI systems trained on vast datasets capable of powering everything from chatbots to code generation. With AWS services like Amazon Bedrock and SageMaker, harnessing this power has never been easier.
Learn the A to Z of Amazon Web Services (AWS)
Learn about the core AWS's services like compute, storage, networking services and how they work with other services like Identity, Mobile, Routing, and Security. This course provides you with a good grasp an all you need to know of AWS services. This course has been designed by three AWS Solution Certified Architects who have a combined industry experience of 17 years. We aim to provide you with just the right depth of knowledge you need to have.
In this blog, we’ll discuss foundation models, why they matter, and how to get started with them on AWS.
Foundation models are large-scale AI models pretrained on massive datasets. They are versatile across different applications with minimal task-specific training. Think of them as a Swiss army knife for AI—capable of handling text, images, and code with minimal customization.
Unlike traditional machine learning models, which require task-specific training from scratch, foundation models provide a strong base that can be fine-tuned for specific applications like chatbots, content creation, and code generation. This adaptability makes them highly efficient for real-world AI solutions.
Foundation models are game-changers in several domains and transform how different tasks can be handled. Here are a few domains where they make a significant impact:
Natural language processing (NLP): Models like GPT generate human-like text, powering chatbots, content generation, and summarization.
Computer vision:
Code generation:
With these capabilities, businesses can simplify operations, boost efficiency, and drive innovation across industries. AWS provides services to access, customize, and deploy foundation models, which enables businesses and developers to harness their capabilities without worrying about infrastructure complexities.
The buzz around foundational models is justified—they bring real value and are hard to ignore. Let’s discuss some of the benefits offered by foundational models that make them truly indispensable:
Companies are often racing against time while building AI solutions for their products. Building AI models from scratch can feel like reinventing the wheel. Foundation models eliminate this hurdle by offering ready-to-use intelligence, allowing businesses to leapfrog straight into innovation.
AI development is often associated with hefty infrastructure and training expenses. Foundation models help you avoid these costs by offering pretrained capabilities that can be fine-tuned without massive resource investment.
Foundation models are not one-size-fits-all—they’re designed for customization. Whether creating a virtual assistant for customer support, automating sentiment analysis, or personalizing recommendations, you can adjust these models to fit your unique requirements.
With foundation models, you can focus on innovation instead of infrastructure and tedious model training, making them a cornerstone of modern AI workflows.
Become an AWS Professional
Amazon Web Services (AWS) is the most comprehensive and widely used cloud platform in the world. AWS is used by millions of clients - including the fastest-growing startups, most prominent corporations, and top government agencies - to reduce costs, become more agile, and innovate faster. This path will lead you to develop web applications using AWS architecture and learn about linked entities like databases and networking. By the end, you'll have professional-level skills to develop AWS-based web applications confidently.
AWS provides specialized tools to make foundation models accessible, customizable, and easy to deploy. Let’s dive into the key services:
Picture this: You’re a startup founder racing to integrate AI into your product but don’t want the hassle of managing servers or infrastructure. Amazon Bedrock is the solution you need.
Amazon Bedrock is a managed service that allows developers to access and integrate foundation models from leading providers without worrying about infrastructure setup, scaling, or maintenance. Bedrock is a gateway to pretrained models that are hosted, maintained, and readily available through APIs.
Bedrock provides a plug-and-play experience for foundation models. It is ideal for businesses needing rapid deployment and not wanting to manage the underlying infrastructure.
Bedrock provides us with the following benefits:
Model variety: Bedrock offers a curated selection of foundation models from various providers, allowing developers to choose the best model for their use case. Some key providers and their model capabilities include:
Anthropic: Provides models designed for conversational AI, code generation, and natural language processing.
Cohere: Offers models optimized for text classification, summarization, and semantic search.
Stability AI: Specializes in text-to-image generation models.
No infrastructure overhead: Bedrock manages the resources on our behalf, so there’s no need to set up GPUs, storage, or other infrastructure components. AWS scales the resources to match usage.
Customizable prompts: Bedrock allows the users to fine-tune prompts to better align with tasks like customer support, content generation, or sentiment analysis. We can also adjust the inference configurations to our liking.
Bedrock is a suitable solution for quickly deploying chatbots without training models, generating personalized marketing content, and creating AI-driven visual content for social media or advertisements.
If you’re looking to fine-tune pretrained models or even build your own from scratch, Amazon SageMaker is your go-to tool. It can be considered a powerful workshop for serious customization.
Amazon SageMaker is a full-fledged machine learning platform designed for developers and data scientists who want more control and flexibility in working with models, including foundation models. Unlike Bedrock, SageMaker allows for extensive customization, fine-tuning, and even training models from scratch.
SageMaker is a customization and training powerhouse. It offers a comprehensive suite of features catering to every machine learning life cycle stage, making it an ideal choice for beginners and experts. Here’s what a typical MLOps pipeline looks like in Amazon SageMaker:
Below are some of the core capabilities of SageMaker:
SageMaker JumpStart: A quick way to explore and use pretrained foundation models. It includes ready-to-use models and notebooks for tasks like text analysis, image classification, and code generation.
Fine-tuning foundation models: Use SageMaker’s built-in tools to train custom or fine-tune foundation models with your data, improving accuracy and alignment with specific business needs.
Model training and deployment: Easily deploy foundation and custom models into production with scalable endpoints and low-latency inference.
Advanced features: SageMaker includes debugging tools to monitor training, cost-saving features like managed spot training, and seamless integration with AWS data sources like S3, Redshift, and RDS.
AWS ensures you have the right tools for any AI journey, whether you need quick deployment or deep customization.
Deploying a Machine Learning Model with Amazon SageMaker
Deploying a Machine Learning Model with Amazon SageMaker
One powerful use case of generative AI is data augmentation and synthesis. This involves creating synthetic data—images, audio, text, or tabular—to enhance existing datasets or generate entirely new ones. This synthetic data can be used to train machine learning models, test applications, or improve overall data quality.
A prime example of this is MedSynth, a company specializing in generating synthetic medical data for healthcare research and development. By leveraging Amazon Bedrock, MedSynth gains access to advanced foundation models (FMs) like Anthropic Large from Anthropic and Stability GAN from Stability AI. These models allow MedSynth to create highly realistic and diverse synthetic data, including medical images, electronic health records, and clinical notes.
Once the data is generated, MedSynth utilizes Amazon SageMaker Data Wrangler to process and label the synthetic data, ensuring it is ready for use in various applications. This streamlined approach enables MedSynth to deliver high-quality synthetic data to its customers, supporting research and development without the limitations of real-world data constraints.
This combination of Amazon Bedrock and SageMaker accelerates the creation of synthetic datasets and ensures that the data is accurate and useful for advancing machine learning applications in health care.
AWS simplifies working with foundation models, making it accessible and efficient for developers. You can interact with foundation models seamlessly using straightforward API calls by leveraging services like Amazon Bedrock. The following code snippet demonstrates how to interact with an enabled foundation model on Bedrock, highlighting the ease of integrating powerful AI capabilities into your applications:
from botocore.exceptions import ClientErrorimport boto3# Initialize the Bedrock Runtime clientclient2 = boto3.client("bedrock-runtime",aws_access_key_id="<AWS_ACCESS_KEY_ID>",aws_secret_access_key="<AWS_SECRET_ACCESS_KEY>",region_name="us-east-1")# Foundation model IDmodel_id = "anthropic.claude-3-sonnet-20240229-v1:0"# User's message for sentiment analysisuser_message = "I am so happy and excited to start this new journey!"# Conversation setupconversation = [{"role": "user","content": [{"text": ("Analyze the sentiment of the following message and provide a concise response ""indicating whether it is positive, negative, or neutral. "f"Message: '{user_message}'")}]}]try:# Send the sentiment analysis prompt to the modelresponse = client2.converse(modelId=model_id,messages=conversation,inferenceConfig={"maxTokens": 1024, "temperature": 0.5},additionalModelRequestFields={"top_k": 250})# Extract and print the sentiment analysis resultresponse_text = response["output"]["message"]["content"][0]["text"]print(f"Sentiment Analysis Result: {response_text}")except (ClientError, Exception) as e:print(f"ERROR: Can't invoke '{model_id}'. Reason: {e}")exit(1)
Note: Ensure that you replace the
<AWS_ACCESS_KEY_ID>
and<AWS_SECRET_ACCESS_KEY>
placeholders on lines 7 and 8, respectively, and make sure that the account you are using has access to the specific model before executing the code.
Here’s a brief explanation of the code:
Lines 1–6: Define the connection details for the Bedrock Runtime client, including the AWS access key, secret key, and region name.
Line 13: Specify the foundation model ID to be used for inference.
Line 16: Define the user’s message that will be analyzed for sentiment.
Lines 19–32: Structure the conversation prompt by specifying the role of the “user” and asking the foundation model to analyze the sentiment of the provided message.
Lines 36–41: Send the conversation prompt to the Bedrock model using the converse
method. For controlling the response, specify inference configuration parameters like maxTokens
and temperature
.
Lines 44–45: Extract the sentiment analysis result from the model’s response and print it to the console.
Lines 46–48: Handle any exceptions during the model invocation and provide an error message.
When crafting your AI masterpiece, AWS provides the ultimate platform for innovation. Here’s why it stands out:
A hassle-free workspace for innovators: AWS eliminates the complexities of setting up servers, managing infrastructure, and scaling, offering a seamless environment for AI development. By handling these operational tasks, AWS ensures users can focus entirely on creating, customizing, and deploying foundation models easily and efficiently.
Seamless integration with AWS services: AWS offers a rich ecosystem of services that work harmoniously with foundation models. Whether you’re building an intelligent chatbot or a recommendation engine, AWS ensures every piece fits perfectly. For example:
Amazon S3: Effortlessly store customer interaction data or conversation histories.
AWS Lambda: Automate follow-up tasks or actions based on customer queries.
Amazon EventBridge: Trigger workflows or send notifications with precision.
Cost-effective innovation: AWS’s pay-as-you-go pricing model makes it easy to scale from a small prototype to a production-ready solution without breaking the bank. You only pay for what you use, enabling businesses of all sizes to innovate affordably and efficiently.
With AWS, the path from idea to execution is smoother, smarter, and more cost-effective.
Below is a brief list of the foundation model providers available on AWS:
Provider | Models | Specialization | Best For |
Amazon | Nova, Titan | Language and multimodal AI capabilities | NLP, multimodal AI, content creation, and cost-efficient AI workloads |
Anthropic | Claude | Conversational AI | Chatbots, customer support, and advanced dialogue systems |
AI21 Labs | Jamba, Jurassic | Advanced language generation | Summarization, content creation, and natural language understanding |
Arcee AI | SuperNova, Nova, Llama | Domain-specific AI | Business intelligence, niche AI tasks, and tailored language models |
Camb.ai | MARS6 | Computer vision | Image recognition, video analysis, and automated quality assurance |
Cohere | Command R, Embed, Rerank, Command | Language understanding and embeddings | Semantic search, personalized recommendations, and multilingual tasks |
EvolutionaryScale, PBC | ESM3-open | Advanced text processing | Deep semantic search and niche language-specific tasks |
Gretel | Gretel Navigator Tabular | Data privacy and synthetic data generation | Generating synthetic data for AI training while preserving privacy |
Hugging Face | Bloom, OPT, DistilBERT, RoBERTa, Falcon, and more | Versatile AI and transformer-based models | Multimodal AI, NLP, image tasks, and customization |
IBM Data and AI | Granite, Granite Code Instruct | Enterprise-focused language AI | Enterprise AI solutions, customer insights, and business analytics |
John Snow Labs | Medical LLM, Medical Text Translation | Healthcare and clinical data processing | Clinical text analysis, medical data structuring, and health insights |
Karakuri, Inc. | Karakuri LM | Robotics and AI integration | Industrial automation, robotic AI tasks, and precision engineering |
LG CNS | EXAONE | Enterprise AI | Business intelligence, enterprise solutions, and automated workflows |
LiquidAI | Liquid LFM | Multimodal AI | Combining text and image analysis for robust AI solutions |
Meta | LLaMA, RoBERTa, DINO | Cutting-edge AI innovations | Research, multilingual tasks, and open-source AI advancements |
Mistralai | Mistral-7B, MistralMix, and more | Compact and efficient AI models | AI on edge devices, lightweight deployments, and specialized NLP |
NCSoft | Llama, VARCO | Gaming and visual AI | Enhancing game interactions, story generation, and player experience |
NVIDIA | Nemotron | GPU-optimized AI | High-performance NLP, speech recognition, and enterprise AI workloads |
Preferred Networks, Inc. | PLaMo | Deep learning | Training and deploying custom AI models with high scalability |
Stability AI | Stable Diffusion, DreamBooth | Creative content generation | Artistic image creation, graphic design, and marketing content generation |
Stockmark | Stockmark-LLM | Text generation and summarization | Generative AI, content summarization, and creative writing |
Solar | Solar variants | Text generation and NLP | Real-time customer interactions, text-based automation, and multilingual tasks |
Wind Tower | Sugarloaf, Anthill, Llama3-Tower Vesuvius | Translation and generative AI | Multilingual NLP, content localization, and automated translation |
Writer | Palmyra | Text generation and summarization | Medical report generation, financial text summarization, and business intelligence |
Integrating foundation models into your applications requires strategic planning to ensure they are secure, cost-effective, and optimized for success. Here are three essential best practices to guide your journey:
Security first: Security is paramount when working with AI, especially when handling sensitive data. To ensure your AI solutions are secure, use AWS Identity and Access Management (IAM) for managing access controls and permissions, limiting who can interact with your data and models. We can use Amazon KMS (Key Management Service) to encrypt data before storing it in an S3 bucket. The Titan Embeddings model then converts this encrypted data into vector embeddings and saves them in a vector store. The vector store uses the encryption key to decrypt the data, making it accessible to Bedrock knowledge bases. These vector embeddings can be used with an LLM foundation model to build chatbot applications.
Cost-efficient scaling: Cost control is a key concern when scaling AI applications. While foundation models can scale to handle large amounts of data and requests, it’s essential to start small and gradually increase resources as needed. Use AWS Cost Explorer to monitor costs and track resource usage so you can adjust your infrastructure as your business grows. This allows you to scale efficiently without incurring unexpected expenses, keeping costs manageable as your AI solution expands.
Fine-tuning tips: Fine-tuning is the key to unlocking the full potential of foundation models, transforming their versatility into task-specific excellence. The process begins with high-quality, curated datasets tailored to the target application—like IMDb reviews for sentiment analysis or precision-labeled data for medical imaging—ensuring the model learns relevant patterns. Avoiding biased datasets or those with poor edge-case coverage is critical to robust generalization. Starting small with a limited dataset helps test and refine the model before scaling up, while regularization techniques like
Ignoring these principles can have serious consequences. Without robust security, sensitive data is exposed to breaches, eroding trust and risking legal repercussions. Overlooking cost-efficient scaling can lead to unnecessary expenses, making your solutions financially unsustainable. Finally, poor fine-tuning results in subpar model performance, such as inaccurate medical diagnoses, potentially endangering lives and tarnishing reputations.
Following these best practices sets the stage for long-term success—ensuring your AI solutions are secure, cost-effective, and finely tuned to meet your unique needs. Start small, stay strategic, and leverage AWS tools to unlock the full potential of foundation models.
While foundation models are powerful, several challenges that can affect the effectiveness of AI applications must be considered.
Navigating model bias: Bias in AI models is an ongoing concern, especially for foundation models trained on large datasets. These models can unintentionally learn and amplify biases in the data, leading to unfair or discriminatory outcomes. A prime example is Amazon’s AI recruiting tool, which showed a preference for male candidates over female ones, reflecting biases in the training data. To mitigate such risks, companies can leverage AWS tools like SageMaker Clarify, which helps evaluate and address bias in AI models. These tools can detect prediction disparities and ensure that models make fair and unbiased decisions. Proactively identifying and correcting biases is essential for creating ethical AI solutions. This is particularly important for hiring, lending, or healthcare businesses, where bias can have significant real-world consequences.
Customization hurdles: Adapting foundation models to specialized applications can be challenging. While these models are designed to be versatile, they may not always perform well for niche use cases. For instance, a healthcare startup using a general-purpose foundation model for medical image analysis faced accuracy issues because the model wasn’t trained on the specific types of medical images they were working with. To overcome this, they had to invest significant time fine-tuning the model to better understand the nuances of their specialized dataset. Amazon SageMaker allows businesses to customize and fine-tune models, but this process requires expertise in the domain and machine learning. Companies must understand the limitations of these models and be prepared to dedicate time and resources to adapt them effectively. Despite the challenges, customization can lead to better performance and more tailored solutions.
Understanding model capabilities: Foundation models are highly capable, but they aren’t perfect. These models excel at many tasks but may struggle with complex or highly specific scenarios requiring deeper context or creativity. For example, a company using a language model to generate marketing content found that while the model produced grammatically correct text, it lacked the creativity and brand voice they sought. They had to incorporate human input to ensure the content resonated with their target audience. It’s important to have realistic expectations when using foundation models and to understand when additional specialized models or human input may be necessary. By acknowledging their limitations, companies can use these models more effectively, integrating them into their workflows to leverage their strengths while mitigating weaknesses.
Consider integrating other AWS AI/ML services with foundation models to build robust and comprehensive AI solutions. This combination can enhance models’ capabilities and help deliver more complete solutions.
Amazon Rekognition: This service specializes in analyzing images and videos. Combining Rekognition with foundation models can enable advanced capabilities like image recognition or automated video content analysis if an application involves visual data.
Amazon Transcribe: For speech applications, Amazon Transcribe can convert audio into text, enabling services like voice transcription or chatbots that understand and process spoken language.
Integration tip: Combining foundation models with services like Rekognition or Transcribe allows you to handle multimodal data (text, images, video, and audio) and create innovative AI solutions that go beyond the capabilities of a single model.
Imagine building a customer support system for an e-commerce company that handles inquiries in various formats, including text messages, voice calls, and emails with attached images (e.g., pictures of damaged products). We can develop an innovative multimodal AI solution by leveraging a fine-tuned foundation model alongside AWS Rekognition and AWS Transcribe.
Historical customer service data is prepared and annotated to fine-tune the foundation model to highlight common intents and resolutions. The fine-tuning process uses Amazon SageMaker, ensuring the model is optimized for effectively understanding and responding to customer inquiries.
Voice call analysis: Using AWS Transcribe, the system converts customer voice calls into text. The foundation model then processes the text to generate a suitable response or escalate complex cases to human agents.
Image analysis: Customers often attach photos of damaged products. AWS Rekognition analyzes these images, identifying the extent of the damage and cross-referencing it with the product catalog to verify claims. The information is then passed to the foundation model to generate a suitable response or escalate complex cases to human agents.
Here’s an illustration of what the solution looks like:
What are foundation models best known for?
Solving math equations
Performing specialized AI tasks with pretrained capabilities
Storing large datasets
Enhancing computer hardware performance
Foundation models are revolutionizing AI, making powerful capabilities more accessible across industries. However, leveraging their full potential requires addressing challenges such as model bias and customization hurdles and understanding their limitations.
Whether you need chatbots, code generation, or intelligent automation, AWS offers tools like Amazon Bedrock for seamless AI integration and SageMaker for deep customization. AWS empowers developers to create ethical, customized, and impactful AI solutions, from mitigating biases to fine-tuning models for niche applications.
Ready to build with foundation models? Try one of our hands-on Cloud Labs on Amazon Bedrock:
Build a RAG Chatbot on AWS: Learn how to create intelligent chatbots using Bedrock Knowledge Base.
Use Amazon Bedrock for Code Development: Discover how to generate, translate, debug, and analyze code with Bedrock.
Building Generative AI Workflows with Amazon Bedrock: Manage prompts and deploy AI-driven agents using AWS Bedrock Flows.
What is the difference between generative AI and foundation models?
What is the AWS Jumpstart program?
What is the difference between a foundation model and an LLM?
What is the difference between deep learning and foundation models?
Which foundation model to choose?
Who is considered the father of AI?
Is GenAI deep learning?
Free Resources