---
title: 'AI Engineer Full Course 2027 | Learn AI, Machine Learning, & AI Agent Development | Simplilearn'
source: 'https://youtube.com/watch?v=VGFGHSc__E8'
video_id: 'VGFGHSc__E8'
date: 2026-11-15
duration_sec: 32285
channel: 'Simplilearn'
---

# AI Engineer Full Course 2027 | Learn AI, Machine Learning, & AI Agent Development | Simplilearn

> Source: [AI Engineer Full Course 2027 | Learn AI, Machine Learning, & AI Agent Development | Simplilearn](https://youtube.com/watch?v=VGFGHSc__E8)

## Summary

This comprehensive course by Simplilearn provides a complete roadmap for becoming an AI engineer, covering everything from foundational concepts to advanced topics like deep learning, reinforcement learning, and building LLM-based chatbots. It includes practical tutorials on TensorFlow, Keras, and various AI applications, making it suitable for beginners and professionals looking to transition into AI.

### Key Points

- **Introduction to AI Engineering** [00:13] — AI engineering involves designing, building, and deploying intelligent systems. The course aims to teach skills for one of the fastest-growing technology careers.
- **Why AI Engineering is Important in 2026** [03:20] — Companies want products that can think faster, understand users, and automate tasks. AI engineering is a career of the future because professionals can turn smart technology into real products.
- **What is AI Engineering?** [04:50] — AI engineering is the work of building smart systems that can learn from data, understand text, images, or speech, and help people solve problems faster. The key is 'building'—not just theory.
- **AI Engineer vs Data Scientist vs ML Engineer** [05:40] — A data scientist studies data and finds patterns. An ML engineer focuses on making models work in real systems. An AI engineer works across the big picture, building, connecting, deploying, and improving AI-powered solutions.
- **Types of AI in 2026** [06:17] — Prediction-based AI (fraud detection), language-based AI (chat, search), vision-based AI (image analysis), and speech-based AI (speech-to-text). These are used in healthcare, finance, retail, and manufacturing.
- **Choosing a Specialization** [07:24] — Don't try to learn everything at once. Build a strong base first, then go deeper into one area that matches the problems you enjoy solving. This makes learning faster and projects stronger.
- **Key AI Domains: NLP, Computer Vision, Robotics** [08:04] — NLP involves working with human language (chat, translation, sentiment analysis). Computer vision focuses on images and video (object detection, quality inspection). Robotics combines software with physical machines.
- **How to Pick a Specialization** [09:12] — Start with your interest. If you enjoy words, choose NLP. If you enjoy images, choose computer vision. If you like machines and sensors, choose robotics. Choose the field where your curiosity stays strong even when it gets difficult.
- **Finding Job Opportunities** [11:09] — AI jobs are in startups, large tech firms, healthcare, finance, retail, and consulting. Use major job platforms, company career pages, and startup-focused platforms like Wellfound.
- **Top Resources for Job Hunting** [12:14] — LinkedIn is strong for job search. Company career pages are important. Wellfound is useful for startup roles. Kaggle and Devpost help build visibility through competitions and hackathons.
- **Building a Resume and Online Presence** [12:42] — A strong AI resume should show skills, tools, projects, outcomes, and links to real work. LinkedIn recommends adding relevant skills. GitHub matters—use a profile readme and pin important repositories.
- **Networking Tips** [13:19] — Stay active on LinkedIn by sharing project learnings. Use skills endorsements and assessments. Participate in hackathons on Devpost and Kaggle competitions to build connections.
- **Future-Proofing Your Career** [13:58] — AI changes quickly. Stay curious and update skills steadily. The World Economic Forum places AI, information processing, and robotics among major forces changing jobs.
- **Continuous Learning Strategies** [14:39] — Keep one small weekly habit (follow GitHub trends, check Hugging Face). Learn by building—small experiments help more than reading. Keep learning focused—pick one area and stay with it.
- **Research and Community** [15:42] — Engage with arXiv for new papers. Hugging Face Hub hosts over 2 million models and 500,000 datasets. Kaggle remains a strong learning community.
- **2026 Success Action Plan** [16:51] — Don't wait for the perfect time. Start small and keep moving forward. In the first 1-2 months, focus on Python and statistics. Next 2 months, learn ML basics and build small projects. Then specialize and build a portfolio.
- **Introduction to AI and Machine Learning** [19:06] — AI is the intelligence displayed by machines. Machine learning provides systems the ability to learn from experience without being explicitly programmed. Data science is an umbrella term that encompasses data analytics, data mining, and ML.
- **Relationship Between AI, ML, and Data Science** [25:14] — Data gathering and transformation come under data science. Machine learning techniques (supervised/unsupervised) are used for predictions. Deep learning is a subfield of ML using neural networks. AI combines predictions and insights to perform actions.
- **Traditional Programming vs Machine Learning** [30:04] — In traditional programming, you hardcode decision rules. In ML, you train a model with data to learn the relationship between input and output. The trained model is evaluated against test data.
- **Machine Learning Techniques** [31:50] — Classification, categorization, clustering, trend analysis, anomaly detection, visualization, and decision making.
- **Real-Time Applications of ML** [34:17] — Image processing (face tagging, OCR), robotics (humanoid robots), data mining (fraud detection), video games (Pokemon Go), text analysis (spam filtering, sentiment analysis), and healthcare (disease diagnosis).
- **8-Month AI Engineer Plan** [37:54] — Month 1: CS fundamentals and Python. Month 2: Data structures and algorithms. Month 3: Version control, SQL, and data manipulation. Month 4: Statistics for AI. Month 5: EDA and machine learning. Month 6: MLOps and projects. Month 7: Deep learning. Month 8: NLP or computer vision.
- **Why Reinforcement Learning?** [47:08] — Training a model requires a lot of data which might not always be available. Reinforcement learning allows machines to learn by themselves through trial and error, exploring new solutions.
- **What is Reinforcement Learning?** [48:46] — A subbranch of ML that trains a model to return an optimum solution by taking a sequence of decisions by itself. The robot learns the best path by the time taken on each path.
- **Supervised vs Unsupervised vs Reinforcement Learning** [49:26] — Supervised learning uses labeled data with known outputs. Unsupervised learning uses unlabeled data and finds patterns. Reinforcement learning learns from rewards and errors, following a trial-and-error approach.
- **Key Terms in Reinforcement Learning** [52:15] — Agent (the model being trained), Environment (training situation), Action (possible steps), State (current position), Reward (feedback), and Policy (determines how the agent behaves).
- **Markov Decision Process** [56:21] — A reinforcement learning policy used to map a current state to an action where the agent continuously interacts with the environment to produce new solutions and receive rewards.
- **Reinforcement Learning Demo: Tic-Tac-Toe** [59:50] — A Python demo using Anaconda and Jupyter Notebook. The model plays against itself to learn. Training 50,000 rounds takes about 5 minutes. The reward system and action selection are key.
- **What is Q-Learning?** [01:20:34] — A reinforcement learning policy that fills the next best action given a current state. It chooses actions at random and aims to maximize the reward.
- **Important Terms in Q-Learning** [01:22:24] — State (current position), Action (step taken), Reward (positive or negative), Episodes (terminating state), Q-values (how good an action is), and Temporal difference (formula to find Q-value).
- **Steps in Q-Learning** [01:25:01] — 1. Create an initial Q-table with all values zero. 2. Choose an action and perform it. 3. Update values in the table. 4. Get the reward and calculate the Q-value using the Bellman equation. 5. Continue until the table is filled or an episode ends.
- **Q-Learning Demo: Shortest Path** [01:27:52] — A Python demo using Q-learning to find the shortest path between two points. The agent iterates 1000 times, using a reward table and Bellman's equation.
- **Introduction to Deep Learning** [01:42:25] — Deep learning is a subset of machine learning that uses neural networks. It works with unstructured data like images, voice, and text. Feature extraction happens automatically.
- **What are Neural Networks?** [01:48:12] — Neural networks are based on biological neurons. They simulate the human brain using artificial neurons. Inputs are multiplied by weights, a bias is added, and an activation function decides the output.
- **What is a Perceptron?** [01:49:50] — A perceptron is a fundamental unit of neural networks. It can be a single neuron used for binary classification. It takes inputs, multiplies by weights, adds a bias, and passes through an activation function.
- **Implementing Logic Gates with Perceptrons** [01:54:19] — In 1943, Warren McCulloch and Walter Pitts implemented AND, OR, and NOR gates using single-layer perceptrons. XOR required a multi-layer perceptron (MLP).
- **Types of Neural Networks** [01:59:25] — Artificial Neural Networks (ANN), Convolutional Neural Networks (CNN) for image processing, Recurrent Neural Networks (RNN) for speech and text, Deep Neural Networks, and Deep Belief Networks.
- **Applications of Deep Learning** [02:00:24] — Gaming (AlphaGo), generative adversarial networks for synthesizing images/music, autonomous cars, robots (Sophia), and medical diagnostics (cancer detection).
- **How Neural Networks Identify Images** [02:03:28] — Images are represented as pixel values. A 28x28 image has 784 pixels. The neural network is trained to identify patterns in these pixels to classify images (e.g., square, circle, triangle).
- **Activation Functions** [02:10:54] — Activation functions (ReLU, sigmoid) decide whether a neuron should fire. They take the weighted sum as input and output a value (0 or 1).
- **Cost Function and Backpropagation** [02:11:48] — The cost function measures the difference between predicted and actual output. Backpropagation feeds the error back to adjust weights and biases. Gradient descent optimization minimizes the cost function.
- **Introduction to TensorFlow** [02:16:32] — TensorFlow is an open-source platform by Google for deep learning. It uses tensors (multi-dimensional arrays) and graphs for computation. It runs on CPUs and GPUs.
- **MNIST Database** [02:21:22] — A collection of 70,000 handwritten digits (55,000 training, 10,000 test, 5,000 validation). It's the 'hello world' of deep learning, with built-in utility functions.
- **TensorFlow Code for MNIST** [02:26:08] — Import TensorFlow, load MNIST with one-hot encoding, create placeholders and variables, build a softmax model, define loss and optimizer, run a session for 1000 iterations, and evaluate accuracy (around 91%).
- **TensorFlow Object Detection API** [02:52:35] — Use a pre-trained model (SSD with MobileNet) to detect objects in videos. The model is frozen and imported. It detects objects frame by frame, drawing boxes and labels.
- **Introduction to Convolutional Neural Networks (CNN)** [03:03:43] — CNNs are feed-forward neural networks used for image analysis. They use convolution operations to detect patterns. Key layers: convolution, ReLU, pooling, and fully connected.
- **Pioneer of CNN: Yann LeCun** [03:06:11] — Yann LeCun, director of Facebook AI research, built the first CNN called LeNet in 1988 for character recognition.
- **Convolution Operation** [03:08:01] — Every image is represented as arrays of pixel values. A filter matrix slides over the image, computing dot products to detect patterns. This reduces the image to a convolved feature map.
- **ReLU Layer** [03:15:31] — Performs elementwise operation, setting negative pixels to zero. This introduces nonlinearity to the network.
- **Pooling Layer** [03:17:56] — Downsampling operation that reduces dimensionality. Max pooling with a 2x2 filter and stride of 2 reduces the feature map size.
- **Flattening and Fully Connected Layer** [03:21:17] — Flattening converts 2D arrays into a single linear vector. This becomes the input to a fully connected layer for classification.
- **CNN Use Case: CIFAR-10** [03:25:02] — Classify images across 10 categories (ship, frog, deer, bird, airplane, automobile, cat, dog, horse, truck) using a CNN in TensorFlow/Keras.
- **One-Hot Encoding** [03:31:39] — Converts labels into a vector of 10 values (0 or 1). For example, 'cat' might be represented as [0,0,0,1,0,0,0,0,0,0].
- **Loss Function and Optimizer** [03:53:47] — Cross-entropy loss measures the error. The Adam optimizer is used for training. The learning rate is a key hyperparameter.
- **Deep Learning Applications** [04:05:00] — Predictions (rain, earthquakes), speech comprehension, image recognition, and real-time bidding for advertising.
- **Why Deep Learning is Important** [04:07:34] — Works with unstructured data, handles complex operations, automatic feature extraction, and achieves best performance with large data.
- **Neuron Operations** [04:10:10] — Product of each input and weight is found, sum of weighted products is computed, a bias is added, and the result is passed through an activation function.
- **Cost Function** [04:12:08] — The difference between predicted and actual output. The least cost is obtained by adjusting weights and biases iteratively.
- **Training a Neural Network** [04:16:02] — The predicted output is compared with the actual output using a cost function. Backpropagation sends the error backward to adjust weights. This continues until the cost cannot be reduced further.
- **Deep Learning Platforms** [04:18:14] — Torch (Lua), Keras (Python), TensorFlow (Python), and DL4J (Java/Scala). TensorFlow is the most popular.
- **TensorFlow Details** [04:19:50] — Tensors are vectors or matrices of n dimensions. All computations involve tensors. Architecture: pre-processing data, build a model, train and estimate.
- **TensorFlow Use Case: Adult Income Prediction** [04:21:08] — Use TensorFlow to predict if income is >50K or <=50K based on features like age, education, and occupation. Achieves ~79% accuracy.
- **Introduction to Recurrent Neural Networks (RNN)** [04:49:51] — RNNs handle sequential data by saving the output of a layer and feeding it back into the network. They have memory of previous inputs.
- **Applications of RNN** [04:51:50] — Image captioning, time series prediction (stock prices), natural language processing (sentiment analysis), and machine translation.
- **How RNN Works** [04:54:44] — RNN saves the output of a layer and feeds it back to predict the output of the next layer. The hidden state is a function of the previous hidden state and the current input.
- **Types of RNN** [04:56:20] — One-to-one (vanilla), one-to-many (image captioning), many-to-one (sentiment analysis), and many-to-many (machine translation).
- **Vanishing and Exploding Gradients** [04:57:50] — During training, the slope can be too small (vanishing gradient) or too large (exploding gradient), making training difficult. Solutions include identity initialization, truncating backpropagation, and gradient clipping.
- **Long Short-Term Memory (LSTM)** [05:01:35] — LSTMs are a special kind of RNN capable of learning long-term dependencies. They have a chain-like structure with four interacting layers.
- **LSTM Processing Steps** [05:04:19] — 1. Forget irrelevant parts of the previous state. 2. Selectively update cell state values. 3. Output only certain parts of the cell state.
- **LSTM Use Case: Stock Price Prediction** [05:10:53] — Use an LSTM network to predict Google stock prices based on 2012-2016 data. The model uses 60 time steps and is trained with Keras.
- **Introduction to Keras** [05:43:30] — Keras is a high-level deep learning API written in Python. It uses TensorFlow, PyTorch, etc., as backends for fast computation.
- **Keras Models** [05:46:34] — Sequential model (linear stack of layers) and Functional model (multi-input, multi-output, complex branches).
- **Keras Use Case: Clinical Trial Data** [05:50:44] — Predict the possibility of side effects based on age. Data consists of 2100 patients. The model uses a sequential neural network with dense layers.
- **Saving and Loading Models with Keras** [06:19:49] — Use model.save('mask_detector.model') to save a model. Load it with load_model() for real-time use.
- **Face Mask Detection with Keras** [06:20:05] — Build a Keras model to check if a person is wearing a mask in real-time. Uses MobileNetV2 as a base model, with data augmentation and transfer learning.
- **Neural Network Tutorial** [06:54:18] — Covers what is a neural network, what they can do, how they work, types, and a use case to classify dogs and cats.
- **Activation Functions** [07:03:15] — Sigmoid (0 to 1), threshold (0 or 1), ReLU (max(0, x)), and hyperbolic tangent (-1 to 1).
- **Types of Artificial Neural Networks** [07:08:54] — Feed forward, radial basis function, self-organizing, recurrent, convolution, and modular neural networks.
- **Use Case: Classify Dogs and Cats** [07:14:17] — Use a CNN in Keras to classify photos of dogs and cats. The model uses convolution, max pooling, flatten, and dense layers.
- **Introduction to LLMs and Chatbots** [07:47:34] — LLMs are large language models trained on huge amounts of text. They can generate human-like text. Chatbots use LLMs to respond to queries.
- **What is an LLM?** [07:49:29] — Large language models are trained on huge amounts of text and can generate human-like text. They are an enhanced version of NLP tools.
- **How LLMs Work** [07:50:51] — LLMs break down text into tokens (words or subwords). These tokens are converted into numerical representations (vectors). The model uses attention mechanisms to understand context.
- **Attention Mechanism** [07:54:52] — Based on the paper 'Attention is All You Need' (2017). It uses self-attention and multi-head attention layers. Transformers use encoder and decoder blocks.
- **Types of Chatbots** [07:56:39] — Rule-based chatbots (pre-written scripts) and AI-based chatbots (use LLMs like ChatGPT, Claude, Gemini).
- **Setting Up the Development Environment** [07:59:52] — Use OpenAI API, Jupyter Lab, Streamlit, and LangChain. Need to set up API keys securely.
- **Data Collection and Preparation** [08:02:30] — Collect data in CSV, JSON, or web scraping. Use numpy and pandas to refine data. For this course, use pre-trained models from OpenAI API.
- **Retrieval Augmented Generation (RAG)** [08:04:18] — RAG finds the most relevant keywords from the query, searches through data, and generates contextual answers. It uses chunking, embeddings, and vector search.
- **Zero-Shot Text Classification** [08:07:19] — Using a pre-trained model without additional training to classify new data. For example, using ChatGPT to classify organization-specific issues.
- **Sentiment Analysis with LLMs** [08:10:00] — Determine the emotional tone of text (positive, negative, sad, happy). Use models like DistilBERT for sentiment analysis.
- **Practical Implementation: LLM Chatbot** [08:11:39] — Use LangChain and Streamlit to create a chatbot. Set up OpenAI API key, initialize the LLM, create a conversation chain, and design a simple UI.
- **Creating Digital Clones with HeyGen** [08:29:16] — HeyGen is a tool to create realistic digital avatars. Steps: sign up, choose a plan, create an avatar, record/train, and generate videos.
- **Building an iOS App with AI** [08:40:10] — Use AI tools like Bolt and Expo to build iOS and Android apps without extensive coding. Generate prompts with Claude, build with Bolt, and deploy with Expo.

## Transcript

application, create AI powered solution, automate complex task and develop the skill required for one of the fastest growing technology careers. That is exactly what AI engineering helps you achieve. Hello everyone and welcome to
this AI engineer full course by simply learn. Today, artificial intelligence is transforming almost every industry from healthcare and finance to automation, development. Businesses are not just using AI tools anymore. They are looking
for professionals who can design, build and deploy intelligent AI systems. AI developing machine learning models, building generative AI application, creating AI assistant, working with large language model and solving real
world business problems. With advancement in technologies like genai, agentic AI and automation, learning AI engineering skills can help you prepare for exciting career opportunities in modern technology landscape. In this
artificial intelligence and AI engineering, AI engineer road map, skills, tools and career path, Python programming for AI, data science and learning algorithms and model development, deep learning and neural
networks, natural language processing and large language models, generative AI and prompt engineering, building AI application and chat bots, agentic AI and AI automation, AI tools and framework used by industries, AI
whether you're a beginner, a student, a developer or a data professional or someone looking to transition into AI, this course will help you understand the concepts, tools and skills required to start your AI journey today. By the end
of this course, you will understand how AI systems are built, how modern AI application work and how you can develop the skills needed to become an AI let's get started. Also, if you're interested in building a career in
to check out our professional certificate in AI and machine learning by simply learn. This program helps you build advanced AI skills by covering machine learning, deep learning, gen AI, and AI automation. You will also learn
how to create AI powered application, conversational chatbot, and intelligent solution using modern AI tool. The program includes 12 plus hands-on practical learning experiences and exposure to modern AI tool to help you
explore emerging technologies like Genai, a genic AI, large language models and AI powered automation while building a strong foundation for AI engineering roles with expertled training, hands-on project and career support. This program
helps you develop the skills needed to stay ahead in rapidly evolving AI landscape. So, if you're looking to start or advance your AI career, this expertise and prepare for the future of artificial intelligence. But before we
move on, here's a short quiz to test your knowledge. Which AI technology allow AI system to understand and generate humanlike text? First is database management system, second is large language model, third is operating
system or fourth is network protocols. Comment your answer in the comment section below. So, let us start with the first idea. Why is AI engineering getting so much attention in 2026? Well, the answer is simple. Technology is no
longer just about building apps or websites. Now, companies want products that can think faster, understand users better, and automate tasks and make engineering is becoming such an important career. In 2026, businesses
are looking for people who can build useful, smart systems and not just study them. This is one of the biggest reasons why AI engineering stands out. &gt;&gt; Job reports continue to show strong momentum for AI and data related roles
and technology focused jobs are expected to keep growing in the coming years. So if someone asks you why this is a career of the future, the answer is this professionals who can turn smart technology into real products and real
this career is growing, let's look at the second part and that's about the let's talk about the opportunities and impact. So the opportunities in AI engineering are wide. You can work in healthcare, finance, retail, education,
manufacturing, robotics, entertainment, and even cyber security. Smart tools are now being used in chat support, recommendation systems, fraud detection, and voice tools where image analysis, coding support, and business automation
also play an important role. The impact is also huge. AI engineers help save time, reduce manual work, improve customer experience, and make products more useful. Open source AI projects are also growing fast which means that
learners and builders now have more chances to practice build projects and enter the field. So this field is not just giving strong job opportunities, work in the future. So now that we've seen why this field is growing, let's
understand what AI engineering actually means. In simple words, AI engineering is the work of building smart systems which can learn from data, understand text, images or speech and help people solve problems faster. But the most
important word here is building. This role is not only about learning theory. working tools, apps, and product features. For example, an AI engineer may help build a chatbot for customer support, a recommendation system for
shopping apps, a fraud alert system for banking or image checking feature for healthcare or manufacturing. So the easiest way to explain this role is this. AI engineering is about taking smart technology and making it useful in
clear, let's move on to the next part and understand how it's different from the nearby roles. So now that we know what AI engineering means, let us clear one common confusion. Many people mix up AI engineers, data scientists, and
machine learning engineer. But their focus is different. A data scientist usually works more on studying data, finding patterns, and creating insights. A machine learning engineer focuses more on taking models and making them work
properly inside real systems. An AI engineer on the other hand usually works across the big picture. Building, connecting, deploying and improving AI powered solutions inside products or business tools. So the easiest way to
explain it is this. A data scientist studies the experiments. The machine learning engineer focuses on the model system and the AI engineer helps bring the full smart feature into real use. So now that the difference is clear, let's
the main types of AI and where we can see them in 2026. So now let's talk about the different types of AI in a very simple way. So one type is prediction based AI. This uses past data to predict something like fraud
detection or sales forecasting. Another type is language based AI which works with chat, search, summaries and even writing tools. Then we have vision based AI. This works with images and videos like product inspection or medical
scans. Then we also have speech based AI which can turn speech into text or text into natural sounding voice. So in 2026, these applications are everywhere. In healthcare, AI helps with scans and records. In finance, it helps with
detecting fraud and improve customer support. And in retail, it powers recommendations and smarter planning. In manufacturing, it checks defects using cameras and video tools. So AI is no longer limited to just one industry.
parts of everyday business and technology. So now that we know the and talk about the skills and technologies that you need to learn. So step is choosing a direction. This
and trying to learn everything at once usually leads to confusion. In 2026, the field is growing across language tools, image and video systems, smarter software, robotics and employees continue to use AI in information
processing and automation as a major business trends for the next few years. every topic. It is to build a strong base first and then go deeper into one area that matches the kind of problems that you enjoy solving. So this makes
learning faster projects stronger and your decisions much easier. Now let's move on to the overview of key AI domains like NLP, computer vision and robotics. One major area is NLP which means working with human language. So
this includes things like chat systems, search, translation, sentiment analysis, summarization. Official cloud documentation describes NLP as understand and generate human language. Another major area is computer vision
which focuses on image and video. So this includes object detection, reading text from images, face and landmark detection, quality inspection and video understanding. So this is widely used in healthcare, manufacturing, retail and
security systems. Then there's robotics where software meets a physical machine. This area includes warehouse robots, industrial automation, mobile robots and independently in real environments. So the international federation of robotics
says that AI and the autonomy in robotics is one of the most top global robotics trends for 2026. And beyond these, there are also speech and audio systems and multimodel systems which work across text, image, and audio
together. So this is becoming one of the biggest practical shifts in 2026 because many modern products now combine more than just one type of input. Now let's move on to how to pick a specialization based on your interests. So the easiest
way to choose a specialization is to start with your interest. If you enjoy working with words, search, writing tools and documents, then NLP may be the right fit for you. So if you enjoy images, video design, inspection or
may suit you better. If you like machines, movements, sensors, factory systems or autonomous devices, then robotics could be a strong direction. Now, let us connect that with the 2026 trends. Multimodel systems are becoming
more important because products are increasingly combining text, image, and audio together. Robotics is also becoming more advanced with AI and autonomy becoming highlighted as the top robotics trends for 2026. And across
software development, GitHub's Okro says that AI is reshaping how developers choose and build technology. So a simple rule works well here. Choose the field where your curiosity stays strong even when the topic gets difficult. Trends
keeps you learning long enough to become good at it. Now let's move on to some real life examples of specialized AI career paths. A language focused path should lead to roles which help you build search tools, chat systems,
text analysis features. So these are useful in chatbot support, education, legal work, finance and even enterprise software. A vision focused path could lead to work in medical imaging, smart retail, OCR systems, video analysis or
defect detection in manufacturing. Cloud providers now offer readytouse image and video tools for these exact types of use cases. A robotics focused path could lead to industrial automation, warehouse robotics, autonomous mobile robots, and
smarter factory systems. The robotics industry in 2026 outlook highlights autonomy in new commercial applications as major growth areas and a broader multimodel path could lead to products that combine text, image, audio and
workflow automation in one experience. So that is why specialization is not about choosing the kind of real world problems that you want to solve first. So now that the direction is clear, the next step is finding real opportunities
in 2026. So here the AI jobs are no longer limited to one type of company. They are showing up in startups, large tech firms, healthcare, finance, retail, manufacturing, and consulting. LinkedIn's job pages currently show
roles worldwide, including many internship and entry- level openings, which makes one thing very clear. The demand is real and the market is very search in three places at the same time. First, use major job platforms. Second,
check company career pages directly. And third, look up startup focused platforms because many new AI roles appears earlier than they do on traditional job boards. So that combination gives a much better view on the market. Now let's
move on to top resources for finding job opportunities globally in 2026. So LinkedIn remains one of the most strongest places to search because it supports direct job search, job recommendations and alerts based on
activity. Along with that, company career pages are still important because many roles are posted first there. For startup roles, Wellfound is especially useful because it focuses on tech and startup hiring. So beyond job boards,
Kaggle and Dev post are also valuable in different ways. Kaggle competitions help build visibility through real problem solving and dev post is one of the main places where hackathons are listed and managed. So these may not look like job
projects, referrals, and hiring conversations. Now let's move on to building a resume and online presence for AI engineering. A strong AI resume proof-paced. It should clearly show skills, tools, projects, outcomes, and
links to real work. LinkedIn officially recommends adding relevant skills because that improves how your profile is discovered, and it also allows recruiters to match you to more suitable roles. The open to work setting and job
alerts also helps you improve visibility during job search. GitHub matters just as much. GitHub's own docs recommend using a profile readme showcasing your best projects and pinning important repositories. so that hiring teams can
quickly see your work. A clean GitHub plus a focused LinkedIn profile can say more than just a long resume. Now, let's get some networking tips from LinkedIn to hackathons. Networking works best when it feels natural. A strong start is
to stay active on LinkedIn by sharing project learnings, upgrading skills, and the field. LinkedIn also supports skills and endorsements, assessments, recruiter regular profile activity more useful
competitions are another powerful way to grow. Devost is built around hackathons and Kaggle has beginner friendly getting started competitions designed for people with little or no machine learning background. So these spaces help build
connections at the same time. Now let's learn how you can futureproof your internship path is clear, the next step is making sure that your career stays relevant. So this matters because AI changes quickly. New tools, new
workflows, and new ways of building products keep appearing every few months. GitHub's recent October findings says that AI is reshaping how developers choose and build technology, which shows that this field is not slowing down at
all. At the same time, the World Economic Forum continues to place AI, information processing, robotics among the major forces changing jobs and proofing your career does not mean that you're trying to learn every new thing.
way, staying curious and updating your skills in a very steady way. So the the ones chasing every trend. They're the ones who keep the basics strong and So now that the mindset is clear, let's move on to the next part and look at
feeling overwhelmed. With that being said, let us move on to learn some continuous learning strategies. So a simple strategy works best here. First, you have to keep one small weekly habit. That could be following GitHub trend
reports, checking what is new on a hugging face learn and spending time on one recent topic instead of 10 random ones. GitHub's official reporting shows that AI related development is driving major shifts in software while hugging
face now offers structured courses across language models, agents, audio, vision, robotics, and open-source AI workflows. Second, learn by building. Reading is useful, but small experiments help much more. Try a notebook, mini
feature, or a simple small project whenever a new idea seems practical. competition pages are useful for this because they combine short lessons, real data sets, and hands-on challenges for different skill levels. Third, keep your
learning focused. Pick one area, stay with it for more than one week, and then move on. That is much better than jumping from topic to topic every day. Once the learning strategy is clear, the next question is very obvious. Where do
new ideas and deeper understandings come from? So that brings us to research and community. So here is why engaging with research and AI community is crucial. So with the field which is moving before those ideas become mainstream products.
So archive remains one of the main open access places where new AI and machine learning papers appear with active recent submissions across the AI and machine learning categories. So that does not mean reading every paper. It
directions, benchmarks and problems people are trying to solve. Community matters because learning becomes faster when you're connected to people who are building. Hugging Faces Hub now hosts over 2 million models, 500,000 data
it one of the strongest places to explore practical work, open tools, and collaboration. Kaggle also remains a strong learning community through solutions. So staying connected to research and community is not extra
work. It's one of the easiest ways to stay updated, discover better ideas, and now that this futurep proofing mindset chapter. So, here's your 2026 success action plan. So, now that the full road
map is clear, let us bring everything together into one simple action plan. So, the biggest mistake many people make is waiting for the most perfect time, of confidence before they begin. But careers don't grow in that way. They
grow when you start small and keep moving forward step by step. In 2026, engineering career is not to rush. It's to follow a clear plan, stay consistent, and keep building proof of your skills. So that way, the journey feels practical
and manageable instead of confusing. So here's what a simple timeline can look like. So in the first one or two months, focus on Python, basic statistics, and working in notebooks. So this is not the stage where the goal is not speed, the
goal is comfort. You should be able to read code, write small programs and the next two months, start learning machine learning basics and build two or three small projects. So these projects don't have to be advanced. They just
these show that you can apply what you've learned. After that, spend the next 2 3 months going deeper into the specialization. That could be language based systems, image based systems, robotics or any other direction that
stronger project in that area improving your GitHub and start shaping your resume and LinkedIn profile around the work that you have done. Then begin roles, freelance work or project based opportunities. At the same time, stay
active in communities. Keep learning and keep improving your portfolio and that is how the transition starts becoming real. And this brings us to the final everything before you begin. You do not need the perfect background, the perfect
matters is taking the first step and staying consistent after that. One notebook can become a project, one project can become a portfolio and one that one opportunity can completely change your career path. So do not wait
for someday. Start with one small skill, one lesson and one small project. forward are not the ones who know what they're doing at the beginning. They are start building. And with that, the road map is complete. Now it's time to take
the first step. Introduction of artificial intelligence and machine artificial intelligence and machine learning. able to define artificial intelligence, describe the relationship between
artificial intelligence and data science, define machine learning, machine learning, artificial intelligence, and data science. Describe different machine learning
approaches. Identify the applications of machine learning. Let's understand how the field of artificial intelligence emerged. Let's first understand the reason behind the emergence of AI. Data economy is one
of the factors behind the emergence of AI. It refers to how much data has grown over the past few years and how much more it can grow in the coming years. When you look at this graph, you can clearly understand how the volume of
data has grown. You can see that since 2009, the data volume has increased by 44 times with the help of social websites. The explosion of data has given rise to a new economy and there is a constant battle for ownership of data
between companies to derive benefits from it. Now that you know that data has grown at a rapid pace in the past few years and is going to continue to grow, let's understand the need for AI. As you know,
the increase in data volume has given rise to big data which helps manage huge amounts of data. Data science helps analyze that data. So the science associated with data is going toward a new paradigm where one can teach
machines to learn from data and drive a variety of useful insights giving rise to artificial intelligence. Now you may ask what is artificial intelligence? Artificial intelligence refers to the
intelligence displayed by machines that simulates human and animal intelligence. &gt;&gt; It involves intelligence agents, the autonomous entities that perceive their environment and take actions that maximize their chances of success at a
given goal. Artificial intelligence is a technique that enables computers to technique that enables computers to mimic human intelligence using logic. It is a program that can sense, reason, and act.
Let's look at some of the areas where artificial intelligence is used. Artificial intelligence is redefining industries by providing greater personalization to users and automating processes. One example of artificial
intelligence in practice is self-driving cars. Self-driving cars are computer controlled cars that drive themselves. In these cars, human drivers are never required to take control to safely
operate the vehicle. These cars are also known as autonomous or driverless cars. known as autonomous or driverless cars. Let's see how Apple uses AI. iPhone users can experience the power of Siri, the voice. It simplifies navigating
through your iPhone as it listens to your voice commands to perform tasks. For instance, you can ask Siri to call your friend or to play music. Siri is your friend or to play music. Siri is fun and is extremely convenient to use.
Another example is Google's Alph Go, which is a computer program that plays the board game Go. It is the first computer program to defeat a world champion at the ancient Chinese game of Go. Amazon Echo is another product. It's
a home control chatbot device that responds to humans according to what they are saying. It responds by playing music, movies, and more. If you've got compatible smartome devices, you can tell Echko to dim the lights or turn
appliances on or off. You can use AI and chess. And here is an example of a chess. And here is an example of a concierge robot from IBM called IBM Watson. The IBM Watson AI has typically been in the headlines for composing
music, playing chess, and even cooking food. Let's move ahead and look at some sci-fi movies with a concept of artificial movies with a concept of artificial intelligence. The films featuring AI
reflect the everchanging spectrum of our emotions regarding the machines we have created. Humans are fascinated by the concept of artificial intelligence and this is reflected in the wide range of movies on AI.
Recommendations systems are used by a lot of e-commerce companies. Let's see how they work. Amazon collects data from users and recommends the best product according to the user's buying or shopping pattern.
For example, when you search for a specific product in the Amazon store and add it to your cart, Amazon recommends some relevant products based on your past shopping and searching pattern. So before you buy the selected product, you
get recommendations based on your interest. And there is a possibility that you may also buy the relevant product with the selected product. If not, you have the chance to compare the selected product with the recommended
Now let's move ahead and understand the relationship between artificial intelligence, machine learning, and data science. Even though the terms artificial intelligence, AI, machine learning, and
data science fall in the same domain and are connected to each other, they have their specific applications and meaning. Let's try to understand a little about each of these terms. Artificial intelligence systems mimic or replicate
human intelligence. Machine learning provides systems the ability to automatically learn and improve from the experiences without being explicitly programmed. Data science is an umbrella term that encompasses data analytics,
data mining, machine learning, artificial intelligence, and several other related disciplines. Let's look at the flow diagram and try to understand the relationship between AI, machine learning, and data science.
Interestingly, ML is also an element of artificial intelligence. So the first step is data gathering and data transformation. This step basically comes under data science. Data transformation is the process of
converting data from one format or structure into another format or structure. Data transformation is important to activities such as data management and data integration. After gathering data, we would want to
use the data to make predictions and derive insights. In order to get predictions out of the data set, we use machine learning techniques such as supervised learning or unsupervised learning. On an overview level,
supervised and unsupervised learning are the machine learning techniques used to set. &gt;&gt; Now, you must be thinking where deep learning comes into the picture. Deep learning is a sub field of machine
learning involved with algorithms. It uses artificial neural networks which are modeled on the structure and performance of neurons in the human brain. Deep learning is most effective when there isn't a clear structure to
the data that you can just exploit and build features around. &gt;&gt; Now, the next step in the flow diagram is to get insights from predictions being made. In order to do so, you need to use data analysis, which actually is
the process under data science. Now, when you are done with all of these, you must want your data to perform some actions. This is where AI comes into the picture. Artificial intelligence combines predictions and insights to
perform actions based on the human decision and automated decision. Now let's move ahead and understand the relationship between artificial intelligence, machine learning and data science.
Let's look at the relationship between artificial intelligence and machine learning. Artificial intelligence is the engineering of making intelligent machines and programs. Machine learning provides systems the ability to learn
from past experiences without being explicitly programmed. Machine learning allows machines to gain intelligence thereby enabling artificial thereby enabling artificial intelligence.
between machine learning and data science. Data science and machine learning go hand in hand. Data science helps evaluate data for machine learning algorithms. Data science covers the whole spectrum of data processing while
machine learning has the algorithmic or statistical aspects. Data science is the use of statistical methods to find patterns in the data.
Statistical machine learning uses the same techniques as data science. Data science includes various techniques like statistical modeling, visualization, and pattern recognition. Machine learning focuses on developing algorithms from
focuses on developing algorithms from the data provided by making predictions. So what is machine learning? Machine learning is the capability of an artificial intelligence system to learn by extracting patterns from data. It
usually delivers quicker, more accurate results to help you spot profitable results to help you spot profitable opportunities or dangerous risks. Now you must be curious to understand the features of machine learning.
Machine learning uses the data to detect patterns in a data set and adjust program actions accordingly. Pattern detection can be defined as the classification of data based on knowledge already gained or on
statistical information extracted from the patterns. It focuses on the development of computer programs that can teach themselves to grow and change when exposed to new data by using a method called reinforcement learning. It
uses external feedback to teach the system to change its internal workings in order to guess better next time. It enables computers to find hidden insights using iterative algorithms without being explicitly programmed.
Machine learning uses algorithms that learn from previous data to help produce reliable and repeatable decisions. It automates analytical model building using the statistical and machine learning algorithms that tease patterns
and relationships from data and express them as mathematical equations. Let's understand the different machine learning approaches.
traditional programming and machine learning? In traditional programming, data and program is provided to the computer. It processes them and gives the output. However, the machine learning approach is very different. In
machine learning, algorithms are applied on the given data and output. The result of the applied algorithm and calculations is a learning model that helps machine to learn from the data. In traditional programming, you code the
behavior of the program. But in machine learning, you leave a lot of that to the machine to learn from data. Now, let's first understand the traditional programming approach. Traditionally, you would hardcode the decision rules for a
problem at hand, evaluate the results of the program, and if the results were satisfactory, the program would be deployed in production. If the results were not as expected, one would review the errors, change the program, and
evaluate again. This iterative process continues till one gets the expected result. What is the machine learning approach? In the new machine learning approach, the decision rules are not hardcoded.
The problem is solved by training a model with the training data in order to derive or learn an algorithm that best represents the relationship between the input and the output. This trained model is then evaluated against test data. If
the results were satisfactory, the model would be deployed in production. And if the results are not satisfactory, the training is repeated with some changes. Machine learning techniques. Machine learning uses a number of
theories and techniques from data science. Here are some machine learning techniques. Classification, categorization, clustering, trend analysis, anomaly detection, visualization, and decision making.
Let's look at these techniques. Classification is a technique in which the computer program learns from the data input given to it and then uses observations. Classification is used for predicting
discrete responses. Classification is used when we are training a model to used when we are training a model to predict qualitative targets. Categorization is a technique of organizing data into categories for its
most effective and efficient use. It makes free text searches faster and provides a better user experience. Clustering is a technique of grouping a set of objects in such a way that objects in the same group are most
similar to each other than to those in other groups. It is basically a collection of objects on the basis of similarity and dissimilarity between them. Trend analysis is a technique aimed at
projecting both current and future movement of events through the use of movement of events through the use of time series data analysis. It represents variations of low frequency in a time series. The high and medium frequency
fluctuations being out. Anomaly detection is a technique to identify cases that are unusual within data that is seemingly homogeneous. Anomaly detection can be a key for solving intrusions by indicating a
presence of intended or unintended induced attacks, defects, faults, and so on. Visualization is a technique to present data in a pictorial or graphical format. It enables decision makers to see analytics presented visually. When
data is shown in the form of pictures, it becomes easy for users to understand it. Decisionmaking is a technique or skill that provides you with the ability to influence managerial decisions with data as evidence for those
Now I am sure you have a better understanding of the overview of machine learning. So let's look at some real time applications of machine learning. Artificial intelligence and machine
learning are being increasingly used in various functions such as image various functions such as image processing, robotics, data mining, video games, text analysis, and healthcare. Let's look at each of them in more
Let's look at each of them in more details. So what is image processing? It is a technique to convert an image into a digital format and perform some operations on it so as to induce an enhanced image or to extract some
helpful information from it. Let's look at some of the examples of image processing. Facebook does automatic face tagging by recognizing a face from a previous user's tagged photos. Another example is optional character
recognition which scans printed docs to digitize the text. Self-driving cars are another big example of image processing. Autopilot is an optional drive system for Tesla cars. When autopilot is engaged, cars can self- steer, adjust
speed, detect nearby obstacles, apply the brakes, and park. Now, let's see how robotics uses machine learning. Robots are machines that can be used to do certain jobs. Some of the examples of robotics are where a humanoid robot can
read the emotions of human beings or an industrial robot is used for assembling and manufacturing products. So let's look at some realtime applications of machine learning. Let's see what data mining is. It is the method of analyzing
hidden patterns in data. Let's look at some of the applications of data mining. It is used for anomaly detection to detect credit card fraud and to determine which transactions vary from usual purchasing patterns.
It is also used in market basket analysis which is used to detect which analysis which is used to detect which items are often bought together.
profiles. Machine learning is also applied in many video games in order to give predictions based games in order to give predictions based on data. In a Pokemon Go battle, there
is a lot of data to take into account to correctly predict the winner of a battle. And this is where machine learning becomes useful. A machine learning classifier will predict the result of the match based on this data.
Let's move on to one of the most popular applications of machine learning, which is text analysis. It is the automated process of obtaining information from text. One example of text analysis is spam filtering which is used to detect
spam in emails. Another example is sentimental analysis which is used for classifying an opinion as positive, negative or neutral. It detects public sentiment in Twitter feed or filters customer complaints. It is also used for
information extraction such as extracting specific data address, extracting specific data address, keyword or entities. There are many applications of machine learning in the healthcare industry
learning in the healthcare industry identifying disease and diagnosis, drug discovery and manufacturing, medical imaging diagnosis and so on. Some of the companies that use machine learning have revolutionized the healthcare industry
revolutionized the healthcare industry are Google DeepMind Health, BioBeats, are Google DeepMind Health, BioBeats, Health Fidelity, and Ginger.io. &gt;&gt; Today, we'll take you through the exciting road map of becoming an AI
engineer. If our content picks your interest and helps fuel your curiosity, don't forget to subscribe to our channel. Hit that bell icon so you never miss an update. Now let's embark on this AI journey together. As artificial
intelligence continues to revolutionalize various industries, AI engineers stand at the forefront of this technological wave. These professionals are essential in crafting intelligence systems that address complex business
challenges. AI projects often stumble due to poor planning, subpar architecture or scalability issues. AI engineers play a crucial role in overcoming these hurdles by merging cuttingedge AI technologies with
strategic business insights. So in this video, we'll guide you through the essentials of becoming an AI engineer. Let's start with the basics. What does an AI engineer do? An AI engineer builds AI models using machine learning
algorithms and deep learning neural networks. These models are pivotal in generating business insights that influence organizational decision making. From developing applications that leverage sentiment analysis for
systems for visual recognition and language translation, the scope of an AI engineer's work is vast and impactful. So to succeed as an AI engineer, you need a blend of technical progress and soft skills. So now let's break down
this 8th month plan. Month one, computer science fundamentals and beginners Python. So before we delve into AI, it's crucial to establish a strong foundation in computer science. This month you should focus on the following topics.
Data representation. Understanding bits and bytes, how text and numbers are stored and a binary number system is foundational for everything in comprehending how computers interpret and process data. Now, next comes
computer networks. Learn the basics of computer networks including IP addresses and internet routing protocols. It's essential to understand how data travels across networks using UDP, TCP and HTTP which form the backbone of the internet
programming basics. Begin with the basics of programming like variables, strings, numbers, conditionals, loops, and algorithm basics. These fundamentals simple programs. Simultaneously, you'll
language for AI. So learn about variables, numbers, strings, lists, dictionaries, sets, pupils, and control structures like if conditionals and for modules. Understand how to create
functions including lambda functions and work with modules by using pip install to add functionality to your projects. Next comes file handling and exceptions. You should also practice reading from and writing to files as well as handling
exceptions to make your programs more robust. finally grabs the basics of classes and objects which are crucial for writing organized and efficient sets the stage for more complex programming tasks that you'll encounter
in the following months. Now in month two, you'll move on to data structure building on the foundations from month one, we'll now del into data structure and algorithm. So familiarize yourself with the concept of bigger notation to
algorithms and data structures. Learn about edits, link list, hash tables, stacks, cues, trees, and graphs. Mastering these structures will allow you to store and manipulate data effectively. Now, next comes algorithms.
You should explore algorithms such as binary search, bubble sort, quick sort, merge sort, and recussion. These are essential for optimizing your code and skills. So, you can dive into inheritance, generators, iterations,
list comprehensions, decorators, multi-threading, and multipprocessing. These topics will enable you to write more efficient and scalable code. So handle complex data operations and enhance your coding efficiency. Now in
month three, you'll move on to version control, SQL and data manipulation. So in the third month, the focus shifts to collaboration and data management. understand the importance of version control systems, especially Git and
GitHub. So learn basic commands such as add, commit, and push. You should also learn how to handle branches, reward changes and understand concepts like invaluable for tracking changes and collaborating with other developers.
Next, pull requests. Master the art of creating and managing pull requests to contribute to collaborative projects. Next, we'll dive into SQL for managing databases. So first we'll start with SQL basics. So learn about relational
databases and how to perform basic queries and then you'll move on to advanced queries. Understand complex query techniques such as CT, subqueries and window functions. And then comes joins and database management. So study
different types of joins like left, right, inner and full jar. You should also learn how to create databases, manage indexes and write stored procedures. Additionally, you'll use numpy and pandas for data manipulation
and learn basic data visualization techniques. This comprehensive skill set will be crucial as you move into more advanced data science topics. So now in statistics for AI. So mathematics and
this month is dedicated to these critical subjects. So first learn about descriptive versus inferial statistics, continuous versus discrete data, nominal versus ordinal data, measures of central tendency like mean, median, mode and
standard deviation. After that understand the basis of probability and delve into normal distribution, correlation and coariance. After which So you can study the central limit theorem, hypothesis testing, p values,
confidence intervals and so on. In parallel, you should also study linear algebra and calculus. So in linear algebra, learn about vectors, matrices, egan values and ean vectors. And in calculus, cover the basics of integral
and differential calculus. So this mathematical foundation is essential for developing and understanding AI models, setting you up for success as you transition into machine learning. Now in month five comes exploratory data
learning. So with a solid foundation in math and statistics, you are now ready to delve into machine learning. Number one, pre-processing. Learn how to handle NA values, treat out layers, perform data normalization, and conduct feature
encoding techniques such as one hot and label encoding. You'll also explore with a focus on regression and classification and learn about linear models like linear and logistical regression and nonlinear models like
decision tree random forest etc. And then understand how to evaluate models using metrics such as mean squared error mean absolute error me for regression and accuracy decision recall etc. Then comes hyperparameter tuning. Learn about
techniques like grid search CV and random search CV for optimizing your unsupervised learning. Here you can study clustering techniques like K means and hierarchical clustering and delve into dimensionality reduction with PCA.
So this month's focus on EDA and model building will prepare you for more to the next phase, you'll begin to work on deploying these models and real world scenarios. So in month six comes MLOps and machine learning projects. So this
month we'll cover the operational aspects of machine learning and work on practical projects. So in MLOps basics learn about APIs particularly using fast API for Python and server development. Understand DevOps fundamentals including
CI/CD pipelines and containerization with Docker and Kubernetes. You should also gain familiarity with at least one cloud platform like AWS or Azure. Now in month seven comes deep learning. So in this month we delve into the world of
neural network. So learn about neural networks including forward and backward propagation and build multi-layer perceptrons. After which you'll move on explore convolutional neural networks which are CNN's for image data and
sequence models like RNNs and LSTMs. So this deep learning knowledge will be crucial as you move into specialized areas of AI in the final month. Now in the final month, the eighth month comes NLP or computer vision. So the final
in either natural language processing, NLP or computer vision. So first we'll NLP track. So here you should learn about rejects text representation methods like count vectorizer TF b word tovec embeddings and text classification
with nave base and familiarize yourself with the fundamentals of libraries like spacy and NLTK and work on end toend NLP project and talking about computer processing techniques like filtering edge detection image scaling and
rotation utilize libraries like OpenCV and build upon the CNN knowledge from prep-processing ing and augmentation. So by the end of this month, you should have a solid foundation in your chosen specialization ready to embark on your
AI engineering career. So in conclusion, adopting AI is more than just a trend. It's a strategic move that can transform your organization's approach to machine professional certificate course in AI and machine learning which is designed
excel in this dynamic field. Through live classes led by industry experts, master classes from IIT Kpur faculty and hands-on projects, you'll gain a competitive edge in AI. To enroll in this program, candidates should have a
bachelor's degree with a 50% or higher average, preferably two or more years of knowledge in programming and mathematics. Check out the course link all for today's video on becoming an AI engineer. We hope you found this guide
valuable and informative. &gt;&gt; Why reinforcement learning? Training a machine learning model requires a lot of data which might not always be available to us. Further, the data provided might not be reliable. Learning from a small
subset of actions will not help expand the vast realm of solutions that may work for a particular problem. And you can see here we have the robot learning can see here we have the robot learning to walk. Um, very complicated setup when
start asking questions like if I'm taking one step forward and left, what happens if I pick up a 50 lb object? How does that change how a robot would walk? program because there's no actual information on it until the it's
actually tried out. Learning from a small subset of actions will not help expand the vast realm of solutions that may work for a particular problem. And we'll see here it learned how to walk. This is going to slow the growth
that technology is capable of. Machines need to learn to perform actions by themselves and not just learn off humans. And you see the objective climb a mountain. Real interesting point here is
that as human beings, we can go into a very unknown environment and we can adjust for it and kind of explore and play with it. Most of the models, the non-reinforcement models in computer u
machine learning aren't able to do that very well. Uh there's a couple of them that can be used or integrated. See how it goes is what we're talking about with reinforcement learning. So what is reinforcement learning? Reinforcement
learning is a subbranch of machine learning that trains a model to return an optimum solution for a problem by taking a sequence of decisions by itself. Consider a robot learning to go from one place to another. The robot is
given a scenario must arrive at a solution by itself. The robot can take different paths to reach the destination. It will know the best path by the time taken on each path. It might even come
up with a unique solution all by itself. And that's really important as we're looking for unique solutions. Uh we want the best solution, but you can't find it unless you try it. So we're looking at uh our different systems, our different
model. We have supervised versus unsupervised versus reinforcement learning. And with the supervised learning, that is probably the most controlled environment. Uh we have a lot of different supervised learning models
where there's linear regression, neural networks, um there's all kinds of things in between, decision trees. The data provided is labeled data with output values specified. And this is important because when we talk about supervised
for all this information. You already know the picture has a motorcycle in it. So you're supervised learning. You already know that um the outcome for tomorrow for you know going back a week. You're looking at stock. You can already
looks like. So you have an answer for it. And you have labeled data which is used. You have an external supervision and solves problems by mapping labeled input to known output. So very controlled
unsupervised learning and unsupervised learning is really interesting because it's now taking part in many other models. They start with an you can actually insert an unsupervised learning model um in almost either supervised or
reinforcement learning as part of the system which is really cool. Uh data provided is unlabeled data. The outputs are not specified. machine makes its own predictions used to solve association with clustering problems. Unlabeled data
is used. No supervision. Solves problems by understanding patterns and discovering output. Uh so you can look at this and you can think um some of these things go with each other. They belong together. So
different ways. And there's a lot of different algorithms that look at this. there's some really cool images that come up of what unsupervised learning is. How it can pick out say uh the area of a donut. One model will see the area
divide it into three sections based on its location versus what's next to it. So there's a lot of stuff that goes in with unsupervised learning. And then we're looking at reinforcement learning. Probably the biggest industry in today's
market uh in machine learning or growing market. It's very in its very infant stage uh as far as how it works and what it's going to be capable of. The machine learns from its environment using rewards and errors used to solve
rewards and errors used to solve rewardbased problems. No predefined data is used. No supervision follows trail and error problem solving approach. Uh so again we have a random at first you start with a random I try this it works
and this is my reward. doesn't work very well maybe or maybe doesn't even get you you get your reward back and then it looks at that and says well let's try with these different things finding the best route. So let's take a look at
important terms in today's reinforcement model and this has become pretty standardized over the last uh few years so these are really good to know. We have the agent uh agent is the model that is being trained via reinforcement
learning. So this is your actual u entity that has however you're doing it a Q table or whatever combination thereof. This is the actual agent that you're
using. This is the model and you have your environment. Uh the training situation that the model must optimize to is called its environment. Uh and you can see here I guess we have a robot who's trying to get a chest full
of gyms or whatever. And that's the output. And then you have your action. This is all possible steps that can be taken by the model and it picks one action and you can see here it's picked three different uh routes to get to the
chest of diamonds and gems. [sighs] We have a state the current position have a state the current position condition returned by the model. And you could look at this uh if you're playing like a video game. This is the
screen you're looking at. Uh so when we go back here uh the environment is a whole game board. So, if you're playing one of those Mobius games, you might have the whole game board going on. Uh, but then you have your current position.
Where are you on that game board? What's around that? What's around you? Um, if you were talking about a robot, the environment might be moving around the yard, where it is in the yard, and what it can see, what input it has in that
location. That would be the current position condition returned by the model. And then the reward uh to help the model move in the right direction, it is rewarded. Points are given to it to appraise some kind of action. So,
yay, you did good or if uh didn't do as good, trying to maximize the reward and have the best reward possible. And then policy. Policy determines how an agent will behave at any time. It acts as a mapping between action and
present state. This is part of the model. What what is your action that you're you're going to take? what's the policy you're using to have an output from your agent. One of the reasons they separate a policy as its own entity is
that you usually have a prediction um of a different options and then the policy well how am I going to pick the best based on those predictions I'm going to guess at different options and we'll actually weigh those options in and find
the best option we think will work. Uh, so it's a little tricky, but the policy works. Let's go ahead and take out look at a reinforcement learning example. And just in looking at this, we're going to take a look uh consider what a dog um
that we want to train. Uh so the dog would be like the agent. So you have your your puppy or whatever. Uh and then your environment is going to be the you're training them. And then you have an action. We want to teach the dog to
fetch. So action equals fetching. Uh and then the dog to perform various actions by offering incentives such as a dog biscuit as a reward. The dog will follow a policy to maximize
this reward and hence will follow every command and might even learn new actions like begging by itself. Uh so you have b you know so we start off with fetching. It goes oh I get a biscuit for that. it tries something else and you get a
handshake or begging or something like that and it goes oh this is also rewardbased and so it kind of explores things to find out what will bring it as biscuit and that's very much like how a reinforced model goes is it uh looks for
different rewards how do I find can I try different things and find a reward that works the dog also will want to run around and play and explore it environment uh this quality of model is called exploration
so there's a little randomness going going on in exploration and explores new parts of the house. Climbing on the sofa doesn't get a reward. In fact, it usually gets kicked off the sofa.
So, let's talk a little bit about Marov's decision process. Uh Marov's decision process is a reinforcement learning policy used to map a current state to an action where the agent continuously interacts with the
environment to produce new solutions and receive rewards. And you'll see here's all of our different uh uh vocabulary we just went over. We have our reward, our state, our agent, our environment interaction. And so even though the
environment kind of contains everything um that you you really when you're actually writing the program, your environment is going to put out a reward environment is going to put out a reward and state that goes into the agent. Uh
the agent then looks at this uh state or it looks at the reward usually um first and it says okay I got rewarded for whatever I just did or I didn't get rewarded and then it looks at the state and then it comes back and if you
and then it comes back and if you remember from policy the policy comes in um and then we have a reward. The policy is that part that's connected at the bottom. And so it looks at that policy and it says, "Hey, what's a good action
that will probably be similar to what I did?" Or um uh sometimes they're action that's going to bring me a different reward? So, taking the time to just understand these different pieces as they go is
pretty important in most of the models today. Um, and so a lot of them actually have templates based on this that you can pull in and start using. Um, pretty straightforward as far as once you start seeing how it works. Uh, you can see
your environment sends it says, "Hey, this is the agent did this. If you're a character in a game, this happened and it shoots out a reward in a state." The agent looks at the reward, looks at the new state, and then takes a little guess
action." And then that action goes back into the environment. it affects the environment. The environment then changes depending on what the action was and then it has a new state and a new reward that goes back to the agent. So
in the diagram shown, we need to find the shortest path between node A and D. Each path has a reward associated with it and the path with a maximum reward is what we want to choose. The nodes A, B, C, Denote the nodes to travel from node
C, Denote the nodes to travel from node uh A to B is an action. Reward is the cost of each path and policy is each path taken. path taken. And you can see here A can go uh to B or
A can go to C right off the bat or it can go right to D. And if you explored all three of these uh you would find that A going to D was a zero reward. Um A going to C and D would generate a different reward. Or you could go AC B
D. There's a lot of options here. Um and so when we start looking at this diagram, you start to realize that even though uh today's reinforced learning models do really good at u finding an answer, they end up trying almost all
the different directions you see. And so they take up a lot of work uh or a lot of processing time for reinforcement learning. They're right now in their infant stage and they're really good at solving simple problems. And we'll take
in a tic-tac-toe game. Uh but you can see here uh once it's gone through these and it's explored, it's going to find the AC d is the best reward. It gets a full 30 points for it. So let's go ahead and take a look at a reinforcement
learning demo. Uh in this demo, we're going to use reinforcement learning to make a tic-tac-toe game. You'll be playing this game against the machine learning model. And we'll go ahead and we're doing it in
Python. So, let's go ahead and go through um I always uh not always actually have a lot of Python tools. Let's go through um Anaconda, which will open up a Jupyter notebook. Seems like a lot of steps, but it's worth it to keep
a nice display when you're in the Jupyter notebook for doing Python. So, here's our Anaconda Navigator. I open up the notebook, which is going to take me to a web page. And I've gone in here and created a new uh Python folder.
enabled it. Change the name to tic-tac-toe. Uh, and then for this tic-tac-toe. Uh, and then for this example, uh, we're going to go ahead and import a couple things. We're going to, um, import numpy as np. We'll go ahead
and import pickle. Numpy, of course, is our number array. And, uh, pickle is just a nice way sometimes for storing, uh, different information, uh, different here. Uh, and so we're going to create a class
called state. I'm going to start with that. And there's a lot of lines of code to this uh class that we're going to put in here. Don't let that scare you too much. There's not as much here. Um it looks
like there's going to be a lot here, but there really is just a lot of setup going on in the in our class state. And so we have up here, we're going to so we have up here, we're going to initialize it. Um we have our board. Um,
it's a tic-tac-toe board, so we're only dealing with nine spots on the board. Uh, we have player one, player two, uh, is end. We're going to create a board minute. We're just going to store some information in there. Symbol of player
equals one. Um, so there's a few things going on as far as the initialization. Uh, then something simple. We're just going to get the hash um of the board. you get the information from the board on there, which is uh columns and rows.
so if you get three in a row, that's what this whole section here is for. Uh let me go ahead and scroll up a little bit. And you can get a copy of this code if you send a note over to SimplyLearn.
We'll send you over um this particular file and you can play with it yourself and see how it's put together. I don't want to spend a huge amount of time on this uh because this is just some real general Python coding.
Uh but you can see here we're just going through all the rows and you add them together and if it equals three, three in a row. Same thing with columns. diagonal. That's what all this stuff does here is it just goes through the
ahead and put There we go. Um, and then it comes down here and we do our sum and it says true uh minus three. It just says did somebody win or is it a tie? So, you got to add up all
the numbers on there anyway just in case they're all filled up. And next, we also need to know available positions. Um, these are ones that don't no one's ever used before. This way, when you try something or the computer tries
something, uh, it's not going to give it an illegal move. That's what the available positions is doing. Uh then we want to update our state. And so you have your position going in. We're just sending in the position that you just
chose. And you'll see there's a little user interface we put in there. You pick user interface we put in there. You pick pick the row and column in there. And again, I mean, this is a lot of code. Uh so really it's kind of a thing
little bit and just read through it, get a copy of it. Uh great way to understand a copy of it. Uh great way to understand how this works. And here is a given reward. Um, so we're going to give a reward. Result equals self-winner. This
is one of the hearts of what's going on here. Uh, is we have a result self.winner. So if there's a winner, then we have a result. If the result equals one, here's our feedback. Uh, if it doesn't equal one, then it gets a
zero. So it only gets a reward in this particular case if it wins. And that's important to know because different uh systems of reinforced
learning do rewarding a lot differently depending on what you're trying to do. depending on what you're trying to do. This is a very simple example with a 3x3 board. Imagine if you're playing a video game. Uh certainly you only have so many
actions, but your environment is huge. You have a lot going on in the environment. And suddenly a reward system like this is going to be just um It's going to have to have different rewards and different setup. And there's
all kinds of advanced ways to do that as far as weighing you add weights to it. And so they can add the weights up depending on where the reward comes in. So it might be that you actually get a reward. In this case, you get the reward
at the end of the game. And I'm spending just a little bit of time on this note. But there's different ways to add up those rewards. It might have like if you take a certain path, um the first reward is going to be weighed a little
the last reward is actually winning the game or scoring or whatever it is. So, this reward system gets really complicated in some of the more advanced complicated in some of the more advanced uh setups. Um in this case though you
can see right here that they give a a 0.1 and a 0.5 reward um just for getting a picking the right value and something that's actually valid instead of picking an invalid value. So rewards again that's like key
that's huge. How do you feed the rewards back in? Uh then we have a board reset. goes back and resets the board to the beginning because it's going to try out learning. It's going to do it by trial and error. So, you have to keep
there's the play. We want to go ahead and play uh rounds equals 100. Depends on what you want to do on here. Um you can set this different. You obviously set that to higher level, but this is just going to go through and you'll see
in here uh that we have player one and player two. This is this is the computer playing itself. Uh, one of the more powerful ways to learn to play a game or
even learn something that isn't a game is to have two of these models that are basically trying to beat each other. And so they always they keep finding explore new things. This one works for this one, so this one tries new things. It beats
this. We've seen this in um chess, I think, was a big one where they had the two players in chess with reinforcement learning. uh is one of the ways they train one of the top um computer chess playing algorithms.
going to choose an action. It's going to try something. And the more it tries stuff, um the more we're going to record the hash, we actually have a board hash where they self get the hash set up on here where it stores all the
information. And then once you get to a win, one of them wins, it gets the reward. Uh then we go back and reset and try again. And then kind of the fun part we actually get down here is uh we're going to play
come in here and see what that looks like when you put your own information does the same thing it did above. It gives it a reward for its things um or
gives it a reward for its things um or sees if it wins or ties. Um looks at available positions, all that kind of fun stuff. And then finally, we want to show the board. Uh so it's going to print the board out each time.
Really um as an integration is not that exciting. What's exciting uh in here is one looking at this reward system. Whoops. Play one more up. The reward system is really the heart of this. How do you reward the different uh setup and
the other one is when it's playing it's got to take an action. And so what it chooses for an action is also the heart of reinforcement learning. How do we of reinforcement learning. How do we choose that action? And those are really
key to right now where reinforcement learning is uh in today's uh technology is uh figuring this out. How do we reward it and how do we guess the next
best action? So we have our uh environment and you can see the environment is we're going to be or the state uh which is kind of like what's state depending on what happens. And we want to go ahead and create our agent.
Uh in this case, our player. So each one is let me go and grab that. And so we is let me go and grab that. And so we look at a class player. Um really going on is what how is this player figuring out how to maneuver
around the board? And then the board of course returns a state uh that it can look at and a reward. Uh so we want to take a look at this. We have a name uh self state. This is class player. And when we say class player, we're not
talking about a human player. We're talking about um just a uh the computer interesting. So remember I told you depending on what you're doing, there's depending on what you're doing, there's going to be a decay gamma. Um
explore rate. Uh these are what I'm talking about is how do we train it? Um as you try different moves, it gets to the end. The first move is important,
but it's not as as important as the last one. And so you could say that the last one has the heaviest weight. And then as you as you get there, the first one, let's see, the first move gives you a five reward, the second gives you a two
reward, and the third one gives you a 10 reward because that's the final ending. You got it. The 10's going to count more than the first step. Uh, and here's our, uh, we're going to, you know, get the board information coming in and then
part that I was talking about that was so important. Uh so once you have your training going on, we have to do a little randomness. And you can see right little randomness. And you can see right here is our NP random uh uniform. So
it's picking out a random number. Take a random action. And this is going to just pick which row and which column it is. Um and so choosing the action. This one you can see we're just doing random states. uh choice, length of positions,
action position, and then it skips in there and takes a look at the board uh for P and positions. You get it's actually storing the different boards each time you go through so it has a record of what it did so it can properly
weigh the values. And this simply just appends a hash state. What's the last state? Pinned it to the uh u to our states on here. Here's our feedback rewards. So the reward comes in and it's going to take a look at this and say is
it none? Uh what is the reward? And here is that formula remember I was telling you about up here um that was important because it has decay gamma times the because it has decay gamma times the reward. This is where as it goes through
each step and this is really important. This is this is kind of the heart of this of what I was talking about earlier. Uh, you have step one and this might have a a reward of two. You have step two. I probably should have done
ABC. This has a step three. Uh, step four and so on till you get to step in. And this might have a reward of 10. Uh, so reward of 10.
We're going to add that, but we're not adding uh let's say this one right here. Uh let's say this reward here right before 10 was um let's say it's also 10. It just makes the the math easy. So we had 10 and 10. We had 10. This is 10 and
10 in whatever it is. But it's time it's 0.9. Uh so instead of putting a full 10 0.9. Uh so instead of putting a full 10 here, we only do nine. That's uh 0.9 time 10.
um as far as the decay times the reward minus the cell state value uh it basically adds in it says here's one or here's two. I'm sorry I should have done this ABC would have been easier. Uh so the first move goes in here and it puts
two in here. Uh then we have our self uh setup on here. You can see how this gets pretty complicated in the math, but this is complicated in the math, but this is really the key is how do we train our
states and we want the the final state, the win to get the most points. If you win, you get most points. Um, and the first step gets the least amount of points. So, you're really training this almost in reverse. You're retraining
you're training it from the last place where you have like it says okay this is now where need to sum up my rewards and I want to sum them up going in reverse and I want to find the answer in reverse kind of an interesting uh uh play on the
stuff out and of course we want to go ahead and reset the board down here uh save the policy load policy going in between the agent and the state to figure out what's going on let's go
ahead load that up. And then finally, we want to go ahead and create a human player. And the human player is going to be a little different uh in that uh you
choose an action row and column. Here's your action. Uh if action is if action in positions, meaning positions that are available, uh you return the action. If not, it just keeps asking you until you get an
action that actually works. And then we're going to go ahead and append to worry about because it returns the action up here and feed forward. Uh again this is because it's a human
um at the end of the game bat propagate and update state values. This part isn't and update state values. This part isn't being done because it's not programming uh the model. Uh the model is getting its own rewards. So we've gone ahead and
loaded this in here. Uh so here's all our pieces. And the first thing we want to do is set up uh P1 player one uh P2 player two. And then we're going to send our players to our state. So now it has P1
P2. And it's going to play and it's going to play 50,000 rounds. Now we can it's not going to get the full results. In fact, you know what? Uh, let's go
with it because I want to show you something here. Oops. Somewhere in there I forgot to load something. There we go. I must have forgot to run this run.
board rows and columns 3x3. U there is actually in the state it references that. We can just tack it on on the end. It was supposed to be at the beginning. Uh, so now I've only set this up with um, see where are we going here? I've
only set this up to train five times. And the reason I did that is five times. And the reason I did that is we're going to uh, come in and actually that and we can see how it differs on there.
run. And we're going to go ahead and save the policy. Um, so now we have our player one and our player two policy. Uh, the way we set it up, it has two separate policies loaded up in there.
And then we're going to come in here and we're going to do uh player one is going to be the computer experience rate zero. Load policy one. Human player human. And we're going to go ahead and play this. Now remember, I only went through it um
uh just one round of training. In fact, minimal training. And so it puts an X there. And I'm going to go ahead and do row zero, column one. You can see this row zero, column one. You can see this is very uh basic on here. And so I put
in my zero. And then I'm going to go zero, block it, zero, zero. And you can see right here, it let me win. Uh just like that, I was able to win. Zero
like that, I was able to win. Zero two. And woo, human wins. So I only trained it five times. We're going to run this again. And this time, uh, run this again. And this time, uh, instead of five, let's do 5,000 or
50,000. I think that's what the guys in the back had. And this takes a while to the back had. And this takes a while to train it. This is where reinforcement learning really falls apart. Look how simple this game is. We're talking about
simple this game is. We're talking about uh a 3x3 set of columns. And so for me uh a 3x3 set of columns. And so for me to train it on this um I could do a Q much quicker. Um you could build a quick Q table with almost all the different
options on there and uh you would probably get a the same result much quicker. We're just using this as an example. So when we look at reinforcement learning, you need to be very careful what you apply it to. It
sounds like a good deal until you do like a large neural network where you're doing um you set the neural network to a learning increment of one. So every time it goes through it learns and then you do your actions. So you pick from the
learning uh setup and you actually try actions on the learning setup until you get the what you think is going to be the best action. So you actually feed what you think is right back through the neural network. There's a whole layer
there which is really fun to play with. and then it has an output. Well, think of all those processes. I mean, that is just a huge amount of work it's going to do. Uh, let's go ahead and skip ahead here. Give it a moment. It's going to
take a a minute or two to go ahead and run [sighs] now to train it. Uh, we went ahead and let it run and it took a while. This this took um I got a pretty powerful
this took um I got a pretty powerful processor and it took about five minutes plus to run it. and we'll go ahead and uh run our player setup on here. Oops, it brought in the last Whoops, it brought
in the last round. So, give me just a moment to reddo the policy save. There we go. I forgot to save the policy back in there and then go ahead and run our player again. So, we've saved the policy and
then we want to go ahead and load the policy for P1 as a computer. And we can see the computer's gone in the bottom right corner. I'm going to go ahead and right corner. I'm going to go ahead and go uh one one which is the center
and it's gone right up the top. And if you have ever played tic-tac-toe, you know the computer has me. Uh but we'll go ahead and play it out. Row zero, column two. There it is. And then it's gone here. And so I'm going to go ahead
gone here. And so I'm going to go ahead and go row 0 one two. No, 01. There we go. And column zero. That's where I want it. Oh, and it says I Okay, you your
action. There we go. Boom. Uh, so you can see here we've got a Didn't catch the win on this. It said tie. Um, kind of funny that it didn't catch the win on But if we play this a bunch of times, you'll find it's going to win more and
more. The more we train it, the more the reinforcement happens. This lengthy training process uh is really the stopper on reinforcement learning. As this changes, reinforcement learning will be one of the more
powerful uh packages evolving over the next decade or two. In fact, I would even go as far as to say it is the most important uh machine learning tool and artificial intelligence tool out there as it learns not only a simple
tic-tac-toe board, but we start learning environments. And the environment would translating a language or something from one language to the other, so much of it is lost if you don't know the context it's in. What's the environments it's
in? And so being able to attach environment and context and all those things together is going to require reinforcement learning to do. the tic-tac-toe board, it's kind of fun
to play with. Uh run it, you can test it out, you can do uh you know, test it for different uh uh values. You can switch from P1 computer uh where we loaded the policy one to load the policy two and just see how it
varies. There's all kinds of things you can do on there. So what is Q-learning? Q-learning is reinforcement learning policy which will fill the next best action given a current state. It chooses this action at random and aims to
maximize the reward. And so you can see here's our standard reinforcement learning graph. Um, by now if you're doing any reinforcement learning, you should be familiar with this where you have your agent, your agent takes an
action, the action affects the environment, and then the environment sends back the reward or the feedback and the state it's the new state the chessboard? Where is it at in the video game? Um, if your robots's out there
picking trash up off the side of the road, where is it at on the road? Consider an ad recommendation system. Usually when you look up a product online, you get ads which will suggest the same
product over and over again. Using Q-learning, we can make an ad recommendation system which will suggest related products to our previous purchase. The reward will be if user clicks on the suggested product.
And again, you can see um you might have a lot of products on uh your web advertisement or your pages, but it's still not a float number. It's still a set number. And that's something to be aware of when you're using Q-learning.
And you can see here that if you have a 100 people clicking on ads and you click and say, "Okay, this person clicked on this ad. what is the best set of ads two ads afterwards based on where they
look at some important terms when we talk about Q-learning. Uh we have states the state S represents the current position of an agent in an environment. Um the action the action A is the step taken by the agent when it is particular
state. Rewards for every action the agent will get a positive or negative reward. And again, uh, when we talk about states, we're usually not with when you're using a Q table, you're not
usually talking about float variables. You're talking about true false. Um, and we'll take a closer look at that in a second. And episodes when an agent ends up in a terminating state and can't take a new action. Uh, this might be if
you're playing a video game, your character stepped in and is now dead or character stepped in and is now dead or whatever. uh Q values used to determine how good an action A taken at a particular state S is Q A of S and
temporal difference a formula used to find the Q value by using the value of the current state and action and previous state and action and very I mean there's Bellman's equation which basically is the equation that kind of
uh covers what we just looked at in all those different terms. The Bellman equation is used to determine the values of a particular state and deduce how good it is to be in take that state. The optimal the optimal state will give us
the highest optimal value factor influencing Q values. The current state and action that's your SA. So your current state and your action. Uh then you have your previous state and action which is your S um I guess prime. I'm
not sure how they how they reference that. S prime A prime. So this is what happened before. Uh then you have a reward for action. So you have your R reward and you have your maximum expected future reward.
And you can see there's also a learning rate put in there and a discount rate. Uh so when we're looking at these just like any other model, we don't want to like any other model, we don't want to have an absolute um final value on here.
We don't want it to. If you do absolute values, instead of taking smaller steps, you don't really have that approach to the solution. You just have a jump and then pretty soon if you jump one solution out, that's what's going to be
the new solution. Whichever one jumps up really high first. Um, kind of ruining the whole idea of doing a random selection. And I'll go into the random selection in just a second. Steps in Q-learning.
Step one, create an initial Q table with all values initialized to zero. Again, all values initialized to zero. Again, we're looking at 01. Uh, so are you, you know, here's our action. We start, we're an idle. We took a wrong action. We took
a correct action and end. And then we have our um actions fetching, sitting, and running. And of course, we're just using the dog example. And choose an action and perform it. Update values in the table. And of course, when we're
choosing an action, we're going to kind of do something random and just randomly pick one. So, you start out and you sit and you have then a um then depending on that um um action you took, you can now update the value for sitting after you
start from start to sitting. Get the value of the reward and calculate the val the value Q value using the Bellman equation. And so now we attach a reward to sitting. And when we attach all those rewards, we
continue the same until the table's filled with or an episode ends. back to the random side of this. And there's a few different formulas they use for the random um setup to pick it.
do their standard one because someone's usually gone in and done the math uh for the optimal uh spread. Uh but you can look at this. If I have running has a reward of 10, sitting has a reward of
seven, fetching has a reward of five. Um, just kind of without doing like a a means, you know, using the bell curve for the means value. And like I said, there's some math you can put in there to pick so that you're more like so that
but even if you were just going to do an average on this, you could do an average, a random number by adding them all together. Uh so you get 10 + 7 + 5 all together. Uh so you get 10 + 7 + 5 is 22. You could do 0 to 22 and or 0 to
21 but 1 to 22. 1 to five would be fetching uh and so forth. You know the last 10. So you can just look at this as what percentage are you going to go for that particular option.
Um and then that gets your random setup in there. And then as you slowly increment these up, uh you see that uh u if you're idle u where's one? Here we go. Sitting at the end, if you're at the end of wherever you're at, sitting gets
a reward of one. Um where's a good one on here? Oh, wrong action. Running for a wrong action gets almost no reward. So that becomes very very less likely to still might have a percentage of coming up. And that's where the random
programming in Q-learning comes in. The below table gives us an idea of how many times an action has been taken and how positively correct action or negatively wrong action it is going to affect the next state. So let's go ahead and dive
in and pull up a little piece of code and see what this looks like um in Python. Uh in this demo we'll use Q-learning to find the shortest path between two given points.
&gt;&gt; If getting your learning started is half the battle, what if you could do that for [music] free? Visit Skillup by SimplyLearn. Click on the link in the description to know more. &gt;&gt; If you've seen my videos before, um I
like to do it in the uh Anaconda Jupiter notebook um setup just because it's really easy to see and it's a nice demo. Uh and so here's my Anaconda. This one I'm actually using a Python 36 environment that I set up in here. And
we'll go ahead and launch the Jupyter notebook on this. And once we're in our Jupyter notebook, uh, which has the kernel loaded with Python 3, we'll go ahead and create a new Python 3 uh, folder in here.
And we'll call this, uh, Q learning. And to start this demo, let's go ahead and import our uh, numpy array. We'll just run that. So, it's
imported. And like a lot of these uh, model programs, when you're building them, you spend a lot of time putting it all together. Um and then you end up with this really short answer at the end. Uh and we'll we'll take a look at
that as we come into it. So we we go ahead and start with our location to ahead and start with our location to state. Uh so we have um L1, L2. These are our nine locations 1 to nine. And then of course the state is going to be
0 1 2 3 4. It's just a mapping of our location to a integer on there. And then we have our actions. Our actions are simply uh moving from
uh one location to another. So I can go to I can go to location zero. I can go to location 1 2 3 4 5 6 7 8. Uh so these are my actions. I can choose these are the locations of our state.
And if you remember earlier, I'd mentioned uh um that the limitation is that you you don't want to put in um a continually growing table because you can actually create a dynamic Q table where you continually add in new values
as they arise because um if you have float values, it just becomes infinite and then your memory in your computer's gone or you know it's not going to work. At the same time, you might think, well, that kind
of really limits the the Q t learning setup, but there are ways to use it in setup, but there are ways to use it in conjunction with other systems. And so, you might look at uh well, I do um I've been doing some
work in stock um and one of the questions that comes out is to buy or questions that comes out is to buy or sell the stock. And the state coming in might be um you might take it and create what we call buckets.
Um where anything that you predict is going to return more than a certain amount of money um the error for that stock that you've had in the past, you start putting the creating these buckets. You realize you do have a
limited amount of information coming in. You no longer have a float number. You now have um bucket one, two, three, and four. And then you can take those buckets, put them through a a Q-learning table, and come up with the best action.
gambling. Stock is pretty much gambling if you're doing day trading. You're not doing long-term u investments. And so you can start looking at it like that. A lot of the um current feeds say that the best algorithms used for day traders,
where you're doing it on your own, is really to ask the question, do I want to trade the stock? Yes or no? and now you have it in a Q-learning table and now you can see where that can be a really powerful tool at the end of doing a
basic linear regression model or something um what is the best investment there. Uh, and so if we're going to have Uh, and so if we're going to have rewards, these rewards we just create.
Um, it says uh if basically if you're uh this should match our Q table because it's going to be uh you have your state and you have your action across the top if you remember from the dog. And so we have whatever state we're in going down
and then the next action and what the reward is for it. Um, and of course, if you were actually doing a u something more connected, your reward would be based on uh the actual environment it's in. And then we want to go ahead and
create a state to location uh so we can map the indexes. So just like we defined our rewards, uh we're going to go and do state to location. Um and you can see here it's a a dictionary setup for location state and locationto state with
items and We also need to um define what we want for learning rates. Uh you remember we had our two different
rates um as far as like learning from the past and learning from the current. So we'll go ahead and set those to uh 75 and the alpha set to 0.9. And we'll see that when we do the formula. And of course any of this code uh send a note
to our SimplyLearn team. They'll get you a copy of this code on here. Let's go ahead and pull. There we go. The new next two sections. Um, since we're going to keep it short
and sweet. Here we go. So, let's go ahead and create our agent. Um, so our agent is going to have our initialization where we send it all the information. Uh, we'll define our self gamma equals gamma. We could have just
set the gamma rate down here instead of uh submitting it. It's kind of nice to keep them separate because you can play with these numbers uh our self-alpha. Um then we have our location state. We'll set that in here. Um we have our choice
of actions. Um we're going to go ahead and just embed the rewards right into the agent. So obviously this would be coming from somewhere else uh instead of from uh self-generated. and then a self state to location equals our state to
location uh dictionary. And we go ahead and create a Q-learning table. And I went ahead and just set the Q-learning table up to um uh 0 to zero. What what what the setup is uh location to state. How many of them are there? Uh and this
just creates an array of zero to zero setup on there. And then the big part is the training. We have our rewards new equals a copy of self.rewards. rewards ending state equals the self-location
state end location. So this is whatever we end up at. Rewards new equals ending state plus ending state equals 999. Just kind of goes to a dead end. And we start
kind of goes to a dead end. And we start going through iterations so this we're going to come back and we're going to call call it on here. Uh,
let me just erase that. Switch it to an arrow. There we go. Uh, so what we're doing is we're going to send in here to train it. We're going to say, hey, um, I want to iterate through this a thousand times and see what happens. Now, this
part would actually be instead of iterating, you might have your external environment and they're going back and forth and you iterate through outside of here. Uh, but just for ease of use, our agent's going to come in here and
iterate through this. Sometimes I'll put this iteration in here and I'll have it call the environment and say, "Hey, this is what I did. What's the next state?" And the environment does its thing right in here as I iterate through it.
Uh, and then we want to go ahead and pick a random state to start with. That's what's going on here. You have to start somewhere. Um, and then you have start with just an empty thing for playable actions and we'll fill that up.
we're going to iterate through the rewards matrix to get the states uh directly reachable from the randomly chosen current state. Assign those chosen current state. Assign those states to a list named playable actions.
And so you can see here we have uh range nine. I usually use length of whatever I'm looking at uh which is our locations or states as they are. uh we have a reward. So we want to look at the current the rewards uh the new reward is
current the rewards uh the new reward is our uh is in our chart here of rewards our uh is in our chart here of rewards new uh current state um plus J. Uh J being what is the next state we want to try. And so we go ahead and do our
try. And so we go ahead and do our playable actions and we append J. And so we're doing is we're randomly trying different things in here to see reward. And then of course we go ahead and
choose our next state. Uh so we have our random choice playable actions. And if you remember I mentioned on this let me just go ahead and uh oops let's do a free form. When we were talking about the next state uh this right here just
does a random selection. Instead of a random uh selection, you might do something where uh whatever the best selection is, which might be option selection is, which might be option three here. And then so you can see that
it might use a bell curve and then option two over here might have a bell curve like this. Oops. And we start looking at these averages and these spreads. Um or we can just add them all together and pick the one that kind of
goes in all of those. Uh so those are some of the options we have in here. We just go with a random choice. Uh that's usually where you start, play with it. Um and then we have our reward section down here. And so we want to go ahead
and find well in this case the temporal difference. Uh so you have your rewards new plus the self gamma. And this is the formula we were looking at. This is Bellman's equation here. Uh so we have our current value, our learning rate,
our discount rate involved in there, the reward system coming in for that. Uh and we can add it all together. This is of course our uh maximum expected future setup in here. Uh so this is all of our our Bellman's equation that we're
looking at here. And then we come up in here and we update our Q table. That's all this is on this one. Uh that's right here. We have um self Q current state here. We have um self Q current state next state and we add in our um alpha
to train all of it at once in case there's slight differences coming in there. We want to slowly approach the answer. Uh and then we have our route equals the start location and next location equals start location.
So we're just incrementing. We took a step forward. And then finally, remember I was telling you how uh we're going to do all this and just have some simple thing at the end where it just generates a simple path. We're going to go ahead
and and get the optimal route. We want to find the best route in here. And so we've created a definition for the optimal route down here. Just scroll down for that. And we get the optimal route. uh we go ahead and put the
information in including the Q table self uh start location in location next location route Q and it says while next location is not equal to end location. So while we can still go our start location equals self-loation to state
start location. So we already have our best value for the start location. Uh the next state looks at the Q table and says, "Hey, what's uh the next one with the best value?" And then the next location, we go ahead and pull that in
and we just append it. That's what's going on down here. next location. And we just go through all the steps. And we'll go ahead and run this. And now that we have our Q table, our um
Q agent loaded, we're going to go ahead and uh take our Q agent, load them up with our alpha, gamma that we set up above um along with the location step, above um along with the location step, action, reward, state to location, and
action, reward, state to location, and uh our goal is to plot a course between L9 and L1. And we're going to go through a 100 a thousand iterations on here. And so when I run that, it runs pretty quick. Uh why
is this so fast? Um if you've been running neural networks and you've been doing all these other models, you sit here and wait a long time. Well, we're very small amount of data. These are all integers. These aren't float values.
There's not a the math is not heavy on the on the processing end. And this is where Q tables are so powerful. If you have a small amount of information coming in, you very quickly uh get an answer off of this. even though we went
through it a thousand times to train it. And you'll see here we have L9 85 2 and one. And that's based on our reward table we had set up on there. And this is the shortest path going between these different uh setups in here. And if you
remember in our reward table, uh you can see that if you start here, you can go to here. There's places you can't go. That's how this reward table was set up. That's how this reward table was set up. So I can only go to certain places.
Uh so kind of a little maze setup in there and you can play with it. This is really fun uh setup to play with. Uh and you can see how you can take this whole code and you can like I was saying earlier you can embed it into another
you put things into buckets and you're trying to guess the best investment, the best course of action. Long as you can take that course of action and and uh uh reduce it down to a yes no. Um, or if you're using text, you can use a one hot
encoder. Which word is next? There's all kinds of things you can do with a Q table, uh, depending on just how much information you're putting in there. So, we've, uh, found the shortest distance
rules or state rewards we have to get from point A to point B and what available actions there are. &gt;&gt; Hello and welcome to this tutorial on deep learning. My name is Moan and in the next about one one and a half hours
I will take you through what is deep learning and into TensorFlow environment to show you an example of deep learning. Now there are several applications of deep learning really very interesting and innovative applications and one of
them is identifying the geographic location based on a picture. And how does this work? The way it works is pretty much we train an artificial neural network with millions of images which are tagged. Their geoloccation is
tagged and then when we feed a new picture, it will be able to identify the geoloccation of this new image. For example, you have all these images especially with maybe some significant monuments or or u significant locations
and you train with millions of such images and then when you feed another image it may not be exactly one of those that you have trained. It can be idea of training. It will be able to recognize for example that this is a
picture from Paris because it is able to recognize the Eiffel Tower. So the way recognize the Eiffel Tower. So the way it works internally if we have to look a little bit under the hood is these images are nothing but this is digital
information in the form of pixels. So each image could be a certain size. It can be 256 x 256 pixel kind of a resolution and then each pixel is either
having a certain grade of color and all that is fed into the neural network and that is fed into the neural network and it then gets trained in and it's able to based on these pixels pixel information it is able to get trained and able to
recognize the features and extract the features and thereby it is able to identif ify these images and the location of these images and then when you feed a new image it kind of based on the training it will be able to figure
out where this images from. So that's the way a little bit under the hood how it works. So what are we going to do in this tutorial? We will see what is deep learning and what do we need for deep learning and one of the main components
of deep learning is neural network. So we will see what is neural network what is a perceptron and how to implement logic gates like and or nor and so on using perceptrons the different types of neural networks and then applications of
deep learning and we will also see how neural networks works. So how do we do the training of neural networks and at the end we will end up with a small demo
the end we will end up with a small demo code which will take you through in TensorFlow. Now in order to implement deep learning code there are multiple libraries or development environments that are available and TensorFlow is one
of them. So the focus at the end of this would be on how to use TensorFlow to write a piece of code using Python as a programming language. And we will take up a an example which is a very common one which is like the hello world of
deep learning the handwriting number recognition which is a mnest commonly known as mnest database. So we will take a look at emnest database and how we can train a neural network to recognize handwritten numbers. So that's what you
handwritten numbers. So that's what you will see in this particular video. So let's get started. What is deep learning? Deep learning is like a subset of what is known as a highlevel concept called artificial intelligence. You must
be already familiar must have heard about this term artificial intelligence. So artificial intelligence is like the highle concept if you will and in order to implement [clears throat] artificial intelligence applications we use what is
known as machine learning. And within machine learning, a subset of machine learning is deep learning. Machine learning is a little bit more generic learning is a little bit more generic concept. And deep learning is one type
will see a little later in maybe the following slides a little bit more in detail how deep learning is different from traditional machine learning. But to start with we can mention here that deep learning uses one of the
differentiators between deep learning and traditional machine learning is that deep learning uses neural networks and we will talk about what are neural networks and how we can implement neural networks and so on and so forth as a
part of this tutorial. So a little deeper into deep learning. Deep learning primarily involves working with complicated unstructured data compared to traditional machine learning where where we normally use structured data.
In deep learning the data would be primarily images or voice or maybe text file. So and it is large amount of data as well and deep learning can handle complex operations. It involves complex operations. And the other difference
between traditional machine learning and deep learning is that the feature extraction happens pretty much automatically. In traditional machine learning, feature engineering is done manually. The data scientists, we data
scientists have to do feature engineering, feature extraction. But in deep learning that happens automatically and of course deep learning for large amounts of data, complicated unstructured data, deep learning gives
very good performance. Now as I mentioned one of the secret sources of deep learning is neural networks. Let's see what neural networks is. Neural see what neural networks is. Neural networks is based on our biological
neurons. The whole concept of deep learning and artificial intelligence is based on human brain and human brain consists of billions of tiny stuff called neurons. And this is how a
called neurons. And this is how a biological neuron looks. And this is how biological neuron looks. And this is how an artificial neuron looks. So neural networks is like a simulation of our human brain. Human brain has billions of
human brain. Human brain has billions of biological neurons and we are trying to simulate the human brain using artificial neurons. This is how a biological neuron looks. It has dendrites and the corresponding
component with an artificial neural network is or an artificial neuron are the inputs. They receive the inputs through dendrites and then there is the cell nucleus which is basically the processing unit in a way. So in
artificial neuron also there is a piece which is an equivalent of this cell nucleus and based on the weights and biases. We will see what exactly weights
and biases are as we move the input gets processed and that results in an output. In a biological neuron the output is sent through a synapse and in an artificial neuron there is an equivalent of that in the form of an output. And
biological neurons are also interconnected. So there are billions of neurons which are interconnected. In the same way, artificial neurons are also interconnected. So this output of this neuron will be fed as an input to
another neuron and so on. Now in neural network, one of the very basic units is a perceptron. So what is a perceptron? A perceptron can be considered as one of
the fundamental units of neural networks. It can consist at least one neuron but sometimes it can be more than one neuron but you can create a perceptron with a single neuron and it can be used to perform certain
functions. It can be used as a basic binary classifier. It can be trained to do some basic binary classification. And this is how a basic perceptron looks
like. And this is nothing but a neuron. You have inputs x1, x2, x uh to xn and there is a summation function and then there is what is known as an activation function and based on this input what is known as the weighted sum. The
activation function either gets gives an output like a zero or a one. So we say the neuron is either activated or not. So that's the way it works. So you get the inputs. These inputs are each of the inputs are multiplied by a weight and
there is a bias that gets added and that whole thing is fed to an activation function and then that results in an output. And if the output is correct, it is accepted. If it is wrong, if there is an error, then that error is fed back
and the neuron then adjusts the weights and biases to give a new output and so on and so forth. So that's what is known as the training process of a neuron or a
neural network. There's a concept called perceptron learning. So perceptron learning is again one of the very basic learning processes. The way it works is somewhat like this. So you have all these inputs like x1 to xn and each of
these inputs is multiplied by a weight and then that sum this is the formula and then that sum this is the formula the equation. So that sum wi x i sigma of that which is a sum of all these product of x and w is added up and then
a bias is added to that. The bias is not dependent on the input but or the input values but the bias is common for one neuron. However the bias value keeps
Once the training is completed, the values of these weights W1, W2 and so on and the value of the bias gets fixed. So that is basically the whole training
process and that is what is known as the perceptron training. So the weights and biases keep changing till you get the accurate output. And the summation is of course passed through the activation function. As you see here, this wixi
function. As you see here, this wixi summation plus B is passed through activation function and then the neuron gets either fired or not and based on that there will be an output that output is compared with the actual or expected
value which is also known as labeled information. So this is the process of supervised learning. So the output is already known and um that is compared and thereby we know if there is an error or not and if there is an error the
error is fed back and the weights and biases are updated accordingly till the error is reduced to the minimum. So this iterative process is known as perceptron
learning or perceptron learning rule and this error needs to be minimized. So till the error is minimized this iteratively the weights and biases keep
changing and that is what is the training process. So the whole idea is to update the weights and the bias of the perceptron till the error is minimized. The error need not be zero. The error may not ever reach zero. But
the idea is to keep changing these weights and bias so that the error is minimum. the minimum possible that it can have. So this whole process is an iterative process and this is the iteration continues till either the
iteration continues till either the error is zero which is uh unlikely situation or it is the minimum possible within these given conditions. Now in 1943 two scientists Warren Melikch and Walter Pittz came up with an experiment
where they were able to implement the logical functions like and or and nor logical functions like and or and nor using neurons and that was a significant
breakthrough in a sense. So they were able to come up with the most common logical gates. they were able to implement some of the most common logical gates which could take two inputs like a and b and then give a
corresponding result. So for example in case of an and gate a and b and then the output is a b in case of an orgate it is a plus b and so on and so forth and they were able to do this using a single layer perceptron. Now most of these
gates it was possible to use single layer perceptron except for XR and we will see why that is in a little bit. So this is how an AND gate works. The inputs A and B the output should be fired or the neuron should be fired only
when both the inputs are one. So if you have 0 0 the output should be zero. For have 0 0 the output should be zero. For 0 1 it is again 0 1 0 again 0 and 1 1 the output should be one. So how do we implement this with a neuron? So it was
found that by changing the values of weights it is possible to achieve this logic. So for example if we have equal weights like 7.7 and then if we take the
sum of the weighted product. So for example 7 into 0 and then 7 into 0 will give you zero and so on and so forth. And in the last case when both the inputs are one you get a value which is greater than one which is the threshold.
So only in this case the neuron gets activated and the output is there is an output. In all the other cases there is no output because the threshold value is one. So this is implementation of an AND gate using a single perceptron or a
single neuron. Similarly an orgate. In order to implement an argate in case of an orgate the output will be one if either of these inputs is one. So for example 01 will result in one or rather in all the cases it is one except for 0
0. So how do we implement this using a perceptron once again if you have a perceptron with weights for example 1.2. Now if you see here if in the first case when both are zero the output is zero. In the second case when it is 0 and 1
1.2 2 into 0 is 0 and then 1.2 into 1 is 1 and [clears throat] in the second case similarly the output is 1.2 in the last case when both the inputs are one the output is 2.4. So during the training process these weights will keep changing
and then at one point where the weights are equal to w1 is equal to 1.2 and w2 is equal to 1.2 the system learns that it gives the correct output. So that is implementation of orgate using a single neuron or a single layer perceptron. Now
XR gate this was one of the challenging ones. They tried to implement an XR gate with a single level perceptron but it was not possible and therefore in order to implement an XR. So this was like a a roadblock in the progress of U neural
network. However, subsequently they realized that this can be implemented an realized that this can be implemented an XR gate can be implemented using a multi-level perceptron or MLP. So in this case there are two layers instead
of a single layer and this is how you can implement an XR gate. So you will see that X1 and X2 are the inputs and there is a hidden layer and that's why there is a hidden layer and that's why it is denoted as H3 and H4 and then you
take the output of that and feed it to the output at 05 and provide a threshold here. So we will see here that this is the numerical calculation. So the
the numerical calculation. So the weights are in this case for X1 it is 20 and minus 20 and once again 20 and minus 20. So these inputs are fed into H3 and 20. So these inputs are fed into H3 and H4. So you'll see here for H3 the input
H4. So you'll see here for H3 the input is 0 1 1 and for H4 it is 1 0 1 1. And if you now look at the output final output where the threshold is taken as 1. If you use a sigmoid with the threshold one you will see that in these
threshold one you will see that in these two cases it is zero and in the last two cases it is one. So this is the implementation of XR. In case of XR only when one of the inputs is one you will get an output. So that is what we are
seeing here. If we have either both the inputs are one or both the inputs are zero then the output should be zero. So that is what is an exclusive orgate. So it is exclusive because only one of the inputs should be one and then only
you'll get an output of one which is satisfied by this condition. So this is a special implementation. An XR gate is a special implementation of a perceptron. Now that we got a good idea about perceptron, let's take a look at
seen what is a perceptron, we have seen what is a neuron. So we will see what exactly is a neural network. So neural network is nothing but a network of these neurons and they are different types of neural networks. There are
about five of them. These are artificial neural network, convolutional neural network, then recursive neural network or recurrent neural network, deep neural network and deep belief network. So, and each of these types of neural networks
have a special you know they can solve a special kind of problems. For example, convolutional neural networks are very good at performing image processing and image recognition and so on. Whereas RNN
are very good for speech recognition and also text analysis and so on. So each type has some special characteristics and they can uh they are good at performing certain special kind of tasks. What are some of the applications
tasks. What are some of the applications of deep learning? Deep learning is today used extensively in gaming. You must have heard about Alph Go which is a game created by a startup called Deep Mind which got acquired by Google and Alph Go
which got acquired by Google and Alph Go is an AI which defeated the human world champion Lee Sedall in this game of go. So gaming is an area where deep learning is being extensively used and a lot of research happens in the area of gaming
as well. In addition to that nowadays there are neural networks a special type called generative adversarial networks which can be used for synthesizing either images or music or text and so on and they can be used to compose music.
So the neural network can be trained to compose a certain kind of music and autonomous cars. So you must be familiar with Google, Google's self-driving car and today a lot of automotive companies are investing in this space and uh deep
learning is a core component of this autonomous cars. The cars are trained to recognize for example the road the the lane markings on the road signals any
obstruction and so on and so forth. So all this involves deep learning. So that's another major application and uh that's another major application and uh robots we have seen several robots
including Sophia you may be familiar with Sophia who was given a citizenship by Saudi Arabia and there are several such robots which are very humanlike and the underlying technology in many of these robots is deep learning. Medical
these robots is deep learning. Medical diagnostics and healthc care is another major area where deep learning is being used. And within healthcare diagnostics again there are multiple areas where deep learning and image recognition
image processing can be used. For example for cancer detection as you may be aware if cancer is detected early on it can be cured. And one of the challenges is in the availability of specialists who can diagnose cancer
using these diagnostic images and various scans and and so on and so forth. So the idea is to train neural network to perform some of these activities so that the load on the cancer specialist doctors or oncologists
uh comes down and there is a lot of research happening here and there are already quite a few applications that are claimed to be performing better than human beings in this space. Can be lung cancer, it can be breast cancer and so
on and so forth. So healthcare is a major area where deep learning is being applied. Let's take a look at the inner working of a neural network. So how does an artificial neural network let's say identify can we train a neural network
to identify the shapes like squares and circles and triangles when these images are fed. So this is how it works. Any image is nothing but it is a digital
information of the pixels. So in this particular case, let's say this is an particular case, let's say this is an image of 28x 28 pixel and this is an image of a square. There's a certain way in which the pixels are lit up and so
these pixels have a certain value maybe from 0 to 256 and 0 indicates that it is from 0 to 256 and 0 indicates that it is black or it is dark and 256 indicates it
is completely it is white or lit up. So that is like an indication or a measure that is like an indication or a measure of the how the pixels are lit up. And so this is an image is let's say consisting of information of 784 pixels. So all the
information what is inside this image can be kind of compressed into these 784 pixels. The way each of these pixels is lit up provides information about what
exactly is the image. So we can train neural networks to use that information neural networks to use that information and identify the images. So let's take a and identify the images. So let's take a look how this works. So each neuron the
value if it is close to one that means it is white whereas if it is close to zero that means it is black. Now this is a an animation of how this whole thing
works. So these pixels one of the ways of doing it is we can flatten this image of doing it is we can flatten this image and take this complete 784 pixels and feed that as input to our neural network. The neural network can consist
of probably several layers. There can be a few hidden layers and then there is an input layer and an output layer. Now the input layer takes these 784 pixels as input. The values of each of these pixels and then you get an output which
can be of three types or three classes. One can be a square, a circle or a triangle. Now during the training process there will be initially obviously you feed this image and it will probably say it's a circle or it
will say it's a triangle. So as a part of the training process, we then send that error back and the weights and the biases of these neurons are adjusted
till it correctly identifies that this is a square. That is the whole training is a square. That is the whole training mechanism that happens out here. Now let's take a look at a circle. Same way. So you feed [snorts] these 784
pixels. There is a certain pattern in which the pixels are lit up and the neural network is trained to identify that pattern. And during the training
process once again it would probably initially identify it incorrectly saying this is a square or a triangle and then that error is fed back and the weights
and biases are adjusted finally till it finally gets the image correct. So that is the training process. So now we will take a look at same way a triangle.
So now if you feed another image which is consisting of triangles. So this is the training process. Now we have trained our neural network to classify trained our neural network to classify these images into a triangle or a circle
and a square. So now this neural network can identify these three types of objects. Now if you feed another image and it will be able to identify whether it's a square or a triangle or a circle. Now what is important to be observed is
that when you feed a new image it is not necessary that the image or the the triangle is exactly in this position. Now the neural network actually
identifies the patterns. So even if the triangle is let's say positioned here not exactly in the middle but maybe at the corner or in the side it would still identify that it is a triangle and that is the whole idea behind pattern
recognition. So how does this training process work? This is a quick view of how the training process works. So we have seen that a neuron consists of inputs. It receives inputs and then there is a weighted sum which is nothing
there is a weighted sum which is nothing but this x i wi summation of that plus the bias and this is then fed to the activation function and that in turn gives us a output. Now during the training process initially obviously
when you feed these images when you send maybe a square it will identify it as a triangle and when you maybe feed a triangle it will identify as a square and so on. So that error information is fed back and initially these weights can
be random. Maybe all of them have zero values and then it will slowly keep changing. So the as a part of the training process the values of these training process the values of these weights W1, W2 up to WN keep changing in
such a way that towards the end of the training process it should be able to identify these images correctly. So till then the weights are adjusted and that is known as the training process. So and these weights are numeric values. It
could be 0.5.25.35 and so on. It could be positive or it could be negative. And the value that is coming here is the pixel value as we have seen. It can be anything between 0 to 1. You can scale it between 0 to 1 or
to 1. You can scale it between 0 to 1 or 0 to 256 whichever way 0 being black and 256 being white. And then all the other colors in between. So that is the input. So these are numerical values. this multiplication or the product wi xi is a
numerical value. You need to keep in mind that the bias is fixed for a neuron. It doesn't change with the inputs whereas the weights are one per input. So that is one important point to be noted. So but the bias also keeps
changing. Initially it will again have a random value but as a part of the training process the weights the values of the weights W1 W2 WN and the value of of the weights W1 W2 WN and the value of B will change and ultimately once the
training process is complete these values are fixed for this particular values are fixed for this particular neuron W1 W2 up to WN and plus the value of the B is also fixed for this particular neuron and in this way there
will be multiple neurons and each there may be multiple levels of neurons here and that's the way the training process works. So this is another example of multilayer. So there are two hidden layers in between and then you have the
input layer values coming from the input layer. Then it goes through multiple an output layer. And as you can see there are weights and biases for each of these neurons in in each layer and all of them gets keeps changing during the
training process. And at the end of the training process all these weights have a certain value and that is a trained model and those values will be fixed once the training is completed. All right. Then there is something known as
activation function. Neural networks consists of one of the components in neural networks is activation function and every neuron has an activation function and there are different types of activation functions that are used.
It could be a relu, it could be sigmoid and so on and so forth. And the activation function is what decides whether a neuron should be fired or not. So whether the output should be zero or one is decided by the activation
function and the activation function in turn takes the input which is the weighted sum. Remember we talked about wixi plus b. That weighted sum is fed as a input to the activation function and then the output can be either a zero or
a one. And there are different types of activation functions which are covered in an earlier video you might want to watch. All right. So as a part of the training process we feed the inputs the
label data or the training data and then it gives an output which is the predicted output by the network which we indicate as yhat and then there is a labeled data because we for supervised learning we already know what should be
the output. So that is the actual output and in the initial process before the training is complete obviously there will be error. So that is measured by what is known as a cost function. So difference between the predicted output
and the actual output is the error and the cost function can be defined in different ways. There are different types of cost functions. So in this case it is like the average of the squares of the error. So and then all the errors
are added which can sometimes be called as sum of squares sum of square errors or SSC and that is then fed as a feedback in what is known as backward propagation or back propagation and that helps in the network adjusting the
weights and biases and so the weights and biases get updated till this value the error value or the cost function is minimum. Now there is a optimization
technique which is used here called gradient descent optimization and this algorithm works in a way that the error which is the cost function needs to be minimized. So there's a lot of mathematics that goes behind this. For
example, they find the uh local minima and the global minima using the differentiation and so on and so forth. But the idea is this. So as a training process as the as the part of training the whole idea is to bring down the
error which is like let's say this is the function the cost function at certain levels it is very high the cost value of the cost function or the output of the cost function is very high. So the weights have to be adjusted in such
a way and also the bias of course that the cost function is minimized. So there is this optimization technique called gradient descent that is used and this
is known as the learning rate. Now gradient descent you need to specify what should be the learning rate and the learning rate should be optimal because learning rate should be optimal because if you have a very high learning rate
if you have a very high learning rate then the optimization will not converge because at some point it will cross over to the side. On the other hand, if you to the side. On the other hand, if you have very low learning rate, then it
might take forever to convert. So you need to come up with the optimum value of the learning rate. And once that is done using the gradient descent optimization, the error function is reduced and that's like the end of the
training process. All right. So this is another view of gradient descent. So this is how it looks. This is your cost function. the output of the cost function and that has to be minimized using gradient descent algorithm and
these are like the parameters and weight could be one of them. So initially we start with certain random values so cost will be high and then the weights keep changing and in such a way that the cost function needs to come down and at some
point it may reach the minimum value and then it may increase. So that is where the gradient descent algorithm decides that okay it has reached the minimum value and it will kind of try to stay here. This is known as the global
minima. Now sometimes these curves may not be just for explanation purpose. This has been drawn in a nice way but sometimes these curves can be pretty erratic. There can be some local minima here and then there is a peak and then
and so on. So the whole idea of gradient descent optimization is to identify the global minima and to find the weights and the bias at that particular point.
So that's what is gradient descent and then this is another example. So you can have these multiple local minima. So as you can see at this point when it is coming down it may appear like this is a minimum value but then it is not. This
is actually the global minimum value and the gradient descent algorithm will make an effort to reach this level and not get stuck at this point. So the algorithm is already there and it knows how to identify this global minimum and
that's what it does during the training process. Now in order to implement deep learning there are multiple platforms and languages that are available but the most common platform nowadays is tensorflow and so that's the reason we
have uh this tutorial we created this tutorial for tensorflow. So we will take you through a quick demo of how to write a tensorflow code using python and tensorflow is uh an opensource platform created by Google. So let's just take a
look at the details of TensorFlow. And so this is a a library a Python library. So you can use Python or any other languages. It's also supported in other languages like Java and R and so on. But Python is the most common language that
Python is the most common language that is used. So it is a library for developing deep learning applications especially using neural networks. And it consists of primarily two parts if you will. So one is the tensors and then the
other is the graphs or the flow. That's the way the name that's the reason for this kind of a name called tensorflow. So what are tensors? Tensors are like multi-dimensional arrays if you will. That's one way of
looking at it. So usually you have a one-dimensional array. So first of all you can have what is known as a scalar which means a number. And then you have a one-dimensional array something like this which means this is like a set of
array. Then you can have a two-dimensional array which is like a two-dimensional array which is like a matrix and beyond that sometimes it gets three-dimensional array. But TensorFlow can handle many more dimensions. So it
can have multi-dimensional arrays. That is the strength of TensorFlow and which makes computation deep learning computation much faster and that's the reason why TensorFlow is used for developing deep learning applications.
So TensorFlow is a deep learning tool and this is the way it works. So the data basically flows in the form of tensors and the way the programming works as well is that you first create a graph of how to execute it and then you
actually execute that particular graph in the form of what is known as a tensorflow code as we move forward. So all the data is managed or manipulated
in tensors and then the processing happens using this graphs. There are certain terms called like for example ranks of a tensor. The rank of a tensor is like a dimensional dimensionality in a way. So for example if it is scalar so
there is just a number just one number the rank is supposed to be zero and then it can be a one-dimensional vector in which case the rank is supposed to be one and then you can have a two-dimensional vector typically like a
matrix then in that case we say the rank is two and then if it is a three-dimensional array then it rank is three and so on. So it can have more [clears throat] than three as well. So it is possible that you can store
multi-dimensional arrays in the form of tensors. So what are some of the properties of TensorFlow? I think today it is one of the most popular platform. TensorFlow is the most popular deep learning platform or library. It is open
source. It's developed by Google, developed and maintained by Google. But important things about TensorFlow is that it can run on CPUs as well as GPUs.
GPU is a graphical processing unit just like CPU is central processing unit. Now in earlier days GPU was used for primarily for graphics and that's how the name has come and one of the reasons is that it cannot perform generic
activities very efficiently like CPU but it can perform iterative actions or computations extremely fast and much faster than a CPU. So they are really
good for computational activities and in deep learning there is a lot of iterative computation that happens. So in the form of matrix multiplication and in the form of matrix multiplication and so on. So GPUs are very well suited for
this kind of computation and TensorFlow supports both GPU as well as CPU. And there's a certain way of writing code in TensorFlow. We will see as we go into the code and of course TensorFlow can be used for traditional machine learning as
well but then that would be an overkill but just for understanding it may be a good idea to start writing code for a normal machine learning use case so that you get a hang of how TensorFlow code works and then you can move into neural
networks. So that is um just a suggestion but if you're already familiar with how tensorflow works then probably yeah you can go straight into the neural networks part. So in this tutorial we will take the use case of
recognizing handwritten digits. This is like a hello world of deep learning. And this is a nice little M&amp;S database is a nice little database that has images of
handwritten digits nicely formatted because very often in deep learning and neural networks. We end up spending a lot of time in preparing the data for training. And with MNEST database, we can avoid that. you already have the
data in the right format which can be directly used for training and MNEST directly used for training and MNEST also offers a bunch of built-in utility functions that we can straight away use and call those functions without
worrying about writing our own functions and that's one of the reasons why MNEST database is very popular for training purposes initially when people want to learn about deep learning and TensorFlow this is the database that is used and it
has a collection of 70,000 handwritten digits and a large part of them are for training. Then you have test just like in any machine learning process and then
you have validation and all of them are labeled. So you have the images and they're labeled and these images they look somewhat like this. So they are look somewhat like this. So they are handwritten images collected from a lot
of individuals. People have these are samples written by human beings. They have handwritten these numbers. These numbers going from 0 to 9. So people have written these numbers and then the images of those have been taken and
formatted in such a way that it is very easy to handle. So that is MNEST database and the way we are going to implement this in our TensorFlow is we
will feed this data especially the training data along with the label training data along with the label information and uh the data is basically these images are stored in the form of the pixel information as we have seen in
one of the previous slides. All the images are nothing but these are pixels. So an image is nothing but an arrangement of pixels and the value of the pixel either it is lit up or it is not or in somewhere in between. That's
how the images are stored and that is how they are fed into the neural network and for training. Once the network is trained when you provide a new image it
will be able to identify within a certain error of course and for this we will use one of the simpler neural network configurations called softmax
network configurations called softmax and for simplicity what we will do is we will flatten these pixels. So instead of taking them in a two-dimensional arrangement we just flatten them out. So for example, it starts from here. It is
for example, it starts from here. It is a 28x 28. So there are 784 pixels. So pixel number one starts here. It goes all the way up to 28. Then 29 starts all the way up to 28. Then 29 starts here and goes up to 56 and so on. And
the pixel number 784 is here. So we take all these pixels, flatten them out and all these pixels, flatten them out and feed them like one single line into our neural network. And this is a what is known as a softmax layer. What it does
known as a softmax layer. What it does is once it is trained it will be able to identify what digit this is. So there are in this output layer there are 10 are in this output layer there are 10 neurons each signifying a digit and at
any given point of time when you feed an image only one of these 10 neurons gets activated. So for example, if this is trained properly and if you feed a
number nine like this, then this particular neuron gets activated. So you get an output from this neuron. Let me just use uh a pen or a laser to show you
here. Okay. So you're feeding a number nine. Let's say this has been trained. And now if you're feeding a number nine, this will get activated. Now let's say this will get activated. Now let's say you feed one to the trained network then
this neuron will get activated. If you feed two this neuron will get activated and so on. I hope you get the idea. So this is one type of a neural network or an activation function known as softmax layer. So that's what we will be using
here. This is one of the simpler ones for quick and easy understanding. So this is how the code would look. We will go into our lab environment in the cloud and uh we will show you there directly but very quickly this is how the code
looks and uh let me run you through briefly here and then we will go into the Jupyter notebook where the actual code is and we will run that as well. So as a first step first of all we are using Python here and that's why the
using Python here and that's why the syntax of the language is Python and the first step is to import the TensorFlow library. So and we do this by using this line of code saying import tensorflow as TF. TF is just for convenience. So you
can name give any name and once you do this TF is TensorFlow is available as an object in the name of TF and then you can run its uh methods and accesses its attributes and so on and so forth. And MNEST database is actually an integral
part of TensorFlow. And that's again another reason why we as a first step we always use this example mnest database example. So you just simply import mnest
database as well using this line of code and you slightly modify this so that the labels are in this format what is known as one hot true which means that the
label information is stored like an array and uh let me just uh use the pen to show what exactly it is. So when you do this one hot true what happens is
do this one hot true what happens is each label is stored in the form of an array of 10 digits and let's say the number is uh 8. Okay. So in this case all the remaining values there will be a bunch of zeros. So this is like array at
position zero. This is at position one position two and so on and so forth. Let's say this is position 7. Then this is position 8 that will be one because our input is 8 and again position 9 will be zero. Okay. So one hot encoding this
one hot encoding true will kind of load the data in such a way that the labels the data in such a way that the labels are in such a way that only one of the digits has a value of one and that indicates. So based on which digit is
one we know what is the label. So in this case the eighth position is one. Therefore, we know this sample data the value is 8. Similarly, if you have a two here, let's say, then the labeled information will be somewhat like this.
So, you have your labels. So, you have this as zero, the zero position, the first position is also zero. The second position is one because this indicates number two. And then you have third as zero and so on. Okay. So, that is the
significance of this one hot true. All right. And then we can check how the data is uh looking by displaying the the data. And as I mentioned earlier, this
is pretty much in the form of digital form like numbers. So all these are like pixel values. So you will not really see an image in this format. But there is a way to visualize that image. I will show you in a bit. And uh this tells you how
many images are there in each set. So the training there are 55,000 images in training and in the test set there are 10,000 and then validation there are 5,000. So altogether there are 70,000 images. All right. So let's uh move on
images. All right. So let's uh move on and we can view the actual image by uh using the mattplot clip library. And this is how you can view this is the code for viewing the images. And you can view them in color or you can view them
in grayscale. So the cap is what tells in what way we want to view it. And what are the maximum values and the minimum values of the pixel values. So these are the max and minimum values. So of the pixel values. So maximum is one because
this is a scaled value. So one means it is uh white and uh zero means it is black and in between is it can be anywhere in between black and white. And
the way to train the model there is a certain way in which you write your certain way in which you write your TensorFlow code and um the first step is to create some placeholders and then you create a model. In this case, we will
use the softmax model, one of the simplest ones. And um placeholders are primarily to get the data from outside into the neural network. So this is a very common mechanism that is used. And uh then of course you will have
variables which are your you remember these are your weights and biases. So for in our case there are 10 neurons and uh each neuron actually has 784
because each neuron takes all the inputs. So if we go back to our slide here actually every neuron takes all the 784 inputs. Right? This is the first neuron. It has it receives all the 784. This is the second neuron. This also
receives all the 7. So each of these inputs needs to be multiplied with a weight. And that's what we are talking about here. So these are this is a a about here. So these are this is a a matrix of 784
matrix of 784 values for each of the neurons. And uh values for each of the neurons. And uh so it is like a 10x 784 matrix because so it is like a 10x 784 matrix because there are 10 neurons. And uh similarly
there are biases. Now remember I mentioned bias is only one per neuron. So it is not one per input unlike the weights. So therefore there are only 10 biases because there are only 10 neurons in this case. So that is what we are
creating a variable for biases. So this is uh something little new in TensorFlow. You will see unlike our regular programming languages where everything is a variable. Here the variables can be of three different
types. You have placeholders which are primarily used for feeding data. You have variables which can change during the course of computation. And then a third type which is not shown here are constants. So these are like fixed
numbers. All right. So in a regular programming language you may have everything as variables or at the most variables and constants. But in TensorFlow you have three different types placeholders, variables and
constants. And then you create what is known as a graph. So TensorFlow programming consists of graphs and tensors as I mentioned earlier. So this can be considered ultimately as a tensor and then the graph tells how to execute
the whole implementation. So that the execution is stored in the form of a graph. And in this case what we are doing is we are doing a multiplication. TF you remember this TF was created as a TensorFlow object here. One more level
one more. So TF is available here. Now, TensorFlow has what is known as a matrix multiplication or matal function. So that is what is being used here in this
case. So we are using the matrix multiplication of TensorFlow. So that multiplication of TensorFlow. So that you multiply your input values X with W. Right? This is what we were doing. XW plus B. You're just adding B. And this
is in very similar to one of the earlier slides where we saw sigma xi wi. So that's what we are doing here. Matrix multiplication is multiplying all the input values with the corresponding weights and then adding the bias. So
that is the graph we created. And then we need to define what is our loss function and what is our optimizer. So in this case we again use the in this case we again use the tensorflow's APIs. So tf.n NN softmax
cross entropy with logics is the uh API that we will use and reduce mean is what that we will use and reduce mean is what is like the mechanism whereby which says is like the mechanism whereby which says that you reduce the error and optimizer
for doing deduction of the error. What optimizer are we using? So we are using gradient descent optimizer. We discussed about this in couple of slides uh earlier. And for that you need to specify the learning rate. You remember
we saw that there was a a slide somewhat like this and then you define what should be the learning rate. How fast you need to come down. That is the learning rate. And this again needs to
be tested and tried and to find out the optimum level of this learning rate. It shouldn't be very high in which case it will not converge or shouldn't be very low because it will in that case it will take very long. So you define the
optimizer and then you call the method minimize for that optimizer and that will kickstart the training process and so far we've been creating the graph and in order to actually execute that graph we create what is known as a session and
then we run that session and once the training is completed we specify how many times how many iterations we want it to run. So for example in this case we are saying thousand steps. So that is a exit strategy in a way. So you specify
the exit condition. So a training will run for thousand iterations. And once that is done we can then evaluate the model using some of the techniques shown here. So let us get into the code quickly and see how it works. So this is
our cloud environment. Now you can install TensorFlow on your local machine as well. I'm showing this demo on our existing cloud but you can also install TensorFlow on your local machine and uh there is a separate video on how to set
up your TensorFlow environment. You can watch that if you want to install your local environment or you can go for other any cloud service like for example Google cloud, Amazon or cloud labs. Any of these you can use and u run and try
of these you can use and u run and try the code. Okay. So it has got started.
All right. So this is our deep learning tutorial uh code and uh this is our TensorFlow environment and uh so let's get started. The first we have seen a little bit of a code walk through uh in the slides as well. Now
you will see the actual code in action. So the first thing we need to do is import tensorflow and then we will import the data and we need to adjust import the data and we need to adjust the data in such a way that the
one hot is encoding is set to true one hot encoding right as I explained earlier. So in this case the label values will be shown appropriately and if we just check what is the type of the data. So you can see that this is a uh
data. So you can see that this is a uh data sets Python data sets and if we check the number of images the way it looks. So this is how it looks it is an looks. So this is how it looks it is an array of type float 32. Similarly
the number if you want to see what is the number of training images there are 55,000 then there are test images 10,000 and then there are test images 10,000 and then validation images 5,000. Now let's take
a quick look at the data itself visualization. So we will use um visualization. So we will use um mattplot lip for this and um if we take a look at the shape now shape gives us like the dimension of the tensors or or
or the arrays if you will. So in this case the training data set if we see the size of the training data set using the method shape it says there are 55,000 method shape it says there are 55,000 and 55,000 by 784. So remember this 784
and 55,000 by 784. So remember this 784 is nothing but the 28x 28 28 into 28. So that is equal to 784. So that's what it is showing. Now we can take just uh one is showing. Now we can take just uh one image and just see what is the the first
image and see what is the shape. So again size obviously it is only 784. Similarly you can look at the image itself the data of the first image itself. So this is how it it shows. So large part of it will probably be zeros
because as you can imagine in the image only certain areas are written rest is blank. So that's why you will mostly see zeros either it is black or white. But
then there are these values are so the values are actually they are scaled. So the values are between 0 and one. Okay. So this is what you're seeing. So certain locations there are some values and then other locations there are
and then other locations there are zeros. So that is how the data is stored and loaded. If we want to actually see what is the value of the handwritten image. Uh if you want to view it, this is how you view it. So you create like
is how you view it. So you create like do this reshape and um mattplot lib has this um feature to show you these images. So we will actually use the images. So we will actually use the function called um im show and then if
function called um im show and then if you pass this parameters appropriately you will be able to see the different images. Now I can change the values in this position. So which image we are looking at right? So we can say if I
looking at right? So we can say if I want to see what is there in maybe 5,000 right? So 5,000 has three. Similarly you can just say five. What is in five? Five as eight. What is in 50?
you're wondering uh how I'm executing this code shift enter in case you're not familiar with Jupyter notebooks. Shift enter is how you execute each cell individual cell and if you want to execute the entire program you can go
execute the entire program you can go here and say run all. So that is how here and say run all. So that is how this code gets executed. And um here again we can check what is the maximum value and what is the minimum value of
this pixel values. As I mentioned this is it is scaled. So therefore it is between the values lie between 1 and zero. Now this is where we create our zero. Now this is where we create our model. The first thing is to create the
required placeholders and variables and that's what we are doing here as we have that's what we are doing here as we have seen in the slides. So we create one seen in the slides. So we create one placeholder and we create two variables
which is for the weights and biases. These two variables are actually These two variables are actually matrices. So each variable has 784x 10 matrices. So each variable has 784x 10 actual values. Okay. So one for this 10
is for each neuron there are 10 neurons and 784 is for the pixel values inputs that are given which is 28 into 28 and the biases as I mentioned one for each
neuron. So there will be 10 biases they are stored in a variable by the name B. And this is the graph which is basically the multiplication of these matrix multiplication of X into W and then the bias is added for each of the neurons.
bias is added for each of the neurons. And the whole idea is to minimize the error. So let me just execute. I think this code is executed. Then we define what is our the Y- value is basically the label value. So this is another
placeholder. We had x as one placeholder and y true as a second placeholder and this will have values in the form of uh 10digit 10digit uh arrays and uh since
10digit 10digit uh arrays and uh since we said one hot encoded the position which has a one value indicates what is the label for that particular number. All right. Then we have cross entropy which is nothing but the loss loss
function and we have the optimizer. We have chosen gradient descent as our optimizer. Then the training process itself. So the training process is nothing but to minimize the cross
entropy which is again nothing but the loss function. So we define all of this in the form of a graph. So the up to here remember what we have done is we have not exactly executed any tensorflow code till now we are just preparing the
graph the execution plan that's how the tensorflow code works. So the whole structure and format of this code will be completely different from how we normally do programming. So even with people with programming experience may
find this a little difficult to understand it and it needs quite a bit of practice. So you may want to view this uh video also maybe a couple of times to understand this flow because the way TensorFlow programming is done
is slightly different from the normal programming. Some of you who let's say have done uh maybe spark programming to some extent will be able to easily understand this. Uh but even in spark
the the programming the code itself is pretty straightforward behind the scenes the execution happens slightly differently but in tensorflow even the code has to be written in a completely different way. So the code doesn't get
executed uh in the same way as you have written. So that that's something you need to understand and a little bit of practice is needed for this. So so far what we have done up to here is creating the variables and feeding the variables
and um or rather not feeding but setting up the variables and uh the graph that's up the variables and uh the graph that's all defining maybe the uh what kind of a network you want to use for example we want to use a softmax and so on. So you
have created the variables how to load the data, loaded the data, viewed the data and prepared everything but you have not yet executed anything in TensorFlow. Now the next step is the execution in TensorFlow. So the first
step for doing any execution in TensorFlow is to initialize the variables. So anytime you have any variables defined in your code, you have variables defined in your code, you have to run this piece of code always. So you
need to basically create what is known as a a node for initializing. So this is a node. You still are not yet executing anything here. You just created a node for the initialization. So let us go ahead and create that. And
here onwards is where you will actually execute your code uh in TensorFlow. And in order to execute the code, what you will need is a session. TensorFlow session. So tf session will give you a session. And there are a couple of
different ways in which you can do this. But one of the most common methods of doing this is with what is known as a with loop. So you have with tf do
with loop. So you have with tf do session as says and with a colon here. And this is like a block starting of the block. And these indentations tell how block. And these indentations tell how far this block goes. And this session is
far this block goes. And this session is valid till this block gets executed. So that is the purpose of creating this width block. This is known as a width width block. This is known as a width block. So with tf session as you say
sess.run in it. Now ces.run run will execute a node that is specified here. So for example here we are saying ces run. Ces
is basically an instance of the session right. So here we are saying tf session. So an instance of the session gets created and we are calling that cess and created and we are calling that cess and then we run a node within that one of
the nodes in the graph. So one of the nodes here is in it. So we say run that particular node and that is when the initialization of the variables happens. initialization of the variables happens. Now what this does is if you have any
variables in your code in our case we have W is a variable and B is a variable. So any variables that we created you have to run this code you have to run the initialization of these variables otherwise you will get an
error. Okay so that is the that's what this is doing. Then we within this width this is doing. Then we within this width block we specify a for loop and we are saying we want the system to iterate for thousand steps and perform the training.
That's what this for loop does. Run training for thousand iterations. And what it is doing basically is it is fetching the data or these images.
Remember there are about 50,000 images but it cannot get all the images in one shot because it will take up a lot of memory and performance issues will be there. So this is a very common way of performing deep learning training. You
always do in batches. So we have maybe 50,000 images but you always do it in batches of 100 or maybe 500 depending on the size of your system and so on and so
forth. So in this case we are saying okay get me 100 uh images at a time and get me only the training images. Remember we use only the training data for training purpose and then we use test data for test purpose. You must be
familiar with machine learning. So you must be aware of this but in case you are not in machine learning also not this is not specific to deep learning but in machine learning in general you have what is known as training data set
have what is known as training data set and test data set. your available data. Typically you will be splitting into two parts and using the training data set for training purpose and then to see how well the model has been trained you use
the test data set to check or test the validity or the accuracy of the model. So that's what we are doing here and you observe here that we are actually calling an MNEST function here. So we are saying mnest train next batch right?
So this is the advantage of using MNEST database because they have provided some very nice helper functions which are readily available otherwise this activity itself we would have had to write a piece of code to fetch this data
in batches that itself is a a lengthy exercise. So we can avoid all that if we are using MNEST database and that's why we use this for the initial learning phase. Okay. So when we say fetch what it will do is it will fetch the images
into X and the labels into Y and then you use this batch of 100 images and you run the training. So ces.run basically what we are doing here is we are running
the training mechanism which is nothing but it passes this through the neural network passes the images through the neural network finds out what is the output and if the output obviously the initially it will be wrong. So all that
feedback is given back to the neural network and thereby all the W's and B's network and thereby all the W's and B's get updated till it reaches thousand iterations. In this case the exit criteria is thousand but you can also
specify probably accuracy rate or something like that for the as an exit criteria. So here it is it it just says that okay this particular image was wrongly predicted. So you need to update your weights and biases. That's the
feedback given to each neuron. And that is run for thousand iterations. And typically by the end of this thousand iterations the model would have learned to recognize these handwritten images. Obviously it will not be 100% accurate.
Obviously it will not be 100% accurate. Okay. So once that is done after so this happens for thousand iterations. Once that is done you then test the accuracy of these models by using the test data set. Right? So this is what we are
little complicated because if you're seeing this for the first time, you need to understand uh the various methods of TensorFlow and so on. But it is TensorFlow and so on. But it is basically comparing the output with what
has been what is actually there. That's all it is doing. So you have your test data and uh you're trying to find out what is the actual value and what is the predicted value and seeing whether they are equal or not. TF do.qual, right? and
how many of them are correct and so on and so forth and based on that the accuracy is uh calculated as well. So this is the accuracy and uh that is what we are trying to see how accurate the model is in predicting these uh numbers
or these digits. Okay. So let us run this. This entire thing is in one cell. So we will have to just run it in one shot. It may take a little while. Let us see. And u not bad. So it has finished the thousand iterations and what we see
the thousand iterations and what we see here as an output is the accuracy. So we see that the accuracy of this model is around 91%. around 91%. Okay. Now which is pretty good for such
a short exercise within such a short time we got 90% accuracy. However in real life this is probably not sufficient. So there are other ways in to increase the accuracy. We will see probably in some of the later tutorials
how to improve this accuracy, how to change maybe the hyperparameters like number of neurons or number of layers and so on and so forth and uh so that this accuracy can be increased beyond 90%. Hello and welcome to the TensorFlow
90%. Hello and welcome to the TensorFlow object detection API tutorial. In this video, I will walk you through the TensorFlow code to perform object detection in a video. So, let's get started. This part is basically you're
importing all the libraries. We need a lot of these libraries. For example, lot of these libraries. For example, numpy. We need image io datetime and pill and so on and so forth. And of course, mattplot lib. So we import all
these libraries and then there are a bunch of variables which have some paths for the files and folders. So this is regular stuff. Let's keep moving. Then we import the mattplot lib and make it inline and uh a few more imports. All
right. And then these are some warnings. We can just ignore them. So if I run this code once again it will go away. All right. And then here onwards we do the model preparation. Now what we're going to do is we're going to use an
existing neural network model. So we are not going to train a new one because that really will uh take a long time and uh it needs a lot of uh computation resources and so on and it is really not required. There are already models that
have been trained and in this case it is the SSD with mobile net. That's the model that we are going to use and uh this model is trained to detect objects and uh it is readily available as open source. So we can actually use this and
if you want to use other models there are a few more models available. So you can click on this link here and uh let more models but we have chosen this particular one because this is uh
faster. It may not be very accurate but that is one of the faster models. But on this link you will see a lot of other models that are readily available. These are trained models. Some of them would take a little longer but they may be
more accurate and so on. So you can probably play around with these other models. Okay. So we will be using that model. So this piece of code this line is basically importing that model and this is also known as a frozen model.
The term we use is frozen model. So we import download and import that and then we will actually use that model in our code. All right. So these two cells we
have downloaded and imported the model and then once it is available locally we will then load this into our program. All right. So we are loading this into
memory and uh you need to perform a couple of additional steps which is basically we need to to map the numbers to text. As you may be aware when we actually build the model and when we run
predictions the model will not give a text the output of the model is usually a number. So we need to map that to a text. So for example if the network
predicts that the output is five. We know that five means it is an airplane things like that. So this mapping is done in this next cell. All right. So let's keep moving. And then we have a helper code which will basically load
the data or load the images and transform into numpy arrays. This is also used in doing object detection in images. So we are actually going to reuse because video is nothing but it consists of frames which in turn are
images. So we are going to pretty much use reuse the same code which we used for doing object detection in images. So this is where the actual detection starts. So here this is the path for where the images are stored. So this is
here once again we are reusing the code which we wrote for detecting objects in an image. So this is the path where the images were stored and this is the extension and this was done for about two or three images. So we will continue
two or three images. So we will continue to use this and uh we go down I'll skip this section. So this is the cell where we are actually loading the video and converting it into frames and then using frame by frame we are detecting the
objects in the image. So in this code what we are doing basically is there a few lines of code what they do is basically once they find an object a box will be drawn around those uh each of those objects and the input file the
name of the input video file is uh traffic it is the extension is mp4 and uh we have this video reader it's a excellent object which is basically part of this class called image IO so we can read and write videos using that and uh
the video that we are going to use is traffic.mpp4. You can use any MP4 file but in our case I picked up video which has uh like car. So let me just show
you. So this is in this object detection folder. I have this MP4 file. I'll just quickly play this video. It's a little slow. Yeah. Okay. So here we go. This is the video. It's a short one. relatively small video so that for this particular
demo and what it will do is once we run our code it will detect each of these cars and it will annotate them as cars. So in this particular video we only have cars we can later on see with another video. I think I have cat here so we can
also try with that but let's first check with this uh traffic video. So let me go back. So we will be reading this frame by frame and um no actually we will be reading the video file but then we will be analyzing it frame by frame and we
will be reading them at 10 frames per second that is the rate we are mentioning here and analyzing it and then annotating and then writing it back. So you will see that we will have a video file name something like this
traffic annotated and um we will see the annotated video. So let's go back and run through this piece of code and then we will come back and see the annotated uh video. This might take a little while. So I will pause the video after
running this particular cell and then come back to show you the results. All right. So let's go ahead and run it. So it is running now. And it is also important that at the end you close the video writer so that it is similar to a
file pointer. When you open a file, you should also make sure you close it so that it doesn't hog the resources. So, it's very similar at the end of it. The last piece or last line of code should be video_riter.close.
All right. So, I'll pause and then I'll come back. Okay. So, I will see you in a little bit. All right. So, now as you can see here, the processing is done. The hourglass has disappeared. That means the video has been processed. So,
let's go back and check the annotated video. We'll go back to my file manager. So this was the original traffic.mpp4 and now you have here traffic_an and now you have here traffic_an annotated mp4. So let's go and run this
and see how it looks. You see here it has got each of these cars are getting detected. Let me pause and show you. So we pause here it says
car 70%. Let us allow it to go a little further. It detects something on top. What is that truck? Okay. So I think because of the board on top it somehow thinks there is a truck. Let's lay some more and see if it detects anything
else. So this is again a car looks like. So let us Yeah. So this is a car and it has confidence level of 69%. Okay. This is again a car. All right. So basically
till the end it goes and detects each and every car that is passing by. Now we can quickly repeat this process for another video. Let me just show you the other video which is a cat. Again there is uh this cat is not really moving or
anything but it is just standing there staring and moving a little slowly and uh our application will our network will detect that this is a cat and uh even when the cat moves a little bit in the other direction it'll continue to detect
and show that it is a cat. Okay. So yeah. So this is how the original video is. Let's go ahead and change our code to analyze this one and see if it detects our network detects this cat. Close this. Here we go. And I go back to
my code. All we need to do is change this traffic to cat. The extension it will automatically pick up because it is given here and then it will run through. So very quickly once again what it is doing is this video reader video reader
has a a neat little feature or interface whereby you can say for frame in video reader. So it will basically provide frame by frame. So you're in a loop frame by frame and then you take that each frame that is given to you take it
and analyze it as if it is an image individual image. So that's the way it works. So it is uh very easy to handle this. All right. So now let's once again run just this cell. Rest of the stuff remains the same. So I will run this
cell again. It will take a little while. So the hourglasses come back. I will pause and then come back in a little while. All right. So the processing is done. Let's go and check the annotated video. Go here. So we have cat
annotated.mpp4. Let's play this. All right. So you can see here it is detecting the cat. And in the beginning you also saw it detected something else here. There looks like it detected one more object. So let's just
go back and see what it has detected here. Let's see. Yes. So what is it trying to show here? It's too small. Not able to see. But uh it is trying to
detect something. I think it is saying it is a car. I don't know. All right. Okay. So in this video there's only pretty much only one object which is a cat. And uh let's wait for some time and see if it continues to detect it when
the cat turns around and moves as well. Just in a little bit that's going to happen and we will see. There we go. And in spite of turning the other way, I
think our network is able to detect that it is a cat. So let me freeze and then show here. It is actually still continues to detect it as a cat. All right. So that's pretty much it. I think that's the only object that it detects
in this particular video. Okay, so close this. So that's pretty much it. Thank you very much for watching this video and you have a great day and in case you have any questions, please uh put them below the video here and we will be more
than happy to get back to you and make sure you put your email id so that we questions. Thank you once again. Bye-bye. &gt;&gt; Today we're going to be covering the convolutional neural network tutorial.
Do you know how deep learning recognizes the objects in an image? And really this particular neural network is how image recognition works. It's very central, one of the biggest building blocks for image recognition. It does it using
convolution neural network. And we over here we have the basic picture of a hummingbird. Pixels of an image fed as input. You have your input layer coming in. So it takes that graphic and puts it into the input layer. You have all your
output layer and your output layer. or one of those is going to light up and go into depth. We're going to actually go back and forth on this a number of times today. So, if you're not catching all the image, um don't worry, we're
going to get into the details. So, we have our input layer accepts the pixels arrays. And you can see up here where they've actually um labeled each block of the bird in different arrays. So, we'll dive into deep as to how that
looks like and how those matrixes are set up. your hidden layer carry out feature extraction by performing certain calculations and manipulation. So this is the part that kind of reorganizes that picture multiple ways until we get
some data that's easy to read for the neural network. This layer uses a matrix filter and performs convolution operation to detect patterns in the image. And if you remember that convolution means to coil or to twist.
So we're going to twist the data around and alter it and use that operation to detect a new pattern. There are multiple hidden layers like convolution layer relu is how that is pronounced and that's the rectified linear unit that
has to do with the activation function that's used. Pooling layer also uses multiple filters to detect edges, corners, eyes, feathers, beak, etc. And just like the term says, pooling is pooling information together. And we'll
look into that a lot closer here. So if you're if it's a little confusing now, squared away with that. And then finally, there is a fully connected layer that identifies the object in the image. So we have these different layers
they come into the final area and that's where we have say one node or one neural network entity that lights up that says it's a bird. What's in it for you? We're going to cover an introduction to the
CNN. What is convolution neural network? how CNN recognizes images. We're going at the individual layers in the convolutional neural network. And finally, we do a use case implementation using the CNN. We'll begin our
introduction to the CNN by introducing the pioneer of convolutional neural network, Yan Leon. He was the director of Facebook AI research group. Built the first convolutional neural network called Lynette in 1988. So these have
been around for a while and have had a chance to mature over the years. It was used for character recognition tasks like reading zip code digits. Imagine processing mail and automating that process. CNN is a feed forward neural
network that is generally used to analyze visual images by producing data with a grid-like topology. A CNN is also known as a convenet. And very key to this is we are looking at images. That was what this was designed for. And
you'll see the different layers as we dig in mirror some of the other some of them are actually now used since we're using uh TensorFlow and KAS in our code layers appear in a lot of your other neural network frameworks. Uh but in
this case, this is very central to processing images and doing so in a variety that captures multiple images and really drills down into their different features. In this example here, you see flowers of two varieties,
orchid and a rose. I think the orchid is much more dainty and beautiful and the couple rose bushes in my yard. Uh they go into the input layer. That data is then sent to all the different nodes in the next layer, one of the hidden layers
based on its different weights and its setup. It then comes out and gives those a new value. Those values then are uh multiplied by their weights and go to then you have the output layer and one of those nodes comes out and says it's
and says it's a rose depending on how was well it was trained. What separates the CNN or the convolutional neural network from other neural networks is a convolutional operation forms a basis of any convolutional neural network. In a
CNN, every image is represented in the form of arrays of pixel values. So here we have a real image of the digit 8 uh that then gets put onto its pixel values represented in the form of an array. In this case you have a two-dimensional
array. And then you can see in the final in form we transform the digit 8 into its representational form of pixels of zeros and one where the ones represent and the zeros represent the white background. To understand the
convolution neural network or how that convolutional operation works, we're going to take a side step and look at matrices. In this case, we're going to simplify it. We're going to take two matrices A and B of one dimension. Now
kind of separate this from your thinking as we learn that you want to focus just on the matrix aspect of this and then we'll bring that back together and see put the pieces for the convolutional operation. Here we've set up two arrays.
We have uh in this case they're a single dimension matrix and we have a= 537597 and we have b= 1 2 3. So in the convolution as it comes in there it's going to look at these two and we're going to start by doing multiplying
them. A * B. And so we multiply the arrays elementwise and we get 5 6 where arrays elementwise and we get 5 6 where five is the 5 * 1, 6 is 3 * 2, and then
the other six is 2 * 3. And since the two arrays aren't the same size, they're truncate the first one, and we're going to look at the second array multiplied first array. Now, that's going to be a little confusing. Remember, a computer
gets to repeat these processes hundreds of times. So, we're not going to just We'll see. We'll bring those back in. And then we have the sum of the product. And then we have the sum of the product. In this case, 5 + 6 + 6= 17. So, in our
A * B, our very first digit in that matrix of A * B is 17. And if you remember, I said we're not going to forget the other digits. So, we now have 325. We move one set over and we take 325 and we multiply that times B. And
325 and we multiply that times B. And you'll see that 3 * 1 is 3, 2 * 2 is four, and so on and so on. We sum it up. So now we have the second digit of our A * B product in the matrix. And we continue on with that same thing. So on
and so on. So then we would go from uh 375 to 759 to 597. This short matrix that that we have for A, we've now covered all the different entities in A that match three different levels of B. Now, in a little bit, we're going to
cover where we use this math at this multiplying of matrices and how that works. Uh, but it's important to understand that we're going through the parts to it to match the smaller matrix with the larger matrix. I know a lot of
people get lost at is, you know, what's going on here with these matrixes. Uh, you break it down. We're looking at a section of A and we're comparing it to B. So when you break that down your mind like that, you realize, okay, so I'm I'm
just taking these two matrices and comparing them and I'm bringing the comparing them and I'm bringing the value down into one matrix A * B. We're juicing that information in a way that will help the computer see different
aspects. Let's go ahead and flip over again back to our images. Here we are back to our images talking about going to the most basic two-dimensional image you can get to. Consider the following two images. the image for the symbol
backslash. When you press the backslash, the above image is processed. And you can see there for the image for the forward slash is the opposite. So when we click the forward slash button, that flips uh very basic. We have four pixels
that. Here we have a little bit more complicated picture. We take a real image of a smiley face. U then we represent that in the form of black and white pixels. So if this was an image in the computer, it's black and white. And
like we saw before, we convert this into the zeros and ones. So where the other just four dots, now we have a significantly larger image coming in. So all together here in just a little bit. Layers in convolutional neural network.
When we're looking at this, we have our convolution layer. And that really is the central aspect of processing images and the convolutional neural network. That's why we have it. And then that's going to be feeding in. And you have
your relu layer which is you know as we talked about the rectified linear unit. We'll talk about that a little bit later. The relu is an how it act is how that layer is activated is the math behind it. What makes the neurons fire.
You'll see that in a lot of other neural networks when you're using it just by itself. It's for processing smaller amounts of data where you use the atom activation feature for large data coming in. Now, because we're processing small
amounts of data in each image, the relu layer works great. You have your pooling data together. Pooling is a neural network term. It's very commonly used. I like to use the term reduce. So, if you're coming from the map and reduce
this data through all these networks and then we're going to reduce it. We're finally, we have the fully connected layer. That's where our output's going to come out. So we have started to look at matrixes. We've started to look at
the convolutional layer and where it fits in and everything. We've taken a look at images. So we're going to focus more on the convolution layer since this is a convolutional neural network. A convolution layer has a number of
filters and perform convolution operation. Every image is considered as a matrix of pixel values. Consider the following 5x5 image whose pixel values are only 0 and one. Now, obviously, when we're dealing with color, there's all
kinds of things that come in on color processing, but we want to keep it And so, we have our image pixels. Uh, so we're sliding the filter matrix over the image and computing the dot product to detect the patterns. And right here,
filter come from? This is a bit confusing because the filter is going to be derived uh later on. We build the filters when we program or train our
model. So you don't need to worry what the filter actually is. What you do need to understand how a convolution layer works is what is the filter doing You don't have just one filter. You'll
look for different aspects. And so the filter might be looking for just edges. We'll cover that a little bit more detail in a minute. Right now we're just focusing on how the filter works as a matrix. Remember earlier we talked about
multiplying matrices together. And here we have our two-dimensional matrix. And you can see we take the filter and we multiply it in the upper left image and multiply it in the upper left image and you can see right here 1* 1 1* 0 1* 1 we
multiply those all together then sum them and we end up with a convolved feature of four. We're going to take that and sliding the filter matrix over productduct to detect patterns. So we're just going to slide this over. We're
it over one notch. Predict the second one and so on and so on all the way through until we have a new matrix. And this matrix which is the same size as a filter has reduced the image and whatever filter whatever that's
filtering out is going to be looking at just those features reduced down to a smaller uh matrix. So once the feature maps are extracted the next step is to move them to the relu layer. So the relu
layer the next step first is going to perform an elementwise operation. So each of those maps coming in if there's negative pixels. So it sets all the negative pixels to zero. Um and you can see this nice graph where it just zeros
out the negatives and then you have a value that goes from zero up to whatever value is coming out of the matrix. This introduces nonlinearity to the network. Uh so up until now we have a when we say linearity we're talking about the fact
that the feature has a value. So it's a linear feature. this feature um came up and has let's say the feature is the edge of the beak. You know, it's like or look at that and say, "Okay, this feature has a value from -10 to 10 in
this case." Um if it was one, it' say, "Yeah, this might be a beak. It might not. Might be an edge right there." A minus 5 means no, we're not even going to look at it. It's a zero. And so we end up with an output. And the output
takes all these featured features. Remember, we're not just running a number of filters on this image and so we end up with an rectified feature map that is looking at just the features coming through and how they
weigh in from our filters. So here we have an input of a it looks like a toucan bird very exotic looking real image is scanned in multiple convolution and the relu layers for locating features and
you can see up here it's turned it into a black and white image and in this case we're looking in the upper right hand corner for a feature and that box scans over a lot of times it doesn't scan one pixel at a time a lot of times it will
skip by two or three or four pixels uh to speed up the process that's one of the ways you can compens compensate if you don't have enough resources on your computation for large images and it's not just one filter slowly goes across
the image. Uh you have multiple filters have been programmed in there. So you're going over the different aspects of the image and just sliding across there and image and just sliding across there and forming a new matrix. One more aspect to
note about the relu layer is we're not just having one relu coming in. Uh so not only do we have multiple features going through but we're generating multiple relu layers for locating the features that's very important to note
you know so we have a quite a bundle we have multiple filters multiple railu uh which brings us to the next step forward propagation now we're going to look at the pooling layer the rectified feature map now goes through a pooling layer
pooling is a downsampling operation that reduces the dimensionality of the do we're trying to take a huge amount of information and reduce it down to a single answer. This is a specific kind of bird. This is an iris. This is a
rose. So you have a rectified feature map. And you see here we have a rectified feature map coming in. Um we set the max pooling with a 2x two filters and a stride of two. And if you remember correctly, I talked about not
going one pixel at a time. Uh well, that's where the stride comes in. we end up with a 2x two pulled feature map, but instead of moving one over each time and looking at every possible combination, we skip a we skip a few there. We go by
just do every other one. Um, and this reduces our rectified feature map, which as you can see over here, 16x 16 to a 4x4. So, we're continually trying to filter and reduce our data so that we can get to something we can manage. And
over here you see that we have the max uh 3 4 1 and two. And in the max pooling little bit different than what we were looking at before. So coming from the
rectified feature, we're now finding the max value and then we're pulling those features together. So instead of think of this as image of the map, think of this as how valuable is a feature in that area. How much of a feature value
best or the maximum feature for that area. It might have that one piece of the filter of the beak said, "Oh, I see then it skips over and says, "I see a
this one is rated as a four." We don't want to sum it together cuz then, you know, you might have like five ones. And it'll say, "Ah, five." But you might it'll say, "Ah, five." But you might have uh four zeros and one 10. And that
beak." Where the ones will say, "Probably not a beak." A little strange but you can see how that pulled feature map comes down. And we're just looking for the max value in each one of those matrixes. Pooling layer uses different
filters to identify different parts of the image like edges, corners, body, the image like edges, corners, body, feathers, eyes, beak, etc. Um, I know I uh each feature could be each a different part of the bird coming in.
So, let's take a look at what that looks like. Structure of a convolution neural network. So far, this is where we're at right now. we have our input image coming in and then we use our uh filters and there's multiple filters on there
that are being developed to kind of twist and change that data and so we little filter maybe it's a 2x two we multiply it by each piece of the image and if we step two then it's every other piece of the image that generates
multiple convolution layers. So we have a number of convolution layers we have um set up in there that's looking at that data. We then take those convolution layers. We run them through the relu setup. And then once we've done
through the relu setup and we have multiple relus going on, multiple layers those multiple layers and we're going to be pooling them. So now we have the pooling layers or multiple poolings going on. Up until this point we're
dimensions. You can have three dimensions. Some strange data setups other things they can have four, five, six, seven dimensions. Uh so right now we're looking at 2D image dimensions coming in into the pooling layer. So the
next step is we want to reduce those dimensions or flatten them. So flattening flattening is a process of converting all of the resultant two-dimensional arrays from pulled feature map into a single long
continuous linear vector. So over here you see where we have a pulled feature map. Maybe that's the bird wing and it has values 6847 and we want to just flatten this out and turn it into 6847 or a single linear vector. And we find
out that not only do we do each of the pulled feature maps, we do all of them into one long linear vector. So now we've gone through our convolutional neural network part and we have the input layer into the next setup. All
pooling layers and we've flattened them out and combined them into a single linear vector going in. So after we've done the flattening, we have uh just a much. So it's important to go back and take a look at each of the steps we've
network so far is we have our convolution where we twist it and we filter it and multiply the matrices. We end up with our convolutional layer which uses the relu to figure out the values going out into the pooling. as
you have numerous convolution layers that then create numerous pooling layers pooling that data together which is the max value which one we want to send and then we're going to take all of that from each of the pooling layers and
going to combine them into a single input going into the final layer. Once you get to that step you might be looking at that going boy that looks like the normal input to most neural network and you're correct it is. So
once we have the flattened matrix from the pooling layer that becomes our input. So the pooling layer is fed as an input to the fully connected layer to classify the image. And so you can see as our flattened matrix comes in in this
case we have the pixels from the flattened matrix fed as an input back to our toucan or whatever that kind of bird that is. Um I need one of these to comes into our forward propagation network. Uh, and that will then have the
different weights coming down across. And then finally, it selects that that's a bird and that it's not a dog or a cat in this case, even though it's not labeled. The final layer there in red is our output layer. Our final output layer
that says bird, cat, or dog. So, quick recap of everything we've covered so far. We have our input image, which is twisted and multiply. The filters are multiplied times the uh matrix the two matrixes multiplied all the filters to
create our convolution layer. Our convolution layers there's multiple building multiple layers off the different filters. Then goes through the relu as this activation and that creates our pooling. And so once we get into the
pooling layer, we then and the pooling look for who's the best, what's the max value coming in from our convolution. And then we take that layer and we flatten it and then it goes into a fully connected layer, a fully connected
neural network and then to the output. And here we can see the entire process how the CNN recognizes a bird. This is kind of nice cuz it's showing the little pixels and where they're going. You can see the filter is generating this
shows up in the bottom part of the convolution network. And then based on that, it uses the reloo for the pooling. the pooling then find out which one's the best and so on all the way to the fully connected layer at the end or the
classification and the output layer. So that'd be a classification neural network at the end. So we covered a lot of theory up till now and you can imagine each one of these steps has to be broken down in code. So putting that
together can be a little complicated. Not that each step of the process is overly complicated, but because we have so many steps. Uh we have one, two, three, four, five [snorts] different steps going on here with
substeps in there. We're going to break that down and walk through that in code. So in our use case implementation using the CNN, we'll be using the CR10 data set from Canadian Institute for Advanced Research for classifying images across
let me know whether it's going to be a toucan or some other kind of bird, but we do get to find out whether it can categorize between a ship, a frog, deer, bird, airplane, automobile, cat, dog, horse, truck. So, that's a lot of fun.
And then if you're looking anything in the news at all of our automated cars, and everything else, you can see where this kind of processing is so important As far as what's coming out in the
really cool stuff. We're starting to see this just about everywhere in industry. Uh so great time to be playing with this and figuring it all out. Let's go ahead and dive into the code and see what that looks like when we're actually writing
our script. Before we go on, let's do uh one more quick look at what we have here. Let's just take a look at data batch one keys. And remember in Jupyter notebook, I can get by with not doing the print statement. If I put a variable
variable. And you can see under data batch one for the keys since this is a dictionary we have the batch one label data and file names. Uh so you can actually see how it's broken up in our data set. So for the next step or step
four as we're calling it uh we want to display the image using mattplot library. There's many ways to display the images. You could even uh well mplot library is really good for this. And we'll also look at our first reshape
uh setup or shaping the data. So you can have a little glimpse into what that importing our map plot. And of course since I am doing Jupyter notebook, I need to do the mapplot inline command so it shows up on my page. So here we go.
We're going to import mapplot library.pipplot is plt. And if you remember mapplot library, the piplot is like a canvas that we paint stuff onto. And there's my percentage sign mapplot library in line. So it's going to show
up in my notebook. And then of course we're going to import numpy as np for our numbers python array setup. And let's go ahead and set u x equals to data batch one. So this will pull in all the data going into the x value. And
then because this is just a long stream of binary data uh we need to go a little bit of reshaping. So in here we have to go ahead and reshape the data. We have 10,000 images. Okay looks correct. And this is kind of an interesting thing. It
research this myself to figure out what's going on with this data. And what what's going on with this data. And what it is is it's a 32x 32 picture. And let me do this. Let me go ahead and do a drawing pad on here. Uh so we have 32
bits by 32 bits and it's in color. So there's three bits of color. Now I don't this. It probably has to do with how they originally encoded it. But most pictures put the three afterward. So, what we're doing here is we're going to
take uh the shape, we're going to take the data, which is just a long stream of information, and we're going to break it up into 10,000 pieces. And those 10,000 pieces then are broken into three pieces each. And those three pieces then are
32x 32. You can look at this like an oldfashioned projector where they have blue projector, and the green projector. And they add them all together, and each one of those is a 32x 32bit. So that's probably how this was originally
formatted was in that kind of ideal. Things have changed. So we're going to transpose it and we're going to take the three which was here and we're going to put it at the end. So the first part is reshaping the data from a single line of
bit data or whatever format it is into 10,000x3x 32x32. And then we're going to 10,000x3x 32x32. And then we're going to transpose the color factor to the last transpose the color factor to the last place. So it's the image then the 32x 32
here. And then finally we're going to take this uh which is three bits of data and put it at the end. So it's more like we do we process images. Now and then as type this is really important that we're going to use an integer 8. You can come
in here and you'll see a lot of these they'll try to do this with a float or a float 64. What you got to remember though is a float uses a lot of memory. So once you switch this into uh something that's not integer 8, which is
goes up to 128, you are just going to the the amount of RAM, let me just put that in here, is going to go way up the amount of RAM that it loads. Uh so you try the other ones and see what happens if you have a lot of RAM on your
computer, but for this exercise, this will work just fine. And let's go ahead and take that and run this. So now our X variable is all loaded and it has all the images in it from the batch one data batch one. And just to show we were
talking about with the as type on there. If we go ahead and take X0 and just look for its max value, let me go ahead and run that. Uh you'll see it doesn't Oops, I said 128. It's 255. Uh you'll see it doesn't go over 255 because it's an
we're keeping that down to. We're keeping those values down. So they're keeping those values down. So they're only 255 0 to 255 versus a float value which would bring this up um exponentially in size. And since we're
exponentially in size. And since we're using the map plot library, we can do um oops, that's not what I wanted. Since we're using the map plot library, we can take our canvas and just do a plt. IM for image show. And let's just take a
look at what x0 looks like. And it comes in I'm not sure what that is, but you can see it's a very lowgrade image uh broken down to the minimal pixels on there. And if we did the same thing, oh, let's do uh let's see what one looks
see. Run on there, not enter. Let's hit the run on that. Uh and we can see this is probably a semitr. That's a good guess on there. And I can just go back in over and over. And we'll look at three. Uh that looks like a dump truck
unloading. Uh and so on. You can do any of the 10,000 images. We can just jump to 55. Uh looks like some kind of animal looking at us there. Probably a dog. And just for fun, let's do just one more uh uh run on there. And we can see a nice
car for our image number four. Uh so you can see we paste through all the at them. And they've been reshaped to fit our view and what the uh mattplot library uses for its format. So the next step is we're going to start creating
some helper functions. We'll start by a one hot encoder to help us. We're processing the data. Remember that your labels, they can't just be words. They have to switch it. And we use the one hot encoder to do that. And then we'll
hot encoder to do that. And then we'll also create a uh class uh cfar helper. So it's going to have an init and a setup for the images. And then finally, can see what that looks like. And then
actually going to start creating our model, our actual neural network model. So let's start by creating our one hot encoder. We're going to create our own here. Uh and it's going to return an out and we'll have our vector coming in and
our values equal 10. What this means is that we have the 10 values, the 10 possible labels. And remember, we don't look at the labels as a number cuz a car isn't one more than a horse. That'd be just kind of bizarre to have horse
equals 0, car equals 1, plane equals 2, cat equals 3. So a cat plus a car equals cat equals 3. So a cat plus a car equals what? Uh so instead we create a numpy array of zeros and there's going to be 10 values. So we have a 10 different
values in there. So you have uh zero or one. One means it's a cat, zero means it's not a cat. Um in the next line it might be that uh one means it's a car, zero means it's not a car. So instead of having one output with a value of 0 to
10, you have 10 outputs with the values of 0 to one. That's what the one hot encoder is doing here. And we're going to utilize this in code in just a look at the next helpers. We have a few
build. And when you're working with a very complicated Python project, dividing it up into separate definitions and classes is very important. Otherwise, it just becomes really unggainainely to work with. So let's go
ahead and put in our next helper, uh, which is a class. And this there's a lot here. And let's just start uh we can put a space right in there. There we go. That looks a little bit more readable. Add a second space. So, we're going to
create our class, the cipher helper, and we'll start by initializing it. Now, there's a lot going on in here. So, let's start with the uh init part. Uh self doi equals zero. That'll come in in a little bit. We'll come back to that in
the lower part. We want to initialize our training batches. So, when we went batch. We don't need the meta batch, but we do need the data batch. 1 2 3 4 five
and we do not want the testing batch in here. This is just the self all train batches. So we're going to come make an array of of all those different images. And then of course we left the test batch out. So we have our self.test
batch. Uh we're going to initialize the training images and the training labels and also the test images and the test labels. So these are just this is just to initialize these variables in here. Then we create another definition down
here and this is going to set up the images. Let's just take a look and see what's going on in there. Now we could have all just put this as part of the uh innit part uh since this is all just helper stuff. But breaking it up again
makes it easier to read. It also makes it easier when we start executing the So that way we have a nice print statement to say, hey, we're now running here. We're going to set up these self-training images at this point. And
that's going to go to a numpy array vstack. And in there, we're going to load up uh in this case the data for D and self all train batches. Again, that points right up to here. So, we're going to go through each one of these uh files
they're not a file anymore. We've brought them in. Data batch one points to the actual data. And so, our self-training images is going to stack them all into our into a numpy array. And then it's always nice to uh get the
training length and that's just a total number of uh self-training images in there. And then we're going to take the self-training images. And let me switch marker colors because I am getting a little too much on the markers up here.
Oops, there we go. Bring down our marker change so we can see it a little better. And at this point, this should look familiar. Where did we see this? Well, when we wanted to uh uh look at this above and we wanted to look at the
images in the mattplot library, we had to reshape it. So, we're doing the same thing here. We're taking our self-training images and uh based on the training length, total number of images because we stacked them all together.
So, now it's just one large file of images. We're going to take and look at images. We're going to take and look at it as our our three video cameras that are each displaying a 32x 32. And we're going to switch that around so that now
we have um each of our images that stays the same place. And then we have our 32x the same place. And then we have our 32x 32 and then by our three our last our three different values for the color. And of course we want to go ahead and uh
they run this where we say divide by 255. That was from earlier. It just 255. That was from earlier. It just brings all the data into 0ero to one. That's what this is doing. So, we're turning this into a 0 to one array,
turning this into a 0 to one array, which is uh all the pictures 32x 32x3. self-training labels and we're going to pump those through our one hot encoder them together. And uh again, we're converting this into an array that goes
from uh instead of having horse equals 1, dog equals 2, and then horse plus dog would equal three, which would be cat. Now, it's going to be uh, you know, an array of 10 where each one is 0ero to one. Then, we want to go ahead and set
up our test images and labels. And, uh, when we're doing this, you're going to the rest of Let me just change colors right here. This is no different than training set. Uh, we're going to stack the different uh, images. Uh, we're
going to get the length of them so we know how many images are in there. uh but it's nice to let the computer do it, especially if it ever changes on the other end and you're using other data. And again, we reshape them and transpose
them. And we also do the one hot encoder. Same thing we just did on our training images. So now our test images are in the same format. So now we have a definition which sets up all our images in there. And then the next step is to
go ahead and batch them or next batch. And let's do another breakout here for batches because this is really important to understand tends to throw me for a little loop when I'm working with TensorFlow or KAS or a lot of these. We
have our data coming in. If you remember, we had like 10,000 photos. Let me just put 10,000 down here. We don't want to run all 10,000 at once. So, we want to break this up into batch sizes. And you also remember that we had the
number of photos. In this case, uh length of test or whatever number is in there. Uh we also have 32x 32x3. So when we're looking at the batch size, we want to change this from 10,000 to um
going to do batches of 100. So we want to look at just 100, the first 100 of the photos. And if you remember, we set selfi equal to zero. Uh so what we're
x. We're going to get the next batch from the very initialize. We've already initialized it for zero. So, we're going to look at X from zero to batch size, which we've set to 100. So, just the first 100 images. And then we're going
to reshape that into uh and this is important to let the data know that important to let the data know that we're looking at 100x 32x 32x3. Now, we've already formatted it to the 32x 32x3. This just sets everything up
correctly so that X has the data in there in the correct order, in the correct shape. And then the Y, just like the X, uh, is our labels. So our training labels again they go from zero to batch size. In this case they do self
is going to keep changing. And then finally we increment the self i because we have zero. So we so the next time we call it we're going to get the next batch size. And so basically we have x and y. x being the photograph data
coming in and y being the label. And that of course is labeled through one hot encoder. So if you remember correctly, if it was say horse is equal to zero, it would be um one for the zero position since this is the horse and
then everything else would be zero in here. Let me just put lines through Hard to see that array. So let's go ahead and take that and uh we're going to finish loading it since this is our class. And now we're armed with all this
um uh our setup over here. Let's go ahead and load that up. And so we're going to create a variable ch with the cf helper in it. And then we're going to do ch. setup images. Uh now we could have just put all the setup images under
two parts, it makes it much more readable. And um also if you're doing as far as the setup. Let's go ahead and run that. And you can see where it says
labels, setting up test images. And that's one of the reasons we broke it up you can actually have print statements in there telling you what's going on, which is really nice. Uh they did a good job with this setup. I like the way that
one quick note, you want to remember that batch to set up the next batch is we have to run uh batch equals ch next batch of 100 because we're going to use the 100 size. Uh but we'll come back to that. We're going to use that. Just
we're going to be using in a minute from the definition we just made. So now thing we want to do is we want to import our TensorFlow as TF. I'll just go ahead and run that. So it's loaded up. And you can see we got a a warning here. Uh
changes. It's always growing and they're going to be depreciating one of the uh values from float 64 to float type or is treated as an NP float 64. Uh nothing to even affect what we're working on because we've set all of our stuff to a
because we've set all of our stuff to a 255 value or 0 to one. And do keep in mind that 0ero to one value that we converted to 255 is still a float value. Uh but it'll easily work with either the uh numpy float 64 or the numpy dtype
float. It doesn't matter which one it goes through. So the depreciation would not affect our code as we have it. And in our tensorflow uh we'll go ahead. Let a moment so you can get better view of the um what we're typing in. Uh we're
going to set a couple placeholders here. And so we have we're going to set x And so we have we're going to set x equals tf placeholder tf float 32. We just talked about the float 64 versus the numpy float. We're actually just
going to keep this at float 32 more than uh significant number of decimals for a placeholder, we're going to set the shape equal to and we've set it equal to none because at this point we're just holding the place on there. We'll be
setting up as we run the batches. That's what that first value is. And then 32x 32x3. That's what we've reshaped our data to fit in. And then we have our y true equals placeholder tf float 32. And
the shape equals none, 10. 10 is the 10 different labels we have. So it's an array of 10. And then let's create one more placeholder. We'll call this hold prob or hold probability. And we're going to use this. We don't have to have
a shape or anything for this. This placeholder is for what we call dropout. If you remember from our theory before, we drop out so many nodes is looking at or the different values going through which helps decrease bias. So we need to
go ahead and put a a placeholder for that also. And we'll run this. So it's three different placeholders. And since we're in TensorFlow, when you use KAS, we're in TensorFlow direct. Kas sits on TensorFlow. We're going to go ahead and
going to create something to help us initialize the weights, initialize our bias. If you remember that each uh layer has to have a bias going in. We're going to go ahead and work on our our conversional 2D, our max pool. So, we
have our pooling layer, our convolutional layer, and then our normal and put those all into definitions. And let's see what that looks like in code. And you can also grab some of these helper functions from the MN, the uh
NIST setup. Let me just put that in there if you're under the TensorFlow. but we're going to go ahead and do our own. And we're going to create our uh we're doing this is so that you can actually start thinking about what's
going on in the back end. So, even though there's ways to do this with an automation, sometimes these have to be tweaked and you have to put in your own to be doing that. We're just going to recreate them for our code. And let's
take a look at this. We have our weights. And so, what comes in is going to be the shape, and what comes out is going to be uh random numbers. So, we're random numbers based on the shape with a
standard deviation of 0.1. Kind of a fun way to do that. And then the TF variable, uh, init random distribution. So, we're just creating a random distribution on there. That's all that is for the weights. Now, you might
change that. You might have a a higher standard deviation. In some cases, you actually load preset weights. That's pretty rare. Usually, you're testing like that, and you want to see how those weights configure with each other. Uh
need to go ahead initialize the bias with a constant. Uh in this case we're using 0.1. A lot of times the bias is just put in as one and then you have your weights to add on to that. Uh but we're going to set this as 0.1. Uh so we
want to return a convolutional 2D in this case a neural network. This is uh would be a layer on here. What's going on with the con 2D is we're taking our data coming in. uh we're going to filter it. Strides, if you remember correctly,
strides came from here's our image and then we only look at this picture here and then maybe we have a stride of one. So we look at this picture here and we filters going on there. The other thing this does is that we have our data
this does is that we have our data coming in as 32 by 32 by 3. And we want three dimensions and it's going to reformat this as just two dimensions. So
it's going to take this number here and combine it with the 32x 32. So this is a reducing our data down using different means and it connects down. I'm just going to jump down one here. uh it goes with the convolutional layer. So you
have your your kind of your pre-formatting and the setup and then that goes through on there. And you can see here we have a net weights by the shape a net bias shape of three because we have the three different uh here's
our three again. And then we return the TFN relu with the convention 2D. So this convolutional uh has this feeding into it right there. It's using that as part of it. And of course the input is the XY plus B the bias. So that's quite a
mouthful, but these two are the are the keys here to creating the convolutional layers there. The convolutional 2D coming in and then the convolutional creates all those filters we saw. Then of course we have our pooling. Uh so
conventional layer, we want to pull the data. Uh if you remember correctly on the on the pool side and let me just get rid of all my marks. It's getting a go ahead and jump back to that slide. Let's just take a look at that slide
over here. Uh so we have our image coming in. We create our convolutional layer with all the filters. Remember the filters go um you know the filter is coming in here and it looks at these four boxes and then if it's a step let's
say step two it then goes to these four boxes and then the next step and so on. Uh so we have our convolutional layer that we generate or convolutional layers. They use the uh relu function. Um there's other functions out there for
this though. the relu is the uh most the one that works the best at least so far. our pooling. Now, if you remember correctly, the pooling was max. Uh so if we had the filter coming in and they did the multiplication on there and we have
a one and maybe a two here and another one here and a three here, three is the one here and a three here, three is the max. And so out of all of these, you three. And if the max is over here, two or whatever it is, that's what goes into
pooling. Uh so again, we're reducing that data down. We're reducing it down as small as we can. And then finally, we're going to flatten it out into a single array. And that goes into our fully connected layer. And you can see
that here in the code right here, we're going to create our normal full layer. from our pooling layer. This will go into some kind of flattening process and then that will be fed into the full the different layers going in down here. Um,
and so we have our input size. You'll see our input layer get shape which is is coming in. Uh, and then input size initial weights is also based on uh the input layer coming in. And the input size down here is based on the input
layer shape. So, we're just going to already use the shape and already have our size coming in. And of course, uh you have to make sure you init the bias. Always put your bias on there. And we'll do that based on the size. So, this will
return TF.mmatmo input layer W +B. This is just a normal down here. That's what we're going to return. So, that was a lot of steps we went through. Let's go ahead and run that. So, those are all loaded in there.
And let's go ahead and uh create the layers. Let's see what that looks like. Now that we've done all the heavy lifting and everything, uh, we get to do all the easy part. Let's go ahead and create our layers. We'll create a
convolution layer one and two, two different convolutional layers. And then we'll take that and we'll flatten that out. Create a reshape pooling in there for our reshape. And then we'll have our full uh layer at the end. So, let's
convolutional layer. Then we come in here and let me just run that real quick. And I want you to notice on here the three and the 32. This is important because coming into this convolutional layer, we have three different channels
and 32 pixels each. Uh so that has to be in there. The four and four you can play with. This is your filter size. So if you remember, you have a filter and you have your image and the filter slowly steps over and [snorts] filters out this
image depending on what your step is. For this particular setup, 44 is just fine. That should work pretty good for what we're doing and for the size of the once you have your convolutional layer set up, you also need to pool it. And
automatically set up so that it would see the different shape based on what's coming in. So here we have max tool by 2x two and we put in the convolutional convolutional layer we just created goes right back into it. And that right up
here, as you can see, is the X. It's coming in from here. So, it knows to look at the first model and set the the data accordingly. Set that up uh so it matches. And we went ahead and ran this already. I think I ran it. Let me go and
one layer, let's go ahead and do a second layer down here. And it's uh we'll call it convo 2. It's also a convolutional layer on this. And you'll see that we're feeding convolutional one in the pooling. So it goes from
convolutional one into convolutional one pooling from convolutional one pooling into convolutional two and then from convolutional two into convolutional two pooling. And we'll go ahead and take this and run this. So these variables
are all loaded into memory. And for our flatten layer, uh let's go ahead and we'll do uh since we have 64 coming out of here and we have 4x4 going in, let's of here and we have 4x4 going in, let's do 8x 8x 64. So let's do 4,096.
that's how many bits are coming through on the flat layer. And we'll reshape this. So we'll reshape our uh convo 2 pooling. And that will feed into here, going to set it up as a single layer that's 4,096 in size. That's what that
means there. We'll go ahead and run this. So we've now created this variable, the convo flat. And then we have our first full layer. This is the final uh neural network where we have the flat layer going in. And we're going
to again use the uh relu for our uh setup on there on a neural network for evaluation. And you'll notice that we're going to create our first full layer. Our normal full layer. That's our definition. So we created that. That's
creating the normal full layer. And our input for the data comes right here from the this goes right into it. Uh the convo flat. So this tells it how big the data is. And we're going to have it come out. It's going to have uh 1024. That's
how big the layer is coming out. We'll go ahead and run this. So now we have our full layer 1. And with the full layer one, we want to also define the full one dropout to go with that. So our full layer one comes in uh keep
Remember we created that earlier. And the full layer one is what's coming into it. And this is going backwards and training the data. We're not training every weight. we're only training a percentage of them each time, which
helps get rid of the bias. So, let me go ahead and run that. And uh finally, we'll go ahead and create a y predict, which is going to equal the normal full one dropout and 10 cuz we have 10 labels in there. Now, in this neural network,
That would be another option to play with. You can also play with instead of 1024, you can use other numbers for the way that sets up and what's coming out going to do just the one layer and the one layer drop out. And you can see if
easy just to feed in the full one dropout into full layer two. And then full layer two dropout would have full layer two feed into it. And then you'd For right now, this is great. This particular data set is tried and true,
and we know that this will work on it. And if we just type in Y predict, and we run that, uh, we'll see that this is a tensor object. Uh, shape question mark 10 dtype 32. a quick way to double check what we're working on. So now we've got
all of our uh we've done a setup all the way to the Y predict which we just did. loss function and make sure that's set up in there. Uh create the optimizer and
then uh train our optimizer and create a variable to initialize all the global TF variable to initialize all the global TF variables. So before we dive in to the um loss function, let me point out one quick thing or just kind of a recap over
a couple things. And that is when we're playing with this these setups um we pointed out up here we can change the 44 and use different numbers there. They change your outcome. So depending on what numbers you use here will have a
huge impact on how well your model fits. And that's the same here with the 1024. Also, this is also another number that if you continue to raise that number, you'll get um possibly a better fit. You might overfit. And if you lower that
number, you'll use less resources. And generally, you want to use this in um the exponential growth. And exponential being 2 4 8 16. And in this case, the
next one down would be 512. You can use any number there, but those would be the ideal numbers uh when you look at this data. So the next step in all this is we need to also create uh a way of tracking how good our model is. And we're going
to call this a loss function. And so we're going to create a cross entropy loss function. And so before we discuss exactly what that is, let's take a look and see what we're feeding it. Uh we're going to feed it our labels. And we have
our true labels and our prediction labels. Uh so coming in here is we're sending in or the two different probability distributions is one that we know is true and what we think it's going to be. Now this function right
here when they talk about cross entropy uh in information theory the cross entropy between two probability distributions over the same underlying set of events measures the average number of bits needed to identify an
event drawn from the set. That's a mouthful. Uh really we're just looking at the amount of error in here. How many of these are correct and how many of it matches and we're going to look at that. We're just going to look at the
reduced to the mean means here. So we're looking at the average error on this. And so the next step is we're going to take the error. We want to know uh our cross entropy or our loss function. How much loss we have. That's going to be
part of how we train the model. So when you know what the loss is and we're training it. You feed that back into the back propagation setup. And so we want our optimizer. We're going to create the optimizer using an atom optimizer.
of optimizing the data. Atom's the most popular used. Uh so our optimizer is going to equal the TF train atom optimizer. If you don't remember what the learning rate is, let me just pop this back into here. Here's our learning
have all your weights and your different nodes that are coming out. Here's our node coming out. Um, and it has all its weights and then the error is being prop sent back through in reverse on our neural network. So, we take this error
and we adjust these weights based on the different formulas. In this case, the don't want to just adjust them completely. We don't want to change this coming through. Cuz if we made that kind of adjustment, it's going to be biased
through is. Instead, we're going to multiply that by 0.001 and make a very small shift in this weight. So our delta W is only 0.001 of the actual delta W of
from the atom. And then we want to go ahead and train it. So our training or set up a training uh uh variable or function. And this is going to equal our optimizer minimize cross entropy. And we
it's loaded in there. And then we're almost ready to train our model. But before we do that, we need to create one more um variable in here. And we're going to create a variable to initialize all the global TF variables. And when we
all the global TF variables. And when we look at this um the TF global variable initializer, this is a TensorFlow um object. It goes through there and it have going under our TensorFlow and then
initializes those variables. Uh so it's kind of like a magic wand because it's TensorFlow. All you need to know about this is that you have to have the initialization on there which is an operation. Um and you have to run that
once you have your setup going. So we'll go ahead and run this piece of code and then we're going to go ahead and train our data. So let me run this. So it's loaded up there. And so now we're going to go ahead and run the model by
creating a graph session. Graph session is a TensorFlow term. So you'll see that coming up. It's one of the things that throws me because I always think of graphics and spark and graph as just general graphing. Uh but they talk about
ahead and run the model and let's go ahead and walk through this uh what's going on here. And let's paste this data in here. And here we go. So, we're going to start off with a with a TF session as cess. So, that's our actual TF session
we've created. Uh, so we're right here with the TF uh session. Our session we're creating, we're going to run TF global variable initializer. So, right off the bat, we're initializing our variables here. Uh, and then we have for
variables here. Uh, and then we have for I and range 500. So, what's going on the data up and we're going to batch it in at 500 points each. We've created our session run. So we're going to do with TF session as session right here. We've
then we're going to run and we're going to go ahead and initialize it. So we have our TF global variables initializer that we created. Um that initializes our we're going to do is we're going to go for I in range of 500 batch equals
ch.next batch. So if you remember correctly, this is loading up um 100 pictures at a time. And uh this is going to loop through that 500 times. So we
are literally doing uh what is that? Uh 500 * 100 is uh 50,000. So that's 50,000 there. And the first process is we're going to do a session run. We're going
variable or optimizer in there. We're had our feed dictionary that we created and we have x equals batch zero coming in. Y true batch one hold the probability 0.5 and then just so that we
can keep track of what's going on we're going to every 100 steps we're going to going to every 100 steps we're going to run a print. So currently on step format accuracy is um and we're going to look at matches equals TF equal TF argument Y
prediction one TF.org max Y true comma one. So we're going to look at this is how many matches it has. And here our ACC uh all we're doing here is we're going to take the matches how many matches they have. It creates it
convert that to float. That's what the TF cast does. And then we just want to know the average. We just want to know the average of the um accuracy. And then we'll go ahead and print that out. Uh print session run accuracy feed
dictionary. So it takes all this and it prints out our accuracy on there. So screen's there. Let's go ahead and take this and let's run it. And this is going to take a little bit to run. Uh so let's see what happens on my old laptop. And
we'll see here that we have our current uh we're currently on step zero. It accuracy. And this will take just a moment to run. And we can see that on our step zero, it has an accuracy of 0.1 or 1028. Um and as it's running, we'll
all the way, but uh this accuracy is going to change a little bit up and down. So we've actually lost some accuracy during our step two. Um, but back after we run it all the way through and see how the different steps come
out. Was actually reading that backwards. Uh, the way this works is the closer we get to one, the more accuracy we have. Uh, so you can see here we've gone from a 0.1 to a 39. Um, and we'll
and see what happens when we're done with the full run. All right, now that we've uh prepared the meal, got it in the oven, and pulled out my finished dish here. If you've ever watched uh any of the old cooking shows, let's discuss
a little bit about this accuracy going on here. And how do you interpret that? We've done a couple things. First, we've defined accuracy. U the reason I got it defined accuracy. U the reason I got it backwards before is you have uh loss or
accuracy. And with loss, you'll get a graph that looks like this. It goes Oops, that's an S, by the way. There we go. You get a graph that curves down like this. And with accuracy, you get a graph that curves up. This is how good
it's doing. Now in this case, uh, one is supposed to be really good accuracy. never crosses one. So if you have an accuracy of one, that is phenomenal. Um, unheard of. And the same thing with loss. If you have a loss of zero, that's
also unheard of. The zero is actually on this this axis right here as we go in Because, you know, if I was looking at this and I go, oh 51, that's uh 51%. You're doing 50/50. No, this is not percentage. Let me just put that in
there. It is not percentage. Uh this is logarithmic. logarithmic. What that means is that 0.2 is twice as What that means is that 0.2 is twice as good as 0.1. And uh when we see 04,
that's twice as good as 2. Real way to convert this into a percentage. You really can't say this is is a direct percentage conversion. What you can do though is in your head if we were to give this a percentage uh we might look
give this a percentage uh we might look at this as uh 50% we're just guessing at this as uh 50% we're just guessing equals 0.1 and if 50% roughly equals 0.1 top remember at the top here here's our
top remember at the top here here's our 1028 the accuracy of 50% then 75% is 1028 the accuracy of 50% then 75% is about 02 and so on and so on don't quote those numbers because it doesn't work that way they say that if you have
95. That's pretty much saying 100%. And if to go look this up. Let me go and remove all my drawings there. Uh so the magic number is 0.5. We really want to be over a 0.5 in this whole thing. And we have
uh both 0504. Remember this is accuracy. If we were looking at loss, then we'd be know, instead of how high it is, we want how low it is. Uh but with accuracy being over a.5 is pretty valid. That means this is pretty solid. And if you
get to a 0.95 then it's a direct correlation. That's what we're looking for here in these numbers. You can see we finished with this model at 0.5135. So still good. Um and if we look at uh when they ran this in the other end,
that goes into it when we see the weights. Uh they got 5251. So a little you'll find your own uh comes up a little bit better or worse depending on through the whole model. We've created,
we train the model and we've also gone through on every 100th run to test the model to see how accurate it is. Welcome to deep learning tutorial. My name is Richard Kersner with the SimplyLearn team. That's www.simplearn.com.
Get certified get ahead. What's in it for you? We're going to go over applications of deep learning. What is deep learning? Why is deep learning important? What are neural networks? The activation function in our neural
network. The cost function that comes in for processing our neural networks. How do neural networks work? Deep learning platforms. And then we'll do introduction to TensorFlow and a use case implementation using TensorFlow. So
hands-on. So start off with the applications of deep learning. Deep learning helps us make predictions about the rain, earthquakes, tsunamis, etc., allowing us to take the required precautions. With deep learning,
machines can comprehend speech and provide the required output. Deep learning enables a machine to recognize people and objects in the images fed to it. And with deep learning, advertisers can leverage data to perform realtime
bidding and targeted display advertising. And these are just a small sample of the myriad of different uses for deep learning today. So what is a deep learning? Deep learning is a sub field of machine learning that deals
structure and function of the brain. And we look at this we have uh the larger category which is artificial intelligence very generic comprehensive um ideal. And in there we have machine learning and then a subcategory of
machine learning is deep learning. So when we talk about artificial intelligence, this is the ability of a machine to imitate intelligent human behavior. So when we look at something, can it solve a problem the way humans
do? Can we take it to that next level? So it's just not repeating some kind of uh simple output that we've programmed it to do. Can it actually start imitating human intelligence? And we look at machine learning. We have the
application of AI that allows a system to automatically learn and improve from experience. So machine learning the most basic machine learning is your linear regression model. You put a bunch of dots on the graph and you draw a line
through them and you have a guess of what X and Y are. Based on uh where what finally we have our deep learning application of machine learning that uses complex algorithms and deep neural nets to train a model. Why is deep
learning important? It works with unstructured data. Machine learning works only with large sets of structured and semistructured data. While deep learning can work with both structured and unstructured data. Handles complex
operations. Deep learning algorithms can perform complex operations easily while machine learning algorithms cannot. Feature extraction. Machine learning algorithms use labeled sample data to extract patterns while deep learning
accepts large volumes of data as input. Analyze the input to extract features out of an object. achieve best performance. Performance of machine learning algorithms decreases as the amount of data increases. So to maintain
the performance of the model, we need deep learning. And this is always a challenge of when do you go from machine learning doing linear regression or other regression models to deep learning neural networks. It really centers
around both uh the complexity as it becomes more and more complex or the problem becomes harder to solve along with the amount of data. So both of those play a huge part in deciding which would best serve your purposes to
predict what your data is going to do and try to predict the outcome. So what are neural networks? With deep learning, a machine can be trained to identify various shapes. So here we have a square coming in. You can see we've broken it
up into the pixels and we want the label to come out square. And if we turn the square slightly sideways, it's still a square and we want it to still say it's a square. With deep learning, a machine can be trained to identify various
shapes or the different patterns of those shapes as they be in this case being rotated. But how is the machine able to do this? So we'll look at a nice able to do this? So we'll look at a nice grid 28x 28 784 pixels. And we look at
that grid, we can look at each one of those pixels as inputs. So a neural network is a system modeled on the human brain. And so we have all our inputs kind of like your eyeball coming in there. It has the sensors in the back,
your different input sensors which are your cones and rods. So each one of those is an input coming in with information and it goes into a neuron and then you sends out a pulse. So the data is fed as an input to the neuron.
The neuron processes the information provided as an input. The information is transferred over weighted channels and this is very central to our neural in gets a different weight and the output is the final value predicted by
the artificial neuron. In this image, we're only looking at one neuron. So of neurons working together and we'll look at how those fit together in just a moment. When we look at one neuron, so
neuron. Let's dig a little deeper so we can get some concepts in here so we can understand the neural network. So what exactly happens within a neuron? We have an activation function. So within each neuron the following operations are
performed. The product of each input and the weight of the channel it's passed over is found. Sum of the weighted products is computed. This is called the weighted sum. And a bias unique to the neuron is added to the weighted sum. And
you can always look at that as if you have an xy graph. Where's your yin intercept? You know the old uh uklidian geometry x or y = 3x + 5. That's your
that come in? And this is a little bit more complicated because it's not like more complicated because it's not like 3x. It's more like 3x1 5x2 6x7. And usually you're dealing with float numbers. So it's not even it
doesn't even look like that. It looks like 0.001 * x13 * x2 and so on. So the numbers get a little confusing, but the concept is very straightforward. We're going to multiply the weight times the value
all together plus the bias. And the final sum is then subjected to the activation function. And the most simplest one is if it's greater than zero, it's one. If it's less than zero,
different there's a lot of other functions that are more reliable than most basic understanding of what you're looking at. 0 or one coming out. In most cases, you actually have a value coming out. And in some cases, we use like a
tangent wave. so that there can be a value between zero and one, but it might be um it it tends to shoot right up to one rather quickly. But, you know, those are things you can fine-tune in your neural network as you start getting to
the solution. Let's keep into the generals here and let's see what's the cost function. And this is so important in understanding how the current neural networks that we're working with are able to learn things. So, we end up with
a cost value. The cost value is the difference between the neural net's predicted output and the actual output from a set of labeled training data. The least cost value is obtained by making adjustments to the weights and biases
iteratively throughout the training process. And when you think about this, we're not just sending one set of numbers through. We're sending all kinds of data in here. So you might have a hundred samples or a thousand samples
and each one of those samples comes in and then we look at the cost for that and we want to get that cost the minimal the average minimal among all the different samples. So we want a general answer on there. You can see here we
denote the predicted output with a little half triangle over it and then the actual output is just a straight y on this. Let's learn how neural networks work. Let's dig in a little deeper in how we program them. How do neural
networks work exactly? In this, we're jumping from a single node into a larger picture. So, our neural network will be trained to identify shapes. And we'll start with the square again, 28x 28 or 784 pixels. And this is kind of a one of
the standard images we work with a lot of times. Our shapes are images of 28x 28 pixels. Each pixel is fed as an input to the neurons in the first layer. So, here we have our input layer. Each one of those, we might flatten that out.
That's the most easiest way to process that, but not the only way to process. long array. And then we have hidden output. And you can see here, we're not looking at just one neuron. We actually
have a row, two hidden layers. And each layer is a row of neurons. And data is passed on from layer to layer over weighted channels. Each one of those inputs is then weighted to each of the next neurons in the next layer in the
hidden layer takes a subset of the inputs and processes it. Let's look into what happens within the neurons. So here we have step one and we can see in here where we have x1 * weight 1 x2 * weight
2 plus b1. That's that top neuron up there. And then we have the next neuron down which is step two. And then in step two they denote the um with the Greek symbol fi. And fi is the activation function based on step one. So it might
be um if it's close to zero it's zero. If it's close to one it's one and it common depending on what activation function you use. The results of the neurons will be activated in the
following layer. So you can see here we have B1 as we looked at with X1 and weighted one X2 and weighted two. And then you would compute B2 the same way and B3 the same way and B4 and B5 and so on. So each neuron has an input from all
the input layers go into each of the hidden layer neuron the first hidden function determines which neurons will be activated in the following layer. And then that activation number goes off to the next layer. So we see here B11, B12,
B13 and B14. And the weights coming in from B1. So let's say B1 fires and it goes into B11. Usually you would see the weights going all the way down. So B2 would have their weights going into B1 and B2 would then go into B11. B1, B2,
B3, and B4 and B5 would then go into B11. And they would have their weights depending on what came out. It might just be zero. So there's nothing coming through or it might be a value between zero and one and so forth for B12, B13,
B14, and B15. And then we take those and they'll have weights attached to each one of those coming out and they go into the final layer. In this case, we have a neuron that represents a square, a neuron that represents a circle, and a
neuron that represents a triangle. And just as before, the information reaching this layer is processed after which a single neuron in the output layer gets activated. But our input was a square. What went wrong here? Remember, we
coming out? It said a circle. Well, don't want it to tell us that squares are circles. Well, our network needs to be trained first. How do we train a network? The predicted output is
compared against the actual output by calculating the cost function. Remember our cost function at the end. We take whatever we said it was going to be and what it actually is and we just subtract those two. And the most common way used
to generate the cost function is as follows is we're going to take the actual value minus the predicted value where you have y and then you have y with the half triangle over it is the predicted and then y is the actual
value. We subtract them. We square that value and then we divide it by two. So it's usually how they generate the cost function. The cost functions determines the error in prediction and reports it back to the neural network. So we're
That's what this is called back propagation. We're going back through the network the other way and we're sending that error back the other way. reduce error. The network is trained
with the new weights and you can see here we have C= 1/2 Y - Y predicted or Y again, the cost is determined and back propagation is continued until the cost cannot be reduced any further. Now, keep in mind, you know, if we have one
picture of a square and it goes through, we actually do just a little training. first one. Otherwise, you'll have a what they call a bias. So, each of those data goes back with our back propagation. and we'll send hundreds of samples on there
until we can get that cost as a whole down as low as we can get so that our average cost is very low without it being biased towards one specific figure. And you can see here we have our input layer, hidden layer and our setup
on here. Similarly, once we've trained it for our square, the network must also be trained to identify circles and triangles too. So we need sets of all of circles and lots of triangles. The weights are this further adjusted in
order to predict the three shapes with the highest accuracy. We can now rely on shapes. And you can see we have a triangle coming in here and it goes and it's going to light up the circle and so on for the square. So before we
dive into some hands-on, let's take a look at some deep learning platforms. The primary programming language, we're going to look at four of these platforms and we're going to start with Torch. The primary programming language is Lua with
primary programming language is Lua with an implementation in C2. Torch's Python implementation is called PyTorch. And this is interesting because Python has become one of the leads in data analysis. So you'll almost always see a
PyTorch or any one of these will have a Python equivalent. And it's slowly spreading throughout the languages. So I'm sure there's within torch it's also probably got a Java setup and definitely has a C because it's primary
implementation is in C. And so we have KASS. KAS is a Python framework for deep learning and USP is reusability of code for the CPU and GPU processing. We have TensorFlow. TensorFlow is deep learning platform by Google. It was developed in
C++ and has its implementation in Python. And just a quick highlight, KAS and TensorFlow have slowly been working together. So there's a lot of things that you can actually put KAS on top of TensorFlow and access TensorFlow.
Although there are still some tools in TensorFlow that that KAS doesn't fully access, but it is a great interface for doing that. And then there's the DL4J is the first deep learning library written for Java and Scala. It is integrated
with Hadoop and Apache Spark. And you remember Apache Spark is written in Scala. That's one of the reasons the DL4J came about is so that it would run on the Spark platform. So let's take an introduction to TensorFlow. Google's
TensorFlow is currently the most popular deep learning library in the world. It has really once they open sourced it, it was just amazing how much it's spread in use and how many tools are linked into TensorFlow. Tensors are vectors or
matrices of n dimensions. And you can see here we have dimension five. We have see here we have dimension five. We have a dimension 4x5 or 5x4 as the case is five rows by four columns. Here's one where it's 3x3x3.
And so this is kind of nice because when you're processing pictures, there are certain things you want to do where you want the pixels to be next to each other. That's very important. Uh same thing if you're processing say a movie,
you might want a 3x3 grid coming in where you have the the layers of the frames coming in to be processed. So you can see how having different dimensions is really helpful in analyzing certain data structures. And this is what's so
great about tensors is you can of course flatten them out like we did earlier or you can process them based on their location. In TensorFlow all computations performed involve tensors. So everything going through is always looked at as
going through is always looked at as tensors as a matrix or matrices of n dimension. TensorFlow architecture is as follows. pre-processing data, build a model, train and estimate the model. And what we'll do is we'll go ahead and dig
into use case implementation with TensorFlow. To do that, I'm actually going to go into uh in this case, I'll be using the Anaconda Navigator. And you can use either Jupyter Lab or Jupyter Notebook. Most people are very familiar
with Jupyter Notebook. It's very commonly web-based. The Jupyter Lab is the next version of Jupyter Notebook and it just lets you have multiple tabs open using Anaconda, you'll go under environments and you want to make sure
that you have your TensorFlow installed. And you can simply uh we'll do this uh I have it installed uh but you could do all. We'll do all. You can do a search the different tensors. It's actually installed in here. Version 1.13.1.
If it wasn't, you could check the box and then run the install on there and start up our Jupyter Lab, which is going to open up. In this case, I use Google Jupyter Notebook, if you're in the notebook, you only have one tab, and you
there's a folder and different things you can do in the uh lab that you can't going to do, you can easily do in the notebook. And you'll start up a new project. Deep learning is what I'm going to call this. And if you're not
familiar, you can definitely we have some tutorials out on the use of Jupyter notebook and how to run it and set it up and things like that. The most basic is we put our code in here. It has a nice display and a nice interface. Uh
display all kinds of things on this page. And then you can just run this So it's not going to show any uh thing until I put some code in there. And of things like that. So the first thing we want to do is we want to import our
tools. Now if you haven't remember you got to install TensorFlow and we'll also use pandas. Pandas is a nice database setup and that again is underneath your environment and you can see here your um whatever you're working on my simply
learn setup where I've installed TensorFlow and pandas in here and I'll going to see anything. So we've just imported those into our notebook that we're working on. So those are now available to us and it helps to have
I'm going to create a path and a test path. And um we'll go ahead and let's just highlight this whole path. And you can always post a note either down below in the YouTube video or you can post a note on simply.com and ask for this path
if you're not quite picking it up, but it is over here at the um uci edu on their setup and it's in their archive. So it's archive.ic.uci.edu/ml edu slml for machine learning/machine-arning-databases/
test. But let's go and just take a look at that. Let me just paste that right in there to our browser window. And here's our adult data. And if I click on there, I'm going to go ahead and open it as a text in my notepad. Um, and the guys in
the back were kind enough to look up to find out what the actual columns were in this uh coming across. So, let me go and take that to pull that information. And before below because these are just variables. Uh, but we can see here that
variables. Uh, but we can see here that we have age, work class, final, WGT. I'm up in just a second to see what that matches. In fact, let's pull that up and can kind of see what we got here. So, we have age. We have our working class
have age. We have our working class state gov. Maybe final wage 77516. education of bachelors education number 13 marital never married admin clerical relationship not in family so on and so on so it goes all the way across here
and so we've pulled out this information native country label etc we'll go ahead and run this and so now we've loaded all our different uh paths and this path by so I don't need to create a separate columns on the adult test and once we've
run this we've set those variables let's go ahead and pull pull that data in. And to do that, we'll use pandas. And we'll create a df train, a df test. Uh each one's going to have our pd for pandas read csv. It'll have our path we put in
there, our path test. The first one went ahead and skipped initial space true names columns. There's our columns in there. Index column equals false. There's no index column. Um on the second one, if we went back into here
and we open up adult test, let me just go ahead and open that up. pad, you'll see there's an actual row up here. We want to skip a 1x3 cross validator uh looking at the same data in there. And here we're going to go ahead and bring
in our data. And then once you bring it in, it's always nice to see what kind of when we talk about shape, we're talking about how many rows and columns, not whether it's been lifting weights. We can see here we have each one has 15
right here. If we counted them, there's going to be 15. And the first data set has 32,561 rows where the second one has 16,281
rows. And it's also good to see just how the data came in. So we'll use the um pandas uh dypes. We'll run that. And you can see here where age came in as an integer, integer 64. Uh working class as an object uh which makes sense. Uh and
then we have our FNL WGT the education as objects or well this is an integer integer object so on all the way down and if we flash back to the data we look at the last column it's less than or equal to 50k and if we scroll down
enough we'll see it's also greater than or equal to 50k. So we'd like to kind of give that its own special setup on that label. So on that feature, we're going to set the label equal to um if it's less than or equal to 50k, it's going to
be zero. And if it's greater than or equal to 50k, it's going to be one. Uh so it's one or the other. That's always a easy easy thing to read. And then we can take this and we can go dft train.l equals label item for item and df train
the labels. There's a lot of ways we can do this. Pandas, this might be actually kind of a slower way. there's a way to do just that setup and do the logic within the um setup instead of doing a loop. Uh but for this this thing, it'll
of data. You know, it's a large data as data goes. And we also want to do it for our test data. Um I didn't really mention that we created two we're looking at two different data sets. One,
we're going to take it and run the test data to see if it works. So, we have our catch it off the bat. If if you were pulling up this, you're going to pull up one the um this is the training set. And
test set, let me just go back and do that. Adult test. One of the thing that we didn't notice that you'll want to pull up is at the end there's a period. So, we're pre-processing our data. We want to make sure that we include that
period in every line on the second setup. So, I go back to my Jupyter notebook. I've got to have a label t which is less than or equal to 50k period or greater than equal to 50k period for one. Otherwise, it's doing
the exact same thing. We're going to change uh the df train label and the df test label to zero or one. We'll just run that. We'll go ahead and print uh the df train label value counts and the df test label value counts. This is
always a good idea because we want to know is there any weird stuff going on there? if there's null values, stuff like that, this will turn up on that setup. And we can see here we have uh zeros, how many zeros, how many ones,
and so on on there. Just a quick view of the data that we're going through. And if we go back up here, go ahead and print the uh train dypes again, and we there, and it give you the new answer cuz it's loaded this information. Uh we
now see it's an integer. And if you go back up here, it was an object. So that what we're doing with this. Now, at this point, we're going to look at the data. And we can see we have a lot of numbers and we have a lot of categories in here.
Uh so categories would be United States male never married versus seven. And we can also see that when we looked at this we have our integers we have our objects working class. So the next thing we want to do on there is we want to go ahead
and the objects and we want to bring that down here. We want to create those categories in a way that the computer can see them. And we'll start with our uh continuous features like age. We can see age integer. FNL WGT is an integer.
Capital gain is an integer. Educational number, there's our educational number as an integer and so on. Uh so if we're going to have these as continuous also need to make a list of the categorical features we want to work
with such as working class, education, marital, occupation, relationship, race, these are all objects. Uh, so that makes sense. And when we flip back over to the data, we can see here we're actually looking at United States. If we continue
lot of United States on this particular one. I was getting worried there for a second that we only had United States, and it was a very biased uh census, came from. And of course, bachelor's, associate, vocational, some college. Uh,
so you can see this is more categorical versus an actual number. Uh so now we have our uh categorical and we have our continuous features and this is just the list of these. So let's go ahead and run that and load that list in there so we
can now start manipulating our data with it. Now we get our first line of TensorFlow code which is exciting. And we're going to create a variable continuous features. And what we're doing in here is we're going to go into
TF uh feature columns. So we have the feature columns. We're going to set those up. numeric columns K for K in continual features. So this is going to go in here and says each one of these is a continual feature and we're going to
feed that into the feature column. Not very exciting on the output uh cuz we're it know what columns are what. Then we're going to create a uh relationship and then we have a relationship and again we're doing TF but in this case we
use feature column. Uh so just like this one, we're telling it feature column and now we do categorical column with vocabulary list. Uh so it's one of the things we can do with TensorFlow and we're going to feed it one we have uh
relationship and so we're just drilling down to the relationship column and these are the options they had. So this is going to be the vocabulary attached to this column and we'll go ahead and run that. So we load up our relationship
and then we're going to do one more uh way of loading. Uh, in this one we're going to do categorical features. And so in categorical features we're going to do TF feature column. There's our um command we've already seen before. And
it's going to be categorical column with hashbucket. We're going to create buckets uh in this case uh for K and categorical features. So it's going to create a bucket for each one of these uh categorical features. And the bucket
size is 1,000. So, we're looking at uh and we've actually kind of repeated in the bucket setup on there, but we wanted to show you three major ways of loading in your different features. One is our features that we know where it's
going to be a number. Uh so, our continuous features, then we can set it as a relationship. Uh in this case, we actually created a vocabulary, husband, not family, very clear vocabulary on there. And then we also are loading just
general categories into buckets. You can set different bucket settings in here. thousand. So pretty much everything since there's not a huge number of categories, each one gets their own kind of bucket setup in there. And as far as
the initial setup, we need to go ahead and create a model. And so this is where it starts to come together. We've um as far as the preset up, we have our TF, we have an estimator. We're going to do linear classifier on the estimator in
classes equals two. So we know there's only two classes we're looking at. We have ongoing train feature columns. And then we have our different we have categorical features plus continuous features. Uh so this basically creates
our model what data is going in. And we'll go ahead and run this. And you can information uh that we had our TensorFlow using default config. You can change a lot of defaults. You can change as far as a model directory uh random
seed saving summary checkpoints. There's all kinds of things you can go in here and set up. Rewrite options keep checkpoint mix etc. At this point, the model hasn't done anything. All we've done is create the model. Uh so let's
just do a real quick rehash of what we've done so far. What we started off with is we grabbed some data. In this case, uh adult and adult test. We have a a training data set and a test data set. Uh we set the columns up. We took a very
short brief exploration of the data and its shape. Um, as far as what we're working with, we changed our label around a little bit so that the label makes a little bit more sense of 01 instead of um, for the machine it's
easier to spit out a zero or one. We can look up here. We double check to make sure we how many zeros and ones we have. Double check our data, make sure it's integer 64. Nothing weird's going on. And then we looked at three different
ways that we can kind of label the data as far as the way we're going to read it. Uh, we have our continuous features and a categorical features. Here's our we went ahead and created our model, we did not put the uh relationship in here.
Uh which you can do. You can actually maybe take it out of um categorical and then have its own on here instead of having categorical features and continuous features and so on. Uh so we've created our setup for our model.
to go ahead and create a function letting it know how to read the data into our model. How are we going to train it? And let's go ahead and create two variables. Uh the first one is going to be features. This is just all the
features that are in there. And then the second one is going to be our label. And this is basically um we're looking at all the different information we can put into it. And then is that person based on that information going to make less
than or greater than 50k? That's what that comes down to. Now the next part uh the definition we're going to create has a lot in it and we're going to feed this definition into our model training. Uh so there's a lot of stuff that goes on
here. First we'll call it get input in function. Def get input function. We have our data set number of epics equals none in batch equals 128 shuffle equals going to return a TF estimator inputs
pandas input function. And in this case it's going to be x equals our pd dataf frame k data set k values for k and features. Y is PD series data set label values batch size equals inbatch number of epics equals number of epics shuffle
equals shuffle. So in here we're passing in uh the number of epics. We're not too once through the data. There's a lot of data in there. We don't need to rerun it. Epics is how many times do you cover all the data and then how many groups of
data do you pull in in batch at a time. So we're only going to look at 128 do about. uh and then it'll go to the next batch and the next batch and the next means that we're randomly picking where they're coming from. Uh and like again
the number of epics for this particular model depending on how much data you running depends on how many epics you need to run and there's a lot of rules on how many epics you need to run. One of them is if your uh training data and
your testing data against your training data. If your testing data starts having that means you're no longer fitting the answer. Uh, so it's kind of these little weird things you start to on
because it actually checks a lot of that for you. Uh, but we're just going to set number of epics equal to zero. And then we have our data set going in. So we're creating our uh, get function. How do we get the data into training our model?
we have our data function. And now it knows where the data is coming from. Uh so we need to go ahead and train it. And that's simply we take our model we created way up here. That's where we take the model there. We've told it what
columns it's going to pull in. So it knows what columns it's looking at. Know get the information from. So now we want to go ahead and train it. And here's our input function equals in this case get input function. And here we tell it that
our data set is a DF train. Number of epics equals none, which is already automatically set up there. In batch equals 128, which is what we have up here, shuffle equals false. And we're going to do 1,000 steps. So, we're
actually going to go through 128 batches, but we're going to do that a thousand times. And we'll go ahead and run this. And I just ran an update. So, because of that update. And then we're back here, and it's still going. To
construct pipelines, use TF data module. Not a big problem. We let it go ahead And it takes it just a moment. There we go. There's our thousand coming out. As you can see here, here's checkpoints for 10,00 ongoing training, 101 global
steps. And this is just all the reverse propagation going on. That's what we're didn't cover is we do it in small increments. So, it's not all done like one error goes all the way back. You'd only do a part of that error. And each
one sends back a little piece and so you slowly adjust your different weights you're going to train your model, we want to know how it did. So we're going to do model evaluate and our input
function equals remember our input function up here that we created way up function and instead of the data set that's coming in, we put in the data set here for training. Where's our training? Input train. There we go. DF train. Uh
now we're going to go ahead and evaluate. And here it is. Uh get input function test. So we're going to test the data out. Number of epics one. We don't need to rerun it more than once. Per batch 128. Uh so on shuffle and
ahead and evaluate this. Let's just see how good our test data did. Uh how good our model was programmed on our training data and how it evaluates on the test. And we can see it going on down here where it's got the evaluating graph was
finalized. Let me just highlight that ongoing model checkpoint TensorFlow running local init evaluate 100 out of a thousand and so on. And once it gets to the end, we get a nice uh output here. We have an accuracy in this case of.79
with a baseline of 76. So now we've created a model. Uh let's go ahead and tweak it a little bit. So we have our accuracy up here. What we're going to do is we're going to look at age. And let's just go ahead and create a new uh square
value for age. And the reason we want to look into the square value of age is we data, you'll find that as a young person, the age keeps increasing. As you decrease. Uh so we square the value of age. And that's very data specific. When
any kind of data that has that kind of like uptick and down tick by squaring it very different results. And so we're going to go and square our age. And this at this point, even at the beginning of this, we're focused on deep learning and
on TensorFlow. But before I would begin even looking at any of this, I would have probably run some kind of heat map or some kind of evaluation in R or sklearn and Python to find out the correlation between different features
each other. And there certainly are some wonderful tools for that because features and other features you bring in. But for the deep learning, we can see how we can just dump it all in there and let it uh sort it out itself. And
function here to take the square variable. In this case, we have dft dft. This is our training and your test variable and the variable age coming in. And we just want to go ahead and create a new under dft. And the new is going to
be the variable name, whatever we put in there, which will be age. Uh, so let's loaded. And certainly we could have just done that as a line of code. Uh, but you start to get the feeling that when you build these u functions, you might use
a number of different features that had have our DF train new. So we're going to create a new training and a new test. variable DF train or DF test. And the variable name is age. And let's just go
ahead and run that. And so now we have our new or DF train new and DF test new. double check the shape of our data and make sure it all matches. And when we look at the um output here, really what's important is that each one of
make sure we're not getting something weird on there. And our training set has 32,561 rows in it. And this one has just over 16,000 in there. And everything's pretty much the same except that in our
continuous features new, we now have the new column we put in there. So we need to change that. And we have our continuous features new down here, which feature column numerical. This should all look familiar because we just did
this. And so we're going to load that up with the new being the new value in And we'll create a model. We'll call it model one. And this is the same that we did before except now we have our continuous features new in here. Uh so
one instead of model. And we're going to build that model right there. Now we told it where to get the data and how to get the data and what features are everything on the features coming in because we still need to also build our
full our um get input function. So where's the input coming from? So, we built the model with the features in it. And now we need to go ahead and create our get input function. This is the same as before, but you'll see um we now have
it with the data set coming in is going to be the same data set up here. And so, if we scroll a little bit to the right, we should see the new. And there it is. right. And so, let's go ahead and run that. Now, we've defined our model. We
defined where the information is coming from. And again, you can go back and identical that we did before, except now we have new as the column for the age. And let's go ahead and train it. There's our input function. Get input function
going to be the same. And everything else is going to be the same. Let's go through here and run the tensor info coming in. And it's going to go through uh in this case where we have steps 1,00 shuffling. So it's going to go randomly
128 per batch. Uh and then the epics is automatic. We're not worried about that today. So now we have a trained TensorFlow model. And with our new model, just like we did before, we want to go ahead and evaluate it. Uh so it's
the same setup we had before with our same get input function with our DF test new in here coming in. So there's our new data coming in. And this is really You make little tiny tweaks to see if you can improve it. One of the best
articles I read recently was you build your model to fail. You want a running model so you actually have something to compare against and then you continually Now I don't expect the accuracy necessarily to get better on this uh
because of the way we partition the data. But we can see here we now have an accuracy of.76 which is a little bit over the baseline and it's about what I would have expected it to be kind of the same. The reason is because we split the
data at the 50, the people making over 50k and those making less. And so the age factor shouldn't be a huge factor. It would be if we were looking at more discrete buckets like 40 to 50, 50 to 60, 60 to 70 when we create buckets. But
up that much. In fact, we could probably run it a dozen times, which would be very bad data science. And we see we actually had a slightly better one up here, but our baseline accuracy was 76. And we come down here, we still see uh
uh here's our accuracy baseline 763. That didn't really change. And you know, much. I could hit the run button a few times. I would probably upbeat the one all right. This is how we learn. This is how we go through and figure out what's
not. What's going to improve the quality of our data so we have a better prediction and what's not. And we can now go ahead and utilize this model. you're actually working with somebody or with your clients and you come in, you
say, "Okay, here's my predictions. We're going to take a create a list and we're to predict and our input function is get input function df test new." Again, this difference, but we'll go ahead and stick with the new data we created. Number of
epics one batch 128. So, all this should look pretty familiar, but we're running all our predictions into the predictions. And let's go ahead and run that. And you'll see it go through the TensorFlow setup. So it's running done
running local ops. And then let's just go ahead and print the DF test new iOS zero. So row zero. And we're going to look at the predictions also for the same location zero. Let's go ahead and run that. And we can see here that we
have age 25 workass private. Um it has all the information coming in for that individual. And then it comes down here. We go ahead and get our u prediction. And in this particular instance, there's our label zero. Uh, and then we come
down here and we see takes a little bit for the setup to look up, but there's our array, which also returns a zero. And it has information for us on there. you can see there's all kinds of additional information you can pull from
this. And likewise, we could do it for position three. Let me go and run that. you can now see here's label one, and here's our logistics output. And again, in this particular setup, but here's the output array, and there's our one. and
they match label one one. So we predicted for the very first one uh zero on the label is going to make under 50,000 and the individual in two working class uh private whatever setup on here capital gain capital loss etc came up as
one meaning they're going to make over 50,000 so we covered a lot I mean this is the basics and you can see as you dig deeper when you look at some of this code let me just go back up here we're way back up here at the very top a
little too far overshot as you start working in here. We have uh one defining your features. And at this point, we didn't show this, but I would probably use either Python or R to show a relationship correlation because they
to pull that up. So, you can see what features are really connected and how they're connected. Uh and then we showed you different features like we have ones that are u integers and then we have ones like sex that are objects. You're
zero or one. You're male or female. You're uh same thing with race. uh probably have just a maybe 16 different races listed there. Ethnicities, things like that. Native country, again, that's you don't have like infinite number of
native countries. You just have a handful. So, we look at this. We have our features. We looked at that. We have our continuous features like age, which is a number or in this case an integer, an education number, how many years and
so on, along with your race, your sex, your relationship, which are just very abbreviated uh categorical data. Uh so, we looked at that. We went in there and we showed you how to um where was it? Here we go. We go back up here. Uh so we
create our model. The model has knows what categories are coming in. That's really important. And this is probably the one of the more complicated parts of this is our input function. And this input function is so important. So I
want to just rehash the input function for that reason. Uh this lets us know how we're pulling the data. It lets us know um if we're going to go through all the data 20 times um or we're going to let the or we're just going to let
TensorFlow itself keep going until the training model reaches a point. That point is based on uh what they call bias. You can become biased on your training data. And so when it hits a certain point where it becomes overly
doesn't really work really good in the keep it generic but as close as possible to the right answer. Uh so generic answers for a huge amount of data and then we have our batch size. Are we
going to shuffle it which we did and then also our estimator inputs. Uh so you have your estimator function here and then of course where the actual data is coming from. So you can see all this is in that get input function. That's
this together. And then we train our model. Um that's pretty straightforward. all your setup, training the model is quick. And then we go ahead and evaluate. And then we can go ahead and create a predict and then you know look
individuals. Uh so it's pretty it gives you a whole roundabout setup on here and how this is set up and how it's working. Certainly there are um a lot more things you can do with TensorFlow. This is the basic TensorFlow and it's always
going to be one of the most exciting fields right now because it is really in an infant stage and just exploding in the market. Welcome to the RNN tutorial. That's the recurrent neural network. So we talk about a feed forward neural
network. In a feed forward neural network, information flows only in the forward direction from the input nodes through the hidden layers if any and to the output nodes. There are no cycles or loops in the network. And so you can see
talking about how it just goes straight forward into the hidden layers. So each to the next hidden layer. It connects to the output layer. And of course we have a nice simplified version where it has a predicted output. They refer to the
input as X a lot of times and the output as Y. Decisions are based on current input, no memory about the past, no future scope. Why recurrent neural network? Issues in feed forward neural network. So one of the biggest issues is
because it doesn't have a scope of memory or time. A feed forward neural network doesn't know how to handle sequential data. Uh it only considers only the current input. So if you have a series of things and because three
points back affects what's happening now and what your output affects what's whatever I put as an output is going to affect the next one. Um a feed forward looks at this is what's coming in. And it cannot memorize previous inputs. So
it doesn't have that list of inputs coming in. Solution to feed forward neural network. You'll see here where it says recurrent neural network and we have our X on the bottom going to H going to Y. That's your feed forward. uh
but right in the middle it has a value C. So there's a whole another process. So it's memorizing what's going on in the hidden layers. And the hidden layers as they produce data feed into the next one. So your hidden layer might have an
output that goes off to Y. Uh but that output goes back into the next prediction coming in. What this does is this allows it to handle sequential data. It considers the current input and also the previously received inputs. And
drawings and um solutions, we should also look at applications of the RNN. Image captioning. RNN is used to caption an image by analyzing the activities present in it. A dog catching a ball in
you know, we have a lot of stuff that analyzes images of a dog and the image of a ball, but it's able to add one more feature in there that's actually catching the ball in midair. Time series prediction. any time series problem like
predicting the prices of stocks in a particular month can be solved using RNN and actually take a look at some stock. One of the things you should know about analyzing stock today is that it is very difficult and if you're analyzing the
whole stock, the stock market at the New York Stock Exchange in the US produces somewhere in the neighborhood if you count all the individual trades and fluctuations by the second um it's like 3 terabytes a day of data. So, we're
analyzing one stock is really tricky. In here, we'll give you a little jump on expect to get rich off of it immediately. Another application of the RNN is natural language processing. Text mining and sentiment analysis can be
language processing. And you can see processing when you stream those three words together is very different than I if I said processing language naturally. So the time series is very important
when we're analyzing sentiments. It can change the whole value of a sentence if you're just counting the words, you might get one sentiment where if you you get a completely different sentiment. When it rains, look for
rainbows. When it's dark, look for stars. Both of these are positive sentiments and they're based upon the order of which the sentence is going in. Machine translation. Given an input in one language, RNN can be used to
translate the input into a different languages as output. I myself am very linguistically challenged, but if you study languages and you're good with languages, you know right away that if you're speaking English, you would say
big cat. And if you're speaking Spanish, you would say cat big. So that translation is really important to get the right order to get uh there's all kinds of parts of speech that are important to know by the order of the
words. Here this person is speaking in English and getting translated. And you can see here a person is speaking in English and this little diagram. I guess that's denoted by the flags. I have a flag. I own it. No. Um, but they're
speaking in English and it's getting translated into Chinese, Italian, French, German, and Spanish languages. Some of the tools coming out are just so cool. So, somebody like myself who's very linguistically challenged, I can
now travel into worlds I would never think of because I can have something translate my English back and forth readily and I'm not stuck with a communication gap. So let's dive into what is a recurrent neural network.
Recurrent neural network works on the principle of saving the output of a in order to predict the output of the layer. Sounds a little confusing. When more sense. And usually we have a propagation forward neural network with
the input layers, the hidden layers, the output layer. With the recurrent neural network, we turn that on its side. So here it is. And now our X comes up from the bottom into the hidden layers into Y. And they usually draw it very
simplified. X to H with C as a loop A to Y where A, B, and C are the perimeters. drawing in here. Digging closer and closer into the H and how it works.
Going from left to right, you'll see that the C goes in and then the X goes in. So the X is going upward bound and C is going to the right. A is going out and C is also going out. That's where it gets a little confusing. So here we have
gets a little confusing. So here we have x in uh c in and then we have y out and x in uh c in and then we have y out and c out and c is based on ht minus one. So our value is based on the y and the h value are connected to each other.
because h can be its own thing. And usually we draw this or we represent it as a function h of t equals a function of c where h of t minus one that's the last h output and x of t going in. So it's the last output of H combined with
the new input of X. Uh where HT is the new state. FC is a function with a parameter C. That's a common way of denoting it. Uh ht minus one is the old state coming out. And then X of T is an input vector at time of step T. Well, we
need to cover types of recurrent neural networks. And so the first one is the most common one which is a one one single output. one to one neural network is usually known as a vanilla neural network used for regular machine
learning problems. Why? Because vanilla is usually considered kind of a just a basic, a lot of times they'll call it the vanilla neural network, uh which is know, like kind of a slang term. People will know what you're talking about
usually if you say that. Then we run one to many. So you have a single input and to many. So you have a single input and you might have a uh multiple outputs. In this case, uh, image captioning as we looked at earlier where we have not just
looking at it as a dog, but a dog catching a ball in the air. And then you have many to one network takes in a sequence of inputs. Examples, sentiment analysis where a given sentence can be classified as expressing positive or
negative sentiments. And we looked at that as we were discussing if it rains, look for a rainbow. So positive sentiment where rain might be a negative sentiment if you were just adding up the words in there. And then of course if
you're going to do a one one mini to one one to many there's many to many networks takes in a sequence of inputs and generates a sequence of outputs. Example machine translation. So we have a lengthy sentence coming in in English
and then going out in all the different languages. Uh you know just a wonderful computations. You know if you're a translator you realize just how different languages. One of the biggest things you need to understand when we're
working with this neural network is what's called the vanishing gradient problem. While training an RNN, your slope can be either too small or very large. And this makes training difficult. When the slope is too small,
the problem is known as vanishing gradient. And you'll see here they have a nice uh image loss of information through time. So if you're pushing not enough information forward, that information is lost. and then when you
third word in the sentence or something like that or it doesn't quite follow the full logic of what you're working on. Exploding gradient problem. Oh, this is one that runs into everybody when you're working with this particular neural
network when the slope tends to grow exponentially instead of decaying. This problem is called exploding gradient. Issues in gradient problem. Long training time, poor performance, bad accuracy. And I'll add one more in
there. uh your computer if you're on a a lower-end computer testing out a model will lock up and give you the memory error. Explaining gradient problem. understand what should be the next word in the sequence. The person who took my
in the sequence. The person who took my bike and blank a thief. The students who got into engineering with blank from Asia. And you can see in here we have our x value going in. We have the previous value going forward. And then
you back propagate the error like you do with any neural network. And as we're we'll have the person took my bike and blank was a thief and the student who got into engineering with a blank were from Asia. Consider the following
So we'll go back to the person who took the bike was blank a thief. In order to understand what would be the next word in the sequence, the RNN must memorize the previous context whether the subject was singular noun or a plural noun. So
was a thief is singular. the student who got into engineering. Well, in order to understand what would be the next word in the sequence, the RNN must memorize the previous context, whether the subject was singular noun or a plural
noun. And so, you can see here the students who got into engineering with blank were from Asia. It might be sometimes difficult for the error to sequence to predict what should be the
output. So, when you run into the gradient problem, we need a solution. the solution to the gradient problem. First, we're going to look at exploding gradient where we have three different solutions depending on what's going on.
One is identity initialization. So, the first thing we want to do is see if we can find a way to minimize the identities coming in instead of having it identify everything just the important information we're looking at.
Next is to truncate the back propagation. So, instead of having uh whatever information it's sending to the next series, we can truncate what it's sending. we can lower that particular uh set of layers, make those smaller. And
we're training it, we can clip what that gradient looks like and narrow the training model that we're using. When you have a vanishing gradient, the option problem, uh we can take a look at weight initialization. Very similar to
the identity, but we're going to add more weights in there so it can identify different aspects of what's coming in better. Choosing the right activation function, that's huge. So we might be activating based on one thing and we
too much about activation functions. So we'll look at that just minimally. Uh there's a lot of choices out there. And then finally there's long shortterm memory networks the LSTMS and we can make adjustments to that. So just like
we can clip the gradient as it comes out we can also um expand on that. We can increase the memory network the size of it so it handles more information. And one of the most common problems in today's uh setup is what they call
long-term dependencies. Suppose we try to predict the last word in the text. The clouds are in the and you probably said sky. Here we do not need any further context. It's pretty clear that the last word is going to be sky.
in the text. I have been staying in Spain for the last 10 years. I can speak fluent. Maybe you said Portuguese or French. No, you probably said Spanish. The word we predict will depend on the previous few words in context. Here we
need the context of Spain to predict the last word in the text. It's possible that the gap between the relevant information and the point where it is needed to become very large. LSTMs help us solve this problem. So the LSTMs
are a special kind of recurrent neural network capable of learning long-term dependencies. Remembering information for long periods of time is their default behavior. All recurrent neural networks have the form of a chain of
repeating modules of neural network connections. In standard RNNs, this repeating module will have a very simple structure such as a single tangent H layer. LSTMs's also have a chain-like structure, but
the repeating module has a different structure. Instead of having a single neural network layer, there are four interacting layers communicating in a very special way. LSTMS are a special kind of recurrent neural network capable
Remembering information for long periods of time is their default behavior. LSTMs's also have a chain-like structure, but the repeating module has a different structure. Instead of having a single neural network layer, there are
four interacting layers communicating in a very special way. As you can see, the deeper we dig into this, the more complicated the graphs get in here. I want you to note that you have x of t minus one coming in. You have x of t
coming in and you have x at t + one and you have h of t minus one and h of t coming in and h of t+1 going out and of course uh on the other side is the output a. Um in the middle we have our tangent h but it occurs in two different
places. So not only when we're computing the x of t + one are we getting the tangent h from x of t, but we're also getting that value coming in from the x of t minus one. So the short of it is as you look at these layers, not only does
it does the propagate through the first layer goes into the second layer back into itself, but it's also going into the third layer. So now we're kind of stacking those up. And this can get very complicated as you grow that in size. It
also grows in memory too and in the amount of resources it takes. Uh but it's a very powerful tool to help us address the problem of complicated long sequential information coming in like we were just looking at in the sentence.
And when we're looking at our long shortterm memory network uh there's three steps of processing processing in the LSTMS that we look at. The first one is we want to forget irrelevant parts of the previous state. you know, a lot of
we're trying to look at whether it's a plural noun or not, they don't really play a huge part in the language. So we want to get rid of them. Then selectively update cell state values. So
values that reflect what we're working on. And finally, we want to put only output certain parts of the cell state. So whatever is coming out, we want to limit what's going out, too. And let's dig a little deeper into this. Let's
just see what this really looks like. Uh so step one decides how much of the past it should remember. First step in the LSTM is to decide which information to be omitted in from the cell in that particular time step. It is decided by
the sigmoid function. It looks at the previous state h at t minus one and the function. So you can see over here we have a function of t equals the sigmoid have a function of t equals the sigmoid function of the weight of f the h at t
minus one and then x at t plus of course you have a bias in there with any of our neural networks. So we have a bias function. So f of t equals forget gate decides which information to delete that is not important from the previous time
step. Considering an STM is fed with the following inputs from the previous and present time step. Alice is good in physics. John on the other hand is good in chemistry. So previous output, John plays football well. He told me
yesterday over the phone that he had served as a captain of his college football team. That's our current input. So as we look at this, the first step is the forget gate realizes there might be a change in context after encounting the
first full stop compares with the current input sentence of exit t. So we're looking at that full stop and then compares it with the input of the new sentence. The next sentence talks about John. So the information on Alice is
deleted. Okay, that's important to know. So we have this input coming in. And if then that's going to be the primary information we're looking at. The position of the subject is vacated and is assigned to John. And so in this one,
bunch of information and we're only passing information on John since that's now the new topic. So step two is then to decide how much should this unit add to the current state. In the second layer, there are two parts. One is a
sigmoid function and the other is a tangent h. In the sigmoid function, it decides which values to let through zero or one. Tangent h function gives the weightage to the values which are passed deciding their level of importance
minus1 to 1. And you can see the two formulas that come up. Uh the i of t equals the sigmoid of the weight of i h of t minus one x of t plus the bias of i. And the C of T equals the tangent of H of the weight of C of H of T minus 1 X
of T plus the bias of C. So our I of T equals the input gate determines which information to let through based on its significance in the current time step. If this seems a little complicated, don't worry because a lot of the
to the case study. Understanding though that this is part of the program is important when you're trying to figure out these what to set your settings at. at this, it should have some semblance to your forward propagation neural
networks where we have a value assigned to a weight plus a bias. Very important steps in any of the neural network layers, whether we're propagating into next or we're just doing a straightforward neural network
propagation. Let's take a quick look at this what it looks like from the human standpoint. Um, as I step out of my suit again, consider the current input at XFT. John plays football well. He told me yesterday over the phone that he had
served as a captain of his college football team. That's our input. Input gate analysis the important information. John plays football and he was a captain of his college team is important. He told me over the phone yesterday is less
important. Hence, it is forgotten. This process of adding some new information can be done via the input gate. Now, this example is as a human form, and we'll look at training this stuff in just a minute. Uh, but as a human being,
if I wanted to get this information from a conversation, maybe it's a Google voice listening in on you or something like that. Um, how do we weed out the information that he was talking to me on the phone yesterday? Well, I don't want
phone yesterday. Or maybe that is important, but in this case, it's not. I want to know that he was the captain of the football team. I want to know that he served. I want to know that John plays football and he was the captain of
two things that I want to take away as a human being. Again, we measure a lot of this from the human viewpoint and that's also how we try to train them so we can Finally, we get to step three. Decides what part of the current cell state
makes it to the output. The third step is to decide what will be our output. decides what parts of the cell state make it to the output. Then we put the cell state through the tangent h to push the values to be between minus1 and one
and multiply it by the output of the sigmoid gate. So when we talk about the output of t, we set that equal to the sigmoid of the weight of zero of the h sigmoid of the weight of zero of the h of t minus one back one step in time by
the x of t plus of course the bias. The h of t equals the out of t times the tangent of the tangent h of c of t. So our oat equals the output gate allows the passed in information to impact the output in the current time step. Let's
consider the example to predicting the next word in the sentence. John played tremendously well against the opponent and one for his team. For his contributions, brave blank was awarded player of the match. There could be a
lot of choices for the empty space. Current input brave is an adjective. Adjectives describe a noun. John could be the best output after brave. Thumbs up for John. Awarded player of the match. And if you were to pull just the
look right because that's not really the subject. We're talking about contributions. Uh you know, brave contributions or brave team, brave player, brave match. Um so you look at this and you can start to train this
looking at and goes, "Oh no, John is what we're talking about. So brave is an adjective. Jon's going to be the best output." and we give John a big thumbs up. And then of course we jump into my favorite part, the case study. Use case
implementation of LSTM. Let's predict the prices of stocks using the LSTM network based on the stock price data between 2012 2016. We're going to try to predict the stock prices of 2017. And this will be a narrow set of data. We're
It turns out that the New York Stock Exchange generates roughly three terabytes of data per day. That's all the different trades up and down of all the different stocks going on and each individual one uh second to second or
nancond to nancond. Uh but we're going to limit that to just some very basic fundamental information. So don't think you're going to get rich off this today. But at least you can give an eye you can give a step forward in how to start
processing something like stock prices. a very valid use for machine learning in today's markets. Use case implementation of LSTM. Let's dive in. We're going to import our libraries. We're going to import the
training set and uh get the scaling going. Um now, if you watch any of our other tutorials, a lot of these pieces should start to look very familiar. It's look at that. And um just a reminder, we're going to be using Anaconda, the
Jupiter notebook. So here I have my Anaconda navigator. When we go under environments, I've actually set up a KAS Python 3.6. I'm in Python 3.6. And u
the newer version. I remember a year ago messing with Anaconda in different versions of Python and different environments. Um Anaconda now has a nice interface. Um and I have this installed both on a Ubuntu Linux machine and on
can go in here and open a terminal window. And then in here, once you're in you're going to start uh installing using pip to install your different modules and everything. Now, we've already pre-installed them, so we don't
don't have them installed in your particular environment, you'll need to do that. And of course, you don't need to use the Anaconda or the Jupiter. You can use whatever favorite Python IDE you like. I'm just a big fan of this because
it keeps all my stuff separate. You can see on this machine I have specifically installed one for KAS since we're going to be working with KAS under TensorFlow. We go back to home. I've gone up here to application and that's the environment
I've loaded on here and then we'll click on the launch Jupyter notebook. Now I've already in my Jupyter notebook um have set up a lot of stuff so that we're Stewart's in the old cooking shows. We want to make sure we have all our tools
to load. And uh if we go up here to where it says new, you can see where you can um create a new Python 3. That's what we did here underneath the setup. installed on it. And I'm actually renamed this. So if you go under file,
you can rename it. We I'm calling it RNN stock. And let's just take a look at into the exciting part. Now we've looked at the tool. And of course, you might be Uh let's start putting that code in there and seeing what those imports and
uploading everything looks like. Now, first half is kind of boring when we hit the run button because we're going to be importing numpy as np. That's uh uh the number python which is your numpy array and the mattplot library. So, we're
going to do some plotting at the end and our pandas for our data set. Our pandas is pd. And when I hit run, uh it really doesn't do anything except for load those modules. Just a quick note, let me just do a quick uh draw here. Whoops.
Shift alt. There we go. You'll notice when we're doing this setup, if I was to divide this up, oops, I'm going to actually uh let's overlap these. Here we actually uh let's overlap these. Here we go.
do is our data fact, depending on what your system is, since we're using KAS, I put an overlap
here. Uh but you'll find that almost maybe even half of the code we do is all about the data prep. And the reason I overlap this with uh KAS, let me just working in. Uh is because KASS has like their own preset stuff. So it's already
pre-built in which is really nice. So there's a couple steps a lot of times that are in the KAS setup. Uh we'll take a look at that to see what comes up in stock. And then the last part is to
evaluate. And if you're working with um shareholders or uh you know classroom the evaluate is the next biggest piece. Um so the actual code here cross is a
little bit more but when you're working with uh some of the other packages you might have like three lines that might be it. All your stuff is in your pre-processing in your data. Since KASS has is is cutting edge and you load the
individual layers, you'll see that there's a few more lines here and cross you spend a lot of times uh like I said with the evaluate. You want to have to say, "Hey, this is what I did. This is what it looks like." So let's go
of just general overview and let's just take a look and see what the next set of code looks like. And in here we have a data set train and it's going to be read using the PD or pandas read CSV and it's
a Google stockpric train.csv. And so under this we have training set And so under this we have training set equals data set train.loation that. So what's going on here? Let's just take a look at let's let's look at
the actual file and see what's going on there. Now, if we look at this, uh, ignore all the extra files on this. Um, I already have a train and a test set to notice because a lot of times we do that as part of the pre-processing of
the data. We take 20% of the data out so we can test it and then we train the our neural network. That way, we can find out how good it is. Uh, but let's go ahead and just take a look and see what that looks like as far as the file
itself. And I went ahead and just opened this up in a basic word pad and text editor just so we can take a look at it. Certainly you can open up an Excel or any other kind of spreadsheet. Um and we note that this is a comma separated
note that this is a comma separated variables. We have a date uh open, high, low, close, volume. This is the standard stuff that we import into our stock and you can look at in stock. It's all free to download. Um in this case we
downloaded it from uh Google. That's why we call it the Google stock price. Um and this specifically is Google. This is the Google stock values from uh as you the Google stock values from uh as you can see here we started off at 1320.
So when we look at this first setup up here uh we have a data set train equals pd_csv. And if you noticed on the original frame uh let me just go back there. They had it set to home Ubuntu downloads Google
stock price train. I went ahead and changed that because we're in the same file where I'm running the code. So, I've saved this particular Python code special paths or have the full path on there. And then, of course, we want to
take out um certain values in here. And you're going to notice that we're using you're going to notice that we're using um our data set and we're now in pandas. Uh so, pandas basically it looks like a spreadsheet. Um, and in this case, we're
going to do I location, which is going to get specific locations. The first value is going to show us that we're pulling all the rows in the data. And the second one is we're only going to look at columns one and two. And if you
switch back on over columns, we always start with zero, which is the date. And we're going to be looking at open and high, which would be one and two.
I'll just label that right there so you can see. Now, when you go back and do this, you certainly can extrapolate and do this on all the columns. Um, but for the example, let's just limit a little bit here so that we can focus on just
some key aspects of stock. And then we'll go up here and run the half is very boring. Whenever you hit the run button, it doesn't do anything because we're still just loading the data and setting it up. Now that we've
loaded our data, we want to go ahead and scale it. We want to do what they call feature scaling. And in here, we're going to pull it up from the sklearn or the SK kit pre-processing import minm max scaler. And when you look at this,
you got to remember that um biases in our data, we want to get rid of that. So if you have something that's like a really high value, um let's just draw a quick graph. and I have something here like the maybe the stock has a value one
stock has a value of 100 and another stock has a value of five. [snorts] Um you start to get a bias between different stocks. And so when we do this we go ahead and say okay 100 is going to be the max and five is going to be the
min and then everything else goes and then we change this and we just squish then we change this and we just squish it down. I like the word squish. So it's it down. I like the word squish. So it's between one and zero. So 100 equals 1 or
1 equals 100 and 0 equals 5. And you can just multiply. It's usually just a simple multiplication. We're using uh multiplication. So it's going to be uh minus 5 and then 100 divided or 95 divided by one. So or whatever value is
is divided by 95. And uh once we've actually created our scale, we've tolding it's going to be from 0 to one. We want to take our training set and we're going to create a training set scaled. And we're going to use our
scaler SC and we're going to fit we're going to fit and transform the training set. Uh so we can now use the SC this this particular object. We'll use it remember we have to also scale that when we go to test our uh model and see how
it works. And we'll go ahead and click on the run again. Uh it's not going to have any output yet because we're just setting up all the variables. Okay. Okay, so we pasted the data in here and we're going to create the data
structure with the 60 time steps and output. First note, we're running 60 time steps and that is where this value here also comes in. So the first thing we do is we create our X train and Y train variables. We set them to an empty
Python array. Very important to remember what kind of array we're in and what to come in here. We're going to go for I in range 60 to 1258. There's our 60 60 time steps. And the reason we want to do this is as we're adding the data in
there, there's nothing below the 60. So if we're going to use 60 time steps, uh includes everything underneath of it. Otherwise, you'll get a pointer error. And then we're going to take our X train and we're going to append training set
scaled. This is a scaled value between zero and one. And then as I is equal to zero and one. And then as I is equal to 60, this value is going to be um 60 - 60 60, this value is going to be um 60 - 60 is zero. So this actually is 0 to I. So
it's going to be 0 to 60, 1 to 61. Let me just circle this part right here. 1 me just circle this part right here. 1 to 61. Uh 2 to 62. And so on and so on. And if you remember, I said 0 to 60. That's incorrect because it does not
this is a count of 60. So it's actually 59. Important to remember that as we're looking at this. And then the second part of this that we're looking at. So if we remember correctly, here we go. we go from uh 0 to 59 of i and then we have
a comma a zero right here. And so finally we're just going to look at the open value. Now I know we did put it in there for one to two. Um if you remember one. So it's just the open value we're looking at just open. Um and then
finally we have ytrain.append training set i to zero. And if you remember correctly I to or I comma zero. If you remember correctly, this is 0 to 59. So there's 60 values in it. Uh so when we do I down here, this is number
60. So we're going to do this is we're creating an array and we have 0 to 59. And over here we have number 60 which is going into the Y train. It's being
appended on there. And then this just goes all the way up. So this is down goes all the way up. So this is down here is uh 0 to 59 and we'll call it 60 since that's the value over here and it goes all the way up to 12 58. That's
where this value here comes in. That's the length of the data we're loading. So we've loaded two arrays. We loaded one array that has uh which is filled with arrays from 0 to 59. And we loaded one array which is just the value. And what
we're looking at you want to think about this as a time sequence. Uh here's my open open open. What's the next one in the series? So we're looking at the want to know what the next one uh 0 through 59, what's 60? 1 through 60,
through 59, what's 60? 1 through 60, what's 61? 2 through 62, what's 62? And so on and so on going up. And then once we've loaded those in our for loop, we go ahead and take xra and yra equals np.array xtra. npray ytra. We're just
converting this back into a numpy array. That way, we can use all the cool tools that we get with numpy array, including reshaping. So, if we take a look and see what's going on here, we're going to take our x train.
We're going to reshape it. Wow. What the heck does reshape mean? Uh, that means we have an array, if you remember correctly, um, so many numbers by 60. That's how wide it is. And so, we're when you when you do x-ra.shape, shape
that gets one of the shapes and you get um x-train.shape of one gets the other shape. And we're just making sure the data is formatted correctly. And so you use this to pull the fact that it's 60 by um in this case, where's that value?
60 by 1199. 1258US 60 1199. And we're making sure that that is shaped correctly. So the data is grouped into uh 11 999 by 60
the end just means at the end because this when you're dealing with shapes and numpy they look at this as layers and so the end layer needs to be one value that's like the leaf of a tree where this is the branch and then it branches
out some more um and then you get the leaf np.shape comes from and using the existing shapes to form it. We'll go ahead and run this piece of code. Again, there's no real output. And then we'll import our different cross modules that
to import the sequential model. We're dealing with sequential data. We have our dense layers. We have actually three layers. We're going to bring in our dense, our LSTM, which is what we're focusing on, and our dropout. And we'll
discuss these three layers more in just a moment. But you do need the with the LSTM, you do need the dropout, and then the final layer will be the dents. But let's go ahead and run this and that'll bring our modules and you'll see we get
an error on here. And if you read it closer, it's not actually an error, it's These things come up all the time when you're working with such cutting edge the time. We're not going to worry too much about the warning. All it's saying
is that the H5PY module, which is part of KAS, is going to be updated at some point. And uh if you're running new stuff on KAS and you start updating your KAS system, you better make sure that your H5 PI is
have an error later on. But you can actually just run an update on the H5 PI We're not going to worry about that today. And I said we were going to jump layers mean. I meant that. And uh we're going to start off with initializing the
layers in. And you'll see that we have the LSTM and then the dropout. LSTM then dropout. LSTM then dropout. What the heck is that doing? So let let's explore that. We'll start by initializing the
RNN regressor equals sequential because we're using the sequential model. And then we're going to start adding our LSTM layer and some dropout regularization. And right there should
be the Q dropout regularization. And if we go back here and remember our exploding gradient, well, that's what we're talking about. The uh dropout drops out unnecessary data so we're not just shifting huge amounts of data
through um the network. So, and so we go in here. Let's just go ahead and uh add we had three of them. So, let me go ahead and put all three of them in. And the second one. And let's put one more in. Let's put that in. And we'll go and
said one more in, but it's actually two more in. And then let's add one more after that. And as you can see, each time I run these, they don't actually look and see what's going on here. So we're going to add our first LSTM layer
in here. We're going to have units 50. The units is the positive integer and it's the dimensionality of the output space. This is what's going out into the next layer. So we might have 60 coming in, but we have 50 going out. We have a
return sequence because it is a sequence data. So we want to keep that true. And in. Well, we already know the shape by just going in here and looking at X train shape. So, input shape equals the X train shape of one comma one. Makes it
all the numbers that put in 60 or whatever else is in there. You just let it tell the regressor what model to use. And so, we follow our STM with a dropout layer. Now, understanding the dropout layer is kind of exciting because one of
the things that happens is we can overtrain our network. That means that our neural network will memorize such specific data that it has trouble predicting anything that's not in that specific realm. To fix for that, each
time we run through the training mode, we're going to take 0 2 or 20% of our we're only going to train on the other ones. And it's going to be random. That way, each time we pass through this, we don't overtrain. These nodes come back
in in the next training cycle. We randomly pick a different 20. And finally, I see a big difference as we go from the first to the second and third have to input the shape because the
here. This auto the next step automatically knows this layer is next layer, it automatically sets that and says, oh, 50 is coming out from our goes into the regressor. And of course,
we have our dropout and that's what's coming into this one. And so on and so don't have to let it know what the shape is. It automatically understands that. And we're going to keep the units the same. We're still going to do 50 units.
It's still a sequence coming through. 50 units and a sequence. Now, the next together. Let's go ahead and take a look at that. And we come in here, we put the output layer, the dense layer. And if you remember up here, we had the three
layers. We had uh LSTM, dropout, and dense. uh dense just says we're going to bring this all down into one output. Instead of putting out a sequence, we just know want to know the answer at this point. And let's go ahead and run
we're doing is setting things up one step at a time. So far, we've brought in our uh way up here, we brought in our data. We brought in our different modules. We formatted the data for training it. We set it up. You know, we
have our Yx train and our Y train. We have our source of data and the answers we're we know so far that we're going to put in there. We've reshaped that. We've come in and built our KAS. We've imported our different layers. And we
have in here, if you look, we have what uh five total layers. Now, KAS is a systems because a lot of other systems put this all in one line and do it automatic, but they don't give you the options of how those layers interface
and they don't give you the options of how the data comes in. KAS is cutting there's a lot of extra steps in building the model, this has a huge impact on the output and what we can do with this these new models from KAS. So we brought
in our dense, we have our full model put together, our regressor. So we need to go ahead and compile it and then we're going to go ahead and fit the data. We're going to compile the pieces so they all come together and then we're
going to run our training data on there and actually recreate our regressor so it's ready to be used. So let's go ahead and compile that. And I can go ahead and run that. And uh if you've been looking at any of our other tutorials on neural
networks, you'll see we're going to use the optimizer atom. Atom is optimized for big data. There's a couple other optimizers out there uh beyond the scope will work pretty good for this. And loss equals mean squared value. So when we're
training it, this is what we want to base the loss on. How bad is our error? squared value for our error and the atom optimizer for its differential math behind them, but certainly it helps to know what they're doing and where
then finally, we're going to do our fit. Fitting the RNN to the training set. We have the regressor.fit, X-RA, Y train, epics, and batch size. So, we know where this is. This is our data coming in for
the X train. Our Y train is the answer we're looking for of our data, our sequential input. Epics is how many times we're going to go over the whole data set. We created a whole data set of X-ray. So this is each each of those
rows which includes a time sequence of 60 and batch size. Another one of those things where KAS really shines is if you were pulling this say from a large file instead of trying to load it all into RAM it can now pick smaller batches up
worried about pulling them off a file today cuz this isn't big enough to uh cause the computer too much of a problem to run. Not too straining on the imagine what would happen if I was doing a lot more than just one column in one
stock. Imagine if I was doing this across all the stocks and I had instead of just the open, I had open, close, a high, low, and you can actually find yourself with about 13 different variables times 60 because there's a
time sequence. suddenly you find yourself with a gig of memory you're completely, you know, if it's just if you're not on multiple computers or into resource problems. But for this, we don't have to worry about that. So,
will actually take a little bit on my computer cuz it's an older laptop. And give it a second to kick in there. There we go. All right. So, we have epic. So, the first run through all the data. And as it's going through, it's batching
them in 32 pieces. So 32 uh lines each time and there's 1198. I think I said 1199 earlier but it's 1198. I was off by one. And each one of these is 13 seconds. So you can imagine this is roughly 20 to 30 minutes run time on
this computer. Like I said, it's an older laptop running at 0.9 GHz on a dual processor. And that's fine. What we'll do is I'll go ahead and stop, go let's see what happens at the end and where this takes us. And like any good
cooking show. I've kind of gotten my latte. I also had some other stuff these numbers jumped up to like 19 seconds, 15 seconds, but you can scroll through and you can see we've run it through 100 steps or 100 epics. So the
of the first things you'll notice is that our loss can is over here. It kind of stopped at 0.0014, but you can see it kind of goes down until we hit about 0.014 three times in a row. So we guessed our epic pretty close since our
loss has remained the same on there. So to find out what we're looking at, we're going to go ahead and load up our test data, the test data that we didn't process yet, and a real stock price data set test location. This is the same
the first place. So let's go ahead and go through this code. And we can see we've labeled it part three, making the predictions and visualizing the results. So the first thing we need to do is go ahead and read the data in from our test
CSV. You see I've changed the path on it for my computer. And uh then we'll call it the real stock price. And again, we're doing just the one column here and the values from iOS. So it's all the rows and just the values from these that
one location. That's the open stock open. And let's go ahead and run that. So that's loaded in there. And then let's go ahead and uh create we have our inputs. We're going to create inputs here. And this should all look familiar.
We're going to take our data set total. We're going to do a little pandas concat from the data set train. Now remember the end of the data set train is part of visualize that just a little bit. Here's our train data. Let me just put tr for
train. And it went up to this value here. But each one of these values generated a bunch of columns. It was 60 across. And this value here equals this one. And this value here equals this one. And so we need these top 60 to go
into our new data. So to find out what we're looking at, we're going to go ahead and load up our test data, the test data that we didn't process yet. And a real stock price data set test I location. This is the same thing we did
place. So let's go ahead and go through this code. And we can see we've labeled it part three, making the predictions and visualizing the results. So the first thing we need to do is go ahead and read the data in from our test CSV.
And you see I've changed the path on it for my computer. And uh then we'll call it the real stock price. And again, we're doing just the one column here and the values from IO location. So it's all the rows and just the values from these
that one location. That's the open stock open. And let's go ahead and run that. So that's loaded in there. And then let's go ahead and uh create. We have our inputs. We're going to create inputs here. And this should all look familiar.
We're going to take our data set total. We're going to do a little panda concat from the data set train. Now remember the end of the data set train is part of the data going in. And let's just visualize that just a little bit. Here's
our train data. Let me just put tr for train. And it went up to this value here. But each one of these values generated a bunch of columns. It was 60 across. And this value here equals this one. And this value here equals this
one. And this value here equals this one. And so we need these top 60 to go into our new data cuz that's part of the next data or it's actually the top 59. here is we're going in, we're doing the real stock price and we're going to just
take the data set test and we're going to load that in. And then the real stock price is our data test location. So we're just looking at that first uh column, the open price. And then our data set total, we're going to take
pandas and we're going to concat. And we're going to take our data set train for the open and our data set test open. And this is one way you can reference couple different ways. We've referenced them up here with the one two, but we
know it's labeled as a panda set is open. So pandas is great that way. Lots of versatility there. And we'll go ahead and go back up here and run this. There we go. And uh you'll notice this is the same as what we did before. We have our
different or concatenated our two data data set total length data set total minus length of data set minus test minus 60 values. So we're going to run this over all of them and you'll see why
running your test set versus your training set, you run them completely see that we're just going to be we'll be looking at the part that uh we didn't train it with to see how well it graphs. And we have our inputs equals inputs
reshapes. So reshaping like we did before, we're transforming our inputs. So if you remember from the transform between 0ero and one and uh finally we want to go ahead and take our x test and we're going to create that x test and
for i in range 60 to 80. So here's our x test and we're appending our inputs i to 60 which remember is 0 to 59 and i, zero on the other side. So it's just the first column which is our open column. And uh once again we take our x test we
convert it to a numpy array. We do the same reshape we did before. And uh then here we have something new right here on these last two lines. Let me just highlight those or or mark them. Predicted stock price equals
regressor.predicts x test. So we're predicting all the stock including both the training and the testing model here. And then we want to take this prediction and we want to inverse the transform. So remember we put them between zero and
much to me to look at a at a float number between 0 and one. I want the cash value is. And we'll go ahead and run this. And you'll see it runs much so wonderful about these neural networks. Once you put them together,
neural network that took us what a half hour to train. Head and plot the data. going to be and we're going to plot it against the real data. What what the Google stock actually did. So, let's go ahead and take a look at that in code.
And let's uh pull this code up. So, we have our PLT. That's our uh oh, if you remember from the very beginning, let me just go back up to the top. We have our mattplot library.pipplot as plt. That's
here. We're going to plot. Let me get my go ahead and plt is basically kind of that always threw me when I'm doing graphs in Python because I always think
you have to create an object and then it loads that class in there. Well, in this case, PLT is like a canvas you're putting stuff on. So if you've done HTML 5, you'll have the canvas object. This is the canvas. So we're going to plot
actually is. And we're going to give that color red. So it's going to be in bright red. We're going to label it real Google stock price. And then we're going going to do it in blue. And it's going to be labeled predicted. And we'll give
give a title to your uh graph, especially if you're going to present this to somebody, you know, to your uh shareholders in the office. And uh the x time series. And we didn't actually put the actual date and times on here. But
incremented by time. And then of course the y label is the actual stock price. plt.leend tells us to build the legend on here so that the color red and and real Google stock price show up on there. And then the plot shows us that
actual graph. So let's go ahead and run this and see what that looks like. And And let let's talk just a little bit about this graph before we wrap it up. Here's our legend I was telling you about. That's why we have the legend
everything. And you'll notice on the bottom we have a time sequence. We didn't put the actual time in here. Now, we could have we could have gone ahead and um plotted the x since we know what the the dates are and plotted this to
dates, but we also know this only the last piece of data that we're looking at. So last piece of data which ends somewhere probably around here on the graph. I think it's like about 20% of the data, probably less than that. We
have the Google price and the Google price has this little up jump and then down. And you'll see that the actual Google instead of uh a turndown here just didn't go up as high and didn't low go uh down. So our prediction has the
same pattern, but the overall value is pretty far off as far as um stock. But column. We're only looking at the open price. We're not looking at how many volumes were traded. Like I was pointing out earlier when we talk about stock
just right off the bat. There's six columns. There's open, high, low, close, volume. Then there's whether uh I mean volume shares. Then there's the adjusted open, adjusted high, adjusted low, adjusted close. They have a special
really be worth based on the [snorts] value of the stock. And then from there, put in here. So, we're only looking at one small aspect, the opening price of the stock. And as you can see here, we did a pretty good job. This curve
follows the curve pretty well. It has like a, you know, little jumps on it, bends. They don't quite match up. So, this bend here does not quite match up with that bend there, but it's pretty darn close. We have the basic shape of
it, and the prediction isn't too far off. And you can imagine that as we add more data in and look at different aspects in the specific domain of stock, representation each time we drill in deeper. Of course, this took a half hour
for my program, my computer to train. So you can imagine that if I was running it might take a little bit longer to train the data. Not so good for doing a quick tutorial like this. So we're going to dive right into what is KAS. We'll also
couple of tutorials because that's where up your sleeves. So we talk about what is KAS. KAS is a high-level deep learning API written in Python for easy implement implementation of neural
networks. It uses deep learning frameworks such as TensorFlow, PyTorch, etc. as backend to make computation faster. And this is really nice because as a uh programmer there is so much stuff out
there and it's evolving so fast it can get confusing and having some kind of highlevel order in there. We can actually view it and easily program these different neural networks uh is really powerful. It's really powerful to
to um uh have something out really quick and also be able to start testing your models and seeing where you're going. So, KAS works by using complex deep learning frameworks such as TensorFlow, PyTorch, um, ML played, etc. as a
backend for fast computation while providing a userfriendly and easy tolearn front end. And you can see here we have the cross API uh, specifications and under that you'd have like TF Karass for TensorFlow, Thano Karass and so on
workflow that this is all sitting on top of. And this is, like I said, it organizes everything. The heavy lifting is still done by TensorFlow or whatever, you know, underlying package you put in
there. And this is really nice because you don't have to um dig as deeply into the heavy and stuff while still having a very robust package. You can get up and running rather quickly and it doesn't distract from the processing time
because all the heavy lifting is done by packages like TensorFlow. This is the organization on top of it. So the working principle of Kass uh the working principle of KASS is KASS uses computational graphs to express and
computational graphs to express and evaluate mathematical expressions. You can see here we put them in blue. They have the expression u expressing complex problems as a combination of simple mathematical operators uh where
we have like the percentage or in this case in Python that's usually your uh case in Python that's usually your uh left your um remainder or multiplication uh you might have the operator of x uh to the power of.3 and it uses useful for
calculating derivatives by using uh back propagation. So if we're doing with neural networks, we send the error back up to figure out how to change it. Uh this makes it really easy to do that without really having not banging your
everything. It's easier to implement distributed computation and for solving complex problems uh specify input and outputs and make sure all nodes are connected. And so this is really nice as you come in through is that um as your
layers are going in there, you can get some very complicated uh different setups nowadays, which we'll look at in just a second. And this just makes it really easy to start spinning this stuff up and trying out the different models.
So we look at cross models. Uh cross model, we have a sequential model. Sequential model is a linear stack of layers where the previous layer leads into the next layer. And this, if you've done anything else,
even like the sklearn with their neural networks and propagation and any of You should have your input layer. It goes into your layer 1, layer two, and then to the output layer. And it's useful for simple classifier decoder
models. And you can see down here we have the model equals a cross sequential. And this is the actual code. You can see how easy it is. Uh we have a layer that's dense. Your layer one has an activation. and they're using the RLU
in this particular example. And then you have your name layer one, layer dense have your name layer one, layer dense RLU, name layer 2, and so forth. Uh, and So, it's really easy just to stack them as you can see here. And it
else for you. And then there's a functional model. And this is really where things are at. This is new. Make sure you update your Kurass or you'll find yourself running this um doing the functional model. you'll run into an
error code because this is a fairly new release and it uses multi-input and multi-output model. The complex model which forks into two or more branches and you can see here we have our image inputs equals your cross input shape
equals 32x 32x3. you have your uh dense layers, dense 64 activation ru similar to what you already saw before. Uh but if you look at the graph on the right, it's going to be a lot easier to
see what's going on. You have two different inputs. Uh and one way you could think of this is maybe one of those is a small image and one of those those is a small image and one of those is a full-sized image. And that feedback
goes into you might feed both of them into one node because it's looking for one thing and then only into one node for the other one. And so you can start to get kind of an idea that there's a lot of use for this kind of split and
this kind of setup uh where you have multiple information coming in but the information's very different even though it overlaps and you don't want it to send it through the same neural network. Um, and they're finding that this trains
faster and is also has a better result depending on how you split the data up coming down. And so in here we do have the two complex uh models coming in. Uh we have our image inputs which is a 32x 32x3 or
three channels or four if you're having [snorts] an alpha channel. Uh you have your dense your layers dense is 64 activation using the RLU very common. Uh X equals dense inputs X layers dense X64 activation equals RLU X outputs equals
activation equals RLU X outputs equals layers dense 10 X model equals cross model inputs equals inputs outputs equals outputs name equals minced model. Uh so we add a little name on there. And again this is this kind of split here.
This is setting us up to um have the input go into different areas. So if probably already have this answer. What are neural networks? Uh but it's always those people who don't fully understand neural networks to dive into them a
little bit or do a quick overview. Neural networks are deep learning algorithms modeled after the human brain. They use multiple neurons which are mathematical operations to break down and solve complex math problems.
And so just like the neuron, one neuron fires in and it fires out to all these other neurons or nodes as we call them. And eventually they all come down to your output layer. And you can see here we have the really standard graph input
layer, a hidden layer and an output layer. One of the biggest parts of any data processing is your data prep-processing. Uh so we always have to touch base on that with a neural network like many of
these models. They're kind of uh when you first start using them they're like you first start using them they're like a black box. You put your data in, you train it and you test it and see how good it was and you have to pre-process
that data because bad data in is uh bad outputs. So in data prep-processing we will create our own data examples set with KAS. The data consists of a clinical trial conducted on 2100 patients ranging from ages 13 to 100
with a the patients under 65 and the other half over 65 years of age. We want to find the possibility of a patient experiencing side effects due to their age. And you can think of this in today's world with uh COVID uh what's
going to go ahead and do an example of that in our uh live hands-on. Like I said, most of this you really need to have hands-on to understand. So, let's go ahead and bring up our Anaconda and uh open that up and open up a Jupyter
notebook for doing the Python code in. Now, if you're not familiar with those, you can use pretty much any of your uh setups. I just like those for doing demos and uh showing people, especially shareholders. It really helps because
flip over to our Anaconda. And the Anaconda has a lot of cool tools. They just added data lore and IBM Watson Studio cloud into the Anaconda framework, but we'll be in the Jupyter Lab or Jupyter Notebook. Um, I'm going
to do Jupyter Notebook for this because I use the lab for like large projects with multiple pieces because it has multiple tabs where the notebook will work fine for what we're doing. And this opens up in our browser window because
that's how Jupyter Notebook Jupyter notebook [snorts] is set to run. and notebook [snorts] is set to run. and we'll go under new create a new Python 3 and uh it creates an untitled Python. We'll go ahead and give this a title and
We'll go ahead and give this a title and we'll just call this uh KAS There we go. We'll go and just rename that. And the first thing we want to go
that. And the first thing we want to go ahead and do is uh get some pre-processing tools involved. And so we need to go ahead and import some stuff for that like our numpy do some random number generation. Um I mentioned
sklearn or your site kit if you're installing sklearn the sklearn stuff installing sklearn the sklearn stuff it's a site kit you want to look up that should be a tool of anybody who is uh doing data science. If you if you're
not if you're not familiar with the sklearn toolkit, it's huge. Uh but there's so many things in there that we always go back to. And we want to go ahead and create some train labels and train samples uh for training our data.
ahead and change this. This is kind of a fun thing you can do. We can change the fun thing you can do. We can change the code to markdown. examples once you've already built this. Uh our example data we're going to do
experimental. There we go. Experimental drug was tested on 2100 individuals between 13 to 100 years of age. Half the participants 100 years of age. Half the participants under 65 and 95% of participants are
under 65 experienced no side effects. Well, 95% of participants over 65 um experience side effects. So, that's kind of where we're starting at. Um, and this is just a real quick example because we're going to do another one with a
little bit more uh complicated information. Uh, and so we want to go ahead and generate our setup. Uh, so we want to do for I and range and we want to go ahead and create, if you look here, we have random
integers, train the labels, append. So, we're just creating some random data. Uh, and let me go ahead and just run that. And so once we've created our random data and if you if I mean you can
from SimplyLearn they'll send you a copy of this or you can zoom in on the video and see how we went ahead and did our train samples append u and we're just using this I do this kind of stuff all the time. I was
running a thing on uh that had to do with errors following a bellshaped curve on uh a standard distribution error. And so what do I do? I generate the data on a standard distribution error to see what it looks like and how my code
processes it since that was the baseline I was looking for in this we're just doing uh uh generating random data for our setup on here our setup on here and uh we could actually go in uh print
print um we'll do train um we'll do train samples and we'll just do the first um five pieces data in there to see what that looks like. And you can see the
first five pieces of data in our train samples is 49, 85, 41, 68, 19. Just That's all that is. Uh, and we generated significantly more than that. Um, let's see, 50 up here, 1,00. Yeah. So, there's
1,00 here. 10,000 numbers we generated. And we could also, if we wanted to find that out, we could do a quick uh print the length of it.
thing. And if you're using numpy, although the length for this is just fine. And there we go. It's actually 2100 like we said in the demo setup in 2100 like we said in the demo setup in there.
our labels. Oh, that was our train labels. We also did samples, didn't we? labels. We also did samples, didn't we? Uh, so we could also print do the same Uh, so we could also print do the same thing.
labels. Um, and let's change this to Um, and let's change this to labels
sure enough, we have 2100. And they're labeled 1 0 1 0 1 0. I guess that's if they have symptoms or not. One symptoms uh zero none. And so we want to go ahead and take our train labels and we'll convert it into a numpy array. And the
same thing with our samples. And let's go ahead and run that. And we also shuffle. Uh this is just a neat feature you can do in uh numpy array here. Put my drawing thing on which I didn't have on earlier. Um I can take the data and I
can shuffle it. Uh so we have our so it's it just randomizes it. That's all um we've already randomized it so it's kind of an overkill. It's not really kind of an overkill. It's not really necessary,
where the data is coming in and a lot of times it's organized somehow and you want to randomize it just to make sure that that you know the input doesn't that that you know the input doesn't follow a certain pattern uh that might
create a bias in your model. And we go ahead and create a scaler. Uh the scaler range uh minimum max scaler feature range 0ero to one. Uh then we go ahead and scale the uh scaled train samples. We're going to go ahead and fit and
transform the data uh so it's nice and scaled. And that is the age. Uh so you can see up here we have 49 85 41. We're just moving that so it's going to be uh between zero and one. And so this is true with any of your neural networks.
you really want to convert the data uh to zero and one otherwise you create a bias. Uh so if you have like a 100 creates a bias versus the math behind it gets really complicated. Uh if you actually start
multiplication addition going on in there that higherend value will eventually multiply down and it will have a huge bias as to how the model fits it and then it will not fit as well. And then one of the fun things we
can do in Jupyter notebook is that if you have a variable and you're not doing anything with it and it's the last one on the line, it will automatically print um and we're just going to look at the first five samples on here. And so it's
going to print the first five samples. And you can see here we go uh 91 95 791. So everything's between zero and one. And that just shows us that we scaled it
properly and it looks good. Uh, it really helps a lot to do these kind of printups halfway through. Uh, you never know what's going to go on there. I don't know how many times I've gotten down and found out that the data sent to
me that I thought was scaled was not and then I have to go back and track it down then I have to go back and track it down and figure it out on there. Uh, so let's go ahead and create our artificial neural network. And for doing
that, this is where we start diving into TensorFlow and KAS. Uh TensorFlow, if you don't know the history of TensorFlow, it helps to uh jump into we'll just use
Wikipedia. Careful, don't quote Wikipedia on these things because you get in trouble. Uh but it's a good place to start. Uh back in 2011, Google brain built disbelief as a proprietary machine learning setup.
TensorFlow became the open source for it. Uh so TensorFlow was a Google it. Uh so TensorFlow was a Google product and then it became uh open- sourced and now it's just become probably one of the de factos when it
comes for neural networks as far as where we're at. Uh so when you see the TensorFlow setup, it it's got like a huge following. There are some other setups like a um the sidekit under the sklearn has their own
little neural network. uh but the TensorFlow is the most robust one out there right now and KAS sitting on top of it makes it a very powerful tool so we can leverage both the KAS uh easiness in which we can build a sequential setup
on top of TensorFlow. And so in here we're going to go ahead and do our input of TensorFlow. Uh and then we have the rest of this is Uh and then we have the rest of this is all KAS here from number two down. Uh
we're going to import from TensorFlow the cross uh connection. And then you have your TensorFlow cross models import sequential. It's a specific kind of model. We'll look at that in just a second. If you remember from the files,
next layer to the next layer. There's no funky splits or anything like that. Uh layers. We're going to import our activation and our dense layer.
activation and our dense layer. And we have our optimizer, Adam. Um, this is a big thing to be aware of how you optimize uh your data. When you first do it, Adam's as good as any. Atom is usually uh there's a number of
optimizer out there. There's about uh there's a couple main ones, but atom is there's a couple main ones, but atom is usually assigned to bigger data. Uh it it just fine, but atom is probably the mostly used, but there are some more out
doing with your layers, your different layers might have different activations on them. And then finally down here, you'll see um our setup where we want to go ahead and use the metrics. And we're going to use the TensorFlow cross
metrics um for categorical cross entropy. Uh so we can see how everything performs when we're done. That's all that is. Um, a lot of times you'll see us go back and forth between TensorFlow and then Scikit has a lot of really good
metrics also for measuring these things. Um, again it's the end of the, you know, your model do? And we'll go ahead and load all that. And then comes the fun part. Um, I actually like to spend hours messing with these things.
You're like, "Ah, you're going to spend hours on four lines of code." Um, no, we That's not what we're talking about when I say spend hours on four lines of code. Uh, what we have here, I'm going to explain that in just a second. We have a
you remember correctly, we mentioned the sequential up here where it goes from one layer to the next. And our first layer is going to be your input.
It's going to be uh what they call dense, which is u usually it's just dense. And then you have your input and your activation. Um, how many units are coming in? We have 16. Uh, what's the shape? What's the activation? And this
is where it gets interesting. Uh, because we have in here, uh, ReLU on two of these and softmax activation on one of these. There are so many
on one of these. There are so many different options for what these mean um, and how they function. How does the ReLU, how does the softmax function? and they do a lot of different things. Um, we're not going to go into the
activations in here. That is what really you spend hours doing is looking at these different activations. Um, and just some of it is just um almost like you're playing with it like an artist. You start getting a fill for
like a uh inverse tangent activation or the tanh activation takes up a huge processing amount. Uh so you don't see it a lot yet it comes up
with a better solution especially when you're doing uh when you're analyzing word documents and you're tokenizing the words and so you'll see this shift from one to the other because you're both trying to build a better model and if
you're working on a huge data set um you'll crash the system it'll just take too long to process u and then you see things like softmax uh softmax X
things like softmax uh softmax X generates an interesting um setup where a lot of these when you talk about RLU it oops let me do this uh RLU there we go RLU has um a setup where if it's less than zero it's zero and then it goes up
um and then you might have what they call lazy uh setup where it has a slight negative to it so that the errors can translate better. Same thing with softmax. It has a slight laziness to it so that errors translate better. All
these little details make a huge different on your model. Um, so one of the really cool things about data science that I like is you build your uh what they call you build to fail. And it's an interesting uh design
fail. And it's an interesting uh design setup. Oops, I forgot the end of my code here. The concept of build a fail is you want the model as a whole to work. So you can test your model out.
test your model out. So what you can do uh you can get to the end and you can do your let's see where was it overshot down here. You can test your test out the quality of your setup on there and
here we go. I did it was right above me. There we go. we start doing your cross entropy and stuff like that is you need a full functional set of code so that when you run it, you can then test your model out and
say, "Hey, it's either this model works better than this model and this is why." Um, and then you can start swapping in these models. And so when I say spend a huge amount of time on pre-processing data, it's probably 80% of your
programming time. Um, well between those two, it's like 8020. You'll spend a lot of time on the models. Once you get the model down, once you get the whole code and the flow down, uh, set depending on your data, your models get more and more
robust as you start experimenting with different inputs, different data streams and all kinds of things. And we can do a simple model summary here. Uh, here's our sequential, here's our layer, our output, a parameter.
This is one of the nice things about KAS is you just, you can see right here, boom, boom, boom. everything set and clear and easy to read. So once we have our model built, uh the next thing we're going to want to do is we want to go
going to want to do is we want to go ahead and uh train that model. And so the next step is of course model training. And when we come in here, this a lot of times it's just paired with the model because it's so straightforward.
model because it's so straightforward. It's nice to print out the model setup so you can have a tracking. But here's our model. Uh the keyword in Kass is compile optimizer atom learning rate. Another
term right there that we're just skipping right over that really becomes skipping right over that really becomes the meat of uh the setup is your that I had an arrow, but I'll just underline it.
A lot of times the learning rate set to 0.0 uh set to 0.01 01. Uh depending on what you're doing, this learning rate um can overfit and underfit. Uh so you'd
of tutorials out on overfitting and underfitting that are really worth reading once you get to that point and understanding. And we have our loss um sparse categorical cross entropy. So this is going to tell KAS how far to go
until it stops. And then we're looking for metrics of accuracy. So we'll go ahead and run that. And now that we've compiled our model, we want to go ahead and um run it, fit it. So here's our model fit. Um we have our scaled to
train samples, our train labels, our validation split. Um in this case, we're going to use 10% of the data for validation. Uh batch size, another number you kind of play with. Not a huge difference as
far as how it works, but it does affect how long it takes to run and it can also affect the bias a little bit. Uh most of the time though, a batch size is between 10 to 100 um depending on just how much data you're processing in there. We want
to go ahead and shuffle it. Uh we're going to go through 30 epics and uh put a verbose of two. Let me just go ahead and run this. And you can see right here, here's our epic. Here's our training. Um here's our loss. Now, if
you remember correctly up here, we set the loss. See, where was it? Um, compiled our data. There we go. Loss. Uh, so it's looking at the sparse categorical cross entropy. This tells us that as it goes, how how
This tells us that as it goes, how how how much um how how much does the um error go down? Uh is the best way to look at that. And you can see here, the lower the number, the better. It just keeps going down. And vice versa.
Accuracy. Do we want let's see where's my accuracy can see 619 69.74 it's going up. We want the accuracy
would be ideal if it made it all the way to one. But we also the loss is more to one. But we also the loss is more important because it's a balance. Um you can have 100% accuracy and your model doesn't work because it's overfitted.
Uh again, you want to look up overfitting and underfitting models. And we went ahead and went through uh 30 epics. It's always fun to kind of watch epics. It's always fun to kind of watch your code going. Um to be honest, I
usually uh uh the first time I run it, I'm like, "Oh, that's cool. I get to see what it does." And after the second time of running it, I'm like, "I like to just not see that." And you can repress those, of course, in your code. Uh
those, of course, in your code. Uh repress the warnings in the printing. And so the next step is going to be building a test set and predicting it. Now, uh so here we go. We want to go ahead and build our test set. And we
have uh just like we did our training set. A lot of times you just split your your initial setup. Uh but we'll go ahead and do a separate set on here. And this is just what we did above. Uh there's no
just what we did above. Uh there's no difference as far as um the randomness that we're using to build this set on here. Uh the only difference is that we already uh did our scaler up here.
data is going to be across the same thing, but this should just be just transform down here instead of fit transform. Uh because you don't want to transform. Uh because you don't want to refit your data um on your testing data.
transforming it because you never want to transform the test data. um easy mistake to make especially on an example like this where we're not doing um you know we're randomizing the data anyway so it doesn't matter too much because
so it doesn't matter too much because we're not expecting something weird predictions. The whole reason we built the model is we take our model, we predict, and we're going to do here's our Xcale data batch size 10 verbose.
And now we have our predictions in here. And we could go ahead and do a um oh, And we could go ahead and do a um oh, we'll print
predictions and five. So we can look at the first five of the predictions. And what we have here is we have our age and uh the prediction on this age versus
what what we think is going to are going to have uh symptoms or not. And the hard to read because we really want a yes no answer. Uh so we'll go ahead and
just uh round off the predictions using the argax um the numpy argax uh for predictions. So it just goes to 01. And if you remember this is a Jupyter
notebook. So I don't have to put the print. I can just put in uh rounded predictions. And we'll just do the first five. And you can see here 0 1 0 0. So that's what the predictions are that we have coming out of this um is no
symptoms, symptoms, no symptoms, symptoms, no symptoms. And just as uh we were talking about at the beginning, we want to go ahead and um take a look at this. There we go. [snorts] Confusion matrixes for accuracy check. uh most
important part when you get down to the end of the story how accurate is your model and see if you can get a better accuracy out of it and for this we'll go ahead and use the scikit u the sklearn metrics uh scikit being where that comes
metrics uh scikit being where that comes from import confusion matrix uh some iteration tools and of course a nice map plot library that makes a big difference so it's always nice to um have a nice graph to look at. Um picture
is worth a thousand words. Um and then we'll go ahead and do call it CM for confusion matrix. Y true equals test labels Y predict rounded predictions. And we'll go ahead and load in our CM.
And I'm not going to spend too much time on the plotting um going over the different plotting code. Uh you can spend uh like whole we have whole tutorials on how to do your different plotting on there. Uh but we do have
here is we're going to do a plot confusion matrix. There's our CM our classes normalized false title confusion matrix. Cap is going to be in blues. And you can see here we have uh to the nearest cap titles all the different
pieces whether you put tick marks or not the marks the classes the color bar. Um here as far as how we're doing the printing of the of the confusion matrix. You can also just dump the confusion matrix um into a seaborn and real quick
get an output. It's worth knowing how to do all this uh when you're doing a presentation to the shareholders. You don't want to do this on the fly. You really nice uh like our guys in the back did. And uh let's go ahead and do this.
Forgot to put together our CM plot labels. We'll go ahead and run that. And then we'll go ahead and call the little the definition little the definition for our mapping.
matrix. That's our the the little script we just wrote. And we're going to dump our data into it. Um so our confusion matrix our classes um title confusion that and you can see here we have our basic
and you can see here we have our basic setup uh no side effects 195 had side setup uh no side effects 195 had side effects uh 200 no side effects that had side effects so we predicted that 10 of them who actually had side effects and
that's pretty good. But I mean I I don't know about you, but you know that's 5% there's 200 here. That's where I get 5% is uh divide these both by by two and you get five out of 100. Uh you can do the same kind of math up here. Not as
quick on the fly because it's 15 and 195. not an easily rounded number, but you can see here where they have 15 people who predicted to have no uh with the no side effects but had side effects kind of set up on there. And these
confusion matrix are so important at the end of the day. This is really where where you show uh whatever you're working on comes up and you can actually show them, hey, this is how good we are or not, how messed up it is.
So this was a uh I spent a lot of time on some of the parts. Uh but you can see here is really simple. Uh we did the random generation of data but when we actually built the model coming up here uh here's our model summary
and we just have a the layers on here that we built with our model on this and ran the prediction. Now we can get a lot over here because we're going to do another uh demo. So that was our basic
introduction to it. We talked about the uh oops here we go. Okay. So implementing a neural network with KASS. After creating our samples and labels, model. We will be working with a sequential model which has three layers.
input layer, our hidden layers, and our output layers. And you can see the input layer uh coming in uh was the age factor. We had our hidden layer and then we had the output. Are you going to have symptoms or not? So, we're going to go
ahead and go with something a little bit more complicated. Um, training our model is a two-step process. We first compile our model and then we train it in our training data set. Uh, so we have compiling. Compiling converts the code
into a form of understandable by machine. We use the atom in the last example, a gradient descent algorithm to optimize a model. And then we trained our model, which means it let it uh learn on training data. Uh,
there, but this is what we just did is we, if you remember from our code we we, if you remember from our code we just had, oops, let me go back here. Um, here's our model that we created summarized. Uh, we come down here and we
compile it. So, it tells it, hey, we're ready to build this model and use it. Uh, and then we train it. This is the part where we go ahead and fit our model and it goes through the training on there and of course we scaled the data
which was really important to do and then you saw we did the creating a confusion matrix with KAS um as we are performing classifications on our data we need a confusion matrix to check the results a confusion matrix breaks down
the various misclassifications as well as correct classifications to get the um and so you can see here this is what we did with a true positive false positive true negative false negative And that is what we went over. Let me
just scroll down here on the end when we printed it out. And you can see we have a nice print out of our confusion matrix uh with the true positive, false positive, false negative, true negative. And so the blue
ones uh we want those to be the biggest numbers because those are the better side. And then uh we have our false predictions on here uh as far as this one. So, it had no side effects, but we predicted, let's see, no side effects,
predicting side effects, and vice versa. &gt;&gt; If getting your learning started is half the battle, what if you could do that for free? [music] Visit Skill Up by SimplyLearn. Click on the link in the description to know more. [music]
&gt;&gt; Now, uh, saving and loading models with KAS. We're going to dive into a more complicated demo. Um, and you're gonna say, "Oh, that was a lot of complication before." Well, if you broke it down, we randomized some data. We created the um
KAS setup. We compiled it. We trained it. We predicted, and we ran our matrix. something a lot a little bit more fun is we're going to do a face mask detection with KAS. Uh so, we're going to build a KASS model to check if a person is
wearing a mask or not in real time. And this might be important if you're at the front of a store. This is something today which is um might be very useful as far as some of our you know making sure people are safe. Uh and so we're
going to look at mask and no mask. And let's start with a little bit on the data. And so in my data I have with a mask. You can see they just have a number of images showing the people in masks. And
again, if you want some of this information, uh, contact SimplyLearn and information as far as people with and without masks so you can try it on your own. And this is just such a wonderful example of this setup on here. So before
I dive into the mask detection, uh, talking about being in the current with COVID and seeing if people are wearing masks, this particular example I had to masks, this particular example I had to go ahead and update to a Python 3.8 8
version. Uh it might run in a 37. I'm not sure. I haven't I kind of skipped 37 and installed 38. Uh so I'll be running in a 3 Python 38. Um and then you also want to make sure your TensorFlow is up to date because the um they call
functional uh layers. That's where they split. If you remember correctly from back uh oh let's take a look at this. Remember from here the functional model and a functional layer allows us to feed in
know different nodes into different layers and split them. Uh very powerful tool very popular right now in the edge of where things are with neural networks and creating a better model. So I've upgraded to Python 3.8 8. And let's go
upgraded to Python 3.8 8. And let's go ahead and open that up and go through uh our next example, which includes uh multiple layers, um programming it to recognize whether someone wears a mask or not, and then uh saving that model so
we can use it in real time. So, we're actually almost a full um end toend course, this is a very simplified version and there'd be a lot more to it. recognizing whether it's someone's face or not. All kinds of other things go
into this. So, let's go ahead and jump into that code and we'll open up a new into that code and we'll open up a new Python 3. Oops. Python 3. It's working Python 3. Oops. Python 3. It's working on it. There we go. Um, and then we want
to go ahead and train our mask. We'll just call this train mask. And we want to go ahead and train mask and save it. Uh, so it's it's uh it's
and save it. Uh, so it's it's uh it's save mask train mask detection, not to be confused with masking data. A little bit different. We're actually talking bit different. We're actually talking about a physical mask on your face.
And then from the cross standpoint, we got a lot of imports to do here. And I'm not going to dig too deep on the imports. Uh, we're just going to go ahead and notice a few of them. Uh, so we have in here, oops, let me go alt D.
There we go. Have something to draw with a little bit here. We have our uh image processing. And the image processing right here, me underline that. Uh, deals with how do we bring images in? Because most images are
bring images in? Because most images are like a a square grid and then each value in there has three values for the three different colors. uh KAS and TensorFlow do a really good job of uh working with that so you don't have to do all the
heavy listening and figuring out what's going to go wrong. Uh and we have the mobile net average pooling 2D. Um this again is how do we deal with the images and pulling them? Uh dropout's a cool thing worth looking up if you haven't
when as you get more and more into KAS and TensorFlow uh it'll auto drop out certain nodes. That way you'll get a better um the notes just kind of die. Uh they find that they actually create more of a bias than a help and they also add
processing time. So they remove them. Um and then we have our flatten. That's where you take that huge array with the three different colors and you find a way to flatten it so it's just a one-dimensional array instead of a 2x
two by3. Uh dense input. We did that in the other one. So that should look a little familiar. Oops. There we go. our input um our model. Again, these are things we had on the last one. Here's our optimizer with our atom.
Um we have some pre-processing on the input that goes along with bringing in the data in. Uh more pre-processing with image to array, loading the image. Um lot of work. You have to import all
these different modules in here, but the truth is is it does everything for you. pre-processing. You're letting the software do the pre-processing. Um, and we're going to be working with the setting something to categorical.
Again, that's just a conversion from a number to a category. Uh, 01 doesn't really mean anything. It's like true false. Um, label binarizer. The same thing. Uh, we're changing our labels around. And then there's our train test
around. And then there's our train test split classification report. um our IM utilities. Let me just go ahead and scroll down here a notch for these. This is something a little different going on down here. This is not part of the uh
TensorFlow or the sklearn. This is the site kit setup in TensorFlow above. Uh site kit setup in TensorFlow above. Uh the path this is part of um Open CV and going out with the Open CV. So, if you want to know more about OpenCV, you'll
get a glance on it in uh this software, especially the ne the second piece when we reload up the data and hook it up to a video camera. We're going to do that on this round. Um, but this is part of the open CV thing. And you'll see CV2 is
usually how that's referenced. Um, but the IM utilities has to do with how do you rotate pictures around and stuff like that, uh, and resize them. And then because it's nice to have a graph tells us how good we're doing. And then of
course our numpy numbers array and just a straight OS access. Wow. So that was a lot of imports. Uh like I said, I'm not going to spend I spent a little time going through them. Uh but we didn't want to go too much into them.
variables that we need to go ahead initialize. We have the learning rate, number of epics to train for, and the batch size. And if you remember correctly, we talked about the learning rate uh to the -4.001 01.
rate uh to the -4.001 01. Um, a lot of times it's 0.001 or 0.001. Usually it's in that um variation depending on what you're doing and how many epics and they kind of play with the epics. The epics is how many times
we're going to go through all the data. Now I have it as two. Um, the actual Now I have it as two. Um, the actual setup is for 20 and 20 works great. The reason I have it for two is it takes a long time to process. One of the
downsides of Jupiter is that Jupiter isolates it to a single kernel. So even though I'm on an 8 core processor uh with 16 dedicated threads,
only one thread is running on this no matter what. So it doesn't matter. Uh so it takes a lot longer to run even though um TensorFlow really scales up nicely. And the batch size is how many pictures do we load at once and process. Again,
play with depending on your data and what's coming in. And the last thing we directory with a data set we're going to run. Uh, and this just has images of
mass and not masks. And if we go in here, you'll see data And if we go in here, you'll see data set. Um, and then you have pictures with mass. They're just images of people with masks on their face. Uh, and then we
have the opposite. Let me go back up here. Without masks. So, it's pretty skew because they tried to format them into very similar uh setup on there. So, see some that are slightly different on here. And that's kind of important thing
to do on a lot of these data sets. Get them as close as you can to each other. And we'll we actually will run in the in this processing of images up here and the cross uh layers and importing and and dealing with images. It does such a
lot of it we don't have to do a whole lot with. Uh so you have a couple things going on there. And so uh we're now going to be this is now loading the um images. And let me see and we'll go ahead and uh create data and labels.
Here's our um uh here's the features going in which is going to be our pictures and our labels going out. And then for categories in our list remember, I just flashed that at you. It had uh uh face mask or or no face mask.
Those are the two options. And we're just going to load into that. We're labels. So, we're just create a huge array. Uh and you can see right now this could be an issue if you had more data at some point. Um, thankfully I have a a
at some point. Um, thankfully I have a a 32 gig hard drive or um RAM. Even that does you could do with a lot less of that. Probably under 16 or even 8 gigs would easily load all this stuff. Um, and there's a conversion going on in
here. I told you about how we are going to convert the size of the image so it resizes all the images. That way our data is all identical the way it comes in. And you can see here with our labels we
have without mask, without mask, without mask. Uh the other one would be with mask. Those are the two that we have going in there. Uh and then we need to change it to the one hot encoding.
And this is going to take our um um up here we had was it labels and data. Uh we want the labels uh to be categorical. So we're going to take labels and change it to categorical. And our labels then equal a categorical list. Uh we'll run
equal a categorical list. Uh we'll run that. And again, if we do uh labels and we just do the last or the first 10. Let's do the last 10 just because um minus 10 to the end. There we go. Just so we can see what the other side looks
like. We now have one. That means they have a mask. One zero one zero so on. Uh one being they have a mask and zero no mask. And if we did this in reverse,
I just realized that this might not make sense if you've never done this before. sense if you've never done this before. Let me run this. 01. Let me run this. 01. So zero is uh do they have a mask on?
Zero. Do they not have a mask on? One. So this is the same as what we saw up here without mask. One equals uh the second value is without mask. So with mass without mask uh and that's just a with any of your data processing
we can't really a zero if you have a 01 output uh it causes issues as far as training and setting it up. So we always want to use a one hot encoder if the values are not actual uh linear val or regression
values or not actual numbers if they represent a thing. And so now we need to go ahead and do our train X, test X, train Y, test Y, um train split test data. And we'll go ahead and make sure it's going to be uh
random. And we'll take 20% of it for testing and the rest for um setting it up as far as training their model. This is something that's become so cool. When they're training these set, uh they realize we can augment the data. What
does augment mean? Well, if I rotate the data around and I zoom in, I zoom out, I rotate it, um, share it a little bit, flip it horizontally,
um, fill mode as I do all these different things to the data, it, um, is able to, it's kind of like increasing the number of samples I have. Uh, so if I have all these perfect samples, what happens when we only have part of the
face or the face is tilted sideways or all those little shifts cause a problem data. So, we're going to create an augment and our image data generator um,
all kinds of cool thing. And this is worth looking up this image data generator and all the different features it has. Um, a lot of times I'll the first time through my models, I'll leave that out because I want to make sure
there's a thing we call build to fail, which is just cool to know. You build the whole process and then you start adding these different things in uh so that you can better train your model. And so we go and run this and then we're
going to load um and then we need to go ahead and you probably would have gotten an error if you hadn't put this piece in right here. Um I haven't run it myself because the guys in the back did this. Uh but we take our base model and one of
the things we want to do is we want to do a mobile net v2. Um and this what we this is a big thing right here include the top equals false. A lot of data comes in with a label on the top row. Uh so we want to make sure that that is not
the case. Uh and then the construction of the head of the model that will be placed on the top of the base model. Uh we want to go ahead and set that up.
of ignoring the warning because it has to do with the uh size of the pictures and the weights for input shape. Um so they'll it'll switch things to defaults. autoshape some of this stuff for you." You should be aware that with this kind
by moving it around and flipping it and doing all kinds of things to it. Uh so other data, it might be if you're working in a different domain.
we're going to have we have our base model. We're going to do our head model equals our base model output. Um and what we got here is we have an average pooling 2D pool size 77 head model. Um head model flatten. So we're
model. Um head model flatten. So we're flattening the data. Uh so this is all flattening the data. Uh so this is all processing and flattening the images and the pooling has to do with some of the ways it can process some of the data.
get down to the lower level and it's processing it. Um and then we have our about a dense just what you think about. And then the head model has a dropout of
And then the head model has a dropout of 0.5. Uh what we can do with a dropout? The dropout says that we're going to drop out a certain amount of nodes while training. Uh so when you actually use the model, it will use all the nodes,
but this drops certain ones out and it helps stop biases from up forming. Uh so it's really a cool feature on here. They discovered this a while back. Uh we have another dense mode and this time we're using soft max activation. Lots of
different activation options here. Softmax is a real popular one for a lot Softmax is a real popular one for a lot of things and so is the RLU and you know there's we could do a whole talk on activation formulas uh and why
what their different uses are and how they work. When you first start out you'll you'll use mostly the RLU and the softmax for a lot of them uh just basic setups. It's a good place to start. Uh and then we have our model
equals model inputs equals base model.input input outputs equals head model. So again, we're still building our model here. We'll go ahead and run And then we're going to loop over all the layers in the base model and freeze
them so they will not be updated during the first training process. Uh so for layer and base model layers, layers.trainable equals false. A lot of times when you go through your data, um you want to kind of jump in partway
through. Um I I'm not sure why in the back they did this for this particular example. Um but I do this a lot when I'm working with series and and specifically in stock data. I wanted to iterate through the first set of 30 data before
it does anything. Um I would have to look deeper to see why they froze it on this particular one. And then we're going to compile our model. Uh so compiling the model atom init layer decay um initial learning
rate over epics and we go ahead and compile. Our loss is going to be the binary cross entropy which we'll have that print out. Optimizer for opt metrics is accuracy. Same thing we had before. Not a huge jump as far as um the
before. Not a huge jump as far as um the previous code. through all this and now we need to go ahead and fit our model. Uh so train the
head of the network print info training head run. Now I skipped a little time because it you'll see the run time here is um at 80 seconds per epic takes a couple minutes for it to get through on a single
One of the things I want you to notice on here while we're while it's finishing the processing is that we have up here our augment going on. So, anytime the train X and train Y go in, there's some randomness
going on there and is jiggling it around what's going into our setup. Uh, of it's going through whatever we set for the batch values, how many we process at a time. And then we have the steps per epic uh the train x the batch size
validation data. Here's our uh test x and test y where we're sending that in. Uh and this again it's validation. One of the important things to know about of the important things to know about validation is our um when both our
training data and our test data have about the same accuracy. That's when you want to stop. That means that our model isn't biased. If you have a higher accuracy on your uh testing, you know,
higher on your actual test data, then something in there is probably uh has a bias and it's overfitted. Uh so that's what this is really about right here with the validation data and validation
steps. So it looks like it's let me go ahead and see if it's done processing. Looks like we've gone ahead and gone through two epics. Again, you could run this through about 20 with this amount of
data and it would give you a nice refined uh model at the end. We're going want to sit around all afternoon and I'm running this on a single thread. So, now that we've done this, we're going to need to evaluate our model and see how
good it is. And to do that, we need to go ahead and make our predictions. Um, these are predictions on our test X to see what it thinks they're going to be. the network. And then we go ahead and go down here and we will need to uh turn
the index in because remember it's it's either zero or one. It's uh 0 one 01. So you have two outputs uh not wearing uh wearing a mask, not wearing a mask. And so we need to go ahead and take that argument at the end and change those
argument at the end and change those predictions to a zero or one coming out. Uh, and then to finish that off, we want to go ahead and let me just put this right in here and do it all in one shot. We want to show a nicely formatted
classification report so we can see what that looks like on here. And there we have it. We have our precision. Uh, it's 97% with a mask. There's our F1 score. 97% with a mask. There's our F1 score. Support without a mask 97%.
Um, so that's pretty high high uh setup on there. you know, three people are going to sneak into the store who are without a mask and that thinks they have people with a mask that's going to flag the person at the front to go, "Oh, hey,
look at this person. He might not have a mask." Um, that's if I guess it's a set up in front of a store. Um, so there there you have it. And of course, one of the other cool things about this is if someone's walking into the store and you
take multiple pictures of them. Um, you know, this is just an it would be a way of flagging and then you can take that average of those pictures and make sure they match or don't match if you're on the back end. And this is an important
step because we're going to this is just cool. I love doing this stuff. Uh, so we're going to go ahead and take our model and we're going to save it. Uh, so model save mass detector.mmodel. We're going to give it a name. Uh we're going
to save the format. Um in this case we're going to use the H5 format. And so this model we just programmed has just been saved. Uh so now I can load it up in model. Now they can use it for whatever. And then if I get more
information uh and we start working with that at some point I might want to update this model um make a better model. And this is true of so many things where I take this model and maybe I'm uh running a prediction on
uh making money for a company and as my model gets better really easy just to push that out to the actual end user. Uh and here we have a nice graph. You can see the training loss and accuracy as we go through the
epics. uh we only did the you know only shows just the one epic coming in here but you can see right here as the uh uh value loss train accuracy and value accuracy starts switching and they start
converging and you'll hear converging this is the convergence they're talking about when they say you're you're um I know when I work in the um scikit with sklearn neural networks this is what they're talking about a convergence is
our loss and our accuracy come together and also up here. And this is why I'd run it more than just two epics. As you can see, they still haven't converged all the way. Uh so that would be a cue for me to keep going.
But what we want to do is we want to go ahead and create a new Python 3 program. [snorts] And we just did our train mask. So now we're going to go ahead and import that and use it and show you in a live
and use it and show you in a live action. uh get a view of uh both myself in the afternoon along with my background of an office which is in the middle still of reconstruction for another month.
um a few items coming in. Uh we have our um mobile net v2 import pre-processing input because we're still going to need that. Um we still have our TensorFlow image to array. We have our load model. That's where most of the
stuff's going on. This is our CV2 or our open CV. Again, I'm not going to dig too deep into that. We're going to flash a little open CV code at you. Uh and we actually have a tutorial on that coming out. um our numpy array, our IM
out. um our numpy array, our IM utilities which is part of the open CV or CV2 setup. Uh and then we have of course time and just our operating going to go ahead and set up on here. And then we're going to create this
And then we're going to create this takes just a moment the heavy lifting. Uh so we're going to detect and predict a mask. We have frame
facet masknet. These are going to be generated by our open CV. We have our frame coming in and then we want to go ahead and and create a mask around the face. It's going to try to detect the face and then set that
up so we know what we're going to be processing through our model. Um and then there's a frame shape here. This is just our height versus width.
That's all HW stands for. Um, they've called it blob, which is a CV2DNN blob form image frame. So, this is reformatting this frame that's going to be coming in literally from my camera. And we'll show you that in a minute.
That little piece of code that shoots that in here. Uh, and we're going to pass the blob through the network and obtain the face detections. Uh so facet set import blob detections facenet forward print detections shape.
Uh so these is this is what's going on here. This is that model we just there and I'll show you in a second where that is, but it's going to be Uh and then we go ahead and initialize our list of faces, their corresponding
locations, and the list of predictions from our face mask network. We're going to loop over the detections. And this is a little bit more work than different faces. What happens if you have a fa a crowd of faces? Um so we're
looping through the detections and the shapes going through here and probability associated with the detection. Uh here's our confidence of detections. We're going to filter out weak detection
by ensuring the confidence is greater than the minimum confidence. Uh so we've set it remember 0ero to one so 0.5 would be our minimum confidence probably is pretty good. Um and then we're going to put in compute bounding
through this it's because we're going to do an open CV and I really want to stick to just the kass part. And so I'm I'm just kind of jumping through all this code. You can get a copy of this code from simply learn and
take it apart or look for the open CV coming out and we'll create a box. Uh the box sets it around the image. Ensure the bounding boxes fall within dimensions of the frame. Uh so we create
a box around what's going what we hope is going to be the face. Extract the face ROI. Convert it from BGR to RGB channel. Again, this is an open CV issue. not really an issue, but it has to do with
times I've forgotten to check the order colors when working with Open CV causes all kinds of fun things when red becomes blue and blue becomes red. Uh, then we're going to go ahead and resize it, process it, frame it. Uh, face frame
setup again. The face, the CVT color, we're going to convert it. Uh, we're we're going to convert it. Uh, we're going to resize it image to array. Pre-process the input. uh pin the face, locate face, start X, start Y and X.
Boy, that was just a huge amount and I skipped over a ton of it. But the bottom line is we're building a box around the face and that box because the Open CV does a decent job of finding the face and that box is going to go in there and
see, hey, does this person have a mask on it? Uh, and so that's what that's what all this is doing on here. And then finally we get down to this where it says predictions equals massnet.predict faces
batch size 32. Uh so these different images are where we're guessing where the face is are then going to go through and generate an array of faces if you will and we're going to look through and say does this face have a mask on it?
And that's what's going right here is our prediction. That's the big thing that we're working for. And then we return the locations and the predictions. The location just tells where on the picture it is and then the
um prediction tells us what it is. Is it a mask or is it not a mask? All right. So, we've loaded that all up. So, we're going to load our serialized face detector model from disk. Um and we have our the path that it was saved in.
different path depending on where you have it or however you want to do it and how you saved it on the last one where we trained it. Uh and then we have our weights path. Um, and so finally our facet here it is equals cb2.dnn
readadnet uh prototext path weights path. And we're going to load that up on here. So let me go ahead and run that. it right down here. I always hate separating these things in there. Um,
mass detector model from disk. This is the the model that we saved. So let's go this is pulling in all the different pieces we need for our model. And then
the next part is we're going to create open up our video. Uh, and this is just kind of fun because it's all part of the Open CV video setup. And let me just put this all in as one. There we go. Uh, so we're
We're going to start it and we're going to run it until we're done. And this is where we get some real like kind of liveaction stuff which is fun. This is what I like working about with images and videos is that when you start
working with images and videos, it's all like right there in front of you. It's visual and you can see what's going on. Uh so we're going to start our video streaming. This is grabbing our video stream source zero start. Uh that means
it's c grabbing my main camera I have hooked up. Um and then you know starting video you're going to print it out. Here's our video source equals zero start. Loop over the frames from the video stream.
Oops, a little redundancy there. Um, let me close. it in the code. So, uh, so while true, we're going to grab the frame from the
threaded video stream and resize it to have the maximum width of 400 pixels. So, here's our frame. We're going to read it, uh, from our visual, uh, read it, uh, from our visual, uh, stream. We're going to resize it.
remember we returned from the our procedure the location and the prediction. So detect and predict mask. We're sending it the frame. We're sending it the face net and the mask
net. So we're sending all the different pieces that say this is what's going through on here. And then it returns our location and predictions. And then for our box and predictions in the location and
predictions um and the box is is again this is an open CV set that says hey this is a box coming in from the location um because you have the two different points on there and then we're going to unpack the
box and predictions and we're going to go ahead and do mask without a mask equals prediction. We're going to create our label. No mask. We're going to create color. If the label equals mask, L00225.
lot more sense when I hit the run button here. Uh, but we have the probability of label and bounding box rectangle in the output frame. Uh, and then we're going to go ahead and show the output from the frame. CV2 im show frame frame. And then
just going to wait till the next one comes through from our feed. And we're going to do this until we hit the stop button pretty much. So, are you ready for this? Let's see if it works.
We've distributed our uh our model. We've loaded it up into our distributed uh code here. We've got it hooked into our camera, and we're going to go ahead and run it. And there it goes. It's going to be running. And we can see the
data coming down here. And we're waiting for the popup. And there I am in my office with my funky headset on. Uh, and you can see in
the background my unfinished wall. And it says up here, no mask. Oh no, I don't have a mask on. Uh, I wonder if I cover my mouth. What would happen? Uh, you can see my no mask goes down a little bit. I wish I brought
a mask into my office. It's up at the house. But you can see here that this says, you know, there's a 95 98% chance that I don't have a mask on. And it's true. I don't have a mask on right now. And this could be distributed. This is
script that you could start, you know, mute install somewhere on a a video feed on a on a security camera or something and then you'd have this really neat uh setup saying, "Hey, do you have a mask on when you enter a store or a public
transportation or whatever it is where they're required to wear a mask?" Uh, let me go ahead and stop that. Now, if you want a copy of this uh code, definitely give us a hauler. We will be going into Open CV in another one. So, I
going into Open CV in another one. So, I skipped a lot of the Open CV um code in here as far as going into detail. Really focusing on the KAS uh saving the model, uploading the model, and then processing a streaming video through it. So, you
actually have this working model that hooks into the video camera, which is just pretty cool and a lot of fun. and really roll up our sleeve and do a lot of coding today. Uh we did the basic
uh demo up above for just pulling in a cross and then we went into a cross whether someone was wearing a mask or not. So very useful in today's world as far as a fully running application. Welcome to the neural network tutorial.
My name is Richard Kersner. I'm with the SimplyLearn team. What's in it for you? Well, today we're going to cover what is a neural network? What can neural networks do? How does a neural network work? Types of neural networks and then
we're going to jump into a use case to classify between the photos of dogs and cats. And we'll do that on the KAS with the TensorFlow in the back. But it's a favorite part is when we dive into the actual script. So what is a neural
know what a neural network is. Here we shopping at a red tag sale. My robots back. So as a matter of fact, you have been using neural network on a daily basis. In today's world, it's just
technology. We're not even aware of it. perform a search for you, you know, like saying your Google or Siri or whoever you use, Amazon Web, self-driving cars, so that's the newest thing coming out.
legal in different states in the US and around the world. Even in the UK, they now have self-driving cars going up and down the street. It's pretty amazing. Computer games use it. A lot of computer games are driven by neural networks in
the back end as part of the game system and how it adjusts to the players. And it's also used in processing the map images on your phone. So every time you do a navigation someplace and it opens it up, they now use neural networks to
help you find the quickest way to get there. Neural network. A neural network is a system or hardware that is designed to operate like a human brain. In today's development, this is so important to understand because we don't
have anything else to compare it to. I'm sure someday in the future, the computer will redefine or the neural network or the AI artificial intelligence will redefine what these mean. But as far as we can today's world, in today's
compare it to what humans do. So, it's we want to compare and how it operates to a human brain and how it solves problems like a human does. What can a neural network do? And really, we're just going to dive in deeper to we just
covered and look at other examples. So, what can a neural network do? Well, let's list out the things neural networks can do for you. Translate text. Boy, we got Google Translate and Microsoft has their own translate. They
have an earpiece. It's supposed to start translating as you talk. What a cool technology. What a cool time to live. Identify faces. Can you imagine all the uses for facial identification? In the case of our uh sample or our code that
identifying dogs and cats. So, not quite as detailed as uh understanding whose face belongs to who. I I'm waiting for the Google glasses to come out so I can see who's who and identify faces as I'm walking around. Have a little name tag
we are close. We can identify the faces and they have all kinds of technologies to bring that information back to us. Recognize speech goes along with the translate text. So now as you're talking into your assistant, it can use that to
do commands, turn lights on, all kinds of things you can do with recognizing speech. Read handwritten text. They're starting to translate all these old text documents that they've had in storage instead of doing it individually where
themsel in a room. You can picture like an old Raiders of the Lost Arc theme archaeologist studying the text. Now it's fed into a computer. They take a picture. They even use neural networks to take a scroll that is so messed up
that they can't undo the scroll and they X-ray it and then they use that X-ray to ever opening the scroll. I mean, just way cool stuff they're starting to do with all this. And of course, control robots. What would be in a neural
And we have our own favorite robot in and goes shopping for us. So, you know, these are just a few of the wonderful things that neural networks are being applied to. It's such an infant stage
technology. What a wonderful time to jump in. And there are a lot of other spend just forever talking about all the different applications from business to whatever you can even imagine. They're now applying neural networks to help us
little bit about all the cool things you can do with a neural network, let's dive in and say, how does a neural network work? So now we've come far enough to understand how neural network works. Let's go ahead and walk through this in
a nice graphical representation. They usually describe a neural network as having different layers. And you'll see that we've identified a green layer, an orange layer, and a red layer. The green layer is the input. So you have your
data coming in. It picks up the input signals and passes them to the next layer. The next layer does all kinds of calculations and feature extraction. times there's more than one hidden layer. We're only showing one in this uh
picture, but we'll show you how it looks like in a more detail in a little bit. And then finally, we have an output layer. This layer delivers the final result. So the only two things we see is the input layer and the output layer.
Now let's make use of this neural network and see how it works. Wonder how traffic cameras identify vehicles registration plate on the road to detect speeding vehicles and those breaking the law? They got me going through a red
That's like the horrible thing. They send you this picture of you and all off of your license plate and your picture. I shouldn't have gone through the red light. So, here we are and we have an image of a car and you can see
consider the image of this vehicle and find out what's on the number plate. The picture itself is 28x 28 pixels and the image is fed as an input to identify the
registration plate. Each neuron has a number called activation that represents the grayscale value of the corresponding pixel range. And we range it from 0ero to one. One for a white pixel and zero for a black pixel. And you can see down
here we have an example where one of the pixels is registered as like 82, meaning it's probably pretty dark. Each neuron is lit up when its activation is close to one. So as we get closer to black on white, we can really start seeing the
the pixel shows us one up there. or it's up. So pixels in the form of arrays are fed to the input layer. And so we see input and you're going to see that the input layer which is green is one
dimension while our image is two dimension. Now when we look at our setup a cool feature that automatically does the work for us. If you're working with an older neural network pattern package, you then convert each one of those rows
so it's all one array. So you'd have like row one and then just tack row two onto the end. You can almost feed the image directly into some of these neural networks. The key is though is that if you're using a 28x 28 and you get a
you're using a 28x 28 and you get a picture of this 30x30, shrink the 30x30 down to fit the 28x 28. So you can't increase the number of input in this remember when you work on neural
networks. And let's name the inputs x1, x2, x3, respectively. So each one of those represents one of the pixels coming in. And the input layer passes it here we now have two hidden layers in this image in the orange. And each one
of those pixels connects to each one of those hidden layers. And the interconnections are assigned weights at random. So they get these random weights that come through. If x1 lights up, then it's going to be x1 times this weight
those weights. The weights are multiplied with the input signal and a bias is added to all of them. So as you can see here we have X1 comes in and it hidden layer nodes or in this case uh whatever you want to call them network
setup the orange dots and so you take the value of X1 you multiply it by the weight for the next hidden layer. So X1 goes to hidden layer 1 X1 goes to hidden layer two X1 goes hidden layer 1 node two hidden layer 1 node three and so on.
And the bias a lot of times they just put the bias in as like another green dot or another orange dot and they give the bias a value one and then all the weights go in from the bias into the next node. So the bias can change. We
have that bias in there. There's things that can be done with it. Generally most of packages out there control that for you so you don't have to worry about figuring out what the bias is. But if you ever dive deep into neural networks,
the answer won't come out correctly. The weighted sum of the input is fed as an input to the activation function to decide which nodes to fire. And for feature extraction, as a signal flows within the hidden layers, the weighted
sum of inputs is calculated and is fed to the activation function in each layer to decide which nodes to fire. So here's our feature extraction of the number plate. And you can see these are still hidden nodes in the middle. And this
take a little detour here and look at the activation function. So we're going to dive just a little bit into the math so you can start to understand where playing with neural networks in your programming. So let's look at the
different activation functions before we move ahead. Here's our friendly red tag shopping robot. And so one is a sigmoid function. And the sigmoid function which function. And the sigmoid function which is 1 / 1 + e to the minus x takes the x
value and you can see where it generates almost a zero and almost a one with a very small area in the middle where it crosses over and we can use that value to feed into another function. So if it's really uncertain it might have a
0.1 or 2 or 3 but for the most part it's going to be really close to one and really close to this case zero zero to one the threshold function. So if you uncertainty in the middle, you just say, "Oh, if x is greater than or equal to
zero, if not, then x is zero." So it's either zero or one. Really straightforward. There's no in between in the middle. And then you have the what they call the reel relu function. And you can see here where it puts out
the value, but then it says, well, if it's over one, it's going to be one. And if it's less than zero, it's zero. So it kind of just deadends it on those two ends, but allows all the values in the middle. And again this like the sigmoid
function allows that information to go to the next level. So it might be important to know if it's a 0.1 or a minus.1 the next hidden layer might pick that up and say oh this piece of information is uncertain or this value
has a very low certainty to it. And then the hyperbolic tangent function. And you can see here it's 1 - e to the minus 2x over 1 + e to the minus 2x. And it's very much along the same theme, a little bit different in here in that it goes
between minus1 and 1. So you'll see some of these it goes 0 to 1, but this one goes minus1 to one. And if it's less than zero, it's, you know, it doesn't fire. And if it's over zero, it fires. And it also still puts out a value. So
of that just like you can with the sigmoid function and the relu function very similar in use and I believe the originally it used to be everything was the most uh commonly used and now they
just kind of use more the relu function the reason is one it processes faster because you already have the value and you don't have to add another compute the one over 1 plus e to the minus x for each hidden node and the data coming off
into the next level if you want to know just how close it is to zero. How close is it not to functioning? You know, is it minus.1 minus.2 usually they're float values. You get like minus point minus.00138
information, but the relu is most commonly used these days as far as the setup we're using. But you'll also see the sigmoid function very commonly used also. Now that you know what an activation function is, let's get back
model would predict the outcome of applying a suitable activation function to the output layer. So we go in here we look at this and we have the optical character recognition OCR is used on the images to convert it into a text in
plate. And as it comes out you'll see the red node and the red node might actually represent just the letter A. So there's usually a lot of outputs when not going to show that on here but you might have it even in the order. It
might be what order the license plates in. So you might have A B CDE E F G you know the alphabet plus the numbers and you might have the 1 2 3 4 5 6 7 8 9 10 places. So it's a very large array that comes out. It's not a small amount of
you know we show three dots coming in eight hidden layer nodes you know two sets of four. We just show one red coming out. A lot of times this is uh you know 28 * 28 if you did 30 * 30 that's you know 900 nodes. So 28 is a
little bit less than that uh just on the input. And so you can imagine the hidden layer is just as big. Each hidden layer is just as big if not bigger. Then the digits. Yeah, it's a lot. There's it's a huge amount of input and output. But
it' be hard to show in one picture. And so it comes up and this is what it identifies a number on the plate. And in this case we have 08-d3858.
through the network and weights are adjusted to minimize the error rate. This is calculated by a cost function when we're training our data. This is the code when we do the data training. So we have stuff we know the answer to
and then we put the information through and it says yes that was correct or no because remember we randomly set all the weights to begin with and if it's wrong you know, are you off by is it if it was like minus one, you're just a little bit
off. If it's like minus300 was your output, remember when we're looking at hyperbolic or whatever, and we're looking at the reel, the could doesn't have an limit on top or bottom. It actually just generates a number. So, if
it's way off, you have to adjust those weights a lot. But if it's pretty close, little bit. And you keep adjusting the weights until they fit all the different training models you put in. So you might have 500 training models and those
weights will adjust using the back propagation. It sends the error backward. The output is compared with the original result and multiple iterations are done to get the maximum accuracy. So not only does it look at
just keeps cycling through these the data making small changes in the network until it gets the right answers. With every iteration, the weights at every interconnection are adjusted based on the error. We're not going to dive into
equation and it gets a little complicated. But I will talk a little bit about some of the different options they have when we look at the code. So look at the different types of artificial neural networks. And this is
like the biggest area growing is how these all come together. Let's see the different types of neural network. And again, we're comparing this to human learning. So here's a human brain. I feel sorry for that poor guy. So we have
a feed for forward neural network simplest form of a they call it a ann a neural network data travels only in one direction input to output. This is what
we just looked at. So as the data comes in all the weights are added it goes to added it goes to the next hidden layer. All the weights are added and it goes to the output. The only time you use the reverse propagation is to train it. So
when you actually use it it's very fast. When you're training it, it takes a all your training data and you start getting into big data because you can The more data you put in, the better trained they get. The applications
vision and speech recognition actually they're pretty much everything we talked about. A lot of almost all of them use this form of neural network at some level. Radio basis function neural network. This model classifies a data
point based on its distance from a center point. What that means is that you might not have training data. So you want to group things together and you create central points and it looks for all the things. You know, some of these
you've ever watched the Sesame Street as a kid, that dates me. So it brings if you don't have the right training model. You can start finding things that are connected you might not have noticed before. Applications, power restoration
systems. They try to figure out what's connected and then based on that they can fix the problem. If you have a huge power system, and self-organizing neural network vectors of random dimensions are input to discrete map
comprised of neurons. So they basically find a way to draw they call them they find a way to draw they call them they say dimensions or vectors or planes one dimension, two dimension, three dimension, four, five, six. They keep
separate the data and connect different data pieces together. applications used to recognize patterns in data like in medical analysis. The hidden layer saves its output to be used for future
prediction. Recurrent neural networks. So the hidden layers remember its output from last time and that becomes part of its new input. Uh you might use that drone. You want to know what your last
help predict what your next change you drone wants to go. applications, text to speech, conversation model. So, you know, I talked about drones, but you know, just identifying on Lexus or
Google Assistant or any of these, they're starting to add in I'd like to play a song on my Pandora, and I'd like it to be at volume 90%. So, you now can connects them together. The input features are taken in batches like a
filter. This allows a network to remember an image in parts. Convolution neural network. today's world in photo identification and taking apart photos that on Google where you have five people together this is the kind of
thing separates all those people so then it can do a face recognition on each person applications used in signal and image processing in this case I use facial images or Google picture images as one of the options modular neural
network it has a collection of different neural networks working together to get the output so wow we just went through all these different types of neural networks. And the final one is to put multiple neural networks together. And I
separated people in a larger photo and individuals in the photo and then do the facial recognition on each person. So one network is used to separate them and the next network is then used to figure out who they are and do the facial
recognition. Applications still undergoing research. This is the cutting edge. You hear the term pipeline and there's actual in Python code and in almost all the different neural network setups out there they now have a
pipeline feature usually and it just means you take the data from one neural network and maybe another neural network or you put it into the next neural other neural networks and feed them into another one. So how we connect the
neural networks is really just cutting edge and it's so experimental. I mean There's not really a science to it because each specific domain has you're in the banking domain, it's going to be different than the medical domain
than the automatic car domain. And suddenly figuring out how those all fit together is just a lot of fun and really cool. So we have our types of artificial neural network. We have our feed forward neural network. We have a radial basis
function neural network. We have our cohenin self-organizing neural network, recurrent neural network, convolution neural network and modular neural network where it brings them all together and u know the colors on the
brain do not match what your brain actually does but they do bring it out that most of these were developed by understanding how humans learn and as we understand more and more of how humans learn we can build something in the
computer industry to mimic that to reflect that and that's how these were developed. So exciting part, use case problem statement. So this is where we jump in. This is my favorite part. Let's use the system to identify between a cat
said we're going to do some Python code. And you can see over here, my hair is Cup of coffee on one side and a little bit of old school. A pencil and a pen on the other side. Yeah, most people now take notes. I love the stickies on the
computer. That's great. That's That is my computer. I have sticky notes on my computer in different colors. So not too far from uh today's programmer. So the problem is is we want to classify photos of cats and dogs using a neural network.
And you can see over here we have quite a variety of dogs in the pictures and cats and you know just sorting out it is a cat is pretty amazing. And why would anybody want to even know the difference between a cat and a dog? Okay, you know
why? Well, I have a cat door. It'd be kind of fun that instead of it little collar with a magnet on it, which is what my cat has, the door would be able to see, oh, that's the cat. That's our cat coming in. Oh, that's the dog.
to let in. Maybe I don't want to let this other animal in cuz it's a raccoon. this one step further and actually apply this. You could actually start a little startup company idea, a self-identifying door. So, this use case will be
implemented on Python. I am actually in Python 3.6. It's always nice to tell that does affect sometimes which modules you load and everything. And we're going to start by importing the required packages. I told you we're going to do
this in KAS. So we're going to import from KAS models sequential from the KAS from KAS models sequential from the KAS layers conversion 2D or CO env.
these do in just a second. But before we do that, let's talk a little bit about And uh you know, in fact, let me go ahead and open a uh the website KASS's website so we can learn a little bit more about KAS. So here we are on the
more about KAS. So here we are on the KAS website and it's uh ke.io. the first thing you'll notice is that KAS runs on top of either TensorFlow Ctk
and I think it's pronounced Thano or Theano. What's important on here is that TensorFlow and the same is true for all these, but TensorFlow is probably one of the most widely used currently packages out there with the KAS. And of course,
change. It's all going to disappear and they'll have something new out there. So, make sure when you're learning this code that you understand what's going on when you look at the code, it's not as complicated once you understand what's
straightforward. And the reason we like KAS and the reason that people are jumping on it right now and it's such a big deal is if we come down here, let me just scroll down a little bit. They talk about user friendliness, modularity,
easy extensibility, work with Python. Python's a big one because a lot of people in data science now use Python, although you can actually access KAS other ways. Is if we continue down here is layers. And this is where it gets
really cool. When we're working with KAS, you just add layers on. Remember about? And we talked about the releuation. You can see right here. Let me just up that a little bit in size. There we go.
That's big. I can add in an reelu layer. And then I can add in a softmax layer in softmax. So you can do each layer separate. Now if I'm working in some of the other kits I use, I take that and I have one setup and then I feed the
output into the next one. This one I can just add hidden layer after hidden layer which makes it very powerful and very fast to spin up and try different setups and see how they work with the data
little bit deeper in here. And a lot of this is very much the same. So when we get to that part, I'll point that out to you also. Now just a quick side note, I'm using Anaconda with Python in it. And I went ahead and created my own
package and I called it the KAS Python 36 because I'm in Python 3.6. Anaconda you're doing a lot of different packages, probably want to create your own environment in there. And the first
thing, as you can see right here, there's a lot of dependencies. A lot of you've done any of these videos. If not, kudos for you for jumping in today. Pip kudos for you for jumping in today. Pip install numpy scypi the scikitlearn
pillow and h5py are both needed for the tensorflow and then putting the kas on there. And then you'll see here uh and pip is just a standard installer that you use with Python. You'll see here that we did pip
install TensorFlow since we're going to do KAS on top of TensorFlow. And then pip install and I went ahead and used the GitHub. So git plus Git. And you'll see here github.com. This is one of their releases, one of the most current
TensorFlow. And you can look up these instructions pretty much anywhere. This is for doing it on Anaconda. Certainly you'd want to install these if you're doing it in Iuntu server setup. you you want to get I don't think you need the
rest in there because they are straightforward and that's actually in some of the instructions they have on necessarily go through this just remember their website on there and then
remember their website on there and then when I'm under my uh Anaconda navigator environments and on the bottom I created a new environment and I called it cross python 36 just to separate everything you can see I have Python 3.5 and Python
36 I used to have a bunch of other ones, but it kind of cleaned house recently. And of course, once I go in here, I can launch my Jupiter notebook, making sure I'm using the right environment that I just set up. This, of course, opens up
my um in this case, I'm using uh Google Chrome. And in here, I could go and just create a new document in here. And this is all in your um browser window when you use the Anaconda. Do you have to use Anaconda and Jupyter Notebook? No. You
whatever setup you're comfortable with and whatever you're doing in there. So, let's go ahead and go in here and paste the code in. And we're importing a number of different settings in here. We have import sequential. That's under the
going to use as far as our neural network. And then we have layers and we have conversion 2D, max pooling 2D, flatten, dense. And you can actually just kind of guess at what these do. We're talking we're working in a 2D
photograph. And if you remember correctly, I talked about how the actual input layer is a single array. It's not in two dimensions. It's one dimension. All these do is these are tools to help flatten the image. So, it takes a
creates its own proper setup. You don't don't have to do anything special with the photograph. You let the carass do you'll see right here they have some stuff that is going to be depreciated
Everything's being changed as we go. You don't have to worry about that too much. second time, the warning will disappear. And this has just imported these packages for us to use. Jupiter's nice about this that you can do each thing
step by step. And I'll go ahead and also zoom in there. Little control plus. That's one of the nice things about being in a browser environment. So, here we are back. Another sip of coffee. If you're familiar with my other videos,
you notice I'm always sipping coffee. I always have a my case latte next to me, ahead and initialize. We're going to call it the CNN or classifier neural network. And the reason we call it a classifier is because it's going to
going to be cat or dog. So when you're doing classification, you're picking specific objects. You're specific. It's a true or false. Yes, no. It is something or it's not. So first thing we're going to create our classifier and
it's going to equal sequential. So their sequential setup is the classifier. That's the actual model we're using. That's the neural network. So we call it a classifier. And uh the next step is to add in our convolution. And let me just
so you can see the whole line. And let's talk a little bit about what's going on here. I have my classifier and I add something. What am I adding? Well, I'm adding my first layer. This first layer we're adding in is probably the one that
takes the most work to make sure you have it set correct. And the reason I say that is this is your actual input. And we're going to jump here to the part And we're going to jump here to the part that says input shape equals 64x 64x3.
What does that mean? Well, that means that our pictures coming in and there's these pictures. Remember we had like the picture of the car was 128x 128 pixels. Well, this one is 64x 64 pixels. And each pixel has three values. That's
where these numbers come from. And it is so important that this matches. I mentioned a little bit that if you have like a larger picture, you have to reformat it to fit this shape. If it comes in as something larger, there's no
input notes. There's no input neural network there that will handle that extra space. So, you have to reshape your data to fit in here. Now, the first layer is the most important because after that, KAS knows what your shape is
coming in here and it knows what's coming out and so that really sets the stage. Most important thing is that input shape matches your data coming in. doesn't. You'll go through there and picture number 55 doesn't match it
correctly. And guess what it does? It usually gives you an error. And then the about the different activations on here. We're using the reelu model. Like I said, that is the most commonly used now because one, it's fast. Doesn't have the
added calculations in it. It just says here's the value coming out based on the here's the value coming out based on the weights and the value going in. And um from there, you know, it's uh if it's over one, then it's good or over zero,
considered not active. And then we have this conversion 2D. What the heck is conversion 2D? I'm not going to go into too much detail in this because this has
little bit more in-depth than we're ready to cover in this tutorial. But this is used to convert from the photo because we have 64x 64x3 and we're just converting it to two-dimensional kind of setup. So it's very aware that this is a
next to each other. And then we're going to add in uh a second convolutional layer. That's what the cov stands for 2D. So it's these are hidden layers. So hidden layers and they are
with a two-dimensional photograph. And you'll see down here that on the last one, we add a max pooling 2D and we put a pool size equals 22. And so what this is is that as you get to the end of these layers, one of the things you
call mapping and then reducing. Wonderful terminology from the big data. We're mapping this data through all these layers. And now we want to reduce it to only two sets. In this case, it's already in two sets because it's a 2D
photograph. But we had, you know, two dimensions by We actually have 64x 64x3. So now we're just getting it down to a 2x two. Just the two dimension third dimension of colors. And we'll go ahead and run these. We're not really
because we're just setting up. This is playing cuz maybe you'll add a different layer in here to do something else to output is. That's what makes KAS so nice is I can with just a couple flips of
code put in a whole new layer that does a whole new processing and see whether that improves my run or makes it worse. And finally, we're going to do the final setup, which is to flatten classifier, add a flatten setup. And then we're
going to also add a layer, a dense layer, and then we're going to add in going to build it. We're going to compile this whole thing together. So, like. And we've even numbered them for you. So, we're going to do the
flattening. And flatten is exactly what it sounds like. We've been working in a actually is in three dimensions because of the pixels. The pixels have a whole another dimension to it of three different values. And we've kind of
resized those down to 2x two. But now we're just going to flatten it. I don't want to have multiple dimensions being worked on by tensor and by kas. I want just a single array. So, it's flattened out. And then step four, full
connection. So we add in our final two layers. And you could actually do all actually leave out this some of these layers and play with them. You do need to flatten it. That's very important. Then we want to use the dents. Again,
we're taking this and we're taking whatever came into it. So once we take or three dimensions as they are and we flatten it to one dimension. We want to take that and we're going to pull it into units of 128. They got that. You
could actually play with that number and get all kinds of weird results. But in get all kinds of weird results. But in this case we took the 64 + 64 is 128. You could probably even do this with 64 or 32. Usually you want to keep it in
shape you're already using is in. And we're using the activation, the reel, just like we did before. And then we finally filter all that into a single output. And it has how many units? One. Why? Because we want to know whether
true or false. It's either a dog or a cat. You could say one is dog, zero is cat. Or maybe you're a cat lover and it's one is cat and zero is dog. And if you love both dogs and cats, you're going to have to choose. And then we use
the sigmoid activation. If you remember from before, we had the reelu and there's also the sigmoid. The sigmoid just makes it clear it's yes or no. We number coming out. And we'll go ahead and run this. And you'll see it's still
all in setup. And then finally, we want to go ahead and compile. And let's put the compiling our um classifier neural network. And we're going to use the optimizer atom. And I hinted at this just a little bit before. Where does
atom come in? Where does an optimizer come in? Well, the optimizer is the reverse propagation. When we're training it, it goes all the way through and says error and then how does it readjust those weights. There are a number of
them. Atom is the most commonly used and it works best on large data. Most people testing on smaller data, see if their model is going to go through and get all larger data sets. They're going to run it on atom anyway, so they just leave it
on atom most commonly used. But there are some other ones out there. You try them if you're stuck in a bind or you might blur that in the future. But usually atom is just fine on there. And then you have two more settings. You
have loss and metrics. We're not going to dig too much into loss or metrics. explore KAS because there are so many choices. This is how it computes the error. There's so many different ways to on your back propagation and your
training. So we're using the atom model, but you can compute the error by um standard deviation. standard deviation squared. They use binary cross entropy. I'd have to look that up to even know what that is. There's so many of these.
ones that look correct that are most commonly used and then you have to go read the KAS site and actually see what these different losses and metrics and what different options they have. So, we're not going to get too much into
the Kass website to explore them deeper. But, we are going to go ahead and run them. And now we've set up our classifier. So, we have an object classifier. And if you go back up here, you'll see that we've added in step one.
We added in our layer for the input. We added a layer that comes in there and uses the reelu for activation. And then it pulls the data. So this is even neural network layer is up here. And then it uses this to pull the data into
a 2x two. So into a two-dimensional array from a threedimensional array with the colors. Then we flatten it. So there's our adder flatten. And then we add another dense what they call dense layer. this dense layer goes in there
layer. this dense layer goes in there and it it downsizes it to 128. It reduces it. So you can look at this as uh we're mapping all this data down the flatten it. So we map it to a flatten
map and then we take it and reduce it down to 128 and we use the reel again. And then finally we reduce that down to just a single output and we use a sigmoid to do that to figure out whether it's yes, no, true, false, in this case
cat or dog. And then finally once we put all these layers together we compile them. That's what we've done here and we've compiled them as far as how it trains to use these settings for the training back propagation. So if you
remember we talked about training our setup and when we go into this you'll see that we have two data sets. We have one called the training set and the testing set. And that's very standard in any data processing is you need to have
that's pretty common in any data processing is you need to have a certain got to know whether it works or not. Is it any good? And that's why you have a where you already know the answer but you don't want to use that as part of
the training set. So in here we jump into part two fitting the classifier neuron network to the images. And then from KAS and let me just zoom in there. Jupyter notebooks. So you can really see. We're going to come in here. We do
the cross pre-processing an image and we import image data generator. So nice of KAS. It's such a high-end product right now going out. And since images are so to help us process the data, which is great. And so we come in here, we do
train data gen, and we're going to create our object for helping us train for reshaping the data so that it's going to work with our setup. And we use an image data generator. and we're going to rescale it. And you'll see here we
have one point which tells us it's a float value on the rescale over 255. Where does 255 come from? Well, that's the scale in the colors of the pictures we're using. They're value from 0 to 255. So, we want to divide it by 255 and
it'll generate a number between 0 and 1. They have sheer range and zoom range. Horizontal flip equals true. And this, of course, has to do with if the photos said, it's a wonderful package. You really need to dig in deep to see all
the different options you have for setting up your images. For right now, some basic stuff here. And let me go ahead and run this code. And again, it still setting up the pre-processing. Let's take a look at this next set of
code. And this one is just huge. We're creating the training set. So the training set is going to go in here and it's going to use our train data gen we just created flow from directory. that's going to access in this case the path
data set training set that's a folder so it's going to pull all the images out of that folder now I'm actually running this in the folder that the data sets in so if you're doing the same setup and you load your data in there and you're
doing this make sure wherever your Jupyter notebook is saving things to that you create this path or you can do the complete path if you need to you know c slash etc and the target size the batch size and class mode is binary. So
the classes we're switching everything to a binary value. Batch size. What the many pictures we're going to batch through the training each time. And the target size 64x 64. A little confusing, but you can see right here that this is
in there and look at all the different settings for your training set. And of pictures. There's all kinds of different settings depending on what you're that and see what happens. And you'll see that it found 800 images belonging
to one classes. So we have 800 images in the training set. And if we're going to do this with uh the training set, we also have to format the pictures in the test set. Now we're not actually doing any predictions. We're not actually
programming the model yet. All we're doing is preparing the data. So we're going to prepare a training set and the test set. So any changes we make to the training set at this point also have to be made to the test set. So we've done
this thing. We've done a train data generator. We've done our training set. And then we also have remember our test set of data. So I'm going to do the same test data gen. And we're going to do this image data generator. We're going
to rescale one over 255. We don't need the other settings, just the single going to create our test set. We're going to do the same thing we did with the test set except that we're pulling it from the test set folder. And we'll
run that. And you'll see in our test set, we found 2,000 images. That's about right. We're using 20% of the images as test and 80% to train it. And then finally, we've set up all our data. We've set up all our layers, which is
that data, making sure it's going in there correctly. And we're actually going to fit it. We're going to train our data set. And let's see what that looks like. And here we go. Let's put the information in here. And let's just
take a quick look at what we're looking at with our fit generator. We have our classifier.fit generator. That's our back propagation. So the information goes through forward with a picture and it says, "Oh, you're either right or
you're wrong." And then the error goes backward and reprograms all those weights. So we're training our neural network. And of course, we're using the training set up here. And then we're going steps per epic. So it's [snorts]
going steps per epic. So it's [snorts] 8,000 steps. Epic means that that's how pictures. So we're going to rerun each of the pictures and we're going to go through the whole data set 25 times, but we're going to look at each picture
during each epic 8,000 times. So we're really programming the heck out of this and going back over it. And then they have validation data equals test set. So going to have our test set to validate it. So, we're going to do this all in
one shot and we're going to look at that and they're going to do 200 steps for looks like in just a minute. Let's go ahead and run our training here and we're going to fit our data. And as it goes, it says epic one of 25. You start
realizing that this is going to take a while. On my older computer, it takes about 45 minutes. I have a dual processor. You know, we're processing uh 10,000 photos. That's not a small amount of photographs to process. So, if you're
on your laptop, you know, which I am, it's going to take a while. So, let's go and a sip and come back and see what this looks like. So, I'm back. You didn't know I was gone. That was actually a lengthy pause there. I made a
couple changes. And let's discuss those changes real quick and why I made them. I'm going to go up here and insert a cell above and let's paste the original code back in there. And you'll see that the original thing was steps per epic
the original thing was steps per epic 8,000, 25 epics, and validation steps 2,000. And I changed these to 4,000 epics or 4,000 steps per epic, 10 epics, and just 10 validation steps. And this will cause problems if you're doing this
as a commercial release, but for demo purposes, this should work. And if you remember our steps per epic, that's how many photos we're going to process. In fact, let me go ahead and get my drawing pen out and uh let's just highlight that
right here. Well, we have 8,000 pictures we're going through. So, for each epic, going to cut that in half. So, it's going to randomly pick 4,000 pictures each time it goes through an epic. And the epic is how many processes. So, this
is 25. And I'm just going to cut that to 10. So, instead of doing 25 runs through 8,000 photos each, which you can do the math of 25 * 8,000, I'm only going to do 10 through 4,000. So, I'm going to run this 40,000 times through the processes.
And the next thing I not you'll you'll want to notice is that I also changed the validation step. And this would cause some major problems in releasing cuz I dropped it all the way down to 10. What the validation step does is it says
we have 2,000 photos in our trainings or in our testing set and we're going to use that for validation. Well, I'm only going to use a random 10 of those to validate. So, not really the best settings, but let me show you why we did
that. Let's scroll down here just a little bit and let's look at the output here and see what that what's going on there. So, I've got my drawing tool back on and you'll see here it lists a run. So, each time it goes through an epic,
it's going to do 4,000 steps. And this is where the 4,000 comes in. So, that's what we have. We have epic one of 10 4,000 steps. So, it's randomly picking through them. And then we're going to look at this number right here. That is
for the whole epic. And that's 2,411 seconds. And if you remember correctly, you divide that by 60, you get minutes. If you divide that by 60, you get hours. Or you can just divide the whole thing by 60 * 60, which is 3600. If 3600 is an
hour, this is roughly 45 minutes right here. And that's 45 minutes to process half the pictures. So if I was doing all the pictures, we're talking an hour and the pictures, we're talking an hour and a half per epic times 36 or no, 25. They
had 25 up above. 25. So that's roughly a couple days, a couple days of don't want to do that. I don't want to come back the next day. Plus, my computer did a reboot in the middle of the night. So, we look at this and we
this out. My computer that I'm running this on is a dual core processor. Uh, this on is a dual core processor. Uh, runs 0.9 GHz per second. For a laptop, but for running something like this, it's probably a little slow. So, we cut
the times down. And the last one was validation. We're only validating it on a random 10 photos. And this comes into effect because you're going to see down effect because you're going to see down here where we have accuracy, value loss,
value, accuracy, and loss. Those are very important numbers to look at. So the 10 means I'm only validating across 10 pictures. That is where here we have value. This is ACC is for accuracy. Value loss. We're not going to worry
about that too much. And accuracy. Now accuracy is while it's running, it's putting these two numbers together. That's what accuracy is. And value accuracy is at the end of the epic. What's our accuracy into the epic? What
we're not going to go so deep, but these numbers are really important when you start talking about these two numbers reflect bias. That is really important. We just put that up there. And bias is a little bit beyond this tutorial. But the
short of it is is if this accuracy, which is being our validation per step is going down and the value accuracy continues to go up, that means there's a bias. That means I'm memorizing the photos I'm looking at. I'm not actually
looking for what makes a dog a dog, what makes a cat a cat. I'm just memorizing them. And so the more this discrepancy grows, the bigger the bias is. And that grows, the bigger the bias is. And that is really the beauty of the KAS neural
features like this that make that really easy to track. So let's go ahead and take a look at the next set of code. So here we are into part three. We're going going to bring in a couple tools for that. And then we have to process the
image coming in and find out whether it's an actual dog or cat if we can actually use this to identify it. And of course the final step of part three is combine these. And of course, you can see me there adding more sticky notes to
my computer screen hidden behind the screen. And you know, last one was don't forget to feed the cat and the dog. So, let's go ahead and take a look at code and put that in our Jupyter notebook. All right. And let's paste
that in here. And we'll start by importing numpy as np. Numpy is a very common package. I pretty much import it on any Python project I'm working on. Another one I use regularly is pandas. They're just ways of organizing the
data. And then NP is usually the standard in most machine learning tools as a return for the data array. Although you know you use a standard data array from Python and we have cross pre-processing import image. This should
take a test image and we're going to set that equal to in this case cat or dog know what? Let me get my drawing tool back on. So let's take a look at this. We have our test image we're loading and in here we have test image one and this
all. So this is all new. Oh, let me shrink the screen down. Let me start that over. So here we have my test image and we went ahead and the cross processing has this nice image setup. So we're going to load the image and we're
we're going to load the image and we're going to alter it to a 64x 64 print. So is nice that way. It automatically sets it up for us so we don't have to redo all our images and find a way to reset those. And then we use also to set the
image to an array. So again, we're all in pre-processing the data just like we pre-processed before with our test information and our training data. And then we use the numpy. Here's our numpy that's uh from our u right up here.
Import numpy as in p expand the dimensions test image axis equal zero. So it puts it into a single array. And then finally all that work all that pre-processing and all we do is we run the result. We click on here and we go
result equals classifier predict test image. And then we find out, well, what quick look and just see what that is. And you can see when I ran it, it comes up dog. And if we look at those images, there it is. Cat or dog image number
one. That looks like a nice floppy eared lab, friendly with his tongue hanging out. It's either that or a very floppy eared cat. I'm not sure which, but a dog. And uh we have a second picture over here. Let's just see what happens
when we run the second picture. We can go up here and change this uh from dog image one to two. We'll run that and it comes down here and says cat. You can see me highlighting it down there as cat. So, our process works. We are able
to label a dog a dog and a cat a cat just from the pictures. There we go. Cleared my drawing tool. And the last thing I want you to notice when we come back up here to when I ran it, you'll see it has an accuracy of one and the
value accuracy of one. Well, the value accuracy is the important one because the value accuracy is what it actually runs on the test data. Remember, I'm only testing it on I'm only validating it on a random 10 photos and those 10
photos just happened to come up one. Now, when they ran this on the server, it actually came up about 86%. This is why cutting these numbers down so far want to make sure you're a little careful of that when you're testing your
when you run it on a more enterprise computer other than your old laptop that with. And we come down here and again, you know, we had the validation of cat. neural network that could distinguish between photos of a cat and a dog.
distinguish. Imagine all the different industries you could dive into with those two different pictures. What about mosquitoes? Could you find the mosquitoes that are friendly? It turns out the mosquitoes that bite us are only
4% of the mosquito population, if even that, maybe 2%. There's all kinds of industries that use this. And there's so many industries that are just now realizing how powerful these tools are. Just in the photos alone, there is a
myriad of industries sprouting up. And I said it before, I'll say it again. What an exciting time to live in with these tools and that we get to play with. So, key takeaways. Well, we covered what is a neural network. We use all kinds of
processing to map images on your phone. We talked about things that a neural network can do. Translate text, identify faces, all the way to control robots. You know, lots of exciting things. How does a neural network work? So, we
discussed that with the different layers going from the picture to the input layer to the hidden layers and their weights to the final output layer. We also talked about how it does the math in computing the output as uh yes or no
categorically true false. We discussed types of artificial neural networks. A lot of vocabulary there from the feed forward neural network which is the most commonly used. That's the one the neural network we used is a feed forward neural
to train and there's all a lot of other ones out there. There's the radial biases, the Cohen self-organizing recurrent neural network, convolution neural network, modular neural network. The big one was modular because it
incorporates pieces of all the other ones. So that whatever you're working on ones. So that whatever you're working on now is a huge conglomerate of multiple networks, just all cutting edge. All of it's new. People even working on it
don't even know where it's going. Again, very exciting times. And finally, we dug through my favorite part. You can see with my uh latte on one side, my old school pens and pencil and all my sticky notes working away. That's not actually
that. And we walked through and actually and dog photo. And you could see where some of the problems are in processing large amounts of photographs and data where that starts to become going from a
single machine on my laptop with this, you know, lower amount of resources all the way to big data. How if you're processing hundreds and thousands of these photos, this now needs to be set up on an enterprise machine or even on a
significantly past the scope of this. The neat part about it though is once you write this code, Mosa's code, they now have tools that you can almost take the same ideas, if not the actual code, and push it right onto a cluster
computation. So really cool times for this. Again, we will get started by a brief introduction to LLMs and chatbots. Later we will dive into setting up the development environment. Then we will understand the collection and
preparation. Followed by that we will understand the implementation of LLMs. Later we will check into chunking and embedding for vector search or rag. implementing query processing and recommendations. Next we have zeroshot
text classification and lastly the sentiment analysis with LLM. Hope I made myself clear with the agenda. Now handing over the session to our experts. &gt;&gt; Hi, welcome all. Welcome to simply learn session on how to create LLM chatbot. In
this course, we are going to talk about what is LLM, what are chatbots. We'll try to see how do we start developing a chatbot using large language models
where we'll try to understand how do we set up the environment. Then we talk about how do we collect and prepare the data for LLMs to understand. Then how do we implement LLMs chunk and embedding vectors that is
required for retrieval augmentation. So that is an embeddings of the data chunks. I will talk about those things. We'll further talk about how do we implement query processing and recommendation systems. We'll give an
understanding on prompt engineering of zeros short text classification which is the type of prompt engineering and we talk about finally with the sentiment analysis with LMS. So we can create multiple types of LLMs and we can create
sentiment analysis LM. At the end of the session, we'll try to develop or go through with a piece of code using lang chain to create a chat model using open AI APIs and we will work on that and try to
using streamllet. That would be the agenda for the day. So how do we create LLM chatbots and we'll start with what is an LLM?
LLMs are nothing but large language models which are trained on very huge amount of text and they have the capability of generating humanlike text.
capability of generating humanlike text. So they are slightly enhanced version of the natural language processing tools that we have seen before in the deep neural network architectures wherein those architectures using LSTM
wherein those architectures using LSTM models or GRU models or similar models with respect to or the RNN models. These models were able to understand the text
and give an understanding of those text that what exactly is the inherent meaning about those text messages. However, the large language models are a However, the large language models are a step ahead of the previous versions and
they are able to gener not only understand the text but they are able to generate the text based upon the information given to them. So that is what we call as a large language models.
These are primarily trained on a very huge amount of data. They do not have any kind of predefined resources. They they trained on a very humongous amount of data. Now how they work? If I talk about how
LLM works, LLM typically takes up the huge amount of text and breaks it down huge amount of text and breaks it down into the pieces we call them as the tokens. Now what is the tokens? as a very small level a very basic level I
can say that tokens are nothing but the words at a very broader perspective you can understand tokens as words so words in any context in any paragraph let's
say you have 10 words or 20 words or 1,000 each word can be considered as one 1,000 each word can be considered as one token at times we can also consider a token at times we can also consider a entire sentence as a word as a token so
that is dependent upon which kind of modeling technique being used. We are using sentence tokens or we are using word tokens. But yes, at a very basic level, at a very grassroot level, you can think of tokens as simple words
which are leotized or stem. So stemmed or words stemming and leveratization are the basic concepts which are coming from the natural language processing part where we try to cut down the words to a basic
root level grassroot level words. So that is the idea behind stem so that we get similar words for every problem. Just for an example you can think of a simple example if I write down few words
simple example if I write down few words for you. I can write down a word break. for you. I can write down a word break. So we were talking about how LLM works. So in general terms, if we talk about how LLM works, LLM will be trying to
process my entire text data and create tokens out of it. So out of those tokens out of it. So out of those tokens, the tokens can be considered as single words or sentences at times depending upon the mechanism that is
depending upon the mechanism that is being used. But you can at a very broader level we can consider tokens as the piece of words which are at a root level words. For example, breaking will become break or into will remain into or
breaks will also become break. So depending which are the root words which generates other words. We'll try to contextualize all words into a single contextualize all words into a single entity which are of similar nature.
transform. Architectures might become just an architect. So depending upon some basic root words that will come to the picture. That is what we call as a
tokenization, stemming and natural language processing. So that's what we try to do. After tokerization, we get small little words as I've mentioned u words or sub words and we try to convert them into a vector representation and we
call them as numerical representation of those words. Let's say every single word in my entire word dictionary I will give them a particular number. Let's say a is them a particular number. Let's say a is at number one, B is at two, lamb is at
three, so on and so forth. So each particular word out of my entire particular word out of my entire contextual words will have a number associated with them. I'm giving a random example and with that we can
random example and with that we can assume different form maybe in hex code form or in in a binary coded form or some other form I can represent them and we can use that numerical representation of each
word in order to understand those words in numerical form because it would be the numerical representation of the data that will help in making things clearer and understandable. Right after this
and understandable. Right after this LLMs once we got the the relevant tokens Now what is an attention mechanism? There's a famous research paper on this which is attention is all you need published in 2017 from Google brain
That paper talks about a self attention mechanism which is the primary source of all transformer models. LLMs also use transformer modeling approach. So that is where it contains of a self potential layer and mask multi
retention layers. So that's the basic underlying principle behind all the LLMs. So we have an encoder block and we have a decoder block and we work on those two blocks together in order to understand what is the input being given
and what could be the potential text that could be generated for the given input. That is what attention mechanism allows us to do. We can discuss the cell potential mechanism in detail in another separate video.
That's what transformer talks about. So these are very different deep learning architectures which actually does not use a neuron kind of thing. If you have architectures, you would have seen that every deep learning architecture at the
hidden level has certain neurons at the center which takes the input and processes it and gives the output. In LMS we use a self attention mechanism module where we replace those neurons by self attention blocks. The self
portions. One is an encoder, other one is a decoder. And again certain LLMs may be just coder module. Certain LMS might be just a decoder module. Certain would be a combination of ports. All the generative ones are the models that are
combination of both encoding and decoding part. Yeah, if I talk about types of chat bots, the chat bots is another example of using large language model. What does chatbot do for us? We ask the question,
we put up a prompt, we put up a query in front of a machine and then machine is able to respond back based on the query being put up. Now there can be two classification of the chat based upon these two versions. The first is a
rule-based chatbot and second one is AI based chatbot. What are the rulebased chatbots? So rulebased chatbots are those where they have a defined set of rules and pre-written scripts for a particular question. Let's say how are
you? So if I have mentioned already or defined if someone asks you how are you it'll give me a particular answer. If that question is not into the vocabulary answer that question. and I'm not trained under that part. So those are
called as rule based chatbot or rule based LLMs. Typically these kind of rule-based LLMs use decision algorithms or random forest orbased algorithms in order to understand and create rules and then give the answers. Typically that's
the underlying logic board that goes behind the rule-based chat bots. Typically not into practice too much these days. We have AI powered chat bots more better. So we'll use in this class as well we
will work on AI based chatbot the rule based chat bots which are very simple to implement and very easy to put up through they will wordings because you will not be able to give sufficient amount of examples right
then you have AI based chat bots you can put up any kind of queries I'm pretty much sure most of us would have used AI based chat bots like chat GPT or entropic right or Gemini you would have used some
of you might have used those some common names that I've taken out so all these are AI based chat bots right depending upon my requirement what requirement that we have what kind of chatbot should I use is very much
important because I need to look at many factors like how much customization is required what is the cost involved how do We are I'm on a deployment. What is my deployment requirements? How much opensource do I want it make make it to
be open source availability for this last and most most important factor is how much is a private data that means a data which is not available publicly for open AI models or opensource models to
open AI models or opensource models to learn from. So do I want to include that data or not? That is also an important factor. If I have to include the data, the type of AI based chatbots will also vary because there will be two types of
AI based chatbot. One that we use with the pre-trained models which will work in this class and the one the other one that uses pre-trained models along with that it also takes up a chunk of data or it can also get trained from some other
data as well that is call as rag approach retrieval augmented approach. so far. Now setting up the development environment. In order to create
many things. There are multiple APIs which are available. But in this particular section, we will use OpenAI API. It is easily and freely available.
environment. I'm going to use Jupyter Lab for it. Some libraries to name few of them. I'm going to use streamllet. We are going to use lang chain. What else? Numpy and mapplot would also be
few libraries. Whether I want to do a cloud-based deployment or onremism deployment depends that dependency needs to be understanded because cloud-based deployments would require a little more resources. We need to ensure about the
correct API access. The API access that I'm going to use is my own personal openi access. So you will I would mention OpenAI key at the place of the code where it is required to put up the OpenAI key. All right. Thank you.
Python understanding. How do we write Python scripts? How do we integrate APIs with the Python scripts? Two important things. We'll use Jupyter notebook in this case and VS code or either you can use any technology because we are going
use any technology because we are going to write down a py file. So whatever you're comfortable with Jupyter notebook, VS Code or just Python working environment, I'm okay with that Python editor.
So API access can be requested from OpenAI coher or hugging face. I'm going to use OpenAI in this class. So I'll show you how to gain open AI access. You can go to platform.openai.com register yourself and you can generate
your openai API key right so transformers I can use blank chain will which will require me to develop a chatbot logic and that's what we're going to do. We can use llama
index for data retrieval or you can use fast API grio that can apply fast API deployment part but we're not going to use that. You can use cloud-based services like AWS, Azure or cloud. We're not going to cover that too as well
because that's not within this call. So data collection and preparation part. So we need to collect the data in the form of either CSV, JSON or web scrapping data. Go to numpy, pandas, create the
data and refine the data. But in this particular section, we are not going to deal with NLT or spacy library. We are not going to train the model as of now. We're going to use pre-trained models from OpenAI API.
So how do we create LLM chatbots? So that will be really practical parts. Then we'll try to understand how do we can create LLM chatbots. What we require is [snorts] few understanding. If I'm going to train up a model for example,
I'm going to train up an LLM model. We need a model architecture downloaded from transfer learning methodologies. You can get all those
either from hugging face or directly from transformers library or directly from tensorflow or pytorch whichever way you're trying to implement. We can get you're trying to implement. We can get them from there. Apart from that, what
kind of model is required? That is also an important thing because if I'm doing a sentiment analysis, I'll require a sentiment analysis. If I'm looking for a require a question and answering approach. If I'm requiring general
question answers, generic models, so I can use generic model like chart GPT. So have to choose the correct model and correct APIs accordingly. That is must first important task that we need to do. Right? That's we have talked about if
I'm trying to use different LLMs are require different kind of things for general versatility GPD is good open source customization lamas are good mistrol for efficiency falcon for scalability so right model will depend
on many factors like performance cost and deployment needs we can get right models whatever models that you want from hugging face or API based models API based models would include like I have open API access and
include like I have open API access and on open API We have a chat GPT 40 mini version which is available for access with me. So I'll use that. Now how to create an LM chatbot? For this we need to understand what is
retrieval augumented generation. So what is that retrieval augmented generation? Suppose I'm trying to do a search for example I typed in a query what is the role of Python? Just a simple word what is the
role of Python. In this scenario, it will try to find out out of my entire context that I've given, what is the rule of Python. It will try to find out what are the most relevant words with respect to the question being asked, the
meaning that it has and based upon that it creates [snorts] a architecture of most important keywords and that keyword is called as R A or retrieval argumented generation. So after that it finds out what are the most important keywords and
extensive search through the data that it has and finds out the correct matching keywords from different resources then from all different resources learn everything and then come back with my solution.
So that is what it is going to do for us. What it allows us to do is the rag us. What it allows us to do is the rag approach is my model or my LLM is not going to give me random vague answers. It's not only create or generate answers
without any context. We'll always try to find out some semantic information and give good contextual answers. Same thing happens with the chunking and numbering and vector search. It it tries to break down the entire text into small
little manageable pieces. We call them tokens again converted to numbers are called as vectors. Again it can be done through many other can be done by lang chain character text splitter. We can do through NLTK or we
can do it from tick token. Tick token is not to be misunderstood with tick tock. It's a different entity algether. Token is a library that allows us to tokenize my text. Then we have transformers like
transformers available which are allows me to create the vectors. Vectors means again numerical representation of my text. Then we store that in the database. Any simple database can work for us. Then we look for the similarity
scores like cosine similarity, util similarity scores or product similarity to find out what kind of matching architectures as I've told you rag uses this approach finds out similar context words. So from there it'll try to get me
those similarity words and find out similar contextual information. &gt;&gt; Then we talk about the implementation of query processing and recommendation. In query processing the idea again change is nothing but but it you ask a
question LLM works around with that again breaks it down into a text form from text it converts vectors and since it's a question so it becomes a question answer kind of approach. So it will find out 10 answers and try to filter out the
best suitable answer for any query that is being done. is being done. Now what is zeros text classification?
retain my model explicitly. Right? So what that is zero sort classification where I'm not putting up any additional resource. What is that meaning is I have a pre-trained model like GPT that is being
trained on very generic knowledge. Very generic knowledge that may not be very specific about the context that I'm asking. Say for example I have chat Guty which is trained on almost everything world but it might not be trained on my
organization's specific issues but I can still ask this question about my organization. It may not be able to give me a very specific answer but it will be is what we call a zeros text classification where I'm not training a
classification where I'm not training a LLM on a specific data rather I'm just creating an LLM from a pre-trained model and asking it for new data installation right how can you find out some classification
models there are lots and lots of available I can just show you very quickly pre-trend classification model you can pre-trend classification model you can go on to huggingface.co co
of pre-trend classification models available you can find out models based models and you can click for the task whatever task that you're looking let's say I'm trying to do some text natural language
processing let's say zero sort classification I zero sshot classification these are the models available I have bought large ML the zerosoft classification model. You can look at that. Go to files and
This is the entire model. You can see that you can read out this reading.md file and find out the information about it. available which you can use. Again it's a GitHub. So you can clone this entire
part and you can clone it from directly from hugging face. clone the repository from hugging face. clone the repository and use it locally. Okay. So any model can be used. So B large minium MLI that's one classification
a lot of things that can be done in zero sort classification. Apart from that you can create transform of pipelines wherein I'm trying to do one transformation followed by another one followed by another one and so on. So
that can be created up. We can use a scikitlan matrix like procedure and recall or f1 scores to find out we have correct classification. We can implement those two. Finally, we'll talk about the sentiment
analysis with LLMs. LMS can also be very much useful in doing the sentiment analysis part. So in sentiment analysis we try to look at how we can determine the emotional tone of any text uh
allowing or enabling chat bots to understand the user sentiment. So we try to train the chat bots on uh emotional cont on a on data which contains emotional aspects. We can define it whether it's a positive or emotion or a
negative emotion or sad emotion or happy emotion. We can pray the alms of God and based upon that training my alms would be able to tell me whether any particular emotions being reflected is what kind of emotion it is. It may not
be able to mimic that emotion but it will be able to tell me what emotion has been reflected in the context. It can be with the audio, it can be with the video or it can text as well. That is a sentiment analysis. Again distl is one
of the very good classification model for sentiment analysis that is what we can use. Sentiment analyzer is available with many other sentiment analyzer is available with distbut robbert llama everywhere we have
a sentiment analyzer available. It's a one of the class in a pre-trend model which is available to analyze the sentiments. So this is what we will talk about through the entire understanding of your
LLMs theoretically. Let's try to practically look at how do we implement practically look at how do we implement that. So I will open up that. So I will open up let me open up my Anaconda Navigator.
So I'm going to open up Anaconda Navigator. Here I have a pre-written I'll explain you each line what it is doing. Hopefully that helps. So here it is. I have just got my
Anaconda Navigator opened up. I'm going to open up my Jupyter Lab environment from here. Wait for that to open up. Should be up and running in a moment from now. So once that opens up we will be able to
So once that opens up we will be able to start doing the coding part of creating start doing the coding part of creating a chart GPT kind of approach where that would be an implementation of chart GPT through chart GPT op API that we can use
at our own local servers or at our own particular end. Essentially that is what replica of chat GPT that you can put up. Okay, I already have this piece of code written down for you. So what are we
going to do here? So I'll put down certain piece of quotes here. This file will be made available in the description too or you can copy it from here. Okay. So what is each of these things
that we're going to do? So I have named that as I have created a Python script here. For that I've gone to file new and I've used a python file. I went into that option and I create a python file. First thing I wrote down is import
stream and st. So this will allow I'll put up certain libraries to be done import prior to that you might be wondering if
I don't have those libraries. So you need to install these. I'm putting that as a comment pip install. Uh or if you're using an environment, environment. So I'll put up that pip install. You need to put up lang chain.
I'm using lang chain here space. You would require streamlet openi. What else? That should be good.
These two will be good. Okay. Okay, you need to install these two libraries lchain and streamllet. What I'm using streamllet for lang chain What I'm using streamllet for lang chain I'm just putting this notes
purpose of building chatbot logic okay and streamllet
for designing UI I'm not going to give too much into designing part we'll take a simple UI as of idea is not to do the designate designing part designing the user
interface. Okay. So a web page user interface I'll say that designing a web based user interface a separate session on streaml can be taken up to design all that part. So streamllet is separate library all
together. So we will import streaml as st that allows me to import streamllet from langchain chat modules. Now this subm module allows me to open or connect or call up the keys or open API keys from the open AAI servers. Okay,
so that is a class that is available chat openai that will allow me to create chat openai that will allow me to create or contain my open AI tools. Then another thing that I need to put up lang chainchains no conversation chain. Now
what does that do? It allows me to create a chain of conversations. That means suppose if I ask one question there's an answer given then I can ask a probing question further. So that allows me to remember the previous past as well
in context to the current conversation. It allows me to create a conversation chain rather than one question one answer and stops instead of that allows me to repeat things on a simultaneous lang chain memory that allows me to
remember the buffer memory. It allows me to remember my previous conversations. Suppose I have started with one conversation and then I want to continue with another conversation. My previous conversation can be saved and used it
conversation can be saved and used it can be reloaded. OS I'm using for very generic purpose to create environment variables if you want to create envir environment variables. Otherwise it's your choice if you can avoid OS as
well if you're not using environment variables. So first thing is to set up your open API API key securely. So for that I'm creating a variable open AI API key and I'm putting that into my streamlet
secrets. Now where are the streamlet secrets right? So these are typically stored in a toml file. I'll just show that. a toml file. I'll just show that. So that will be in your default folder
will have a dot streamlet folder. You need to go into that and install default user account. Inside that you will find a under stream folder
you can find there is a file by the name secrets.l. If it is there you can put it up. If it is not there you need to create a new text document like this. Inside this I just open it up. You need to write down anything. I have used the
to write down anything. I have used the word open AI API key is equal to and you need to mention within quotes your API key whatever you're using it up here and save this
document save as and you go to this place select all files and save this document as secrets tl so that allows you to take secrets tl so that allows you to take your model with encryption so that can
be saved up. So you can just need to save that file. I have already done that. secrets.tml. This file contains my API key, right? I already have that file API key, right? I already have that file here. So that allows me to tell it
streaml go to the secrets and find open API key if it is available in open else you can get it from the environment variable or else otherwise you can variable or else otherwise you can create up here OS. environment.
Those who do not want to use that, you can put up OS.in and create up the same variable by the name open. This is an optional thing.
API key and you can mention key and you can mention is equal to ports your API key
API key that should work so I'll put a comment this is an optional thing right we'll get this this thing
I have put this again in statement. This is for the purpose of else os get environment open key. So if we do not have a key available in secrets it will try to fetch it from the environment. All right. Now we need to initialize the
llm model. How do we initialize my lm model? My llm is equal to chat openai. That's the name of the function that will connect me to openai servers. Open aai. AI key is equal to open AI. API key. I have kept my API key. If you do
not have anything else available, just write down your open AI key directly here. You don't have to create anything at all. Right? You can place it up your open key and you may not want to expose that securely. Then the
temperature, it's the amount of randomness that we want. Now, what does that mean? It means how much randomly generic answers I want to create. the temperature part higher the number more is the randomness I'm trying to bring
temperature value is the better your answers would be okay lastly the model name based upon your access to open API you would be able to access either some of the models I able to access GPD4 or
mini model I mentioned that model if you're able to access GPT4 you can just mention GPD4 or whichever model you have an access or 3.5 turbo depending upon your access you can use that particular model.
After we have initialized the LLM part, we will move on to the next part where I'll set up the memory part. Now, what is that memory part in this on my streamllet platform? I just wanted to make sure if there is any previous
memory available, it should be able to bring that memory for me. If it is not available, I'll start my conversation from a new piece. So I have created a variable memory if memory not in session state right ST dot session state session
state is a variable that creates my value and I'm looking for memory but if be true whether it will be false so if memory not in session state if it is not present I want to create a memory s that
I can assign a memory value to it using conversation buffer memory so whatever that memory. So that will blank at the moment. Then I'll start my conversation. Now this function conversation chain it
actually allows me to create a chain of conversation. The model that I'm going to use is LLM model. The memory is the current memory state that is blank currently blank. So as soon as we keep on moving the memory states gets on
updated verbos will try to make sure that if there is any kind of warnings or something in between these are not being displayed that verbose false that ensures that part we do not see any warnings or anything
apart from that now we need to design the interface that's the model l model part done we will design our interface st setpage config so whatever the web browser page that I'm going to line. I want to put the title as LLM chatbot
page icon if you want to put something. Let's say put up anything. You can put up a GIF image or whatsoever you want. If I can have you leave it writing down one simply
I do not have that small images right now. So you can put a page icon like this. Then title. Now this title will appear up in the center of your page right on the first page on your screen. The lang chain chatbot by simply learn.
Okay. So that will appear up in there. Now we will now use the same place that I'll get a web page whose title will be lm chatbot. page icon will look like
simply lands a name written on that title would be lang chain chatbot by simply that will appear up somewhere in the center of my screen then I'll put up a blank box to receive user input so user input is equal to the name of the
function is st text input st is my streaml library in text input I'm asking this part to display asking you to it to display the word u followed by key is equal to input so it will display up a box and the key input will be displayed
up within the box. So you get to know that here I have to put in the input that here I have to put in the input value. Then conversation which is my conversation chain model that we have created here
conversation.predict the user input. So based upon the input that I give it will create a response. Once it gets the response, I will add to the memory to the chat memory. So session state memory dot chat memory dot add user message
predefined function. So I'll put up user input and add AI message as response. I have added two functions there and then I'm writing up the response. So I'm putting up now on my screen st.right is going to put my
formatted string with a markdown language of bot that will appear in bold and the response. So what are the response from LLM model that has came up that will be printed up here at the last I'm putting up this is an optional thing
completely optional wherein I'm trying to tell you if you want to see the previous histories you can put that up by doing this how
so there is a checkbox I'm creating if s dot checkbox show chart history that will be displayed in front of it there will be checkbox so if I select it this becomes true if I do not select it that remains false for message in ST state
memory chat memory messages. I'll try to see see I have added user messages and AI messages. So that is available in my session state memory chat memory right. memory and I want to recollect all messages. So I'll retrieve all messages
from there and I'll put up what the role in this particular you if message type is human else bot and I'll put down the entire content. So that's what will be printed out on my screen. That completes your entire LLM
creation part. Let's try to work around this. Now for this you need to save this file as chatbot py. Once you have done this open up your terminal. I'll open up a terminal that is nothing
but my Windows terminal, PowerShell terminal. And I'll run this command by putting up streamllet space run space name of my Python
space run space name of my Python script. So it's chatbot. py. That is my Python script. When I execute this, I press enter key on my keyboard and say that you can now see your streamllet
app. I'll just show you this. You can now view your streamllet app. It's starting up the app on the back end. But I'll just show you here on your browser. So that has already opened up a app on my browser. I'll show you that. But it
my browser. I'll show you that. But it says that local URL HTTP localhost 8505 and my network URL is this. So it has gotten an IP address URL as well. I can use either one of those. But if I go to my web browser and see it says that my
window title of I show you. You see that llm chatbot here that's my title on the top put up I don't I had an emoji to come up put up I don't I had an emoji to come up but that did not give up last but you
can see here lang chain chatbot by simply lang that's what I put up here that's the name and it has a context box of you and I have a box to write down I have a show chat history option let's try to search how
try to search how or What is or let's say today's news I win Champions League 2025. Now that's a very generic
question. I'm pressing enter to apply. If everything is good, my API is running. I would get an answer. It says I cannot predict the future. So I don't know who will win the Champions League 2025. The
talented teams and anything can happen in football. So you can ask me any you don't like can put up a new question here.
Tell me the names depending upon how much availability of all participating. So depending upon your prompt you can create up. So it tells me does not know that in the top teams from various leagues including
Premier League, La Liga, Sira, Bundesliga and League One along with some lesserk known leagues compete for a spot. So you can see there are some team names that can be there. Essentially you can also see below
show chat history. If I put that on, you can look at all the things that has been done in this particular. You can see my chart history is available that can be viewed. I removed that show chat history. The
chat history will be part again depending upon the machine that you're using. It is running on my local server. So depending upon hardware, it might be slow or fast. That is how you can do it. The next option that we can do is to
deploy this. In order to deploy this you need to go on to deploy option. You have multiple choices available like you can go stream with community cloud you can go snowflake or you can deploy on your custom platforms. If I
want to go on community cloud I can click on deploy. Now I need to access to my GitHub account. I need to put this code onto GitHub and then I can deploy that can be discussed in a separate session all together. So
that would be it everyone and I would really like you to think of questions and answers. If you have something, put them up into your comment section and we'll definitely respond back. Thank you very much. I'm going to show you how to
create highly realistic digital clone of anyone using hygiene. This tool is an incredible way to generate lifelike avatars and unlock endless creative possibilities for content creators, businesses, and anyone looking to
produce realistic digital representation. So whether you want to create training videos, personalize content, or even bring someone's tutorial will walk you through the process step by step. So guys, watch
this video till the end if you want to learn more about it. Before we move on, let us first understand what exactly is digital clone. A digital clone is essentially a digital version of a person that mimics their appearance or
voice and even behaviors. These clones can be used for wide variety of purposes from creating virtual assistant avatars for training videos or personalized messages to even crafting content for marketing campaigns. The key is that
these clones are powered by artificial intelligence which allows them to mimic the unique trait and characteristics of a real person. Digital clones are created by combining video footage, voice recording, advanced machine
learning techniques to produce digital representation that can speak, move, and interact just like the original person. And with tools like Hijun, this process has become much more easier and accessible. So you can see I'm at the
official website of Hun. Okay, you can access this website if you go all over access this website if you go all over here. Type hijen and you can also go with type hijen digital clone. It will redirect you all over here. Clone
yourself AI. So this is a official website. Now the next step is you have to sign up. So you can see all over here there's a option sign up for free. Just click on this. Now there will be various plans that will be there for you. Like
for example, there would be the free version where you don't have to pay anything. Then you have the creator plan. Okay. Once you have signed up, it is going to show you the given plan. So first one is the free version. You can
try this plan. If you are beginner and want to learn about this tool for most of the users, they can go with the creator plan. You can create up to 5 minutes video long. You can export it at and you have also amazing features like
utilizing language translation. Then you have team where minimum two seats are there and you could see it is built $720 yearly. There are unlimited videos. You can create videos up to 30 minutes 4K video export faster video processing and
there is 5 minutes of avatar 4 videos per month. So these are the thing and for larger scale projects you can also go with the enterprise level plan. It has additional features and scalability options. Now once you have chosen your
plan, you are ready to go. The next step is creating the avatar. So let us click on the free plan and let's say I'm creating my personal project. Let's right click. You can just click content creator. Let's say we are creating a
marketing video. Okay. Now all over here we have to create our avatar. So let's say let us try avatar 4. Let's see what it has. try avatar 4. Let's see what it has. &gt;&gt; Avatar 4 allows you to turn.
over here. So you can click on this and you can create a avatar. So like I have selected this avatar and you could write your script all over here or you could upload or record audio also. So let's say let's take the help of chat GPD to
say let's take the help of chat GPD to create a script. Okay. So let's ask GPT. Okay. So guys, I have taken the help of chat GPT and I have instantly added a script all over here. Now let's say custom motion also. So for custom motion
you can again uh take the help of Chad GBD. Let's ask add. Okay. Now what I've done is I have taken the help of Chad Shiputi and also I have
added in the custom motion also to give much more idea like how my uh avatar is going to do. Now you could choose the given uh resolution. Let's say it's 180p and uh we cannot do that since I'm on a free tier. So go with the 720p and let's
click on generating the video. So guys for the best result you can select the motion option. This allows you to actually give much more description about the motion of your avatar. Now, make sure the avatar you are using is is
well lit, centered, and expressive. This will help make avatar appear more natural and lifelike. The more natural the expression, the better the final avatar will look. Now, the third step, we have to record and train. Now, it's
time to actually record your subject. The footage does not need to be shot in a professional studio setting. It could be done at home, outdoors or in any well-lit environment. The key here is to make sure subject speaks clearly and
directly to the camera. But for this instance, we are actually using the avatar which is already given by hij. Okay. But for the other purpose, if you are creating your own avatar and also make sure that there is pause between
make sure that there is pause between sentences when you are creating a video. For example, uh you could say something like, "Hello, my name is your name and today we are going to show you how to create a digital clone." So add some
brief pauses between the sentence because this is going to help hygiene process the footage more effectively and gives the avatar more human like cadence. Now let's see how video is created. Let's look into this.
Let's select the portrait version. So guys, initially we added this script for our digital clone and we selected this random image and we have given certain script. Now we have used the motion feature of Hen and let us see how this
&gt;&gt; Hey there, I'm your digital assistant here to show you how our amazing software is revolutionizing the way you edit photos, videos and more. All edit photos, videos and more. All powered by cuttingedge AI.
&gt;&gt; Well, it sounds so amazing. just &gt;&gt; just looks like repeat it just looks like a real person for somewhat it get still recognizable that it's an AI clone but uh you can create your own avatars like that so for section of creating
your own avatar what you need to do is just go all over here click on create uh new avatar then you could either go with hyperrealistic avatar or custom photo or you could click on generate so let us try this feature Let's say is me and
try this feature Let's say is me and gender is man. So let's take a a prompt gender is man. So let's take a a prompt from chat GPT.
let's select till personality only and paste this. and paste this. Okay. delete the behavior part and let Okay. delete the behavior part and let us try to see the preview how our avatar
looks like based on our text prompts. Now it has already generated certain a photo for our avatar. Let's select this. Click on save
and in this way you could generate an avatar also by giving the description. So this is a very amazing tool guys. There's a lot of things you could do all Now you could see you can also add a voice. So let's add this voice. Okay.
voice. So let's add this voice. Okay. And let us try to see this. And now there is also option to train this model. But this will take some time and also certain credits. Now if you're someone who is a content creator or
you're creating tutorial videos then this tool you must check it out and you can buy the creator plan that is a most ideal plan for most of the users and then you could access all these features. So this is our photo.
features. So this is our photo. Let us see how our avatar looks like. So now here you could upload the audio also or you could add a script and it will take certain time. So let us ask chat GPD for the same.
just add the given script. Okay, you can add the script all over here. Let's say add the script all over here. Let's say just add the name
and let's say now just add the title and click on submit. It is going to take some time to generate the video. Let us see. Okay. So, it's still in line for processing. It might take some time. But
apart from that, there is also amazing feature for brand. You could do the branding kit also. So, let us explore a bit. So, you could see you could create your own uh branding logos or you could create your product images with the help
of this tool. Very amazing tool. And it also has amazing integration like it has hubspot integration, Adobe express plug-in, Canva app, chat GBD plug-in and through which this tool can be integrated. And um this is labs. Labs is
integrated. And um this is labs. Labs is also a new feature. So someone who is uh into podcasting, you could also try this amazing feature. Now URL to video is also there. Amazing amazing features like instant highlights, interactive
avatar. So as you can see all over here the video is still in the processing line and you don't have to wait for this. What you can do is you can explore this platform and create your own avatar. And that's it guys. We have
successfully created our one avatar today using hygiene. This technology is still evolving and as it improves we can expect more lifelike and interactive avatars. Hygiene has incredible potential. Whether you are creating
personalized video messages, training content, or just exploring new ways to express yourself digitally, digital clones have potential to revolutionize the way we create content and communicate. Imagine the possibilities.
Personalized customer support bots, training videos where presenter is always available, virtual brand ambassadors, or even educational tools that feature instructors who can be physically present. In this tutorial, we
will learn about how to build an iOS application using AI. Building an iOS application no longer requires years of coding expertise thanks to the power of
artificial intelligence. AIdriven tools and no code platforms are making app development accessible to creators from all backgrounds. With just an idea and all backgrounds. With just an idea and the right AI assistant, you can design,
build, and launch your own applications. Beyond the technical ease, this opens up opportunities to monetize your app, generate passive income with creativity and entrepreneurship in your hands. That said, if these are the type of videos
you'd like to watch, then hit that like and subscribe buttons and the bell icon to get notified. How to build an iOS application with AI. Let's have a brief introduction on how to build an iOS app.
Basically, to build an iOS app in the olden days, you needed a platform or an olden days, you needed a platform or an IDE referred as Apple's X code. But now, we are working on a Windows operating system. So, it might not be compatible.
So if you really wanted to work on the Apple's X code, you can go with the virtual machine or you can boot it as a dual boot OS in your PC. But if you wanted to continue development with your Windows operating system, then there are
Windows operating system, then there are ways to do it. So let's get started. And here we will be starting with a demonstration. Let's imagine that you are a person or an entrepreneur with an idea and you found a venture capitalist
to invest in your idea. Now you wanted to visit New York and you wanted to meet your VC. So you are looking for a good workplace or you know some cafes or the best place where you can execute a professional meeting explain your idea
to your venture capitalist but you don't know the perfect place right so you have multiple locations and you don't know the prices and it might be a little complicated with hidden price tags as well so what if you had one application
which would work for both Apple phones as well as Android phones to help not as well as Android phones to help not just you but many other entrepreneurs just like you to find their best meeting location with their rees. Right
now, let's have an idea for that. What would an iPhone have as an application which could support this? And in the same way, what could an Android phone has an application to support this? Right? So now we will try to build both.
So to build an application which supports both Android as well as Apple, we might need a couple of tools. Firstly, an AI agent. So, we will be Firstly, an AI agent. So, we will be going ahead with one of the best uh AI
designers for websites as well as there is a new launch from Bolt which can also help you design applications. So, you need to login. So, Bolt will provide you with some free tokens and free user trials. So you can proceed for free and
trials. So you can proceed for free and also Expo is another development IDE or a kind of uh location where you can launch both Android applications as well as iOS applications for free. Now you also need to create an account in Expo
and you might also have to log in and download an application on your phone for supports. So this is the platform where you can create an application and upload and launch. So you cannot directly upload to iOS from Windows. So
you might have to download the project first then make some modifications if you like and then upload for trials on Xbook and if everything goes fine then you can just proceed. Now I have opened up Claude to help me build a best prompt
so that it is really helpful for Bold to understand my requirements and build me an application. So I'm writing a prompt here. Hi Claude, can you please give me a prompt for an AI to help me create an
application to help me find best location for VC meeting? So you can maybe include cafes or hotels or some good places where the ambience will match professional meetings. So that's the main motto and we'll hit enter.
We'll also copy the same old prompt from here and also see if uh bold can help us out or not. You can just simply copy this prompt and paste it onto bolt and get your things done or you can also try on your own. I chose claude because
claude is best for writing AI prompts. It is the best which understands all your requirements and modifies it in the best way so that AI can understand. So you can directly copy this from here or you can just go back to bold and simply
paste the same prompt that you wrote on claude and replace claude with bold and make some more modifications to it. Maybe um okay let me eliminate the prompt part. So we'll directly place the request for creating the best
request for creating the best application for iOS. That's good. And uh maybe I can also add a few more pointers. So I can also make some modifications since we are looking for location. Maybe I can have the app
should have location based settings. So it should have locations maybe also timings that should be good or it will automatically have it I guess. So automatically have it I guess. So location and uh date and also we can
have budget right. So if you are a person or entrepreneur with just an idea and uh little financial support then you may also have a concern related to budget right. So that should be good based on this
based on this input from the user you need to so the user needs to add the location date. So it should work everything right. Uh find it should work everything right. Uh find the best place for the said data. So
it's obvious since AI is assisting you, it will also have u its own settings which will help it understand if the set date and location are not realistic then automatically reject the requirement. So it's not a big deal there. You can just
it's not a big deal there. You can just try to continue. So yeah one last check. So uh here you have an enhanced prompt from bolt which will automatically help you just like lot to make it better. So I'm going with the enhancing prompt
option over here. So it automatically you know created all those things right and uh the thing what we spoke about invalid entries. So it will also be resolved in this prompt itself. So you can just hit enter and bolt will start
building you an application. So it will write its own files. It will categorize the libraries and all the requirements. And the best part about it is that right and you can just simply download the project and you may have any other ids
project and you may have any other ids on your local system like uh VS code or visual studio. You can just uh run through the application and check if you find any inconsistencies then you can fix them and then just directly go with
expo go and make changes and upload for trial versions right and if it's everything is fine you can just monetize your application. So here you can see we have uh let me expand the screen once again. So here you have an option called
deploy right you can directly deploy from here for a trial version or you can export. So we have both the options here. So let's go through the process. So here you have uh two windows. One is code and another is preview. So we'll
have it on the preview screen right now to see how the preview looks. And if you you can also click on the code option there and it will redirect you to the code section. So here you can see professional meeting when you find app.
So it already named the application. That's really good. And it is creating files and those it is also downloading all the dependencies required to run.
bolt has successfully created nine different code files for you and it also comprehensive professional meeting venue finder app and you can see some preview on the screen on the right hand side and in no time I think we can have a fully
finished user interface. Yeah, there you go. Now you can enter the location. Since we discussed about New York, then we can go with New York. So, uh my bookings, if I have any favorites, save. It will also take care
favorites, save. It will also take care of that. So, it's just the beginner version yet. We haven't added the AI agent to connect with this application. So you can also have the U AI agent like any LLM version like maybe chat GPT
Gemini to help you in real time. You can just have to create a new project on your API section, create some API keys and get assistance from real time AI agent as well. So here we'll set the location to New York as discussed before
and we can also select a date maybe a weekend date or the week day based on the availability of your VC could be great or maybe you have a pre-planned version. So we'll go with the weekend of 28th 7 uh 2025 and maybe in the evening
28th 7 uh 2025 and maybe in the evening time of 400 p.m. should be good and I'll go with a budget of by default it gave me a budget of $100. I can also increase it to maybe 125 or 150. I'll go with 125. And you can just search
and it'll give you some results based on its ability to search through the Google its ability to search through the Google web pages for some u results. Right? So based on your requirements of date, time and budget. So you can also directly
deploy or you can also export. And if you want to you know kind of integrate all the other requirements like GitHub maybe if you upload this project to GitHub and you can get contributions from rest of the developers or maybe
your fellow entrepreneurs and improve the UI or maybe dependency or reliability on the application. Right? So it'll be a good uh thing for that. I'll for now download the project and also maybe I'll try to edit on any of my
also maybe I'll try to edit on any of my local IDE like VS Code or Visual Studio. And here you have the name for your application professional meeting venue finder app. So that's good. I think it named the app as venue find and the
subtitle is uh professional meeting venues. That's good. You can also choose to have a full screen visual and see if there is any screen visual and see if there is any inconsistency in uh the aspect of UI.
Right. And now I'll minimize and I'll click on deploy or maybe uh yeah let's click on deploy. or I think I have a better idea. As we discussed about the API keys, I can hold the deploy function as of now and add
the deploy function as of now and add the API. So let's take a moment to stop the API. So let's take a moment to stop it. Yeah, I'll stop this and uh I will it. Yeah, I'll stop this and uh I will open the open AI API section. Before
that, let me uh give it a prompt. Yeah, we have downloaded it. Yeah, that's the we have downloaded it. Yeah, that's the project. Let's uh extract the project project. Let's uh extract the project files.
it has about uh nine files and also I think it has some readme files as well. think it has some readme files as well. Now let's go to visual studio Now let's go to visual studio and from here we can have access to the
and from here we can have access to the uh file that we just created open folder or maybe you can also have an option of creating a new window algether. So let's go with a new window one. I think I created a new file. Not a new file, new
window. Third option. Yeah, you can close all the previous windows. And here you can just directly open file or open folder. Go to downloads. I think that's where we have it. Project Bold.
that's where we have it. Project Bold. Yeah, project. Select folder. Open. And we have all the files readily available here. All the coding from Bolt
is available here for you. And now what we need is we need an additional file which will help us to add the API keys for our project. So let me open a new
Google window. Yeah. So this is the bold window. Now let's open a new window right next to it. Yeah. We have canled the deployment process. And now I'll write a prompt.
Can you add or create maybe a new uh file or API integration or route for my open AI. So I'll choose
or route for my open AI. So I'll choose open AR GPD project and we will also be sharing the API keys here itself or we can manually add them as well in the Visual Studio Code. That should not be a trouble. I will share
should not be a trouble. I will share you my API keys. Great. Enter. And now it'll make some changes accordingly. While Bolt is working on the API file where we have our APIs, where we will have our APIs. Let's go back to OpenAI.
have our APIs. Let's go back to OpenAI. Login quickly. So, I have uh logged into my account on OpenI. And here we will create a new
project. Create a new secret key. And I'll name it as uh VC meet app we see me project or something like that. And uh create a key. And now make sure you don't share this particular key with anyone because
somebody might misuse it and you will be charged. Let's say this is a free account but if you are a person with a paid plus or pro account from open AI charge EPD then you might have to pay for the purposes which you never used.
So I'll just save it somewhere in my note. note. Yeah, let me tag it as my new VC API and I'll close it and I'll close open AI prompt as well. And here it is also
mentioning API key validation with helpful error messages. So don't share it. Right? So we also might have to find some security concerns. Right? I hope uh the new preview should be ready. Yeah, it's ready. And you can see
the AI assistant is unavailable right now because Bolt worked on its own AI assistant. But now we wanted to get connected to OpenAI's chat GPD. To have that working, we need to confirm the API keys. That means we need to add the API
keys and refresh. Then we will be ready for it. So let's give it a moment and uh go back to the code editor and add the API keys as soon as possible.
So now let's work on the new preview once again. And let me take Los Angeles this time in place of New York. So yeah, that's the right spelling. I think I wrote angles Angeles. And uh let me give a date.
Maybe we'll choose a working day. this time and uh the meeting should be after working hours. So 6 p.m. should be good. 6 p.m. is 18ouble O. And uh budget u I
can manually write that as well. $200 budget and it found about four venues. I It's not it should not be a big deal. We can write a prompt to change the uh you know stock thumbnails to the actual original thumbnails from uh the Google
search results. That should not be a big deal. Yeah, so far so good. Now we are on the preview version again and uh we will go through the code segment also. You can also choose to expand the window so that you can have the code section on
the right hand side in case if you wanted to make some changes on the go. That's the best version that Bolt can help you with and uh you can have a real-time interface just like Xcode does. Right? So that's the best part.
Now let's go back to the original UI what Bolt gave us and we may also uh have a preview a quick preview uh how it does uh look in terms of uh an iPhone
screen. You can choose any of the latest icons like 15 or 16 and see a quick preview as well. So it's currently running a prompt on that front. So so far we have seen a website based user interface. Now we want to also check if
it works and uh we also kind of want to know if it has a good compatibility with the phone you're choosing to work on right so initially we started off working on this application based on two requirements it should also support iOS
requirements it should also support iOS and also the Android phones right so based on the requirement Bolt is working so we also want to see if this supports both phones as well as website three different applications so it's currently
working on the preview so let's give it a moment the instructions. Install Expo. I think it went on scrolling. So here you can
see it gave us three different problems. Should not be a big problem to solve. You can also choose the Bolts uh attempt fix uh quick fix option here which can help you to fix it from bolt itself. It'll run some tests and identify what
It'll run some tests and identify what could be the problem.
