Build Your Own Knowledge Base with Multilingual Q&A Powered by Generative AI
Use Amazon Kendra, Amazon Translate, Amazon Comprehend and Amazon SageMaker JumpStart to build a multilingual knowledge base that can summarize search results.
Part 1 - Build the Smart Database with Amazon Kendra π€
Part 2 - Searching an Amanzon Kendra Index
Part 3 - Add Multilingual Features π€π: Detect the Language of the Text and Translate It
Part 4 - Create ENDPOINT to Invoke Generative AI Large Language Models (LLMs) π
Part 5 - Summarize Answers Using the LLM
Part 6 - π¨ Delete Resources π¨
About | ||
---|---|---|
β AWS Level | Intermediate - 200 | |
β± Time to complete | 30 minutes | |
π° Cost to complete | 1.56 USD X 1 hour. | |
𧩠Prerequisites | - AWS Account - Foundational knowledge of Python | |
π’ Feedback | Any feedback, issues, or just a π / π ? | |
β° Last Updated | 2023-08-21 |
- How to set up an intelligent search service powered by machine learning with Amazon Kendra.
- How to utilize pretrained open-source Generative AI Large Language Models (LLMs).
- How to use Artificial Intelligence service to detect the dominant language in texts.
- How to use Artificial Intelligence service to translate text.
- The user asks the question.
- The language in which the query is made is detected using Amazon Comprehend.
- Using Amazon Translate, the question is translated into the data soruce language.
- The intelligent knowledge base is consulted.
- Use Amazon Kendra's answer and user question to ask the LLM for a summarized and improved answer.
- The answer is translated into the language of the question.
- Provide the summary answer and the source where it can be expanded.
- Part 1 - Build the smart database with Amazon Kendra, using the sample data.π€
- Part 2 - Queries to an index in Amazon Kendra.
- Part 3 - Add multilingual features π€π: detect the language of the text and translate it.
- Part 4 - Create ENDPOINT to invoke Generative AI Large Language Model (LLM) π.
- Part 5 - Summarize answer using the LLM.
- Part 6 - π¨Delete resourcesπ¨.
π¨Note: You can get started for free with the Amazon Kendra Developer Edition, that provides free usage of up to 750 hours for the first 30 days, check pricing here.
- Amazon Comprehend, to detect the dominant language in which the question is asked, using DetectDominantLanguage from Boto3 Comprehend client
- Amazon Translate, to translate the question to the language of the Kendra knowledge base (English in this case) and translate the answer back to the language of the original question, using TranslateText from Boto3 Translate client.
- Text (string): The text to translate.
- SourceLanguageCode (string): One of the supported language codes for the source text, if you specify auto, Amazon Translate will call Amazon Comprehend to determine the source language.
- TargetLanguageCode (string): One of the supported language codes for the target text.
π¨Note: Amazon Translate and Amazon Comprehend have Free Tier for up 12 months. Check pricing here and here.
- Text summarization
- Common sense reasoning / natural language inference
- Question and answering
- Sentence / sentiment classification
- Translation (at the time of writing this blog, between fewer languages than Amazon Translate)
- Pronoun resolution
1. Open the Amazon Sagemaker console | |
2. Find JumpStart on the left-hand navigation panel and choose Foundation models. | |
3. Search for a Flan UL2 model, and then click on View model. | |
4. Open notebook in Studio | |
5. Create a Sagemaker Domain using Quick setup, this takes a few minutesβ³... or Select domain and user profile if you already have one created. | |
6. Follow the steps in jupyter notebook, explore it, and wait for me in step 5 |
- Console:
π¨Note: You have to be careful, because while the endpoint is active, you will be billing. Check pricing here.
- num_return_sequences: corresponds to the number of answers per query that the LLM will deliver.
- max_length: the maximum number of tokens that the model will generate.
- top_k: limit random sampling to choose k value of sample with the highest probabilities.
- top_p: Select an output using the random-weighted strategy with the top-ranked consecutive results by probability and with a cumulative probability <= p.
- do_sample: Set
True
because Flan-T5 model use sampling technique.
text_inputs
in the code) composed of Amazon Kendra document part and the user's question, so that the model understands the context.text_inputs
and discover the best one according to your needs.- Open the Amazon Kendra console.
- In the navigation panel, choose Indexes, and then choose the index to delete.
- Choose Delete to delete the selected index.
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.