How To Choose Your LLM
Large language models (LLM) can generate new stories, summarizing texts, and even performing advanced tasks like reasoning and problem solving, which is not only impressive but also remarkable due to their accessibility and easy integration into applications. In this blog, I will provide you with the tools to understand how LLMs work and select the optimal one for your needs.
📚 Tip: Put the LLM in context of what its role is, for example: "You are a travel assistant".
- Summarize
- Classification
- Question Answering
- Code generation
- Content writing
- Instruccion following
- Multilingual Task
- Embedding: translate the text into a vector representation.
📚 Remember: Use prompt engineer to generate desired outputs.
📚 Tip: : If the LLM you need doesn't have the desired language function, try using a multilenguial LLM for translation or Amazon Translate before sending the prompt.
tokens
, are like the individual building blocks that make up words. For example:- In English, a single token is typically around 4 characters long.
- A token is approximately 3/4 of a word.
- 100 tokens equate to roughly 75 words.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import boto3
import json
bedrock_runtime = boto3.client(
service_name='bedrock-runtime',
region_name='us-east-1'
)
model_id = "ai21.j2-ultra-v1"
prompt="Hola Mundo"
kwargs = {
"modelId": model_id,
"contentType": "application/json",
"accept": "*/*",
"body": "{\"prompt\":\""+ prompt +"\",\"maxTokens\":200,\"temperature\":0.7,\"topP\":1,\"stopSequences\":[],\"countPenalty\":{\"scale\":0},\"presencePenalty\":{\"scale\":0},\"frequencyPenalty\":{\"scale\":0}}"
}
response = bedrock_runtime.invoke_model(**kwargs)
1
2
3
response_body = json.loads(response.get("body").read())
completion = response_body.get("completions")[0].get("data").get("text")
print(completion)
1
Bonjourno! How can I assist you today?
1
2
tokens_prompt = response_body.get('prompt').get('tokens')
df_tokens_prompt = json_normalize(tokens_prompt)[["generatedToken.token"]]
1
2
tokens_completion = response_body.get("completions")[0].get('data')["tokens"]
df_tokens_completion = json_normalize(tokens_completion)[["generatedToken.token"]]
Provider | Model | Supported use cases | Languages | Max tokens Context Window |
---|---|---|---|---|
Anthropic | Claude v2 | Thoughtful dialogue, content creation, complex reasoning, creativity, and coding | English and multiple other languages | ~100k |
Anthropic | Claude v1.3 | Text generation, Conversational, Coding | English and multiple other languages | ~100k |
Cohere | Command | Chat, text generation, text summarization. | English | 4K |
AI21 Labs | Jurassic-2 Ultra | Question answering, summarization, draft generation, advanced information extraction, ideation for tasks requiring intricate reasoning and logic. | English, Spanish, French, German, Portuguese, Italian, Dutch | 8,192 |
AI21 Labs | Jurassic-2 Mid | Question answering, summarization, draft generation, advanced information extraction, ideation. | English, Spanish, French, German, Portuguese, Italian, Dutch | 8,192 |
Amazon | Titan Text Generation 1 (G1)- Lite | Open-ended text generation, brainstorming, summarization, code generation, table creation, data formatting, paraphrasing, chain of thought, rewrite, extraction, Q&A, and chat. | English | 4K |
Amazon | Titan Text Generation 1 (G1) - Express | Retrieval augmented generation, open-ended text generation, brainstorming, summarization, code generation, table creation, data formatting, paraphrasing, chain of thought, rewrite, extraction, Q&A, and chat. | 100+ languages | 8K |
Amazon | Titan Embeddings | Translates text into a numerical representation, Text retrieval, semantic similarity, and clustering. | 25+ languages | 8K |
Meta | Llama-2-13b-chat | Assistant-like chat | English | 128K |
- The LLM’s mission in the application: what problem will the LLM help me to solve?
- The language: Do I need the LLM to understand in multiple languages?
- Length Of Context Window: The amount of text in the input request and generated output.
- Pricing: Where I need to know the cost of the LLM that fits my needs and also ask myself: Are the LLMs available sufficient for what I need? If not, do I need to do fine-tuning?
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.