Artificial Intelligence By Example

Book description

Be an adaptive thinker that leads the way to Artificial Intelligence

About This Book
  • AI-based examples to guide you in designing and implementing machine intelligence
  • Develop your own method for future AI solutions
  • Acquire advanced AI, machine learning, and deep learning design skills
Who This Book Is For

Artificial Intelligence by Example is a simple, explanatory, and descriptive guide for junior developers, experienced developers, technology consultants, and those interested in AI who want to understand the fundamentals of Artificial Intelligence and implement it practically by devising smart solutions. Prior experience with Python and statistical knowledge is essential to make the most out of this book.

What You Will Learn
  • Use adaptive thinking to solve real-life AI case studies
  • Rise beyond being a modern-day factory code worker
  • Acquire advanced AI, machine learning, and deep learning designing skills
  • Learn about cognitive NLP chatbots, quantum computing, and IoT and blockchain technology
  • Understand future AI solutions and adapt quickly to them
  • Develop out-of-the-box thinking to face any challenge the market presents
In Detail

Artificial Intelligence has the potential to replicate humans in every field. This book serves as a starting point for you to understand how AI is built, with the help of intriguing examples and case studies.

Artificial Intelligence By Example will make you an adaptive thinker and help you apply concepts to real-life scenarios. Using some of the most interesting AI examples, right from a simple chess engine to a cognitive chatbot, you will learn how to tackle the machine you are competing with. You will study some of the most advanced machine learning models, understand how to apply AI to blockchain and IoT, and develop emotional quotient in chatbots using neural networks.

You will move on to designing AI solutions in a simple manner rather than get confused by complex architectures and techniques. This comprehensive guide will be a starter kit for you to develop AI applications on your own.

By the end of this book, will have understood the fundamentals of AI and worked through a number of case studies that will help you develop business vision.

Style and approach

An easy-to-follow step by step guide which will help you get to grips with real world application of Artificial Intelligence

Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

Publisher resources

Download Example Code

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Artificial Intelligence By Example
  3. Dedication
  4. Packt Upsell
    1. Why subscribe?
  5. Contributors
    1. About the author
    2. About the reviewers
    3. Packt is searching for authors like you
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Code in Action
      4. Conventions used
    4. Get in touch
      1. Reviews
  7. Become an Adaptive Thinker
    1. Technical requirements
    2. How to be an adaptive thinker
      1. Addressing real-life issues before coding a solution
        1. Step 1 – MDP in natural language
        2. Step 2 – the mathematical representation of the Bellman equation and MDP
          1. From MDP to the Bellman equation
        3. Step 3 – implementing the solution in Python
    3. The lessons of reinforcement learning
      1. How to use the outputs
      2. Machine learning versus traditional applications
    4. Summary
    5. Questions
    6. Further reading
  8. Think like a Machine
    1. Technical requirements
    2. Designing datasets – where the dream stops and the hard work begins
      1. Designing datasets in natural language meetings
      2. Using the McCulloch-Pitts neuron 
      3. The McCulloch-Pitts neuron
      4. The architecture of Python TensorFlow
    3. Logistic activation functions and classifiers
      1. Overall architecture
      2. Logistic classifier
      3. Logistic function
      4. Softmax
    4. Summary
    5. Questions
    6. Further reading
  9. Apply Machine Thinking to a Human Problem
    1. Technical requirements
    2. Determining what and how to measure
      1. Convergence
        1. Implicit convergence
        2. Numerical –  controlled convergence
    3. Applying machine thinking to a human problem
      1. Evaluating a position in a chess game
      2. Applying the evaluation and convergence process to a business problem
      3. Using supervised learning to evaluate result quality
    4. Summary
    5. Questions
    6. Further reading
  10. Become an Unconventional Innovator
    1. Technical requirements
    2. The XOR limit of the original perceptron
      1. XOR and linearly separable models
        1. Linearly separable models
        2. The XOR limit of a linear model, such as the original perceptron
    3. Building a feedforward neural network from scratch
      1. Step 1 – Defining a feedforward neural network
      2. Step 2 – how two children solve the XOR problem every day
      3. Implementing a vintage XOR solution in Python with an FNN and backpropagation
        1. A simplified version of a cost function and gradient descent
        2. Linear separability was achieved
    4. Applying the FNN XOR solution to a case study to optimize subsets of data
    5. Summary
    6. Questions
    7. Further reading
  11. Manage the Power of Machine Learning and Deep Learning
    1. Technical requirements
    2. Building the architecture of an FNN with TensorFlow
      1. Writing code using the data flow graph as an architectural roadmap
        1. A data flow graph translated into source code
          1. The input data layer
          2. The hidden layer
          3. The output layer
          4. The cost or loss function
          5. Gradient descent and backpropagation
          6. Running the session
          7. Checking linear separability
    3. Using TensorBoard to design the architecture of your machine learning and deep learning solutions
      1. Designing the architecture of the data flow graph
      2. Displaying the data flow graph in TensorBoard
      3. The final source code with TensorFlow and TensorBoard
    4. Using TensorBoard in a corporate environment
      1. Using TensorBoard to explain the concept of classifying customer products to a CEO
      2. Will your views on the project survive this meeting?
    5. Summary
    6. Questions
    7. Further reading
    8. References
  12. Don't Get Lost in Techniques – Focus on Optimizing Your Solutions
    1. Technical requirements
    2. Dataset optimization and control
      1. Designing a dataset and choosing an ML/DL model
        1. Approval of the design matrix
          1. Agreeing on the format of the design matrix
          2. Dimensionality reduction
          3. The volume of a training dataset
    3. Implementing a k-means clustering solution
      1. The vision 
        1. The data
          1. Conditioning management
        2. The strategy
      2. The k-means clustering program
        1. The mathematical definition of k-means clustering
          1. Lloyd's algorithm 
        2. The goal of k-means clustering in this case study
        3. The Python program
          1. 1 – The training dataset
          2. 2 – Hyperparameters
          3. 3 – The k-means clustering algorithm
          4. 4 – Defining the result labels
          5. 5 – Displaying the results – data points and clusters
          6. Test dataset and prediction
      3. Analyzing and presenting the results
        1. AGV virtual clusters as a solution
    4. Summary
    5. Questions
    6. Further reading
  13. When and How to Use Artificial Intelligence
    1. Technical requirements
    2. Checking whether AI can be avoided
      1. Data volume and applying k-means clustering
        1. Proving your point
          1. NP-hard – the meaning of P
          2. NP-hard – The meaning of non-deterministic
          3. The meaning of hard
      2. Random sampling
        1. The law of large numbers – LLN
        2. The central limit theorem
          1. Using a Monte Carlo estimator
        3. Random sampling applications
    3. Cloud solutions – AWS
      1. Preparing your baseline model
        1. Training the full sample training dataset
        2. Training a random sample of the training dataset
        3. Shuffling as an alternative to random sampling
      2. AWS – data management
        1. Buckets
        2. Uploading files
        3. Access to output results
      3. SageMaker notebook
      4. Creating a job
      5. Running a job
        1. Reading the results
      6. Recommended strategy
    4. Summary
    5. Questions
    6. Further reading
  14. Revolutions Designed for Some Corporations and Disruptive Innovations for Small to Large Companies
    1. Technical requirements
    2. Is AI disruptive?
      1. What is new and what isn't in AI
        1. AI is based on mathematical theories that are not new
        2. Neural networks are not new
        3. Cloud server power, data volumes, and web sharing of the early 21st century started to make AI disruptive
        4. Public awareness contributed to making AI disruptive
      2. Inventions versus innovations
      3. Revolutionary versus disruptive solutions
      4. Where to start?
    3. Discover a world of opportunities with Google Translate
      1. Getting started
      2. The program
        1. The header
        2. Implementing Google's translation service 
      3. Google Translate from a linguist's perspective
        1. Playing with the tool
        2. Linguistic assessment of Google Translate
          1. Lexical field theory
          2. Jargon
          3. Translating is not just translating but interpreting
          4. How to check a translation
    4. AI as a new frontier
      1. Lexical field and polysemy
      2. Exploring the frontier – the program
        1. k-nearest neighbor algorithm
          1. The KNN algorithm
          2. The program
          3. Implementing the KNN compressed function in
          4. Conclusions on the Google Translate customized experiment
      3. The disruptive revolutionary loop
    5. Summary
    6. Questions
    7. Further reading
  15. Getting Your Neurons to Work
    1. Technical requirements
    2. Defining a CNN
      1. Defining a CNN
      2. Initializing the CNN
      3. Adding a 2D convolution 
        1. Kernel
          1. Intuitive approach
          2. Developers' approach
          3. Mathematical approach
        2. Shape
        3. ReLu
      4. Pooling
      5. Next convolution and pooling layer
      6. Flattening
      7. Dense layers
        1. Dense activation functions
    3. Training a CNN model
      1. The goal
      2. Compiling the model
        1. Loss function
          1. Quadratic loss function
          2. Binary cross-entropy
        2. Adam optimizer
        3. Metrics
      3. Training dataset
        1. Data augmentation
        2. Loading the data
      4. Testing dataset
        1. Data augmentation
        2. Loading the data
      5. Training with the classifier
      6. Saving the model
        1. Next steps
    4. Summary
    5. Questions
    6. Further reading and references
  16. Applying Biomimicking to Artificial Intelligence
    1. Technical requirements
    2. Human biomimicking
      1. TensorFlow, an open source machine learning framework
        1. Does deep learning represent our brain or our mind?
      2. A TensorBoard representation of our mind
        1. Input data
        2. Layer 1 – managing the inputs to the network
          1. Weights, biases, and preactivation
          2. Displaying the details of the activation function through the preactivation process
          3. The activation function of Layer 1
        3. Dropout and Layer 2
        4. Layer 2
        5. Measuring the precision of prediction of a network through accuracy values
          1. Correct prediction
          2. accuracy
        6. Cross-entropy
        7. Training
      3. Optimizing speed with Google's Tensor Processing Unit
    3. Summary
    4. Questions
    5. Further reading
  17. Conceptual Representation Learning
    1. Technical requirements
    2. Generate profit with transfer learning
      1. The motivation of transfer learning
        1. Inductive thinking
        2. Inductive abstraction
        3. The problem AI needs to solve
      2. The Γ gap concept
      3. Loading the Keras model after training
        1. Loading the model to optimize training
        2. Loading the model to use it
          1. Using transfer learning to be profitable or see a project stopped
      4. Defining the strategy
        1. Applying the model
        2. Making the model profitable by using it for another problem
          1. Where transfer learning ends and domain learning begins
    3. Domain learning
      1. How to use the programs
        1. The trained models used in this section
        2. The training model program
      2. GAP – loaded or unloaded
      3. GAP – jammed or open lanes
      4. The gap dataset
        1. Generalizing the Γ(gap conceptual dataset)
        2. Generative adversarial networks
          1. Generating conceptual representations
          2. The use of autoencoders
      5. The motivation of conceptual representation learning meta-models
        1. The curse of dimensionality 
        2. The blessing of dimensionality 
          1. Scheduling and blockchains
          2. Chatbots
          3. Self-driving cars
    4. Summary
    5. Questions
    6. Further reading
  18. Automated Planning and Scheduling
    1. Technical requirements
    2. Planning and scheduling today and tomorrow
      1. A real-time manufacturing process
        1. Amazon must expand its services to face competition
        2. A real-time manufacturing revolution
    3. CRLMM applied to an automated apparel manufacturing process
      1. An apparel manufacturing process
      2. Training the CRLMM
        1. Generalizing the unit-training dataset
          1. Food conveyor belt processing – positive pγ and negative nγ gaps
          2. Apparel conveyor belt processing – undetermined gaps
          3. The beginning of an abstract notion of gaps
        2. Modifying the hyperparameters
        3. Running a prediction program
    4. Building the DQN-CRLMM
      1. A circular process
      2. Implementing a CNN-CRLMM to detect gaps and optimize
      3. Q-Learning – MDP 
        1. MDP inputs and outputs
          1. The input is a neutral reward matrix
          2. The standard output of the MDP function
          3. A graph interpretation of the MDP output matrix
      4. The optimizer
        1. The optimizer as a regulator 
          1. Implementing Z – squashing the MDP result matrix
          2. Implementing Z – squashing the vertex weights vector
        2. Finding the main target for the MDP function
      5. Circular DQN-CRLMM – a stream-like system that never starts nor ends
    5. Summary
    6. Questions
    7. Further reading
  19. AI and the Internet of Things (IoT)
    1. Technical requirements
    2. The Iotham City project
    3. Setting up the DQN-CRLMM model
      1. Training the CRLMM
        1. The dataset
        2. Training and testing the model
          1. Classifying the parking lots
    4. Adding an SVM function
      1. Motivation – using an SVM to increase safety levels
      2. Definition of a support vector machine
      3. Python function 
    5. Running the CRLMM
      1. Finding a parking space
      2. Deciding how to get to the parking lot
        1. Support vector machine
        2. The itinerary graph
        3. The weight vector
    6. Summary
    7. Questions
    8. Further reading
    9. References
  20. Optimizing Blockchains with AI
    1. Technical requirements
    2. Blockchain technology background 
      1. Mining bitcoins
      2. Using cryptocurrency 
      3. Using blockchains
        1. Using blockchains in the A-F network
          1. Creating a block
          2. Exploring the blocks
    3. Using naive Bayes in a blockchain process
      1. A naive Bayes example
        1. The blockchain anticipation novelty
        2. The goal
          1. Step 1 the dataset
          2. Step 2 frequency
          3. Step 3 likelihood
          4. Step 4 naive Bayes equation
    4. Implementation
      1. Gaussian naive Bayes
        1. The Python program
      2. Implementing your ideas
    5. Summary
    6. Questions
    7. Further reading
  21. Cognitive NLP Chatbots
    1. Technical requirements
    2. IBM Watson
      1. Intents
        1. Testing the subsets
      2. Entities
      3. Dialog flow
        1. Scripting and building up the model
      4. Adding services to a chatbot
    3. A cognitive chatbot service
      1. The case study
        1. A cognitive dataset
          1. Cognitive natural language processing
        2. Activating an image + word cognitive chat
        3. Solving the problem 
      2. Implementation
    4. Summary
    5. Questions
    6. Further reading
  22. Improve the Emotional Intelligence Deficiencies of Chatbots
    1. Technical requirements
    2. Building a mind 
      1. How to read this chapter
      2. The profiling scenario
    3. Restricted Boltzmann Machines
      1. The connections between visible and hidden units
      2. Energy-based models
        1. Gibbs random sampling
        2. Running the epochs and analyzing the results
    4. Sentiment analysis
      1. Parsing the datasets
    5. Conceptual representation learning meta-models
      1. Profiling with images
    6. RNN for data augmentation
      1. RNNs and LSTMs
        1. RNN, LSTM, and vanishing gradients
      2. Prediction as data augmentation
        1. Step1 – providing an input file
        2. Step 2 – running an RNN
        3. Step 3 – producing data augmentation
    7. Word embedding
      1. The Word2vec model
    8. Principal component analysis
      1. Intuitive explanation 
      2. Mathematical explanation
        1. Variance
        2. Covariance
        3. Eigenvalues and eigenvectors
        4. Creating the feature vector
        5. Deriving the dataset
        6. Summing it up
      3. TensorBoard Projector
        1. Using Jacobian matrices
    9. Summary
    10. Questions
    11. Further reading
  23. Quantum Computers That Think
    1. Technical requirements
    2. The rising power of quantum computers
      1. Quantum computer speed
      2. Defining a qubit
        1. Representing a qubit
      3. The position of a qubit 
        1. Radians, degrees, and rotations
        2. Bloch sphere
      4. Composing a quantum score
        1. Quantum gates with Quirk
        2. A quantum computer score with Quirk
        3. A quantum computer score with IBM Q
    3. A thinking quantum computer
      1. Representing our mind's concepts 
      2. Expanding MindX's conceptual representations
      3. Concepts in the mind-dataset of MindX
        1. Positive thinking
        2. Negative thinking
        3. Gaps
        4. Distances
      4. The embedding program
      5. The MindX experiment
        1. Preparing the data 
        2. Transformation Functions – the situation function
        3. Transformation functions – the quantum function
        4. Creating and running the score
        5. Using the output
        6. IBM Watson and scripts
    4. Summary
    5. Questions
    6. Further reading
  24. Answers to the Questions
    1. Chapter 1 – Become an Adaptive Thinker
    2. Chapter 2 – Think like a Machine
    3. Chapter 3 – Apply Machine Thinking to a Human Problem
    4. Chapter 4 – Become an Unconventional Innovator
    5. Chapter 5 – Manage the Power of Machine Learning and Deep Learning
    6. Chapter 6 – Don't Get Lost in Techniques, Focus on Optimizing Your Solutions
    7. Chapter 7 – When and How to Use Artificial Intelligence
    8. Chapter 8 – Revolutions Designed for Some Corporations and Disruptive Innovations for Small to Large Companies
    9. Chapter 9 – Getting Your Neurons to Work
    10. Chapter 10 – Applying Biomimicking to AI
    11. Chapter 11 – Conceptual Representation Learning
    12. Chapter 12 – Automated Planning and Scheduling
    13. Chapter 13 – AI and the Internet of Things
    14. Chapter 14 – Optimizing Blockchains with AI
    15. Chapter 15 – Cognitive NLP Chatbots
    16. Chapter 16 – Improve the Emotional Intelligence Deficiencies of Chatbots
    17. Chapter 17 – Quantum Computers That Think

Product information

  • Title: Artificial Intelligence By Example
  • Author(s): Denis Rothman
  • Release date: May 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781788990547