Leanpub Header

Skip to main content

Practical Python Artificial Intelligence Programming

Using Large Language Models, Deep Learning, Machine Learning, Symbolic AI, and Knowledge Representation

This book is 100% completeLast updated on 2026-06-27
+14,714 words in the last 30 days

A fun dive into AI programming with Python.

Minimum price

$8.00

$25.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
About

About

About the Book

This book is meant to be a quick 4 to 5 hour introduction to AI for Python programmers. If you have experience with Large Language Models, Deep Learning, general Machine Leaning and Symbolic AI then you can spend a couple of hours experimenting with the examples.

The author has been a general AI practitioner since 1982, developed neural network products and projects since 1986, and deep learning since 2015 and LLMs since 2022. He has written 20+ books and has 50+ US Patents.

Share this book

Author

About the Author

Mark Watson

Mark Watson is a consultant specializing in LLMs, deep learning, machine learning, knowledge graphs, and general artificial intelligence software development. He uses Common Lisp, Clojure, Python, Java, Haskell, and Ruby for development.

He is the author of 20+ published books on Artificial Intelligence, Deep Learning, Java, Ruby, Machine Learning, Common LISP, Clojure, JavaScript, Semantic Web, NLP, C++, Linux, and Scheme. He has 55 US Patents.

Mark's consulting customer list includes: Google, Capital One, Olive AI, CompassLabs, Disney, Sitescout.com, Embed.ly, and Webmind Corporation.

Mark wrote ten traditional published books for McGraw Hill, Springer Verlag, J Wiley, and Morgan Kaufman publishers before adopting the LeanPub self-publishing platform.

The Leanpub Podcast

Episode 253

An Interview with Mark Watson

Contents

Table of Contents

Cover Material, Copyright, and License

Preface

  1. About the Author
  2. Using the Example Code
  3. Book Cover
  4. Acknowledgements

Python Development Environment

  1. Managing Python with uv

Part 1 - Machine Learning

“Classic” Machine Learning

  1. Example Material
  2. Classification Models using Scikit-learn
  3. Classic Machine Learning Wrap-up
  4. Optional Practice Problems

Regression and Clustering

  1. Regression: Predicting Housing Prices
  2. Clustering: Discovering Groups in Data
  3. Regression and Clustering Wrap-up
  4. Optional Practice Problems

Exploratory Data Analysis and Feature Engineering

  1. Exploratory Data Analysis
  2. Feature Engineering
  3. EDA and Feature Engineering Wrap-up
  4. Optional Practice Problems

Anomaly Detection

  1. The Wisconsin Breast Cancer Dataset
  2. Data Preprocessing
  3. Approach 1: Gaussian Statistical Detector
  4. Approach 2: Isolation Forest
  5. Running the Example
  6. Interpreting the Results
  7. Anomaly Detection Wrap-up
  8. Optional Practice Problems

Part 2 - Deep Learning

The Basics of Deep Learning

  1. Using PyTorch for Building a Cancer Prediction Model
  2. Optional Practice Problems

Natural Language Processing Using Deep Learning

  1. Hugging Face and the Transformers Library
  2. Comparing Sentences for Similarity Using Transformer Models
  3. Deep Learning Natural Language Processing Wrap-up
  4. Optional Practice Problems

Part IV - Overviews of Image Generation, Reinforcement Learning, and Recommendation Systems

Overview of Image Generation

  1. Image Generation Using Stable Diffusion and PyTorch
  2. Image Generation Using Google’s Imagen API
  3. Mini-DALL·E: A Lightweight Alternative
  4. Recommended Reading for Image Generation
  5. Optional Practice Problems

Overview of Reinforcement Learning (Optional Material)

  1. Overview
  2. Available RL Tools
  3. An Introduction to Markov Decision Process
  4. A Concrete Example: Q-Learning with Gymnasium
  5. Reinforcement Learning Wrap-up
  6. Optional Practice Problems

Overview of Recommendation Systems (Optional Material)

  1. TensorFlow Recommenders
  2. Recommendation Systems Wrap-up

Part 3 - Large Language Models

Introduction to Transformers and Large Language Models

  1. The Transformer Architecture
  2. Tokenization
  3. From Transformers to Large Language Models
  4. Key Capabilities of Modern LLMs
  5. Practical Considerations

LLMs with Public APIs

  1. Setup and Authentication
  2. Text Generation
  3. Thinking Models
  4. Multi-Turn Conversations
  5. Multimodal Input: Analyzing Images
  6. Web Search with LLMs
  7. Structured Output
  8. Practical Considerations
  9. Summary
  10. Optional Practice Problems

LLMs with Local Models

  1. Installing Ollama
  2. Downloading and Running Models
  3. Using Ollama from Python
  4. Reasoning with Local Models
  5. Conversation Memory with Ollama
  6. Prompt Caching for Performance
  7. Image to Text Description (Vision Models)
  8. OpenAI-Compatible API
  9. Alternative Tools for Running Local Models
  10. Hardware Considerations
  11. Summary
  12. Optional Practice Problems

Text Adventure Game with an LLM Game Master

  1. How It Works
  2. The System Prompt
  3. The Game Engine
  4. Playing the Game
  5. Customizing Your Adventure
  6. Why This Matters
  7. Running the Example
  8. Summary

Part 4 - Symbolic AI and Knowledge Representation

Symbolic AI

  1. Comparison of Symbolic AI and Deep Learning
  2. Implementing Frame Data Structures in Python
  3. Use Predicate Logic by Calling Swi-Prolog
  4. Swi-Prolog and Python Deep Learning Interop
  5. Soar Cognitive Architecture
  6. Constraint Programming with MiniZinc and Python
  7. Good Old Fashioned Symbolic AI Wrap-up
  8. Optional Practice Problems

Expert Systems Using the Rete Algorithm

  1. 1. Rete Engine Architecture & Design
  2. 2. Implementing the Trickier Parts of Rete
  3. 3. Case Studies & Design Advice
  4. Wrap Up
  5. Optional Practice Problems

Part 5 - Knowledge Representation

Getting Setup To Use Graph and Relational Databases

  1. Querying Wikidata with SPARQL and Python
  2. The SQLite Relational Database for Knowledge Representation
  3. Optional Practice Problems

Optional Material: A Deeper Dive Into Semantic Web and Linked Data

  1. Overview and Theory

Open Knowledge Format (OKF) for Human-Agent Systems

  1. References & Inspiration
  2. What is Open Knowledge Format (OKF)?
  3. Sample Knowledge Bundle Structure
  4. Python Architecture: The OKF Explorer
  5. Example Output
  6. Wrap Up
  7. Optional Practice Problems

Also by the Author

Also by the Author

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub