Kick off your book project in 3 hours! Live workshop on Zoom. You’ll leave with a real book project, progress on your first chapter, and a clear plan to keep going. Saturday, May 16, 2026. Learn more…

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-05-13

A fun dive into AI programming with Python.

Minimum price

$7.99

$7.99

You pay

Author earns

$
PDF
EPUB
WEB
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.

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

Regression and Clustering

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

Exploratory Data Analysis and Feature Engineering

  1. Exploratory Data Analysis
  2. Feature Engineering
  3. EDA and Feature Engineering Wrap-up

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

Part 2 - Deep Learning

The Basics of Deep Learning

  1. Using PyTorch for Building a Cancer Prediction Model

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

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

Overview of Image Generation

  1. Image Generation Using Stable Diffusion and PyTorch
  2. Mini-DALL·E: A Lightweight Alternative
  3. Recommended Reading for Image Generation

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

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

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. OpenAI-Compatible API
  8. Alternative Tools for Running Local Models
  9. Hardware Considerations
  10. 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

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

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

  1. Overview and Theory

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.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

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