Back
Enterprise Ops Platforms

Amazon Bedrock

Author
pfactorial
July 01, 2024
Share
Amazon bedrock
The field of Artificial intelligence has changed a lot over the years.Instead of building AI models from scratch,which requires a lot of computational resources,companies have shifted to using existing models or fine-tuning the existing models if needed.Using pre-trained models like LLMs(Large language models) on a local machine is not always possible, as these models have a large size and required more cpu or gpu usage.How can we integrate an LLM into our application?How to make it possible?
There are cloud services like AWS bedrock which provide large AI models.If we have a custom dataset we can fine-tune these models and integrate it in our apps through an api.In this blog, we are going to explore the uses of the Bedrock platform from AWS, which offers various AI models that we can utilise.
What is Amazon bedrock?

Amazon bedrock is a fully managed service that offers different AI models like llama,claude ,stable diffusion etc.,which we can customise based on our needs. Bedrock is serverless so that we don’t have to manage any infrastructure.The models available in bedrock can be used for different tasks such as text summarisation ,chatbots, text generation, image summarisation etc.
Models
Let’s take a look at some of  the major   models available in bedrock and their use cases.

Claude
Claude  is a Large language model created by the  company Anthropic,whose founders are former members of  OpenAI. Claude can process almost 150000 words as input at once,which means it can process over 500 pages of text.

Command
Command is a large language model from the company cohere.It has various features including text summarisation,text generation,classification etc.
In python we can access the command model using an api key like this:
cohere

Here we can see the text summarisation by ‘command’ model.

Stable diffusion
Stable diffusion is a generative model which has capabilities like text to image generation ,image to image generation etc.
Apart from the models mentioned above there are also other models available in bedrock

Use cases
● You can create and customise chatbots with Bedrock’s models .
● Text and Image generation
● Text summarization

Now we have a basic overview of breadrock. Now let’s understand how we can fine-tune a model in bedrock.
Fine-tuning
We are going to fine-tune the cohere ‘command light’ model to summarise dialogs.

First,we need to go to the Amazon bedrock console using this link :https://console.aws.amazon.com/bedrock/
In the console navigate to Amazon bedrock and click on Custom models.

Customize model Amazon bedrock

For fine-tuning ,click on Customise model and then select create fine-tuning job.

Custom model name amazon bedrock

Then select the model we want to fine-tune.Add a custom name for our custom model and give a name to the training job.

Hyperparameters amazon bedrock

Next, we need to give the url to the dataset stored in an amazon s3 bucket.Amazon s3 is a storage service provided by AWS.The dataset should be in the jsonl format .Don’t confuse it with json.In jsonl format each line is in json format.
dataset_format:

{"completion": "Mr. Smith's getting a check-up, and Doctor Haw...", "prompt": Summarise the following conversation.\n\n#Pers..."}
{"completion": "Mrs Parker takes Ricky for his vaccines. Dr. P...", "prompt": "Summarise the following conversation.\n\n#Pers..."}

Then provide the hyperparameters like the number of epochs ,batch size,learning rate etc. and click on Fine-tune model
Output amazon bedrock

After fine-tuning we need to save our fine-tuned model ,right?
For that, we need to give the link to the amazon s3 bucket where we want to store our outputs.

fine tune  amazon bedrock

Then click finetune model to finetune the model based on a custom dataset.
Using the fine-tuned model
For using our fine-tuned model we need to purchase provision throughput to access the  model.Which simply means we need to pay a fixed amount on a monthly basis for using the model.Also we need to use the AWS support centre to request the number of model units  we want to use.

The most important thing to notice here is that these models are really costly
Price amazon bedrock

Here we can see that the estimated monthly cost of the cohere command light model is 5000 us dollars!
Claude
When we discussed the models available in Amazon Bedrock, we saw Claude, a powerful large language model that has similar performance to ChatGPT.Let’s understand  a little more about Claude and its use cases.

Claude  is a Large language model created by the  company Anthropic,whose founders are former members of  OpenAI. Claude can process almost 150000 words as input at once,which means it can process over 500 pages of text.The model is built to avoid harmful results and the company has an internal team that evaluates the model by testing it with a large number of harmful prompts.The latest model Claude 2 performs really well on coding tests like codex human eval and has scored 88% on GSM8k a large set of grade-school maths problems.
Claude’s API is used by a lot of businesses for improving their customer experience with claude2.
Claude vs ChatGPT
We all have used chatGPT.It is a really useful tool for various tasks.Let’s compare the performance of Claude and chatGPT for  the same task
This is a  text related to Indian history, copied from wikipedia and we want to identify the key points in the text.

The English East India Company was founded in 1600. It gained a foothold in India with the establishment of a factory in Masulipatnam on the Eastern coast of India in 1611 and a grant of rights by the Mughal emperor Jahangir to establish a factory in Surat in 1612. In 1640, after receiving similar permission from the Vijayanagara ruler farther south, a second factory was established in Madras on the southeastern coast. The islet of Bom Bahia in present-day Mumbai (Bombay), was a Portuguese outpost not far from Surat, it was presented to Charles II of England as dowry, in his marriage to Catherine of Braganza; Charles in turn leased Bombay to the Company in 1668. Two decades later, the company established a trade post in the River Ganges delta. During this time other companies established by the Portuguese, Dutch, French, and Danish were similarly expanding in the subcontinent.
The company's victory under Robert Clive in the 1757 Battle of Plassey and another victory in the 1764 Battle of Buxar (in Bihar), consolidated the company's power, and forced emperor Shah Alam II to appoint it the diwan, or revenue collector, of Bengal, Bihar, and Orissa. The company thus became the de facto ruler of large areas of the lower Gangetic plain by 1773. It also proceeded by degrees to expand its dominions around Bombay and Madras. The Anglo-Mysore Wars (1766–99) and the Anglo-Maratha Wars (1772–1818) left it in control of large areas of India south of the Sutlej River. With the defeat of the Marathas, no native power represented a threat for the company any longer.[357]
The expansion of the company's power chiefly took two forms. The first of these was the outright annexation of Indian states and subsequent direct governance of the underlying regions that collectively came to comprise British India. The annexed regions included the North-Western Provinces (comprising Rohilkhand, Gorakhpur, and the Doab) (1801), Delhi (1803), Assam (Ahom Kingdom 1828) and Sindh (1843). Punjab, North-West Frontier Province, and Kashmir were annexed after the Anglo-Sikh Wars in 1849–56 (Period of tenure of Marquess of Dalhousie Governor General). However, Kashmir was immediately sold under the Treaty of Amritsar (1850) to the Dogra Dynasty of Jammu and thereby became a princely state. In 1854, Berar was annexed along with the state of Oudh two years later.[358]

Chat GPT’s output
Chatgpt output amazon bedrock
Claude’s output
Claude output amazon bedrock

Here we can see ,even though ChatGPT gave detailed key points in the text, Claude's outputs are easy to understand and easy to memorise. Both language model’s have their own pros and cons.
Med-Palm 2
In the previous section we discussed Claude and its capabilities.Now, let’s take a look at Med-Palm 2 , a Large Language Model specialised in providing  answers to medical questions.Med-Palm 2 performs well on benchmark datasets for medical question answering.There is also a multimodal version of medpalm which can be used to analyse medical images other than answering medical questions.

Let’s see an answer generated by Med-Palm 2 for a medical question and compare it with the answer of an actual physician.
medpalm amazon bedrock

We can see that the model’s answers are more detailed than the physician’s answer.

Unlike ChatGPT which is a general purpose chatbot Med-Palm 2 is a specialised chatbot for healthcare,hence we can expect Med-Palm 2 to give more accurate  answers than ChatGPT for medical questions.
Use cases
  • Generating medical reports from medical images like x rays.
  • Assisting healthcare professionals based on patient’s history
  • Personal  health assistant for each patient by fine-tuning the model with patient’s  disease history
  •  Medical transcription, the procedure of converting spoken medical observations into written health records.
Competitors
  • Hippocratic AI is a company that provides AI models for healthcare.Their models outperforms GPT-4 on 105 out of 114 healthcare exams and certifications.
  • GatorTron is a clinical LLM developed by a joint effort between University of florida and NVIDIA.
Gemini
Gemini

We all have heard about GPT-4, one of the most powerful AI models ever created.Google just launched their state of the art multimodal language Gemini that performs better than GPT-4 on many tasks.
Performance comparison
In the image we can see the difference in performance of both models.

Gemini is a new AI model from Google .It is a multimodal language model, meaning it can process and understand not just text, but also images, audio, video, and code. This makes it more versatile and powerful than previous language models, which have been limited to text only.

Gemini was trained on a massive dataset of text and code, as well as images, audio, and video. This dataset includes a variety of different sources, such as books, articles, websites, social media, and code repositories. This allows Gemini to learn a wide range of information and concepts, and to apply that knowledge to new tasks.

One of the things that makes Gemini unique is its ability to reason about the world. This means that Gemini can understand the relationships between different things, and can use that understanding to make inferences and predictions. For example, Gemini can look at a picture of a cat and a dog and infer that they are playing together.

Gemini also has a good understanding of language. This means that Gemini can understand the meaning of words and sentences, and can generate text that is both grammatically correct and meaningful. For example, Gemini can write a poem, or translate a piece of text from one language to another.

There are 3 versions for Gemini:
1.  Gemini Nano, optimal for mobile devices;
2. Gemini Pro, which is built for scaling across a wide range of tasks
3.  Gemini Ultra, the largest model capable of undertaking highly complex tasks

Use cases of Gemini

● Generating text, like poems, code, scripts, musical pieces, email, letters, etc.
● Translating languages
● Writing different kinds of creative content
Conclusion
In this blog we have explored the AWS service bedrock where we can customise large generative models and the different LLMs  .The field of AI is advancing and new technologies are being invented everyday.If you want to stay updated about  AI checkout other blogs in  our website for more interesting blogs like this.I hope you learned something new and enjoyed our blog.
DISCOVER MORE. CONNECT WITH US!

Intrigued by what you have read? Dive deeper and stay ahead with the latest insights and trends. We are here to answer your questions and help you explore further.