In Hluti 1 of this series, we presented a solution that used the Amazon Titan Multimodal Embeddings model to convert individual slides from a slide deck into embeddings. We stored the embeddings in a vector database and then used the Large Language-and-Vision Assistant (LLaVA 1.5-7b) model to generate text responses to user questions based on the most similar slide retrieved from the vector database. We used AWS services including Amazon Berggrunnur, Amazon SageMakerog Amazon OpenSearch Serverless í þessari lausn.
In this post, we demonstrate a different approach. We use the Anthropic Claude 3 Sonnet model to generate text descriptions for each slide in the slide deck. These descriptions are then converted into text embeddings using the Amazon Titan textainnfelling model and stored in a vector database. Then we use the Claude 3 Sonnet model to generate answers to user questions based on the most relevant text description retrieved from the vector database.
You can test both approaches for your dataset and evaluate the results to see which approach gives you the best results. In Part 3 of this series, we evaluate the results of both methods.
Lausn yfirlit
The solution provides an implementation for answering questions using information contained in text and visual elements of a slide deck. The design relies on the concept of Retrieval Augmented Generation (RAG). Traditionally, RAG has been associated with textual data that can be processed by large language models (LLMs). In this series, we extend RAG to include images as well. This provides a powerful search capability to extract contextually relevant content from visual elements like tables and graphs along with text.
Þessi lausn inniheldur eftirfarandi hluti:
- Amazon Titan Text Embeddings is a text embeddings model that converts natural language text, including single words, phrases, or even large documents, into numerical representations that can be used to power use cases such as search, personalization, and clustering based on semantic similarity.
- Claude 3 Sonnet is the next generation of state-of-the-art models from Anthropic. Sonnet is a versatile tool that can handle a wide range of tasks, from complex reasoning and analysis to rapid outputs, as well as efficient search and retrieval across vast amounts of information.
- OpenSearch Serverless is an on-demand serverless configuration for Amazon OpenSearch Service. We use OpenSearch Serverless as a vector database for storing embeddings generated by the Amazon Titan Text Embeddings model. An index created in the OpenSearch Serverless collection serves as the vector store for our RAG solution.
- Amazon OpenSearch Ingestion (OSI) is a fully managed, serverless data collector that delivers data to OpenSearch Service domains and OpenSearch Serverless collections. In this post, we use an OSI pipeline API to deliver data to the OpenSearch Serverless vector store.
The solution design consists of two parts: ingestion and user interaction. During ingestion, we process the input slide deck by converting each slide into an image, generating descriptions and text embeddings for each image. We then populate the vector data store with the embeddings and text description for each slide. These steps are completed prior to the user interaction steps.
In the user interaction phase, a question from the user is converted into text embeddings. A similarity search is run on the vector database to find a text description corresponding to a slide that could potentially contain answers to the user question. We then provide the slide description and the user question to the Claude 3 Sonnet model to generate an answer to the query. All the code for this post is available in the GitHub endurhverf.
Eftirfarandi skýringarmynd sýnir inntökuarkitektúrinn.
Verkflæðið samanstendur af eftirfarandi skrefum:
- Slides are converted to image files (one per slide) in JPG format and passed to the Claude 3 Sonnet model to generate text description.
- The data is sent to the Amazon Titan Text Embeddings model to generate embeddings. In this series, we use the slide deck Þjálfa og dreifa stöðugri dreifingu með AWS Trainium & AWS Inferentia from the AWS Summit in Toronto, June 2023 to demonstrate the solution. The sample deck has 31 slides, therefore we generate 31 sets of vector embeddings, each with 1536 dimensions. We add additional metadata fields to perform rich search queries using OpenSearch’s powerful search capabilities.
- The embeddings are ingested into an OSI pipeline using an API call.
- The OSI pipeline ingests the data as documents into an OpenSearch Serverless index. The index is configured as the sink for this pipeline and is created as part of the OpenSearch Serverless collection.
Eftirfarandi skýringarmynd sýnir arkitektúr notendasamskipta.
Verkflæðið samanstendur af eftirfarandi skrefum:
- Notandi sendir inn spurningu sem tengist rennibrautinni sem hefur verið tekin inn.
- The user input is converted into embeddings using the Amazon Titan Text Embeddings model accessed using Amazon Bedrock. An OpenSearch Service vector search is performed using these embeddings. We perform a k-nearest neighbor (k-NN) search to retrieve the most relevant embeddings matching the user query.
- The metadata of the response from OpenSearch Serverless contains a path to the image and description corresponding to the most relevant slide.
- A prompt is created by combining the user question and the image description. The prompt is provided to Claude 3 Sonnet hosted on Amazon Bedrock.
- Niðurstaða þessarar ályktunar er skilað til notanda.
We discuss the steps for both stages in the following sections, and include details about the output.
Forkröfur
Til að innleiða lausnina sem veitt er í þessari færslu ættir þú að hafa AWS reikning og þekkingu á FM, Amazon Bedrock, SageMaker og OpenSearch Service.
This solution uses the Claude 3 Sonnet and Amazon Titan Text Embeddings models hosted on Amazon Bedrock. Make sure that these models are enabled for use by navigating to the Fyrirmynd aðgangur page on the Amazon Bedrock console.
If models are enabled, the Access status will state Aðgangur veittur.
If the models are not available, enable access by choosing Stjórna líkanaaðgangi, selecting the models, and choosing Biðja um aðgang að líkaninu. The models are enabled for use immediately.
Use AWS CloudFormation to create the solution stack
You can use AWS CloudFormation to create the solution stack. If you have created the solution for Part 1 in the same AWS account, be sure to delete that before creating this stack.
AWS svæði | Link |
---|---|
us-east-1 |
|
us-west-2 |
Eftir að staflinn hefur verið búinn til með góðum árangri skaltu fletta í Outputs flipann á staflanum á AWS CloudFormation stjórnborðinu og athugaðu gildin fyrir MultimodalCollectionEndpoint
og OpenSearchPipelineEndpoint
. You use these in the subsequent steps.
CloudFormation sniðmátið býr til eftirfarandi úrræði:
- IAM hlutverk - Eftirfarandi AWS auðkenni og aðgangsstjórnun (IAM) roles are created. Update these roles to apply least-privilege permissions, as discussed in Bestu öryggisvenjur.
SMExecutionRole
með Amazon einföld geymsluþjónusta (Amazon S3), SageMaker, OpenSearch Service, and Amazon Bedrock full access.OSPipelineExecutionRole
with access to the S3 bucket and OSI actions.
- SageMaker minnisbók – All code for this post is run using this notebook.
- OpenSearch Serverless safn – Þetta er vektorgagnagrunnurinn til að geyma og sækja innfellingar.
- OSI leiðsla – Þetta er leiðslan til að taka gögn inn í OpenSearch Serverless.
- S3 fötu – Öll gögn fyrir þessa færslu eru geymd í þessari fötu.
The CloudFormation template sets up the pipeline configuration required to configure the OSI pipeline with HTTP as source and the OpenSearch Serverless index as sink. The SageMaker notebook 2_data_ingestion.ipynb
displays how to ingest data into the pipeline using the beiðnir HTTP library.
CloudFormation sniðmátið býr einnig til net, dulkóðun og gögn aðgangur policies required for your OpenSearch Serverless collection. Update these policies to apply least-privilege permissions.
The CloudFormation template name and OpenSearch Service index name are referenced in the SageMaker notebook 3_rag_inference.ipynb
. If you change the default names, make sure you update them in the notebook.
Prófaðu lausnina
After you have created the CloudFormation stack, you can test the solution. Complete the following steps:
- Á SageMaker stjórnborðinu skaltu velja Fartölvur í siglingarúðunni.
- Veldu
MultimodalNotebookInstance
Og veldu Open JupyterLab. - In Skráavafri, traverse to the notebooks folder to see notebooks and supporting files.
The notebooks are numbered in the sequence in which they run. Instructions and comments in each notebook describe the actions performed by that notebook. We run these notebooks one by one.
- Veldu
1_data_prep.ipynb
til að opna það í JupyterLab. - Á vefsíðu Hlaupa valmynd, veldu Keyra allar frumur til að keyra kóðann í þessari minnisbók.
This notebook will download a publicly available renniþilfari, convert each slide into the JPG file format, and upload these to the S3 bucket.
- Veldu
2_data_ingestion.ipynb
til að opna það í JupyterLab. - Á vefsíðu Hlaupa valmynd, veldu Keyra allar frumur til að keyra kóðann í þessari minnisbók.
In this notebook, you create an index in the OpenSearch Serverless collection. This index stores the embeddings data for the slide deck. See the following code:
You use the Claude 3 Sonnet and Amazon Titan Text Embeddings models to convert the JPG images created in the previous notebook into vector embeddings. These embeddings and additional metadata (such as the S3 path and description of the image file) are stored in the index along with the embeddings. The following code snippet shows how Claude 3 Sonnet generates image descriptions:
The image descriptions are passed to the Amazon Titan Text Embeddings model to generate vector embeddings. These embeddings and additional metadata (such as the S3 path and description of the image file) are stored in the index along with the embeddings. The following code snippet shows the call to the Amazon Titan Text Embeddings model:
The data is ingested into the OpenSearch Serverless index by making an API call to the OSI pipeline. The following code snippet shows the call made using the Requests HTTP library:
- Veldu
3_rag_inference.ipynb
til að opna það í JupyterLab. - Á vefsíðu Hlaupa valmynd, veldu Keyra allar frumur til að keyra kóðann í þessari minnisbók.
This notebook implements the RAG solution: you convert the user question into embeddings, find a similar image description from the vector database, and provide the retrieved description to Claude 3 Sonnet to generate an answer to the user question. You use the following prompt template:
Eftirfarandi kóðabútur veitir RAG vinnuflæðið:
Niðurstöður
The following table contains some user questions and responses generated by our implementation. The Spurning dálkurinn fangar notendaspurninguna og svar column is the textual response generated by Claude 3 Sonnet. The Mynd column shows the k-NN slide match returned by the OpenSearch Serverless vector search.
Niðurstöður Multimodal RAG
Query your index
You can use OpenSearch Dashboards to interact with the OpenSearch API to run quick tests on your index and ingested data.
Hreinsun
To avoid incurring future charges, delete the resources. You can do this by deleting the stack using the AWS CloudFormation console.
Niðurstaða
Enterprises generate new content all the time, and slide decks are a common way to share and disseminate information internally within the organization and externally with customers or at conferences. Over time, rich information can remain buried and hidden in non-text modalities like graphs and tables in these slide decks.
You can use this solution and the power of multimodal FMs such as the Amazon Titan Text Embeddings and Claude 3 Sonnet to discover new information or uncover new perspectives on content in slide decks. You can try different Claude models available on Amazon Bedrock by updating the CLAUDE_MODEL_ID
í globals.py
skrá.
This is Part 2 of a three-part series. We used the Amazon Titan Multimodal Embeddings and the LLaVA model in Part 1. In Part 3, we will compare the approaches from Part 1 and Part 2.
Portions of this code are released under the Apache 2.0 License.
Um höfunda
Amit Arora er gervigreind og ML sérfræðingur hjá Amazon Web Services, sem hjálpar viðskiptavinum fyrirtækja að nota skýjatengda vélanámsþjónustu til að stækka nýjungar sínar hratt. Hann er einnig aðjunkt í MS gagnafræði- og greiningarnámi við Georgetown háskóla í Washington DC
Manju Prasad is a Senior Solutions Architect at Amazon Web Services. She focuses on providing technical guidance in a variety of technical domains, including AI/ML. Prior to joining AWS, she designed and built solutions for companies in the financial services sector and also for a startup. She is passionate about sharing knowledge and fostering interest in emerging talent.
Archana Inapudi is a Senior Solutions Architect at AWS, supporting a strategic customer. She has over a decade of cross-industry expertise leading strategic technical initiatives. Archana is an aspiring member of the AI/ML technical field community at AWS. Prior to joining AWS, Archana led a migration from traditional siloed data sources to Hadoop at a healthcare company. She is passionate about using technology to accelerate growth, provide value to customers, and achieve business outcomes.
Antara Raisa is an AI and ML Solutions Architect at Amazon Web Services, supporting strategic customers based out of Dallas, Texas. She also has previous experience working with large enterprise partners at AWS, where she worked as a Partner Success Solutions Architect for digital-centered customers.
- SEO knúið efni og PR dreifing. Fáðu magnara í dag.
- PlatoData.Network Vertical Generative Ai. Styrktu sjálfan þig. Aðgangur hér.
- PlatoAiStream. Web3 upplýsingaöflun. Þekking aukin. Aðgangur hér.
- PlatóESG. Kolefni, CleanTech, Orka, Umhverfi, Sól, Úrgangsstjórnun. Aðgangur hér.
- PlatoHealth. Líftækni og klínísk rannsóknagreind. Aðgangur hér.
- Heimild: https://aws.amazon.com/blogs/machine-learning/talk-to-your-slide-deck-using-multimodal-foundation-models-hosted-on-amazon-bedrock-and-amazon-sagemaker-part-2/