AI Handbook — From Zero to Hero
Table of Contents
1. Large Language Models
What are LLMs?
Large Language Models are AI systems trained on massive text data to understand and generate human-like text. Examples: GPT-4, Gemini, Claude, Llama.
How LLMs Work
- Tokenization: Breaking text into tokens (words/subwords)
- Embeddings: Converting tokens to numerical vectors
- Attention: Learning relationships between tokens
- Generation: Predicting next token based on context
Key Concepts
- Temperature: Controls randomness (0 = deterministic, 1 = creative)
- Tokens: Units of text (1 token ≈ 0.75 words)
- Context Window: Maximum tokens the model can process
- Fine-tuning: Customizing model for specific tasks
2. Prompt Engineering
Zero-Shot Prompting
Classify the following text as positive, negative, or neutral:
"The food was great and the service was excellent."
Answer: positive
Few-Shot Prompting
Classify the text as positive, negative, or neutral:
Text: "The food was great" → Positive
Text: "The service was terrible" → Negative
Text: "It was okay" → Neutral
Text: "I loved it" →
Chain-of-Thought Prompting
Solve this step by step:
A store has 100 apples. They sell 30% on Monday and 20% of the remaining on Tuesday. How many apples are left?
Step 1: Monday sales = 100 * 0.30 = 30 apples
Step 2: Remaining after Monday = 100 - 30 = 70 apples
Step 3: Tuesday sales = 70 * 0.20 = 14 apples
Step 4: Remaining after Tuesday = 70 - 14 = 56 apples
Answer: 56 apples
3. API Development
import openai
def chat_with_gpt(prompt):
response = openai.ChatCompletion.create(
model="gpt-4",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prompt}
],
temperature=0.7
)
return response.choices[0].message.content
# Usage
answer = chat_with_gpt("What is data science?")
print(answer)
4. RAG Systems
What is RAG?
Retrieval-Augmented Generation (RAG) combines retrieval (searching a knowledge base) with generation (LLM) to provide accurate, up-to-date answers.
RAG Pipeline
- Document Loading: Load PDFs, websites, databases
- Text Splitting: Split documents into chunks
- Embedding: Convert text to vectors
- Vector Store: Store vectors in database
- Retrieval: Search for relevant chunks
- Generation: Generate answer using retrieved context
from langchain.document_loaders import PyPDFLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.embeddings import OpenAIEmbeddings
from langchain.vectorstores import FAISS
# Load document
loader = PyPDFLoader("document.pdf")
documents = loader.load()
# Split text
splitter = RecursiveCharacterTextSplitter(chunk_size=1000)
chunks = splitter.split_documents(documents)
# Create embeddings and vector store
embeddings = OpenAIEmbeddings()
vectorstore = FAISS.from_documents(chunks, embeddings)
# Search
results = vectorstore.similarity_search("What is data science?", k=3)
5. AI Agents
What are AI Agents?
AI agents are autonomous systems that can plan, reason, and use tools to accomplish tasks.
Agent Components
- LLM: The "brain" of the agent
- Tools: Functions the agent can use
- Memory: Short-term and long-term storage
- Planning: Breaking tasks into steps
from langchain.agents import initialize_agent
from langchain.llms import OpenAI
from langchain.tools import Tool
# Define tools
tools = [
Tool(
name="Search",
func=search_web,
description="Search the web for information"
),
Tool(
name="Calculator",
func=calculate,
description="Perform mathematical calculations"
)
]
# Initialize agent
llm = OpenAI(temperature=0)
agent = initialize_agent(tools, llm, agent="zero-shot-react-description")
# Run agent
result = agent.run("What is the population of India divided by 2?")
6. AI Projects for Resume
ChatGPT Clone
Build a chatbot using OpenAI API
RAG System
Build a document Q&A system
AI Agent
Build an agent that can use tools
Prompt Engineering Portfolio
Showcase prompt engineering skills
7. AI Interview Questions
Q: What is the difference between AI, ML, and Deep Learning?
A: AI is the broad field of intelligent systems. ML is a subset of AI that learns from data. Deep Learning is a subset of ML using neural networks.
Q: What is prompt engineering?
A: The art of crafting effective prompts to get desired outputs from LLMs. Includes techniques like zero-shot, few-shot, and chain-of-thought.
Q: What is RAG?
A: Retrieval-Augmented Generation combines searching a knowledge base with LLM generation to provide accurate, up-to-date answers.
Download AI Handbook PDF
Get the complete AI Handbook as a free PDF. Enter your email to receive the download link.
Start Learning with DSWallah
Join 300+ students who transformed their careers with DSWallah. IIT-certified mentor, 50+ real projects, placement support.
WhatsApp for Free Demo →