Saturday, June 29, 2024

Trying some prompts, listing all models and trying embeddings model of Google's Generative AI package

View All Articles on Large Language Models: Lessons in Technology
Step 1: Create an API key for free by logging into Google AI Studio 

A:

B:
C:
D:
E:
F: Your free API key is created. Copy it and save it somewhere.

Trying a couple of things...

import google.generativeai as genai API_KEY = 'A...o' genai.configure(api_key=API_KEY) model = genai.GenerativeModel() response = model.generate_content('Teach me about how an LLM works') print(response.text) **Understanding Large Language Models (LLMs)** **Introduction:** LLMs are advanced machine learning models trained on vast amounts of text data. They can generate human-like text, translate languages, write different types of content, and perform various other text-related tasks. **Working Principle:** LLMs are trained on billions of words of text using a technique called transformer neural networks. These networks process sequential data and learn the relationships between words and phrases within the text. **Training Process:** 1. **Massive Data Collection:** LLMs are trained on enormous datasets of text from various sources, such as books, articles, news, and social media posts. 2. **Tokenization:** The text is broken down into individual words and phrases called "tokens." 3. **Encoding:** Tokens are converted into numerical representations using embedding techniques. 4. **Transformer Architecture:** The transformer neural network processes the encoded tokens, identifying patterns and learning relationships within the text. 5. **Parameter Optimization:** The model adjusts its internal parameters (weights and biases) to minimize a loss function, which measures how well it predicts the next words in the text. 6. **Fine-tuning:** After general training, the LLM can be fine-tuned for specific tasks, such as language translation or content generation. **Capabilities:** * **Text Generation:** LLMs can create original, fluent, and grammatically correct text in response to a given prompt. * **Language Translation:** They can translate text from one language to another with high accuracy. * **Question Answering:** LLMs can extract information from text and answer questions related to the content. * **Summarization:** They can condense large amounts of text into concise and informative summaries. * **Content Creation:** LLMs can generate various types of content, including articles, stories, poems, and website copy. **Applications:** * **Natural Language Processing (NLP):** Sentiment analysis, text classification, chatbots * **Content Generation:** Creative writing, marketing materials, news articles * **Education:** Language learning, essay writing assistance * **Research:** Literature analysis, data extraction * **Customer Service:** Automated response systems, chat support **Limitations:** * **Bias:** LLMs can exhibit biases present in their training data. * **Factual Errors:** They are not immune to factual errors in the sources they are trained on. * **Limited Contextual Understanding:** They may struggle to understand the full context of complex text. * **Ethics:** The use of LLMs raises ethical concerns about authorship, misinformation, and deepfakes.

Listing all models

import pprint for model in genai.list_models(): pprint.pprint(model) Model(name='models/chat-bison-001', base_model_id='', version='001', display_name='PaLM 2 Chat (Legacy)', description='A legacy text-only model optimized for chat conversations', input_token_limit=4096, output_token_limit=1024, supported_generation_methods=['generateMessage', 'countMessageTokens'], temperature=0.25, top_p=0.95, top_k=40) Model(name='models/text-bison-001', base_model_id='', version='001', display_name='PaLM 2 (Legacy)', description='A legacy model that understands text and generates text as an output', input_token_limit=8196, output_token_limit=1024, supported_generation_methods=['generateText', 'countTextTokens', 'createTunedTextModel'], temperature=0.7, top_p=0.95, top_k=40) Model(name='models/embedding-gecko-001', base_model_id='', version='001', display_name='Embedding Gecko', description='Obtain a distributed representation of a text.', input_token_limit=1024, output_token_limit=1, supported_generation_methods=['embedText', 'countTextTokens'], temperature=None, top_p=None, top_k=None) Model(name='models/gemini-1.0-pro', base_model_id='', version='001', display_name='Gemini 1.0 Pro', description='The best model for scaling across a wide range of tasks', input_token_limit=30720, output_token_limit=2048, supported_generation_methods=['generateContent', 'countTokens'], temperature=0.9, top_p=1.0, top_k=None) Model(name='models/gemini-1.0-pro-001', base_model_id='', version='001', display_name='Gemini 1.0 Pro 001 (Tuning)', description=('The best model for scaling across a wide range of tasks. This is a stable ' 'model that supports tuning.'), input_token_limit=30720, output_token_limit=2048, supported_generation_methods=['generateContent', 'countTokens', 'createTunedModel'], temperature=0.9, top_p=1.0, top_k=None) Model(name='models/gemini-1.0-pro-latest', base_model_id='', version='001', display_name='Gemini 1.0 Pro Latest', description=('The best model for scaling across a wide range of tasks. This is the latest ' 'model.'), input_token_limit=30720, output_token_limit=2048, supported_generation_methods=['generateContent', 'countTokens'], temperature=0.9, top_p=1.0, top_k=None) Model(name='models/gemini-1.0-pro-vision-latest', base_model_id='', version='001', display_name='Gemini 1.0 Pro Vision', description='The best image understanding model to handle a broad range of applications', input_token_limit=12288, output_token_limit=4096, supported_generation_methods=['generateContent', 'countTokens'], temperature=0.4, top_p=1.0, top_k=32) Model(name='models/gemini-1.5-flash', base_model_id='', version='001', display_name='Gemini 1.5 Flash', description='Fast and versatile multimodal model for scaling across diverse tasks', input_token_limit=1048576, output_token_limit=8192, supported_generation_methods=['generateContent', 'countTokens'], temperature=1.0, top_p=0.95, top_k=64) Model(name='models/gemini-1.5-flash-001', base_model_id='', version='001', display_name='Gemini 1.5 Flash 001', description='Fast and versatile multimodal model for scaling across diverse tasks', input_token_limit=1048576, output_token_limit=8192, supported_generation_methods=['generateContent', 'countTokens', 'createCachedContent'], temperature=1.0, top_p=0.95, top_k=64) Model(name='models/gemini-1.5-flash-latest', base_model_id='', version='001', display_name='Gemini 1.5 Flash Latest', description='Fast and versatile multimodal model for scaling across diverse tasks', input_token_limit=1048576, output_token_limit=8192, supported_generation_methods=['generateContent', 'countTokens'], temperature=1.0, top_p=0.95, top_k=64) Model(name='models/gemini-1.5-pro', base_model_id='', version='001', display_name='Gemini 1.5 Pro', description='Mid-size multimodal model that supports up to 1 million tokens', input_token_limit=2097152, output_token_limit=8192, supported_generation_methods=['generateContent', 'countTokens'], temperature=1.0, top_p=0.95, top_k=64) Model(name='models/gemini-1.5-pro-001', base_model_id='', version='001', display_name='Gemini 1.5 Pro 001', description='Mid-size multimodal model that supports up to 1 million tokens', input_token_limit=2097152, output_token_limit=8192, supported_generation_methods=['generateContent', 'countTokens', 'createCachedContent'], temperature=1.0, top_p=0.95, top_k=64) Model(name='models/gemini-1.5-pro-latest', base_model_id='', version='001', display_name='Gemini 1.5 Pro Latest', description='Mid-size multimodal model that supports up to 1 million tokens', input_token_limit=2097152, output_token_limit=8192, supported_generation_methods=['generateContent', 'countTokens'], temperature=1.0, top_p=0.95, top_k=64) Model(name='models/gemini-pro', base_model_id='', version='001', display_name='Gemini 1.0 Pro', description='The best model for scaling across a wide range of tasks', input_token_limit=30720, output_token_limit=2048, supported_generation_methods=['generateContent', 'countTokens'], temperature=0.9, top_p=1.0, top_k=None) Model(name='models/gemini-pro-vision', base_model_id='', version='001', display_name='Gemini 1.0 Pro Vision', description='The best image understanding model to handle a broad range of applications', input_token_limit=12288, output_token_limit=4096, supported_generation_methods=['generateContent', 'countTokens'], temperature=0.4, top_p=1.0, top_k=32) Model(name='models/embedding-001', base_model_id='', version='001', display_name='Embedding 001', description='Obtain a distributed representation of a text.', input_token_limit=2048, output_token_limit=1, supported_generation_methods=['embedContent'], temperature=None, top_p=None, top_k=None) Model(name='models/text-embedding-004', base_model_id='', version='004', display_name='Text Embedding 004', description='Obtain a distributed representation of a text.', input_token_limit=2048, output_token_limit=1, supported_generation_methods=['embedContent'], temperature=None, top_p=None, top_k=None) Model(name='models/aqa', base_model_id='', version='001', display_name='Model that performs Attributed Question Answering.', description=('Model trained to return answers to questions that are grounded in provided ' 'sources, along with estimating answerable probability.'), input_token_limit=7168, output_token_limit=1024, supported_generation_methods=['generateAnswer'], temperature=0.2, top_p=1.0, top_k=40)

Getting Embeddings for Input Text

response = genai.generate_embeddings(model="models/embedding-gecko-001", text='Hello World!') print(response) {'embedding': [-0.020664843, 0.0005969583, 0.041870195, ..., -0.032485683]}
Tags: Technology,Large Language Models,

No comments:

Post a Comment