Video summary
Gen AI Course | Gen AI Tutorial For Beginners
Main summary
Key takeaways
Main ideas & lessons
-
Purpose of the mini course
- Start with GenAI fundamentals
- Learn LangChain (a Python framework for building GenAI apps)
- Build two end-to-end GenAI projects:
- Project 1 (Finance/Equity News Research Tool): uses a commercial GPT model
- Project 2 (Retail Q&A Tool): uses an open-source LLM model
-
Generative AI vs Non-Generative AI
- Non-generative AI: uses existing data to make decisions/classifications (examples)
- Chest X-ray → pneumonia detection
- Credit history → loan approval decision
- Key idea: not generating new content—only predicting/deciding.
- Generative AI: creates new content
- Examples: ChatGPT writing text, planning trips, and creating images
- Non-generative AI: uses existing data to make decisions/classifications (examples)
-
Evolution of AI approaches
- Statistical Machine Learning
- Example: predict home price using features like area, bedrooms, age
- Works well with tabular structured data (houses).
- Deep Learning / Neural Networks
- Needed when features are complex/implicit (example: image recognition)
- Cat vs dog: pixels are unstructured, making manual feature definition difficult.
- Recurrent Neural Networks (RNN)
- Motivation: language tasks like translation
- Uses a loop: output from the previous word influences the next step.
- Language Models (next-word prediction)
- Autocomplete behavior (e.g., Gmail/ChatGPT-like)
- Trained to predict the next word given a sequence
- Uses large corpora (Wikipedia/news/books)
- Statistical Machine Learning
-
Self-supervised learning
- Training setup: create training pairs from raw text by masking/filling missing words
- Benefit: doesn’t require labeled datasets for language model training
-
LLMs and Transformers
- LLM size described via parameters (network weights)
- Key breakthrough: “Attention is all you need”
- Introduces the Transformer architecture
- Model families mentioned:
- Text: GPT (OpenAI), BERT (Google mentioned), etc.
- Image: Stable Diffusion / DALL·E-style concepts
- Text-to-video: Sora (example)
-
Analogy-based understanding
- “Stochastic parrot” analogy (language model)
- Predicts next words based on probability + randomness
- Doesn’t “understand” like humans
- LLM analogy (more powerful “parrot” trained on global data)
- Trained on huge datasets across many domains
- Reinforcement Learning with Human Feedback (RLHF)
- Humans help reduce toxic/undesirable outputs
- “Stochastic parrot” analogy (language model)
-
Embeddings & Vector Databases
- Embeddings: numeric vector representation of text that captures meaning
- Enables operations like vector arithmetic (classic examples referenced)
- Vector database: stores embeddings and supports semantic search
- Why traditional SQL isn’t sufficient:
- With millions of vectors, naive similarity search becomes too slow
- Technique mentioned:
- Locality Sensitive Hashing (LSH) to speed up approximate nearest-neighbor search
- Benefits of vector DB:
- Faster search
- Efficient storage/retrieval for semantic matching
-
Retrieval-Augmented Generation (RAG)
- Problem: LLM knowledge may be insufficient or misaligned with private/custom data
- RAG approach (open-book analogy):
- Instead of fully training/fine-tuning, retrieve relevant documents at query time
- Generate an answer grounded in retrieved sources
- Core idea: the LLM uses a database + retrieval step before answering
-
LLM app architecture (“brain + body”)
- LLM = “brain” (knowledge model)
- Backend/server = “body” (API + retrieval + orchestration)
- Hosting options:
- Commercial: OpenAI / cloud APIs
- Cloud alternatives mentioned: Azure OpenAI Service, AWS Bedrock
- Cost consideration:
- If commercial models get too expensive, switch to open-source models
-
LangChain as the tooling framework
- Goal: simplify building LLM apps with:
- Model integration (commercial or open-source)
- Cloud/provider integration
- Retrieval and data connectors
- Additional libraries mentioned:
- Hugging Face Transformers, PyTorch, TensorFlow, etc.
- Goal: simplify building LLM apps with:
Methodologies & step-by-step processes (detailed bullets)
A) End-to-end GenAI app building blocks (conceptual pipeline)
- Choose a model (commercial or open-source)
- Choose a cloud/provider for hosting (e.g., Azure, AWS Bedrock, OpenAI)
- Use a framework like LangChain
- If you need grounded answers over your data:
- Use embeddings
- Store embeddings in a vector database
- Retrieve relevant chunks at query time
- Use RAG to generate answers based on retrieved context
B) LangChain fundamentals workflow (as demonstrated)
1) Create a basic LLM chain (restaurant name generator)
- Install:
langchainopenai
- Steps:
- Configure API key via environment variables
- Create an OpenAI LLM object
- Use
temperatureto control creativity
- Use
- Create a PromptTemplate
- Parameter example:
cuisine
- Parameter example:
- Create an LLMChain
- Combine prompt template + LLM
- Run the chain with an input cuisine
2) Build multi-step outputs using sequential chains
- Use two chains:
- Chain 1: produce restaurant name
- Chain 2: produce menu items given the restaurant name/cuisine
- Use:
- SimpleSequentialChain (single output)
- SequentialChain (multiple outputs)
- Run with a cuisine input; fetch both outputs
3) Build UI quickly with Streamlit (POC)
- Install:
streamlit - Create a Streamlit app that:
- Provides a select box for cuisine
- Calls your chain function when selection changes / user triggers action
- Displays:
- restaurant name
- menu items (split comma-separated items, render in UI)
C) LangChain “agents” methodology (tool-using LLMs)
- Problem addressed:
- LLM knowledge is outdated (example: post-2021 facts)
- LLM may need external tools (search, calculators)
- Agent approach:
- Define tools (e.g., Wikipedia, math, Google Search/SERP)
- Initialize an agent with:
- LLM
- Tools
- Agent type described as “zero-shot react” (reasoning: Thought → Action)
- Agent execution:
- For a query:
- agent reasons about needed tool(s)
- calls tools
- synthesizes a final answer
- For a query:
D) Memory methodology in chat apps (LangChain)
- Default chains are stateless
- Add memory:
- Use ConversationBufferMemory to store full conversation history
- Token/cost control:
- Buffer can grow endlessly → use alternatives:
- ConversationBufferWindowMemory (keep only the last K exchanges)
- Result:
- reduces API token cost
- provides limited short-term context
- Buffer can grow endlessly → use alternatives:
E) Project 1: Equity News Research Tool (RAG-style architecture)
(Presented conceptually; built as an end-to-end POC in Streamlit.)
- User workflow:
- User provides news URLs
- User asks questions
- Tool returns an answer + source URLs
- Why not “just use ChatGPT directly” (limitations listed):
- Copy-pasting long articles is tedious
- Need aggregated knowledge across many articles
- Input length limits (word/token limit)
- Architecture (high-level):
- Document Loader
- Load articles from URLs
- Text Splitting
- Split large docs into chunks (token-limit friendly)
- Overlap chunks for context preservation
- Embedding
- Convert chunks to vector embeddings
- Vector Database
- Store embeddings for fast semantic retrieval (example: FAISS/Chroma/“phase” in demos)
- Retrieval QA
- Retrieve relevant chunks for a question
- Generate an answer grounded in retrieved text
- Document Loader
- Proof-of-concept:
- Streamlit UI:
- left: multiple URLs
- right: question input
- output: answer + sources
- Streamlit UI:
F) Chunking + retrieval QA strategy (stuff vs map-reduce)
-
“Stuff” method:
- Retrieve multiple chunks
- Combine them into one prompt
- Single LLM call
- Drawback: may exceed LLM token limits if chunks are too large
-
“Map-Reduce” method:
- Retrieve multiple chunks
- Make separate LLM calls per chunk
- Combine intermediate answers
- Final synthesis LLM call
- Tradeoff:
- avoids context-length issues
- costs more LLM calls
G) Detailed LangChain document processing pipeline (as taught for the projects)
- Document loading:
- Text file loader (TextLoader)
- CSV loader (CSVLoader)
- Unstructured URL loader (for news/article URLs)
- Text splitting:
- Use CharacterTextSplitter as baseline
- Prefer RecursiveCharacterTextSplitter
- Splits using multiple separators in order (e.g.,
\n,\n\n,.,) - Ensures chunks are more consistently under the limit
- Splits using multiple separators in order (e.g.,
- Vector indexing/search:
- Compute embeddings for chunks
- Store embeddings in a vector index/database
- For each user query:
- embed query
- retrieve top-K similar chunks
- Retrieval QA prompting:
- Provide instruction to answer using retrieved chunks
- Provide “sources” (URLs) derived from chunk metadata
H) Project 2: Retail Q&A Tool (SQL generation with few-shot + vector search)
- Domain goal:
- Natural language question → SQL query → run on MySQL → return answer
- Components described:
- LLM for SQL generation
- Example model: Google Palm via LangChain
- SQL database chain
- Generates SQL from question
- Runs SQL and returns result
- LLM for SQL generation
-
Core challenge:
- LLM mistakes (e.g., wrong aggregation like missing multiplication by quantity)
- LLM can hallucinate non-existent columns (e.g., discount start/end dates)
-
Few-shot learning methodology (as implemented):
- Build a dataset of (question, SQL query) examples where the base model failed
- Steps:
- Collect failing queries + correct SQL (“few-shot examples”)
- Create embeddings for few-shot examples (e.g., Hugging Face embeddings)
- Store examples in a vector database (Chroma)
- Use semantic similarity to retrieve top-K relevant few-shot examples given a new user question
- Construct a prompt:
- include instructions (“use only columns from tables below; don’t select *; don’t invent columns”)
- include retrieved few-shot examples
- Use the prompt with the LLM to generate the correct SQL
-
UI:
- Streamlit app:
- text input for user question
- display answer
- option to inspect generated SQL (debugging via
verbose=True)
- Streamlit app:
Speakers / sources featured (identified in subtitles)
- Peter pande (character/name used in the analogy + equity research persona)
- Rocky by / Rocky Bh (story character/name for the equity research scenario)
- Angela (example name in the email/autocomplete explanation)
- Buddy (parrot analogy character for language model/LLM)
- Peter Pande (retold as “Peter Pand in equity research analyst” persona)
- Tony Sharma (retail store manager persona)
- Loki (data analyst persona)
- Peter P (data scientist persona in retail scenario)
- OpenAI (source/provider for GPT / “open AI” mentioned)
- Google (BERT mentioned; Google Sora mentioned; Google Search/SERP API mentioned)
- Meta (Llama mentioned)
- Wikipedia (used as training data example and as a tool)
- LangChain (framework described as course focus)
- Unstructured (library behind Unstructured URL Loader)
- FAISS / Chroma / Pinecone / Milvus (vector database options mentioned; FAISS/Chroma used in demos)
- Gmail (as an example of autocomplete using language modeling)