100% found this document useful (1 vote)
20 views

Artificial Intelligence Programming with Python From Zero to Hero 1st Edition Perry Xiao - Download the ebook now to never miss important content

The document provides information about various eBooks available for download on ebookmeta.com, focusing on topics such as Artificial Intelligence programming, Python for financial analysis, and Kubernetes security. It includes links to specific titles and details about the authors and their backgrounds. The document also outlines the structure of the book 'Artificial Intelligence Programming with Python' by Perry Xiao, including its chapters and additional resources available online.

Uploaded by

eblihkvant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
20 views

Artificial Intelligence Programming with Python From Zero to Hero 1st Edition Perry Xiao - Download the ebook now to never miss important content

The document provides information about various eBooks available for download on ebookmeta.com, focusing on topics such as Artificial Intelligence programming, Python for financial analysis, and Kubernetes security. It includes links to specific titles and details about the authors and their backgrounds. The document also outlines the structure of the book 'Artificial Intelligence Programming with Python' by Perry Xiao, including its chapters and additional resources available online.

Uploaded by

eblihkvant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 75

Read Anytime Anywhere Easy Ebook Downloads at ebookmeta.

com

Artificial Intelligence Programming with Python


From Zero to Hero 1st Edition Perry Xiao

https://ebookmeta.com/product/artificial-intelligence-
programming-with-python-from-zero-to-hero-1st-edition-perry-
xiao/

OR CLICK HERE

DOWLOAD EBOOK

Visit and Get More Ebook Downloads Instantly at https://ebookmeta.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Python For Financial Analysis From Zero to Hero 1st


Edition Van Der Post

https://ebookmeta.com/product/python-for-financial-analysis-from-zero-
to-hero-1st-edition-van-der-post/

ebookmeta.com

Kubernetes security Guide for beginners from zero to hero


1st Edition Ivan Piskunov

https://ebookmeta.com/product/kubernetes-security-guide-for-beginners-
from-zero-to-hero-1st-edition-ivan-piskunov/

ebookmeta.com

Python Games from Zero to Proficiency Beginner A step by


step guide to coding your first game with Python 1st
Edition Patrick Felicia
https://ebookmeta.com/product/python-games-from-zero-to-proficiency-
beginner-a-step-by-step-guide-to-coding-your-first-game-with-
python-1st-edition-patrick-felicia/
ebookmeta.com

C A BEGINNERS GUIDE TEACH YOURSELF 1st Edition David


Karlins

https://ebookmeta.com/product/c-a-beginners-guide-teach-yourself-1st-
edition-david-karlins/

ebookmeta.com
Painting for a Living in Tudor and Early Stuart England
1st Edition Robert Tittler

https://ebookmeta.com/product/painting-for-a-living-in-tudor-and-
early-stuart-england-1st-edition-robert-tittler/

ebookmeta.com

Building Real-Time Marvels with Laravel: Create Dynamic


and Interactive Web Applications 1st Edition Sivaraj
Selvaraj
https://ebookmeta.com/product/building-real-time-marvels-with-laravel-
create-dynamic-and-interactive-web-applications-1st-edition-sivaraj-
selvaraj/
ebookmeta.com

Entranced Guardian Academy 1 1st Edition Jessica Sorensen

https://ebookmeta.com/product/entranced-guardian-academy-1-1st-
edition-jessica-sorensen/

ebookmeta.com

Compatible Solutes Engineering for Crop Plants Facing


Climate Change 1st Edition Shabir Hussain Wani

https://ebookmeta.com/product/compatible-solutes-engineering-for-crop-
plants-facing-climate-change-1st-edition-shabir-hussain-wani/

ebookmeta.com

Island Encounters Timor Leste from the Outside In 1st


Edition Lisa Palmer

https://ebookmeta.com/product/island-encounters-timor-leste-from-the-
outside-in-1st-edition-lisa-palmer/

ebookmeta.com
Essential Interviewing: A Programmed Approach to Effective
Communication 9th Edition David R Evans

https://ebookmeta.com/product/essential-interviewing-a-programmed-
approach-to-effective-communication-9th-edition-david-r-evans/

ebookmeta.com
Artificial Intelligence
Programming with Python®
Artificial Intelligence
Programming with
Python®
From Zero to Hero

Perry Xiao
Copyright © 2022 by John Wiley & Sons, Inc. All rights reserved.

Published by John Wiley & Sons, Inc., Hoboken, New Jersey.

Published simultaneously in Canada.

ISBN: 978-­1-­119-­82086-­4
ISBN: 978-­1-­119-­82094-­9 (ebk)
ISBN: 978-­1-­119-­82096-­3 (ebk)

No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or
by any means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except as permitted
under Section 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission
of the Publisher, or authorization through payment of the appropriate per-­copy fee to the Copyright Clear-
ance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, (978) 750-­8400, fax (978) 750-­4470, or on the web
at www.copyright.com. Requests to the Publisher for permission should be addressed to the Permissions
Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-­6011, fax (201) 748-­6008,
or online at http://www.wiley.com/go/permission.

Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or war-
ranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all
warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be
created or extended by sales or promotional materials. The advice and strategies contained herein may not
be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in
rendering legal, accounting, or other professional services. If professional assistance is required, the services
of a competent professional person should be sought. Neither the publisher nor the author shall be liable for
damages arising herefrom. The fact that an organization or Website is referred to in this work as a citation
and/or a potential source of further information does not mean that the author or the publisher endorses
the information the organization or Website may provide or recommendations it may make. Further, readers
should be aware the Internet Websites listed in this work may have changed or disappeared between when
this work was written and when it is read.

For general information on our other products and services or for technical support, please contact our Cus-
tomer Care Department within the United States at (800) 762-­2974, outside the United States at (317) 572-­3993
or fax (317) 572-­4002.

Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may
not be available in electronic formats. For more information about Wiley products, visit our web site at
www.wiley.com.

Library of Congress Control Number: 2022931189

Trademarks: Wiley and the Wiley logo are trademarks or registered trademarks of John Wiley & Sons, Inc.
and/or its affiliates, in the United States and other countries, and may not be used without written permis-
sion. Python is a registered trademark of Python Software Foundation. All other trademarks are the property
of their respective owners. John Wiley & Sons, Inc. is not associated with any product or vendor mentioned
in this book.

Cover image: © ktsdesign/Adobe Stock Photos


Cover design: Wiley
This book is dedicated to my family. To my wife, May, my son, Zieger, and
my daughter, Jessica, who make my life complete—­without them, life
would be meaningless. To my parents and my brother, who have shared their
life and love with me that ultimately made me who I am today. To my friends
and colleagues, who supported me throughout my career.

I would also like to dedicate this book to Grace Qing Wang, who sadly
passed away during the course of writing this book. Grace Qing Wang was a
young, energetic professional woman who was passionate about innovation
and artificial intelligence in education. She was also a collaborator and a
good friend. Through Grace I have made many professional connections
that were very beneficial to my career.
About the Author

Dr. Perry Xiao is a professor and course director at the School of Engineering,
London South Bank University in London, United Kingdom. He got his BEng
degree in opto-­electronics, MSc degree in solid-­state physics, and PhD degree
in photophysics. He is a charted engineering (CEng), a Fellow (FIET) from
the Institution of Engineering and Technology (IET), and a Senior Fellow
(SFHEA) from the Higher Education Academy (HEA). He has been teaching
electronics, software, computer networks, and telecommunication subjects
at both the undergraduate level and the postgraduate level for nearly two
decades. He also supervises BEng final project students and MSc project
students every year. His main research interest is to develop novel infrared
and electronic sensing technologies for skin bioengineering applications and
industrial nondestructive testing (NDT). To date, he has finished more than
12 PhD student supervisions, obtained two UK patent applications, published
more than 100 scientific papers, been editorial reviewer for nine journals, and
generated nearly £1 million in research grants.
He is also a director and cofounder of Biox Systems Ltd., UK, a university
spin-­o ff company that designs and manufactures state-­o f-­t he-­a rt skin
measurement instruments, AquaFlux and Epsilon, which have been used in
more than 200 organizations worldwide, including leading cosmetic com-
panies, universities, research institutes, and hospitals.

vii
About the Technical Editors

Dr. Hongmei (Mary) He (FHEA, SIEEE) is an associate professor of cyber-


security in the School of Computer Science and Informatics at De Montfort
University. Previously, she was a lecturer in AI and cyber security at Cranfield
University. She received her PhD in computer science from Loughborough
University in the UK in 2006 and gained sustained experience as a postdoctoral
researcher at various universities. She has worked as an academic in the field
of computer science and engineering for many years and has brief industrial
experience at Motorola Design House in China as a senior embedded system
engineer. Her research can be briefly divided into four themes: AI and data
science, cognitive cybersecurity, cognitive robotics and trustworthy auton-
omous systems, and computing theory and optimization. Dr. He is a senior
member of IEEE in the Computational Intelligence, Cybersecurity, RAS, and
Women in Engineering Societies.

Dr. Weiheng Liao, DPhil (Oxon), is a computer scientist and technology entre-
preneur in AI. He has authored and co-­authored a number of influential papers
in top journals and conferences and is the visiting scholar of several research
universities. His interests include machine learning, AutoML, deep learning,
explainable AI, natural language processing, and their applications in finance
and investment. He cofounded YouShore, one of the world’s first teams to
employ deep NLP to analyze social media data, to extract alternative data, and
to construct alpha signals.
If you want to know more about his recent work, please visit w w w
.madebydata.com.

ix
Acknowledgments

I would like to express my sincere gratitude to Wiley Publishing for giving


me this opportunity. I would also like to thank Devon Lewis, Liz Britten, Pete
Gaughan, Dr. Weiheng Liao, and Hongmei He for their support. Without them,
this book would not have been possible.

xi
Contents at a Glance

Prefacexxiii
Part I Introduction
Chapter 1 Introduction to AI 3
Chapter 2 AI Development Tools 23
Part II Machine Learning and Deep Learning
Chapter 3 Machine Learning 53
Chapter 4 Deep Learning 117
Part III AI Applications
Chapter 5 Image Classification 201
Chapter 6 Face Detection and Face Recognition 265
Chapter 7 Object Detections and Image Segmentations 337
Chapter 8 Pose Detection 433
Chapter 9 GAN and Neural-­Style Transfer 465
Chapter 10 Natural Language Processing 491
Chapter 11 Data Analysis 543
Chapter 12 Advanced AI Computing 613
Index659

xiii
xiv Contents at a Glance

This book is accompanied by bonus content! The following extra elements


can be downloaded from www.wiley.com/go/aiwithpython:
■■ MATLAB for AI Cheat Sheets
■■ Python for AI Cheat Sheets
■■ Python Deep Learning Cheat Sheet
■■ Python Virtual Environment
■■ Jupyter Notebook, Google Colab, and Kaggle
Contents

Prefacexxiii
Part I Introduction
Chapter 1 Introduction to AI 3
1.1 What Is AI? 3
1.2 The History of AI 5
1.3 AI Hypes and AI Winters 9
1.4 The Types of AI 11
1.5 Edge AI and Cloud AI 12
1.6 Key Moments of AI 14
1.7 The State of AI 17
1.8 AI Resources 19
1.9 Summary 21
1.10 Chapter Review Questions 22
Chapter 2 AI Development Tools 23
2.1 AI Hardware Tools 23
2.2 AI Software Tools 24
2.3 Introduction to Python 27
2.4 Python Development Environments 30
2.4 Getting Started with Python 34
2.5 AI Datasets 45
2.6 Python AI Frameworks 47
2.7 Summary 49
2.8 Chapter Review Questions 50
Part II Machine Learning and Deep Learning
Chapter 3 Machine Learning 53
3.1 Introduction 53
3.2 Supervised Learning: Classifications 55

xv
xvi Contents

Scikit-­Learn Datasets 56
Support Vector Machines 56
Naive Bayes 67
Linear Discriminant Analysis 69
Principal Component Analysis 70
Decision Tree 73
Random Forest 76
K-­Nearest Neighbors 77
Neural Networks 78
3.3 Supervised Learning: Regressions 80
3.4 Unsupervised Learning 89
K-­means Clustering 89
3.5 Semi-­supervised Learning 91
3.6 Reinforcement Learning 93
Q-­Learning 95
3.7 Ensemble Learning 102
3.8 AutoML 106
3.9 PyCaret 109
3.10 LazyPredict 111
3.11 Summary 115
3.12 Chapter Review Questions 116
Chapter 4 Deep Learning 117
4.1 Introduction 117
4.2 Artificial Neural Networks 120
4.3 Convolutional Neural Networks 125
4.3.1 LeNet, AlexNet, GoogLeNet 129
4.3.2 VGG, ResNet, DenseNet, MobileNet,
EffecientNet, and YOLO 140
4.3.3 U-­Net 152
4.3.4 AutoEncoder 157
4.3.5 Siamese Neural Networks 161
4.3.6 Capsule Networks 163
4.3.7 CNN Layers Visualization 165
4.4 Recurrent Neural Networks 173
4.4.1 Vanilla RNNs 175
4.4.2 Long-­Short Term Memory 176
4.4.3 Natural Language Processing and Python
Natural Language Toolkit 183
4.5 Transformers 187
4.5.1 BERT and ALBERT 187
4.5.2 GPT-­3 189
4.5.3 Switch Transformers 190
4.6 Graph Neural Networks 191
4.6.1 SuperGLUE 192
4.7 Bayesian Neural Networks 192
Contents xvii

4.8 Meta Learning 195


4.9 Summary 197
4.10 Chapter Review Questions 197
Part III AI Applications
Chapter 5 Image Classification 201
5.1 Introduction 201
5.2 Classification with Pre-­trained Models 203
5.3 Classification with Custom Trained Models:
Transfer Learning 209
5.4 Cancer/Disease Detection 227
5.4.1 Skin Cancer Image Classification 227
5.4.2 Retinopathy Classification 229
5.4.3 Chest X-­Ray Classification 230
5.4.5 Brain Tumor MRI Image Classification 231
5.4.5 RSNA Intracranial Hemorrhage Detection 231
5.5 Federated Learning for Image Classification 232
5.6 Web-­Based Image Classification 233
5.6.1 Streamlit Image File Classification 234
5.6.2 Streamlit Webcam Image Classification 242
5.6.3 Streamlit from GitHub 248
5.6.4 Streamlit Deployment 249
5.7 Image Processing 250
5.7.1 Image Stitching 250
5.7.2 Image Inpainting 253
5.7.3 Image Coloring 255
5.7.4 Image Super Resolution 256
5.7.5 Gabor Filter 257
5.8 Summary 262
5.9 Chapter Review Questions 263
Chapter 6 Face Detection and Face Recognition 265
6.1 Introduction 265
6.2 Face Detection and Face Landmarks 266
6.3 Face Recognition 279
6.3.1 Face Recognition with Face_Recognition 279
6.3.2 Face Recognition with OpenCV 285
6.3.3 GUI-­Based Face Recognition System 288
Other GUI Development Libraries300
6.3.4 Google FaceNet 301
6.4 Age, Gender, and Emotion Detection 301
6.4.1 DeepFace 302
6.4.2 TCS-­HumAIn-­2019 305
6.5 Face Swap 309
6.5.1 Face_Recognition and OpenCV 310
6.5.2 Simple_Faceswap 315
6.5.3 DeepFaceLab 322
xviii Contents

6.6 Face Detection Web Apps 322


6.7 How to Defeat Face Recognition 334
6.8 Summary 335
6.9 Chapter Review Questions 336
Chapter 7 Object Detections and Image Segmentations 337
7.1 Introduction 337
R-­CNN Family 338
YOLO339
SSD340
7.2 Object Detections with Pretrained Models 341
7.2.1 Object Detection with OpenCV 341
7.2.2 Object Detection with YOLO 346
7.2.3 Object Detection with OpenCV and Deep Learning 351
7.2.4 Object Detection with TensorFlow, ImageAI, Mask RNN,
PixelLib, Gluon 354
TensorFlow Object Detection354
ImageAI Object Detection355
MaskRCNN Object Detection357
Gluon Object Detection363
7.2.5 Object Detection with Colab OpenCV 364
7.3 Object Detections with Custom Trained Models 369
7.3.1 OpenCV 369
Step 1369
Step 2369
Step 3369
Step 4370
Step 5371
7.3.2 YOLO 372
Step 1372
Step 2372
Step 3373
Step 4375
Step 5375
7.3.3 TensorFlow, Gluon, and ImageAI 376
TensorFlow376
Gluon376
ImageAI376
7.4 Object Tracking 377
7.4.1 Object Size and Distance Detection 377
7.4.2 Object Tracking with OpenCV 382
Single Object Tracking with OpenCV 382
Multiple Object Tracking with OpenCV384
7.4.2 Object Tracking with YOLOv4 and DeepSORT 386
7.4.3 Object Tracking with Gluon 389
Contents xix

7.5 Image Segmentation 389


7.5.1 Image Semantic Segmentation and Image Instance
Segmentation390
PexelLib390
Detectron2394
Gluon CV 394
7.5.2 K-­means Clustering Image Segmentation 394
7.5.3 Watershed Image Segmentation 396
7.6 Background Removal 405
7.6.1 Background Removal with OpenCV 405
7.6.2 Background Removal with PaddlePaddle 423
7.6.3 Background Removal with PixelLib 425
7.7 Depth Estimation 426
7.7.1 Depth Estimation from a Single Image 426
7.7.2 Depth Estimation from Stereo Images 428
7.8 Augmented Reality 430
7.9 Summary 431
7.10 Chapter Review Questions 431
Chapter 8 Pose Detection 433
8.1 Introduction 433
8.2 Hand Gesture Detection 434
8.2.1 OpenCV 434
8.2.2 TensorFlow.js 452
8.3 Sign Language Detection 453
8.4 Body Pose Detection 454
8.4.1 OpenPose 454
8.4.2 OpenCV 455
8.4.3 Gluon 455
8.4.4 PoseNet 456
8.4.5 ML5JS 457
8.4.6 MediaPipe 459
8.5 Human Activity Recognition 461
ActionAI461
Gluon Action Detection 461
Accelerometer Data HAR 461
8.6 Summary 464
8.7 Chapter Review Questions 464
Chapter 9 GAN and Neural-­Style Transfer 465
9.1 Introduction 465
9.2 Generative Adversarial Network 466
9.2.1 CycleGAN 467
9.2.2 StyleGAN 469
9.2.3 Pix2Pix 474
9.2.4 PULSE 475
9.2.5 Image Super-­Resolution 475
9.2.6 2D to 3D 478
xx Contents

9.3 Neural-­Style Transfer 479


9.4 Adversarial Machine Learning 484
9.5 Music Generation 486
9.6 Summary 489
9.7 Chapter Review Questions 489
Chapter 10 Natural Language Processing 491
10.1 Introduction 491
10.1.1 Natural Language Toolkit 492
10.1.2 spaCy 493
10.1.3 Gensim 493
10.1.4 TextBlob 494
10.2 Text Summarization 494
10.3 Text Sentiment Analysis 508
10.4 Text/Poem Generation 510
10.5.1 Text to Speech 515
10.5.2 Speech to Text 517
10.6 Machine Translation 522
10.7 Optical Character Recognition 523
10.8 QR Code 524
10.9 PDF and DOCX Files 527
10.10 Chatbots and Question Answering 530
10.10.1 ChatterBot 530
10.10.2 Transformers 532
10.10.3 J.A.R.V.I.S. 534
10.10.4 Chatbot Resources and Examples 540
10.11 Summary 541
10.12 Chapter Review Questions 542
Chapter 11 Data Analysis 543
11.1 Introduction 543
11.2 Regression 544
11.2.1 Linear Regression 545
11.2.2 Support Vector Regression 547
11.2.3 Partial Least Squares Regression 554
11.3 Time-­Series Analysis 563
11.3.1 Stock Price Data 563
11.3.2 Stock Price Prediction 565
Streamlit Stock Price Web App569
11.3.4 Seasonal Trend Analysis 573
11.3.5 Sound Analysis 576
11.4 Predictive Maintenance Analysis 580
11.5 Anomaly Detection and Fraud Detection 584
11.5.1 Numenta Anomaly Detection 584
11.5.2 Textile Defect Detection 584
11.5.3 Healthcare Fraud Detection 584
11.5.4 Santander Customer Transaction Prediction 584
Contents xxi

11.6 COVID-­19 Data Visualization and Analysis 585


11.7 KerasClassifier and KerasRegressor 588
11.7.1 KerasClassifier 589
11.7.2 KerasRegressor 593
11.8 SQL and NoSQL Databases 599
11.9 Immutable Database 608
11.9.1 Immudb 608
11.9.2 Amazon Quantum Ledger Database 609
11.10 Summary 610
11.11 Chapter Review Questions 610
Chapter 12 Advanced AI Computing 613
12.1 Introduction 613
12.2 AI with Graphics Processing Unit 614
12.3 AI with Tensor Processing Unit 618
12.4 AI with Intelligence Processing Unit 621
12.5 AI with Cloud Computing 622
12.5.1 Amazon AWS 623
12.5.2 Microsoft Azure 624
12.5.3 Google Cloud Platform 625
12.5.4 Comparison of AWS, Azure, and GCP 625
12.6 Web-­Based AI 629
12.6.1 Django 629
12.6.2 Flask 629
12.6.3 Streamlit 634
12.6.4 Other Libraries 634
12.7 Packaging the Code 635
Pyinstaller635
Nbconvert635
Py2Exe636
Py2app636
Auto-­Py-­To-­Exe 636
cx_Freeze637
Cython638
Kubernetes639
Docker642
PIP647
12.8 AI with Edge Computing 647
12.8.1 Google Coral 647
12.8.2 TinyML 648
12.8.3 Raspberry Pi 649
12.9 Create a Mobile AI App 651
12.10 Quantum AI 653
12.11 Summary 657
12.12 Chapter Review Questions 657
Index659
xxii Contents

This book is accompanied by bonus content! The following extra elements


can be downloaded from www.wiley.com/go/aiwithpython:
■■ MATLAB for AI Cheat Sheets
■■ Python for AI Cheat Sheets
■■ Python Deep Learning Cheat Sheet
■■ Python Virtual Environment
■■ Jupyter Notebook, Google Colab, and Kaggle
Preface

The year 2020 was a year of turmoil, conflicts, and division. The most significant
event was no doubt the COVID-­19 pandemic, which was, and still is, raging
in more than 200 countries and affecting the lives of hundreds of millions of
people. I spent a good part of the year working from home. There are many
disadvantages of remote working; however, it does have at least one advantage:
it saved me at least two hours a day traveling to and from work. This gave me
more time to think about, to plan, and to propose this book.
I am absolutely fascinated with artificial intelligence, and I have read many
artificial intelligence books. But most of the books are heavily focused on the
mathematics of artificial intelligence, which makes them difficult to understand
for people without mathematics or computer science backgrounds. I have
always wanted to write a book that could make it easier to get into the artificial
intelligence field for beginners—­people from all different disciplines. Thanks
to the countless researchers and developers around the world and their open
source code, particularly Python-­based open source code, it is much easier to
use artificial intelligence now than 10 years ago. Through this book, you will
find that you can do amazing things with just a few lines of code, and in some
cases, you don’t need to code at all.
I am a big fan of open source, and for a research field as controversial as
artificial intelligence, it is better for everyone to work together. So, I want to
express my ultimate gratitude to those who made their work available for
the benefit of others.
We are living in an era of digital revolutions and digital technologies such
as artificial intelligence, the Internet of Things, Industry 4.0, 5G technologies,
digital twin, cybersecurity, big data, cloud computing, blockchains, and, on the
horizon, quantum computing. They are all being developed at a breathtaking

xxiii
xxiv Preface

speed. In the future, the Internet of Things will provide a means to connect all
things around us and to use sensors to collect data. The industry version of the
Internet of Things is called Industry 4.0, which will connect all sorts of things for
manufacturers. Digital twin is a digital representation of a process, product, or
service updated from real-­time data. With digital twin, we can predict problems
before they even occur, prevent downtime, develop new opportunities for the
future through simulations. 5G technologies will provide a means for fast and
low-­latency communications for the data. Cybersecurity will provide a means
to protect the data. Big data will provide a means to analyze the data in large
quantity. Cloud computing will provide the storage, display, and analysis of
the data remotely, in the cloud. Blockchains will provide traceability to the data
through distributed ledgers. Quantum computing will make some of the com-
putation faster, in fact, many orders of magnitude faster. Artificial intelligence
will be right at the heart of all the technologies, which allows us to analyze the
data intelligently. As you can see, all these digital technologies are going to
become intertwined to make us work better and live smarter.
That is why I have always said to my students, you can change your future.
Your future is in your hands. The key is learning, even after graduation.
Learning is a lifelong mission. In today’s ever-­evolving world, with all the
quickly developing digital technologies, you need to constantly reinvent your-
self; you will need to learn everything and learn anything. The disadvantage
of fast-­changing technologies is that you will need to learn all the time, but
the advantage is no one has any more advantages than you; you are on the
same starting line as everyone else. The rest is up to you!
I believe artificial intelligence will be just a tool for everyone in the future,
just like software coding is today. Artificial intelligence will no doubt affect
every aspect of our lives and will fundamentally change the way we live, how
we work, and how we socialize. The more you know about artificial intelli-
gence and the more involved you are in artificial intelligence, the better you
can transform your life.
Many successful people are lifelong learners. American entrepreneur and
business magnate Elon Musk is a classic example. As the world’s richest man,
he learned many things by himself, from computer programming, Internet,
finance, to building cars and rockets. British comedian Lee Evans once said
that by the end of the day, if you have learned something new, then it is a good
day. I hope you will have a good day every day and enjoy reading this book!
Professor Perry Xiao
July 2021, London
Preface xxv

Why Buy This Book


Artificial intelligence (AI) is no doubt one of the hottest buzzwords at the
moment. AI has penetrated into many aspects of our lives. Knowing AI and
being able to use AI will bring enormous benefits to our work and lives.
However, learning AI is a daunting task for many people, largely due to the
complex mathematics and sophisticated coding behind it. This book aims to
demystify AI and teach readers about AI from scratch, by using plain language
and simple, illustrative code examples. It is divided into three parts.
In Part I, the book gives an easy-­to-­read introduction about AI, including
the history, the types of AI, the current status, and the possible future trends.
It then introduces AI development tools and Python, the most widely used
programming language for AI.
In Part II, the book introduces the machine learning and deep learning
aspects of AI. Machine learning topics include classifications, regressions,
and clustering. It also includes the most popular reinforcement learning.
Deep learning topics include convolutional neural networks (CNNs) and long
short-­term memory networks (LSTMs).
In Part III, the book introduces AI case studies; topics include image
classifications, transfer learning, recurrent neural networks, and the latest
generative adversarial networks. It also includes the state of the art of GPUs,
TPUs, cloud computing, and edge computing. This book is packed with inter-
esting and exciting examples such as pattern recognitions, image classifications,
face recognition (most controversial), age and gender detection, voice/speech
recognition, chatbot, natural language processing, translation, sentiment anal-
ysis, predictive maintenance, finance and stock price analysis, sales prediction,
customer segmentation, biomedical data analysis, and much more.

How This Book Is Organized


This book is divided into three parts. Part I introduces AI. Part II covers
machine learning and deep learning. Part III covers the case studies, or the
AI application projects. R&D developers as well as students will be inter-
ested in Part III.
Part I
Chapter 1: Introduction to AI
Chapter 2: AI Development Tools
xxvi Preface

Part II
Chapter 3: Machine Learning
Chapter 4: Deep Learning
Part III
Chapter 5: Image Classifications
Chapter 6: Face Detection and Recognition
Chapter 7: Object Detections and Image Segmentations
Chapter 8: Pose Detection
Chapter 9: GAN and Neural-­Style Transfer
Chapter 10: Natural Language Processing
Chapter 11: Data Analysis
Chapter 12: Advanced AI Computing

Example Code
All the example source code is available on the website that accompanies this
book.

Who This Book Is For


This book is intended for university/college students, as well as software and
electronic hobbyists, researchers, developers, and R&D engineers. It assumes
readers understand the basic concepts of computers and their main components
such as CPUs, RAM, hard drives, network interfaces, and so forth. Readers
should be able to use a computer competently, for example, can switch on and
off the computer, log in and log out, run some programs, copy/move/delete
files, and use terminal software such as Microsoft Windows command prompt.
It also assumes that readers have some basic programming experience,
ideally in Python, but it could also be in other languages such as Java, C/C++,
Fortran, MATLAB, C#, BASIC, R, and so on. Readers should know the basic syntax,
the different types of variables, standard inputs and outputs, the conditional
selections, and the loops and subroutines.
Finally, it assumes readers have a basic understanding of computer networks
and the Internet and are familiar with some of the most commonly used Inter-
net services such as the Web, email, file download/upload, online banking/
shopping, etc.
This book can be used as a core textbook as well as for background reading.
Preface xxvii

What This Book Is Not For


This book is not for readers to purely learn the Python programming language;
there are already a lot of good Python programming books on the market. How-
ever, to appeal to a wider audience, Chapter 2 provides a basic introduction to
Python and how to get started with Python programming, so even if you have
never programmed Python before, you can still use the book.
If you want to learn all the technical details of Python, please refer to the
following suggested prerequisite reading list and resources.

Suggested Prerequisite Readings


Computer Basics
Absolute Beginner’s Guide to Computer Basics (Absolute Beginner’s Guides
(Que)), 5th Edition, Michael Miller, QUE, 1 Sept. 2009.
ISBN-­10: 0789742535
ISBN-­13: 978-­0789742537
Computers for Beginners (Wikibooks)
https://en.wikibooks.org/wiki/Computers_for_Beginners
Python Programming
Python Crash Course (2nd Edition): A Hands-­On, Project-­Based Introduc-
tion to Programming, Eric Matthes, No Starch Press, 9 May 2019.
ISBN-­10 : 1593279280
ISBN-­13 : 978-­1593279288
Learn Python 3 the Hard Way: A Very Simple Introduction to the Terri-
fyingly Beautiful World of Computers and Code, 3rd Edition, Zed A.
Shaw, Addison-­Wesley Professional; 10 Oct. 2013.
ISBN-­10 : 0321884914
ISBN-­13 : 978-­0321884916
Head First Python 2e: A Brain-­Friendly Guide, 2nd Edition, Paul Barry,
O′Reilly; 16 Dec. 2016.
ISBN-­10 : 1491919531
ISBN-­13 : 978-­1491919538
Think Python: How to Think Like a Computer Scientist, 2nd Edition, Allen
B. Downey, O’Reilly, 25 Dec. 2015.
ISBN-­10 : 1491939362
ISBN-­13 : 978-­1491939369
xxviii Preface

Python Pocket Reference: Python in Your Pocket, 5th edition, Mark Lutz,
O’Reilly Media, 9 Feb. 2014.
ISBN-­10 : 1449357016
ISBN-­13 : 978-­1449357016
A Beginner’s Python Tutorial (Wikibooks)
https://en.wikibooks.org/wiki/A_Beginner%27s_Python_Tutorial
Python Programming (Wikibooks)
https://en.wikibooks.org/wiki/Python_Programming

Suggested Readings to Accompany the Book


Introduction to Machine Learning with Python: A Guide for Data Scien-
tists, Sarah Guido, O’Reilly Media; 25 May 2016.
ISBN-­10 : 1449369413
ISBN-­13 : 978-­1449369415
Hands-­on Machine Learning with Scikit-­Learn, Keras, and TensorFlow:
Concepts, Tools, and Techniques to Build Intelligent Systems, 2nd
Edition, Aurelien Geron, OReilly, 14 Oct. 2019.
ISBN-­10 : 1492032646
ISBN-­13 : 978-­1492032649
Deep Learning with Python, Francois Chollet, Manning Publications,
30 Nov. 2017.
ISBN-­10 : 9781617294433
ISBN-­13 : 978-­1617294433
Deep Learning (Adaptive Computation and Machine Learning Series),
Illustrated edition, Ian Goodfellow, MIT Press, 3 Jan. 2017
ISBN-­10 : 0262035618
ISBN-­13 : 978-­0262035613
Python Machine Learning: Machine Learning and Deep Learning with
Python, scikit-­learn, and TensorFlow 2, 3rd Edition, Sebastian Raschka,
Vahid Mirjalili, Packt Publishing, 12 Dec. 2019.
ISBN-­10 : 1789955750
ISBN-­13 : 978-­1789955750
Machine Learning Yearning (Andrew Ng’s free ebook)
https://www.deeplearning.ai/machine-­learning-­yearning/
Dive into Deep Learning (Free ebook)
https://d2l.ai/
Preface xxix

What You Need


In this book, you will need the following:
■■ A standard personal computer with a minimum 250 GB hard drive, 8 GB
RAM, and Intel or AMD 2 GHz processor, running a Windows operating
system (Vista/7/8/10, Internet Explorer 9 and above, or the latest Edge
browser, or Google Chrome) or a Linux operating system (such as Ubuntu
Linux 16.04 (or newer) and so on). You can also use a Mac (with Mac OS
X 10.13 and later, administrator privileges for installation, 64-­bit browser).
■■ Python software
https://www.python.org/downloads/

■■ Text editors and Python IDEs (see Chapter 2)


■■ Raspberry Pi (optional)
https://www.raspberrypi.org/

■■ Arduino NANO 33 BLE Sense (optional)


https://www.arduino.cc/en/Guide/NANO33BLESense

This book is accompanied by bonus content! The following extra


elements can be downloaded from www.wiley.com/go/aiwithpython:
■■ MATLAB for AI Cheat Sheets
■■ Python for AI Cheat Sheets
■■ Python Deep Learning Cheat Sheet
■■ Python Virtual Environment
■■ Jupyter Notebook, Google Colab, and Kaggle
Artificial Intelligence
Programming with Python®
Par t

I
Introduction

In This Part:
Chapter 1: Introduction to AI
Chapter 2: AI Development Tools
Part I gives a bird’s-­eye overview of artificial intelligence (AI) and AI development
resources.
CHAPTER

Introduction to AI
“There is no reason and no way that a human mind can keep up
with an artificial intelligence machine by 2035.”
—­Gray Scott (American futurist)

1.1 What Is AI?


1.2 The History of AI
1.3 AI Hypes and AI Winters
1.4 The Types of AI
1.5 Edge AI and Cloud AI
1.6 Key Moments of AI
1.7 The State of AI
1.8 AI Resources
1.9 Summary
1.10 Chapter Review Questions

1.1 What Is AI?


Artificial intelligence (AI) is no doubt one of the hottest buzzwords right now.
It is in the news all the time. So, what is AI, and why is it important? When you
talk about AI, the image that probably pops into most people’s heads is of a
human-­like robot that can do complicated, clever things, as shown in Figure 1.1.
AI is actually more than that.
AI is an area of computer science that aims to make machines do intelligent
things, that is, learn and solve problems, similar to the natural intelligence of
humans and animals. In AI, an intelligent agent receives information from the
environment, performs computations to decide what action to take in order to
achieve the goal, and takes actions autonomously. AI can improve its performance
with learning.

3
4 Part I ■ Introduction

For more information, see the John McCarthy’s 2004 paper titled, “What Is
Artificial Intelligence?”
https://homes.di.unimi.it/borghese/Teaching/AdvancedIntelligent­
Systems/Old/IntelligentSystems_2008_2009/Old/IntelligentSystems_
2005_2006/Documents/Symbolic/04_McCarthy_whatisai.pdf

Figure 1.1: The common perception of AI


(Source: https://commons.wikimedia.org/wiki/File:Artificial_
Intelligence_%26_AI_%26_Machine_Learning_-­_30212411048.jpg)

You may not be aware that AI has already been widely used in many aspects of
our lives. Personal assistants such as Amazon’s Alexa, iPhone’s Siri, Microsoft’s
Cortana, and Google Assistant all rely on AI to understand what you have said
and follow the instructions to perform tasks accordingly.
Online entertainment services such as Spotify and Netflix also rely on AI
to figure out what you might like and recommend songs and movies. Other
services such as Google, Facebook, Amazon, and eBay analyze your online
activities to deliver targeted advertisements. My wife once searched Arduino
boards at work during the day, and in the evening, after she got home, no matter
which websites she visited, ads for Arduino boards kept popping up!
Have you ever used the SwiftKey program on your phone or Grammarly on
your computer? They are also AI.
AI has also been used in healthcare, manufactoring, driverless cars, finance,
agriculture, and more. In a recent study, researchers from Google Health and
Imperial College London developed an algorithm that outperformed six human
Chapter 1 ■ Introduction to AI 5

radiologists in reading mammograms for breast cancer detection. Groupe Renault


is collaborating with Google Cloud to combine its AI and machine learning
capabilities with automotive industry expertise to increase efficiency, improve
production quality, and reduce the carbon footprint. Driverless cars use AI to
identify the roads, the pedestrians, and the traffic signs. The finance industry uses
AI to detect fraud and predict future growth. Agriculture is also turning to AI for
healthier crops, pest control, soil and growing conditions monitoring, and so on.
AI can affect our jobs. According to the BBC, 35 percent of today’s jobs will
disappear in the next 20 years. You can use the following BBC website to find
out how safe your workplace is:
https://www.bbc.co.uk/news/technology-­34066941

1.2 The History of AI


AI can be traced back to the 1940s, during World War II, when Alan Turing,
a British mathematician and computer scientist, developed a code-­breaking
machine called bombe in Bletchley Park, United Kingdom, that deciphered
German Enigma–encrypted messages (see Figure 1.2). The Hollywood movie
The Imitation Game (2014) has vividly captured this period of history. Turing’s
work helped the Allies to defeat the Nazis and is estimated to have shortened
the war by more than two years and saved more than 14 million lives.

Figure 1.2: The bombe machine (left) and the Enigma machine (right)
(Source: https://en.wikipedia.org/wiki/Cryptanalysis_of_the_Enigma)

In October 1950, while working at the University of Manchester, Turing pub-


lished a paper entitled “Computing Machinery and Intelligence” in the journal
Mind (Oxford University Press). In this paper, he proposed an experiment that
became known as the famous Turing test. The Turing test is often described as
a three-­person game called the imitation game, as illustrated in Figure 1.3, in
which player C, the interrogator, tries to determine which player—­A or B—­is a
6 Part I ■ Introduction

computer and which is a human. The interrogator is limited to using the responses
to written questions to make the determination. The Turing test has since been
used to test a machine’s intelligence to see if it is equivalent to a human. To
date, no computer has passed the Turing test.

Figure 1.3: The famous Turing test, also called the imitation game. Player C, the interrogator, is
trying to determine which player—­A or B—­is a computer and which is a human.

AI as a research discipline was established at a workshop at Dartmouth


College in 1956, organized by John McCarthy, a young assistant professor of
mathematics at the college (http://raysolomonoff.com/dartmouth/). The
workshop lasted about six to eight weeks, and it was essentially an extended
brainstorming session. There were about 11 mathematician attendees such as
Marvin Minsky, Allen Newell, Arthur Samuel, and Herbert Simon. They were
widely recognized as the founding fathers of AI. John McCarthy chose the term
artificial intelligence for the new research field.
The history of AI can be divided into three stages, as illustrated in Figure 1.4.
■■ 1950s–1970s, neural networks (NNs): During this period, neural networks,
also called artificial neural networks (ANNs), were developed based on
human brains that mimic the human biological neural networks. An NN
usually has three layers: an input layer, a hidden layer, and an output
layer. To use an NN, you need to train the NN with a large amount of
given data. After training, the NN can then be used to predict results for
unseen data. NNs attracted a lot of attention during this period. After the
1970s, when NNs failed to live up to their promises, known as AI hype,
funding and research activities were dramatically cut. This was called an
AI winter.
■■ 1980s–2010s, machine learning (ML): This is the period when machine
learning flourished. ML is a subset of AI and consists of a set of mathematical
Other documents randomly have
different content
January 13, 1748, coming gaily to Versailles and not in the least anticipating
any evil effect from the charming audacity of his verses, he found the Court
too hot to hold him. He dined in Paris that night at a coffee-house, with a
few other literary men. He arrived rather late. He had come straight from
Versailles, and alone of the company knew what had occurred there. He
made his dinner, after his frugal fashion, off seven or eight cups of black
coffee and a couple of rolls, and was very talkative and amusing. The
conversation turned on the newly imposed tax on playing-cards, and on
luxury. When the dinner was over other visitors at the coffee-house
gathered round him and “plied him with questions.”
He was not exiled. But he had committed an offence which made it
expedient to Go. He knew the Pompadour much too well to suppose she
would put her position in jeopardy by trying to save a friend, even if he
were a Voltaire. “Circumspection is all very well,” he had once written to
d’Argenson, “but it is a melancholy thing in poetry: to be reasonable and
cold is almost the same thing.” For his part, he would rather write even
compliments and madrigals as he chose, and be banished for them, than
remain at Court, tongue-tied and careful. If the Historiographership and the
Academy and the solemn joy of signing oneself Gentleman-in-Ordinary to
the King did not give one freedom, they were useless. Neither Voltaire nor
Émilie had seen Cirey for many months. On the whole, it was best to go.
They left Paris in the deep midwinter at nine o’clock on a January evening,
1748, with the snow thick on the ground and a temperature many degrees
below freezing-point.
CHAPTER XVIII

THE MARQUIS DE SAINT-LAMBERT

One of Madame du Châtelet’s idiosyncrasies was to travel only by night;


and another, to overload the travelling carriage with luggage. She insisted
on having her way in both particulars this time. It has been aptly said of
Voltaire that he was at once patient and hasty. He certainly must have been
patient to take the road with a woman whose packages frequently numbered
a hundred and who could never travel without her lady’s maid. That he
usually lost his temper on such journeys, is simply to say that he was
human.
On the present occasion, as they were nearing Nangis, the hind spring of
the carriage broke, and the overladen vehicle fell over on the side of
Voltaire. Madame du Châtelet, large and bony, the femme de chambre
(whose weight and figure history does not record), and a vast quantity of
bandboxes and parcels, came tumbling on the top of him. He relieved his
feelings by uttering “piercing shrieks.” Two footmen, by getting on the roof
of the overturned carriage and dragging their mistress, the lady’s maid, and
the bandboxes up through the doors “as from a well,” at last released M. de
Voltaire in the same manner. It was bitterly cold and a brilliant starlight
night. The two footmen, aided by the postillions, tried to set the carriage
straight again, and failed. One of the postillions rode on into the next village
for further assistance. And Voltaire and Émilie sat by the roadside on the
carriage cushions, and would have been “perfectly happy” shiveringly
studying astronomy, if they had only had a telescope. They were
philosophers, after all.
The carriage was mended at last. But it had not gone fifty paces before it
broke down again. The workmen, who considered Madame had underpaid
them, had to be brought back by force—and promises. At last the carriage
was able to proceed at a walking pace the nine miles to the Château of
Chapelle, where the travellers halted. They reached Cirey about the middle
of January, 1748, without further adventure.
The month they spent there was a gay one. Neither was anxious for too
many tête-à-têtes. The honeymoon had set for ever. When they were alone,
each wrote all day; in the evenings they read aloud together or played
trictrac. Émilie had an aggravating habit of keeping her Voltaire waiting till
supper was cold while she finished “a little calculation.” That her Voltaire,
himself orderly and punctual, was extremely vif at the delay need not be
doubted. Madame du Deffand had once said that he followed Émilie like a
faithful dog with the collar round his neck. Well, the dog was faithful still.
But the collar irked and worried him; and there were times when he
snapped at the hand that had put it there.
Madame de Champbonin reappeared on the scene very soon, with a
hoydenish twelve-year-old niece in her train. She had been very warmly
invited—if only to finish that solitude à deux. The whole neighbourhood
received invitations presently to act in, or to witness, theatricals. Émilie
wrote charades for the occasion. She played comic parts as well as any
other. Sometimes the servants were pressed into the cast and acted too. The
bonhomme would seem to have been conveniently absent, as usual. Voltaire
doubtless enjoyed the freedom of private life after the slavish etiquette of
the Court. He was certainly able to enjoy theatricals to his last breath.
About the middle of February he and Madame went to visit another
Court, at Lunéville, where the etiquette was not slavish at all, and where a
king was a great deal more anxious to have them than ever dull Louis had
been.
Stanislas, once King of Poland, had been not a little thankful to
exchange that quarrelsome and much quarrelled over kingdom for the
peaceful little duchy of Lorraine, the tranquil enjoyment of a pipe six feet
long and the dolce far niente of his lazy and easy-going mistress, Madame
de Boufflers. He still had the title of King. He still had a position—he was
the father of Marie Leczinska. His miniature Court had all the pleasures and
intrigues of a greater, with no weary formalism. Stanislas had his Jesuit,
Menou, to rule him just as other kings had their priests to rule them. The
priest fought the mistress for the command of the royal puppet, in the
approved, courtly fashion; and the mistress fought the priest, when she was
not too lazy.
The little Court was further ornamented by a child dwarf, who could
sleep in a sabot, and a most beautiful young guardsman, six feet high.
Following the example of Frederick, Stanislas was a feeble author
himself and a very enthusiastic admirer of the literary Voltaire. The literary
Voltaire was not sorry to show the offended Court of France that he stood
well with its offended Queen’s royal father. So the visitors and the visited
were gratified alike.
The visit was a gay one. “Issé” was played; and “Mérope,” when
everyone sobbed just as they had done in Paris. In the evenings they played
lansquenet or talked. It was an agreeable, idle life. Voltaire, ailing as usual,
was humoured and made much of by the King. Émilie overwhelmed the
inert and voluptuous Madame de Boufflers with her energetic friendship.
And then—
The Marquis de Saint-Lambert is one of the most picturesque figures of
his century. Poet and soldier, handsome, haughty and cold, with just enough
disdain in his perfect manner to make every woman adore him and long to
thaw that flawless ice—he had almost every quality which makes riches
superfluous. He was, in fact, nothing but the officer of a company of
Lorraine guards. He was much in Lunéville because he had, said the world,
a fancy for his King’s mistress, Madame de Boufflers. His own age
accounted him celebrated because he wrote the loveliest drawing-room
verses and was the author of a poem called “The Seasons”—much duller
than Thomson’s. The present age only knows him as the man who robbed
Rousseau of Madame d’Houdetot and Voltaire of Madame du Châtelet.
In 1738, when Madame de Graffigny, who was a friend of his, was at
Cirey, she had corresponded with him. He had much wished to be asked to
stay there. Since he knew how “to read and rest in his own room during the
day” and would only expect to be amused in the evenings, Madame du
Châtelet desired to have him for a visitor. But the plan, probably owing to
the rupture with Madame de Graffigny, had never been carried out.
Madame du Châtelet was now two-and-forty years old, and, on the
unanimous testimony of all her female friends, not at all beautiful. But that
inflammable temperament, which years before had made her fling honour
and prudence to the winds and give her heart and life to Voltaire, was hers
still. Age had not quenched the fire. Abstruse thought and long devotion to
the exact sciences had still left her, on one side of her nature, passionately a
woman. Voltaire had passed quickly and easily from love to friendship—but
not Émilie. Her jealousy of Frederick the Great was a proof that she loved
her lover as he had long ceased to love her. As early as 1741, in Brussels,
after his return from his second Prussian visit, she had bitterly reproached
him with no longer caring for her. He had replied to her in verses of which
the following give the keynote.

If you want me still to love


Give me back love’s golden morn;
To the twilight of my days
Join, forsooth, love’s happy dawn.

Even the sunrise touches night.


One hour is mine: and is no more.
We pass: the race which follows us,
Another follows: all is o’er.

In the year after he first met her, on the occasion of Richelieu’s marriage
to Mademoiselle de Guise, in April, 1734, he had written:

Love not too much: and so you may


Love alway.
For were it not the better far to be
Friends for eternity
Than lovers for a day?

He had always been honest at least. If he had been still lover indeed, it
might yet never have occurred to him that there could be cause for jealousy
of Émilie of two-and-forty and a young guardsman of one-and-thirty.
When did that wild passion begin? Did it begin in those idle, early days
of the Lunéville visit, gradually nourished by propinquity, that gay, easy
life, those lovely society verses, and the tantalising fact that Saint-Lambert
was a little bit in love with that stupid, lazy, self-indulgent de Boufflers? It
would have been an irresistible temptation to Émilie’s cleverness and
energy to win away such a man from such a woman.
But it seems more likely that she had no time for designs, that she fell
head over ears in love madly, recklessly, and at once—with that utter
abandon, all foolish and half pathetic, with which an old woman too often
loves a young man. Was it the handsome face and cold manner and heart
that attracted her? The whole eighteenth century found them attractive.
Saint-Lambert had so much, too, of that particularly vague quality called
taste! He liked being amused, though he found it too much trouble to be
amusing himself. And here was one of the cleverest women of her day, or of
any day, who could not be dull if she tried and wanted nothing better than to
entertain him. She was an invigorating change from the sleepy de Boufflers,
at any rate. He was not sorry, too, to obtain the cachet which would accrue
to him for having robbed a Voltaire.
But whether the passion on both sides was born full-grown, dominant,
and irresistible, or had slower roots in vanity and idleness, matters not. It
was soon an accomplished fact. Madame du Châtelet wrote her Saint-
Lambert the most mad, adoring letters on rose-coloured or sky-blue
notepaper with an edge of lace. She put the letters in Madame de
Boufflers’s harp in the salon. And when everyone had gone to bed, the
young guardsman came and found them there. He replied of course. If he
did not adore, he graciously submitted to be adored. “Come to me as soon
as you are up,” wrote the deluded woman. And sometimes, secretly
creeping round by the thickets of the garden, she would visit him. She
hardly thought her conduct required apology. She loved him. That was
enough. Or if it did, well then, for years Voltaire had been but her friend
when he should have been her lover. “I loved for both.” “I had reason to
complain and I forgave all.” She had tried to be satisfied with friendship:
but she could not. She wrote thus to d’Argental in a letter not devoid of
genuine feeling and even of pathos. She had some excuse. But she made the
common mistake of thinking that an excuse and a justification are the same
thing.
The Abbé Voisenon has recorded how once Madame du Châtelet, after, it
may be guessed, a quarrel with Voltaire, spoke of herself as entirely
alienated from him. The Abbé took down one of the eight volumes of
Voltaire’s manuscript letters to her and read some aloud. All his love letters
contained, says the Abbé, more epigrams against religion than madrigals for
his mistress. But when the reader stopped, Émilie’s eyes were wet. She was
not cured yet. A few years later, in 1749, her priestly friend tried the same
experiment. She listened unmoved. She was cured indeed: and the doctor
had been Saint-Lambert.
The Lunéville visit lasted from about February, 1748, until the end of
April. Then Madame du Châtelet left the Court, and returned to Cirey,
where she and Saint-Lambert may have spent a few blissful, uninterrupted
days together. Voltaire prolonged his visit to Stanislas a short time. By May
15th he and Madame du Châtelet were both once more at Cirey en route for
Paris.
During her stay at Lunéville the energetic Marquise had not only found a
lover, but obtained for her bonhomme the lucrative post of the Grand
Marshal of the Household to Stanislas, and a commission in the army for
her son.
But her thoughts were not with husband, son, or friend (as, she still
called her Voltaire), but with M. de Saint-Lambert. Wherever she was she
wrote to him continually—letters filled with passion, abandon, tenderness,
bitterness, doubt. He had purposed taking a journey in Italy, but renounced
it at her pleading. She thanked him with the melancholy effusion and the
humiliating gratitude of the woman who has obtained from her master a
sacrifice she knows to be unwilling. She and her unsuspecting Voltaire
came up to Paris. If she spent her time writing to her lover, Voltaire spent
his in superintending the rehearsals of his new tragedy “Semiramis.” One
day his versatility appeared in a new character, and he wrote a prologue for
his “Death of Cæsar” for a girls’ school that proposed to act it. It is
characteristic of the man that he adapted himself to this entirely new rôle
with the most perfect flexibility and thoroughness. The prologue’s chief
characteristics are its “ease and orthodoxy.” He wrote it leaning on a
mantelpiece, on the spur of the moment. He included a charming little letter
to the Sister Superior and even begged the prayers of that good lady on his
behalf!
On June 28th he and Madame du Châtelet left Paris for Commercy,
another seat of Stanislas, where that King then was.
Voltaire was ill and miserable and Madame a more impossible travelling
companion than ever. On their route, at Châlons-sur-Marne, she must needs
engage in the most vociferous, fatiguing dispute with the landlady of an inn
over a basin of soup.
Commercy was as gay as Lunéville. There were the inevitable operas
and comedies, and on July 14th Providence kindly arranged a total eclipse
of the sun to further amuse the little Court. One of its number had
astronomised ever so many years ago at Sceaux and at Villars: and had not
forgotten those times.
On August 26th he returned to Paris, leaving Madame du Châtelet
behind him. She did not complain of his neglect this time. King Stanislas
also came up to Paris to stay for a few days with his daughter, the Queen.
Voltaire arrived in the capital on the very day of the production of
“Semiramis”—probably August 29, 1748.
There had long been forming a cabal against the piece, headed by enemy
Piron and joined by most of the adherents of that dismal old playwright
Crébillon, who had himself written a clumsy “Semiramis” in 1717. Well,
conspiracy for conspiracy. What weapons you use against me, I have the
right to use against you. That was Voltaire’s theory now as ever. He met
cunning with cunning. He bought up half the seats in the house. He gave
them to persons who could be absolutely relied upon to clap and cry at the
right moments, and to drown all hisses with applause. Theriot helped him.
The d’Argental husband and wife had been already active on his behalf.
Voltaire too had boldly asked the patronage of King Louis and Madame de
Pompadour, and the King, in consideration of the piece having been
originally written for the late Dauphine, agreed to pay the expenses of
putting it on the stage. If the play but once had a hearing Voltaire believed
that no conspiracy could damn it.
The little scheme succeeded fairly well. M. de Voltaire’s friends wept
and applauded to perfection. But the first three acts were received by the
audience as a whole with only a very moderate warmth. And in the fourth,
the play was nearly ruined. It was then the custom in France for the
spectators to sit and walk about on the stage. During this fourth act, at a
scene at the tomb of Ninus, there were so many of them, that the too
enthusiastic player who took the part of the sentinel and was guarding the
tomb, called out: “Make way for the ghost, if you please, gentlemen. Make
way for the ghost!” which set the house in a roar. The playwright, to be
sure, had no reason to find the incident amusing. He complained to the
Lieutenant of Police, and in future performances of “Semiramis” the abuse
was corrected.
That first night, then, was by no means so decidedly successful as its
author had hoped.
On the second night, August 30th, M. de Voltaire, wanting to hear what
his friends as well as his enemies said of the piece behind his back,
disguised himself and went to the famous Café Procope, opposite the
Comédie Française, and largely frequented by literary and theatrical people.
He had been an amateur actor to some purpose, and understood the art of
make-up as well as any professional on the boards. With cassock and bands,
an old three-cornered hat, and an immense full-bottom unpowdered wig that
showed hardly anything of his face except the sharp end of his long, pointed
nose, he looked the part of an abbé to perfection. He put a breviary under
his arm; arrived at the café; possessed himself of a newspaper; chose a dark
corner; put on his spectacles, and read the paper over a modest repast of a
cup of tea and a roll. The café filled presently—journalists, actors, some of
the partisans of Crébillon and some of Voltaire—all fresh from the play and
all anxious to air their views thereon. That sensitive, thin-skinned, long-
nosed abbé in the corner had to exercise all his self-control to keep himself
from contradicting an enemy who criticised unjustly, or a friend who
praised foolishly. But he did it. The rôle pleased his sense of humour. And
one or two of his critics quoted some of his fine passages not amiss. He sat
there for an hour and a half, keenly attentive to the conversation. The result
as a whole was not unsatisfactory. The play would do.
It ran for fifteen nights in succession. When a month or so later a vile
parody appeared on it, Voltaire, supported by her father’s friendship, begged
Marie Leczinska to suppress that parody. But the Queen, remembering
Voltaire not as the man whose “Indiscret” and “Mariamne” had charmed her
youth, but as the imprudent friend of Madame de Pompadour, coldly
declined to interfere. The Pompadour herself could do little. But the parody
did not much harm the original after all. On October 24, 1784, “Semiramis”
was performed at Fontainebleau and well received. The play is still of
interest to English people—not for itself, but for the “Advertisement” which
precedes it: and which contains the most famous and the most adverse
criticism upon Shakespeare in the world. He was “a drunken savage”; and
“Hamlet” “a coarse and barbarous piece which would not be endured by the
dregs of the people in France or Italy.” In his head “Nature delighted to
bring together the noblest imagination with the heaviest grossness.” This
was Voltaire’s most remarkable word on the great Englishman. But it was
not his last.
Before “Semiramis” was performed at Court Voltaire had returned to
Lunéville. The excitements of Paris had been too much for him. From being
always ailing, he was now really ill. Longchamp was his travelling
companion. By the time they reached that unlucky Châlons, on September
12th, Voltaire was in a high fever and compelled to take to his bed in a
wretched post-house. Longchamp, seeing that his condition was critical
(Voltaire never gave in to illness until he could neither stand nor speak),
told the bishop and intendant of the place. They hastened to the patient and
offered him hospitality, which he declined; and then they sent him a doctor.
He listened to the professional advice very patiently. Long ago, at Cirey,
Madame de Graffigny had noted his good humour and politeness in
sickness: and recorded how he was grateful even for advice and prayers!
His gratitude for advice fortunately did not extend to following it. On the
present occasion he heard meekly and replied laconically when he was told
he must be bled and swallow various violent and nauseous mixtures. But he
was not bled and he did not take the medicines. Temperance and exercise in
health, and abstinence and rest in illness, were the main principles of the
system which he followed all his life. That with a wretched constitution and
a fatal habit of taking too little sleep and doing far too much brain-work, he
lived to be eighty-four at a period when the threescore years and ten of the
Psalmist were accounted very old age, is a proof that his régime was not
wholly a mistaken one.
On the present occasion he was so ill that he thought himself dying. But
he still read and still dictated letters to Longchamp; though he was so weak
he could only sign himself “V.” After a few days on a self-imposed diet of
tea, toast, and barleywater, the fever left him. He was far too feeble to stand.
But he made Longchamp wrap him up in his dressing-gown and carry him
into the post-chaise, in which they proceeded towards Lunéville. He was
still so ill that he travelled thirty miles without uttering a single word.
Before this, unknown to him, Longchamp, who was very sincerely attached
to him, had written to tell Madame du Châtelet and Madame Denis of his
condition. Once, Émilie would have hastened to him, and half killed him
with her vigorous, overwhelming affection and attentions. It was as well for
his health that she was quite engrossed with her lover at Lunéville and
simply sent a courier with a message.
That message cheered the sick man a little. If he was but her friend, he
was her very faithful friend. And friendship meant much more to Voltaire
than to most people.
He was better by the time he reached Lunéville. The urgent desire to get
well as soon as possible, on that old principle that illness was a kind of
degradation, may have helped his recovery.
Madame du Châtelet insisted upon his being cheerful because she felt so
herself. He was soon fairly well again, and that miserable journey faded
into a bad dream.
In the early part of the October of 1748, Stanislas, and his little Court
with him, moved again to Commercy. The guilty loves of Madame du
Châtelet and Saint-Lambert were still not even suspected by Voltaire. The
guardsman, who soon resigned his commission to become Grand Master of
Stanislas’s Royal Wardrobe, seems to have been not a little embarrassed by
the vehemence of Émilie’s passion. But in exact proportion as he was cold,
she was ardent. His letters to her have not survived; but from hers to him it
is evident that while she was imprudent, headlong, and reckless, he was at
least cool enough to see danger and discourage the maddest of her schemes.
The discovery of their secret was of course only a matter of time. One
night early in that October of 1748 at Commercy, Voltaire walked into
Madame du Châtelet’s apartments, unannounced as his habit was, and there
in a little room at the end of the suite, lighted by only one candle, he found
the handsome young soldier and his clever, foolish, elderly mistress
“talking upon something besides poetry and philosophy.”
CHAPTER XIX

THE DEATH OF MADAME DU CHÂTELET

If the invasion of Silesia by King Anti-Machiavelli-Frederick-the-Great had


given Voltaire a moral shock difficult to recover from, he experienced a
shock far greater in degree and kind now.
He had been slow to see anything. But when he did see, he saw all. He
broke into the most passionate and violent reproaches. The lofty Saint-
Lambert responded that no one had the right to criticise his conduct, and
that if M. de Voltaire did not like it, he had better leave the château. The
remark irritated Voltaire to a frenzy. Émilie stood by, nonplussed for once in
her life, not at all ashamed, but in very considerable difficulty. One can
fancy the half dark study, the abominably aggravating coolness of Saint-
Lambert, and the inarticulate fury of Voltaire. He flung himself out of the
room in one of the greatest passions of his life. He called Longchamp, said
that he must beg, borrow, or steal a post-chaise, and make ready to start for
Paris that very night. The artful valet went straight to Madame du Châtelet
for an explanation. “No post-chaise is to be found on any consideration,”
said Émilie. An outcry would ruin her reputation. (It is inconceivable, but
true, that Madame du Châtelet considered her reputation as yet
immaculate.) At two o’clock in the morning Longchamp came to his
master’s rooms and announced that a post-chaise was an impossibility. Then
ride to Nancy at daybreak and get one! M. de Voltaire’s passion had not yet
spent its force. He went to bed. And Longchamp crept down again to
Madame du Châtelet. That marvellous woman was writing at her desk, and
announced the extraordinary intention of going to see M. de Voltaire
herself, then and there, and bring him to reason.
She did it. She took a seat on the end of his bed. She spoke to him in
English, that old language of their quarrels and love, and by a tender name,
long disused. Longchamp lit a couple of candles and retired—to listen to
the conversation through the wall. It was the most marvellous conversation
in the world. They spoke in French now. Émilie tried to excuse herself—
somehow. The lean, furious, exhausted, unhappy man in bed started up.
“Believe you!” he cried. “Now! I have sacrificed health and fortune for
you, and you have deceived me.”
And Émilie proceeded to explain with a perfect plainness of speech that
Voltaire had long ceased to love her as a lover, and that since she must love
someone, he should be pleased that her choice had fallen on a mutual
friend, like M. de Saint-Lambert.
How the piercing eyes in the thin face on the pillow must have looked
her through and through! Voltaire answered with a very fine irony:
“Madame, you are always right; but if things must be so, do not let me see
them.”
Before she left him, she embraced him. She had succeeded in her aim so
far that he was calmer.
The rest of the night the energetic woman spent in appeasing Saint-
Lambert, who considered Voltaire had insulted him.
Voltaire was ill in bed the next day. It must be allowed he had an excuse
for illness this time. And behold, as the evening drew in, the young Marquis
comes in person to make inquiries after the invalid’s health, and the invalid
admits him. Saint-Lambert makes very handsome apologies for the hasty
words which had escaped him in a moment of agitation. Voltaire takes him
by both hands and embraces him. “Mon enfant, I have forgotten all. It was I
who was wrong. You are at the happy age of love and pleasure. Make the
most of both.”
The very next day the three met at supper at Madame de Boufflers’s, and
all enjoyed themselves immensely. All idea of the post-chaise and Paris was
dismissed. Did Voltaire recall that gay episode of his youth when he and de
Génonville had shared the smiles of Mademoiselle de Livri?
In 1749, he actually wrote Saint-Lambert a beautiful gallant poem on the
event which had for the time being so much disturbed his peace:

Saint-Lambert, it is all for thee


The flower grows:
The rose’s thorns are but for me:
For thee, the rose—

and went on to say in flowing couplets how the “astronomic, Émilie” had
renounced mathematics and inky fingers for those “beautiful airs which
Love repeats and Newton never knew.”
By October 17th, the ex-lover, the lover, and the mistress had returned to
Lunéville with Stanislas’s Court (of which Voltaire justly complained as
being “a little ambulant”) on terms of perfect amity. The whole episode had
occupied only a few days. And presently Voltaire was once more engrossed
heart and soul in his “History of Louis XV.”
The explanation of his conduct lies, as ever, in character.
He was angry at first because he had an uncommonly quick temper and a
great provocation. But he was always a philosopher as he grew calmer. It
was a very bad world. That was his lifelong conviction. So much the more
reason to make the best of it! He had lost a selfish, irritating, and exigeante
mistress. But there was no reason why he should not keep a clever woman
for a friend. Émilie had, after all, but acted on a principle which was his as
well as hers; that, in the relation of the sexes, when duty ceases to be a
pleasure, it ceases to be a duty also. (It is but just to Voltaire and to Madame
du Châtelet to say that they did not carry this remarkable theory, not yet out
of vogue, into any other department of morals.)
The age looked upon such irregularities simply as subjects for a jest or
an epigram. And every man sees in some degree with the eyes of the time in
which he lives.
So Voltaire wrote “Louis XV.” The pain passed, as sharp pains are apt to
do, quickly. He and Madame du Châtelet, unaccompanied by Saint-
Lambert, left Lunéville for Cirey about December 20, 1748. The journey
was very like a hundred they had made in old times. At that fatal Châlons,
Émilie would call on the bishop and keep the post-horses waiting the whole
day while she played cards, and Voltaire lost his temper with her just as if
he had been her lover still. Once at Cirey, he was engrossed in hard work,
and she wrote a preface to her Newton when she was not writing love
letters to Saint-Lambert. Her infidelity would hardly have altered the course
of her life were it not for that rigorous law that “every sin creates its own
punishment.”
The events that followed are such as are best passed over in the fewest
words possible. In this December of 1748 at Cirey, Madame du Châtelet
found that she was again to be a mother. Saint-Lambert was summoned. He,
Voltaire, and the unhappy woman consulted together on what course they
would take. Émilie was in tears at first; and they all ended in laughter. They
decided on a daring comedy. The Marquis—that simple bonhomme—was
summoned home, fêted, caressed—and deceived. It is sufficient to say that
he was delighted with his wife’s prospects, and thought he had reason to be
so delighted. He left Cirey, spreading the good news abroad. And Madame
du Châtelet complacently considered that her reputation was saved.
Nothing damns the eighteenth century deeper than the fact that this
loathsome story was its darling anecdote; and that his criminal connection
with Madame du Châtelet, and the sinister events which were its
consequence, made Saint-Lambert the very height of fashion. Every
memoir of the period has the tale in detail. Longchamp gloats over it. The
fine ladies of Paris made mots upon it, of which in our day a decent bargee
would be ashamed. If the French Revolution immolated some of the very
persons who brought it about, was the injustice so gross? A Voltaire shared
the vices of the social conditions he condemned, and was himself in some
sort a part of that system which set itself above decency and duty and which
he knew to be fatal to the good of mankind.
He came out of this unclean comedy less smirched than the other actors
therein. But that is to say very little. To be a part of it at all was defilement
enough.
By February 17th of the new year 1749 Voltaire and Émilie were
installed in the Rue Traversière-Saint-Honoré in Paris.
The bonhomme had rejoined his regiment. Saint-Lambert was in
attendance at Lunéville.
Voltaire had written a “Panegyric of Louis XV.” which was to be recited
to his Majesty by Richelieu when the Academy went in a body on February
21st to offer their congratulations to the King upon the establishment of
peace. But, as so often happened with Voltaire’s writings, the thing had
become public too soon. Friend Richelieu, enraged at hearing his recitation
being murmured and quoted by the courtiers about him, would not recite it
at all. Voltaire was not present on the occasion. When he heard what
Richelieu had done, he flung his old friend’s portrait into the fire in a rage.
March 10th saw a brief revival of “Semiramis”: but all the same it was
the fashion just now to prefer Crébillon and his “Catilina.”
On May 27th, Voltaire obtained the privilege of selling his useless post
of Gentleman-in-Ordinary, while he was allowed to retain its title. But
privilege or no privilege, he did not stand well at Court. King Stanislas had
written a work called the “Christian Philosopher”: in which his good
daughter, Queen Marie Leczinska, saw, disapprovingly, the freethinking
influence of Voltaire. He still courted Madame de Pompadour; but no
Pompadour ever yet imperilled her own position for any friend in the world.
Another king and court were, indeed, particularly anxious that Voltaire
should return to them, but Voltaire refused Frederick’s invitation firmly. He
was really ill, as he said. But there was another reason. He had resolved not
to leave Madame du Châtelet until the dark hour that was coming upon her
had passed.
They fell, even in Paris, into their old habit of hard work. Émilie worked
to kill thought, to stifle a dreadful foreboding which was with her always.
She studied mathematics with Clairaut, who had once visited Cirey and was
“one of the best geometricians in the universe.” She shut herself up with
him for hours and hours, resolving problems. She plunged into all kinds of
gaiety. Her letters to Saint-Lambert are the letters of a very unhappy woman
—tortured with jealousy and doubts, exigeante, fearful, unquiet. He was
true to her—and cold. She tried to thaw his ice at the fire of her own
passion. “I do not even love Newton,” she wrote; “only you. But it is a
point of honour with me to finish my work.”
One day, she and Clairaut were so engrossed in their labours, that
Voltaire, whose philosophy never could endure being kept waiting for
meals, bounded up from the supper-table, ran upstairs “four steps at a time,”
found the door locked, and smashed it in with his foot in a rage. “Are you in
league to kill me?” he cried as he went down again, followed by the too-
zealous mathematicians, who had the grace to be ashamed of themselves.
There was a very cross, silent supper à trois. The next morning Madame du
Châtelet, feeling she owed her friend a reparation, suggested that she should
take her morning coffee in his rooms. She did so, out of a priceless
porcelain cup and saucer, which Voltaire, whose temper was still rather
irritable, broke by a clumsy movement. Madame reproached him sharply.
He retaliated. He grumbled a good deal at the exorbitant sum he had to pay
to replace the bric-à-brac. Both he and Émilie were at the end of their
tether. Yet they were good to each other. Émilie felt she owed Voltaire much
for his pardon, and his reasonableness. And Voltaire never appears even to
have thought that her faithlessness as his mistress could exonerate him from
fidelity to her as his friend. He knew that she was unhappy. Compassion
was in his nature. It is that quality which made him to the last hour of his
life, in spite of his gibes and cynicisms, something more than commonly
lovable.
In April, Stanislas had come up for a fortnight to the French Court. The
unhappy Marquise had then been able to make arrangements for a future
sojourn at Lunéville, of great importance to her: and of which she wrote,
eagerly and feverishly, to Saint-Lambert.
Voltaire was now writing a play, “Nanine”—founded on Richardson’s
“Pamela.” When it was produced on June 16, 1749, he had followed his old
plan of filling the house as much as possible with his friends. There were a
few spectators in the gallery, however, who would talk aloud. The nervous
and sensitive author could by no means endure that. Up he got on to his
feet. “Silence, you boors, silence!” he cried; and silent they were. Whenever
he saw his own plays he found it impossible to contain himself. He not only
trained the actors beforehand; but he must lead the laughter and the tears of
the parterre at the performance. And, to be sure, if there is anyone who
should know where a play is pathetic and where it is comic, it is the man
who wrote it.
He and Émilie were in Paris from February until the end of June.
Frederick repeated his invitation warmly. “You are not a sage-femme after
all,” he wrote to Voltaire scornfully, “and Madame will get on very well
without you.” Any sarcasm penetrated Voltaire’s thin skin. But he replied
gravely, “Not even Frederick the Great can now prevent me fulfilling a duty
I believe to be indispensable. I am neither doctor nor nurse, but I am a
friend and will not leave, even for your Majesty, a woman who may die in
September.”
He was true to his word. Late in June, while “Nanine” was still running,
he and Madame du Châtelet went to Cirey at her urgent desire. When they
were there, the most versatile of human creatures, the author of the
“Pucelle” and the prim prologue for a girls’ school, wrote at her request a
eulogy of Saint-Louis, and a very good eulogy too, for an abbé who had to
deliver one before the Academy and could by no means compose it himself.
It was at Émilie’s desire, too, that they left Cirey, after only a fortnight’s
stay there—“these delightful rooms, books and liberty, to go and play at
comets” at Lunéville. A few days at Commercy had preceded their stay at
Lunéville, which they reached on July 21, 1749. It was there that Madame
would find Saint-Lambert. It was there that the event which she dreaded
more every day was to take place. Voltaire was not only sick to death of that
wearisome mockery of astronomy with which Stanislas’s little Court was
still amusing itself, but was further annoyed by being very uncomfortable
and ill-attended to in his rooms, in which he shut himself up as much as he
could. He bore the discomfort—not at all in silence indeed—but he bore it.
A quarrel on the subject with Alliot, who was commissioner-general of
the household of Stanislas, and a very economical commissioner too, burst
out on August 29th, and Voltaire relieved his feelings in some vif little
notes: one of which he addressed to the King himself, and besought his
Majesty to remedy the defects in the meals, lighting, and firing supplied to
his guest. Émilie, who had so urgent a reason for remaining at Lunéville,
did her clever best to soothe her ami. He was soothed apparently.
Meanwhile the little Court went its usual way. Madame de Boufflers was
her smiling, easy self—that dame de volupté “who,” as she said in her
epitaph, “for greater security, made her Paradise in this world.” There were
also the austerer, priestly influences trying to gain Stanislas. Poetry was a
fashion among the guests and the courtiers, as also the inevitable play-
acting. Saint-Lambert was still at work on that lengthy poem, “The
Seasons.” The summer was waning. Émilie plunged into every excess of
gaiety, and every excess of work. She forgot that she was three-and-forty,
not three-and-twenty. To forget everything—that was her aim—to have no
time to think of past or future. His duties often called Saint-Lambert away
to Nancy, and when he was absent the wretched woman endured torments
of loneliness, helplessness, and foreboding. He reassured her when he was
there. He was always so calm! As September drew near she sent for
Mademoiselle du Thil from Paris, that ill-advised friend of hers, once her
lady-companion, who on one memorable occasion had lent her money—to
lose at the Queen’s table. The bonhomme appeared on the scene. Voltaire
was writing constant letters to his friends, anticipating the coming event
gaily. Madame had a herculean constitution. All would be well! She was
still constantly at her desk. She employed many hours in doing up her
manuscripts and letters in parcels, and giving Longchamp directions as to
the persons who were to receive them—if—if——. It was a point of honour
with her, as she had said, to finish Newton. On August 30, 1749, she wrote
her last letter to Saint-Lambert. “I am wretched to a degree which would
frighten me if I believed in presentiments,” she said.
On September 4th, Voltaire was writing delightedly to announce the
birth of a little girl and the well-being of the mother. The infant was sent
straight into the village to be nursed, and in the stress of the painful events
which followed, died almost unnoticed. Madame du Châtelet progressed
favourably. The little Court was in the highest spirits and spent most of its
time in her room. On September 9th, the weather being exceedingly hot, the
patient asked for an iced drink. It was given her and she was seized with
convulsions.
Stanislas’s physician hastened to her and for the moment she seemed
better. The next day, September 10th, the convulsions returned: and two
doctors from Nancy were called in. The Marquise again appeared better. In
the evening Voltaire and the Marquis du Châtelet went down to supper with
Madame de Boufflers—still not the least anticipating any danger.
Longchamp, Saint-Lambert, and Mademoiselle du Thil were left in the
room with the sick woman. Eight or ten minutes later, they heard a rattle in
her throat. They did what they could. Mademoiselle hastened downstairs to
tell Voltaire and the Marquis. The horrified supper-party hurried to the
bedroom and a scene of dreadful confusion ensued. Madame du Châtelet
was already quite unconscious. No one had time to think “of priest, of
Jesuit, or of Sacrament.” But the Marquise was past their help. “She knew
none of the horrors of death,” wrote Voltaire. “It was her friends who felt
those.”
His own anguish of spirit, when the dreadful truth was borne in upon
him, rendered him beside himself. He and Saint-Lambert remained by the
bed awhile. And then Voltaire, who had loved his mistress longer and better
than his supplanter, dragged himself away, blind and dull with misery. He
stumbled at the foot of the staircase without, and when Saint-Lambert, who
had followed, would have helped him, Voltaire turned upon him with a
bitter reproach. Its terms are so unrepeatable that the eighteenth century
repeated them ad nauseam: and the twentieth may as well forget them if it
can.
The brief remainder of that fatal day Voltaire spent in writing the bitter
news to his friends.
If any proof be needed of the vehemence and sincerity of his feeling for
the dead woman, those letters give it.
The next day Madame de Boufflers took from the Marquise’s ring a
portrait of Saint-Lambert and bade Longchamp give the ring to the Marquis
du Châtelet. A little later Voltaire asked Longchamp for the ring in question.
Thirteen years before, he had given Émilie his own portrait for it, with these
lines,

Bavier ’graved this likeness for you.


Recognise it, and his art.
As for me, a greater Master
Has engraved you—on my heart.

His portrait had displaced one of the Duke of Richelieu’s—and now his,
in its turn, had made way for Saint-Lambert’s.
Voltaire might well turn away saying that all women are alike; and trying
to comfort himself with the antique and barren reflection that, after all, it
was the way of the world.
Among Madame du Châtelet’s effects was a large parcel of letters. She
left a memorandum to beg her complaisant husband to burn them unread.
“They can be of no use to him and have nothing to do with his affairs.” He
did so, on his brother’s prudent advice. But Longchamp observed him make
a very wry face at certain ones of which, being uppermost, he caught sight.
The cautious valet rescued from the flames the whole of Voltaire’s “Treatise
on Metaphysics” and some letters, afterwards also burnt. Among the
destroyed manuscripts were historical notes of Voltaire’s, of which he
deplores the loss in his preface to his “Essay on the Manners and Mind of
Nations.” It has been thought, but it is not certain, that the whole of his
eight volumes of letters to Madame du Châtelet also perished in this
conflagration. If they did not, a new Voltaire, a new world, rich in human
interest, as no doubt in wit and philosophy, still remains to be discovered by
some literary Columbus. At present, of all the letters he wrote to her, the
human being with whom he was most intimate and who shared the deepest
secrets of his soul and the highest aspirations of his genius, there can be
found but one gay little note.
Madame du Châtelet was buried with all honour at Lunéville. Paris had
already flayed her dead body with epigrams. She had not been too immoral
for its taste. That was impossible. But she had been far too clever. One
indignant person said that it was to be hoped the cause of her death would
be the last of her airs. “To die in childbed at her age is to wish to make
oneself peculiar: it is to pretend to do nothing like other people.” Frederick
the Great wrote her epitaph. “Here lies she who lost her life in giving birth
to an unfortunate infant and a treatise on philosophy.” Maupertuis and
Marmontel spoke of her in terms of warm admiration. And Voltaire prefixed
to her translation of Newton, published in 1754, at once the kindest and the
truest estimate of her character yet made.
Madame du Châtelet was intellectually a very great woman. She had a
mind essentially clear and logical—the mind of a clever man. She had not
only a passion for learning rare in her sex, but for exactly the kind of
learning in which her sex generally fails. She had, too, an intellectual
fairness strangely unfeminine. She was long the champion of Leibnitz
against Newton; and then, convinced of her mistake, acknowledged it, and
made it the business of her life to prove it and to translate and explain
Newton for the benefit of the French people. In an age busily idle, she was
distinguished by a noble and untiring industry. In an age of scandal, she was
charitable. For all those terrible fine clothes and that passion for high play
and taking youthful parts in amateur theatricals, the laugh of the de Staals
and the du Deffands at her expense turns against them now.
Still preserved among her letters are her “Reflections on Happiness.”
She plainly avows there that “rational self-indulgence” was her idea of it.
Upon that rock her barque split. She chose pleasure before duty and gained
a faithless Richelieu, fifteen jealous, feverish years with Voltaire, and a
wretchedness from the cool love of the lofty Saint-Lambert, of which every
letter she wrote him is proof.
Out of the picture painted by Loir there still looks down the shrewd,
smiling face—reflective eyes, clever forehead, mobile lips, drooping nose
—of the woman who was at once Voltaire’s curse and blessing—who, if she
had been all good might have been his blessing only, and if she had been all
bad would have been curse alone. At the Revolution, some wretches broke
open her coffin to steal the lead.
There had been gold in her heart once, but the world and the flesh had
overlaid it in dross.
CHAPTER XX

PARIS, “ORESTE” AND “ROME SAUVÉE”

The death of Madame du Châtelet marks one of the great epochs of


Voltaire’s life.
For a while he was utterly crushed and broken. He wrote of himself to
his friends as the most wretched of men. He was alone, abandoned, dying.
Everything that made life worth having had been taken from him—and he
would live no longer.
There is not the slightest doubt that he felt passionately every word he
wrote, and that he suffered wretchedly. It was characteristic of his nation
and himself to give grief words. It was characteristic of himself to
remember nothing but good of that “friend of twenty years” who had been
taken from him. He recalled Cirey and the springtime of their passion, and
forgot Lunéville and Saint-Lambert. He remembered the woman of a
splendid intellect and a most just judgment: who was learned without
affectation of learnedness; who had “the genius of Leibnitz, with feeling”;
and the literary style of a Pascal or a Nicole. He remembered “her imperial
sympathy” and not her “shrewish temper.” “The pompons and the world are
of her age, and her merit is above her age, her sex, and ours,” he had written
to the Abbé de Sade in 1733. He thought that now. Her brilliant and ready
understanding of his philosophies, thoughts, aims, came back to him
overwhelmingly. She had sinned against him in the flesh. Her mind had
been his for ever.
It would indeed have been impossible but that a fifteen years’ connection
with such a woman as Madame du Châtelet should have had lifelong effects
upon a character so impressionable as Voltaire’s. Her relentless logic and
her passion for hard facts did a work, and a good work, upon his vivid,
sensitive, bantering, and versatile intelligence. She added correctness to a
style which has no equal in the world for interest, gaiety, and satire. She
forced him to sound the depths his matchless sparkle hid, to examine first
principles, to advance step by step in argument with the stern accuracy of a
Euclid.
From his acquaintance with her he formed his conviction of the mental
equality of women with men. In his first grief at her loss, says Longchamp,
he wrote of her:

The world has lost her! She, sublime, who, living


Loved pleasures, arts, the truth. The gods in giving
Her their soul and genius, kept but for their own
That immortality which is for gods alone.

Voltaire denied the verses. He was in no mood for making mediocre


rhymes, he said. But in 1754 he certainly did write that noble eulogy of her
which forms the preface to her translation and commentary of Newton, and
never afterwards spoke of her—and he spoke of her often—but in terms of
a reverent and a passionate admiration.
For the first few days his grief was overwhelming. King Stanislas was
full of compassion, and three times a day mingled his tears with the
mourner’s.
Lunéville was now naturally horrible to Voltaire. He thought of going to
stay with a certain priestly friend at the Abbey of Senones. Perhaps he
would go back to England! He would have preferred the grave—or thought
he would have preferred it—to either of these alternatives. About
September 14, 1749, he ended by accompanying the Marquis du Châtelet to
Cirey.
It is not difficult to realise that such a temperament as Voltaire’s might
derive a melancholy consolation from revisiting the scene “de ces heureux
jours quand nous étions si malheureux!” It was for the last time. Every
room in the house must have recalled her. Every corner in the garden had its
own memory. There was that inscription over the summer-house—

A Book of Verses underneath the Bough ...


A Jug of Wine ... and Thou....

Here, they had been tender. There, they had quarrelled. It is not always
the most perfectly loved who are the most bitterly mourned. The keenest
grief is called remorse.
That good-natured old lady—Madame de Champbonin—came to Cirey
to mingle her tears with Voltaire’s.
Longchamp was kept busy packing books, furniture, vertu, to be
transmitted to Paris. Voltaire and the Marquis settled their money affairs—
much to the advantage and the satisfaction of that remarkable bonhomme. It
was arranged that Voltaire should take the whole of the house in the Rue
Traversière-Saint-Honoré in Paris—of which hitherto he had only rented a
part from the Marquis. They parted at the end of a fortnight: “on the best of
terms,” though they never saw each other again. Voltaire also retained a
friendship—for Saint-Lambert.
He left Cirey about September 25th, and proceeded by melancholy, slow
stages to Paris. He stopped for a day or two at kindly Madame de
Champbonin’s; at Châlons, and at Rheims, and finally reached the capital.
If the unhappy man had been miserable at Cirey he was a thousand times
more so in Paris. He was alone. The house was in a dreadful confusion with
the du Châtelet furniture being moved out and the Voltaire furniture being
moved in. Voltaire was as sick in body as in mind. He tried to work. He did
work—with his loss and his wretchedness thrusting themselves on his
consciousness all the time. Sometimes in the dead of night, half dreaming,
he would get up and wander about the disordered rooms, and fancying he
saw Madame du Châtelet, call to her. Once, in the dark and cold, he got up
and walking a few steps was too weak to go farther and leant shivering,
supported against a table—“yet reluctant to wake me,” says Longchamp.
The unhappy man stumbled into the next room presently, and against a
great pile of books lying on the floor. Longchamp found him there at last,
speechless and half frozen, in the chilly dawn of the October morning. All
his letters of the month are miserable enough. A few chosen friends were
admitted to see him after a while—Richelieu, the d’Argentals, nephew
Mignot, and Marmontel. They would come and sit by his fire in the
evenings and try to distract his thoughts with talk of the drama, which he
had loved. They did their best to rouse him. He had certainly never needed
rousing before. Frederick the Great wrote brusquely to Algarotti that this
Voltaire talked about his grief so much he was sure to get over it quickly.
Marmontel speaks of him as one moment weeping and the next laughing.
Tears and laughter were both genuine enough, and to such a temperament,
quite natural. There was something of the child in this Voltaire to the very
last—the warm, quick emotions, so keenly felt, and so keenly felt to be
eternal. That they were not eternal does not impair their sincerity in the
least.
He was so lonely and miserable during that dismal autumn in Paris that
one day, exactly upon the same principle as a sorrowing widower marries
his cook and with much the same disastrous results, he asked his niece,
Madame Denis, to come and live with him. She could not do so till
Christmas. Before then, Longchamp declares he had helped his master’s
cure by showing him some letters in which Madame du Châtelet had
spoken slightingly of him. There was certainly bark in that tonic if it was
administered, which seems a little doubtful. How did Longchamp come by
such letters?
There was a sharper bark in the fact that while Voltaire was weeping for
a woman who had been false to him, that dreary old Crébillon was making
fine headway at Court, had a pension from the false Pompadour, and all
Paris applauding his bad verses.
It was his enemy, not his friends, who roused Voltaire at last. He woke as
after a disturbed dream—at first dazed; shook himself; looked round; and
began life afresh.
He was, to be sure, fifty-five years old. But fifty-five in a Voltaire,
though it meant an old and decrepit body, meant a vigorous and eager mind,
thirsting for life and action. He was a man of substance, and a man whose
time was his own. He had no ties. He had a reputation not a little feared. He
had the world before him yet, and a world only he could save. The fighting
zest to turn “dead Catilina of Crébillon into ‘Rome Sauvée’ of Voltaire” was
the spur that urged him back to “life and use and name and fame.”
“Rome Sauvée” had been written in a fortnight in this August of 1749, at
Lunéville. “The devil took possession of me, and said ‘Avenge Cicero and
France: wash out the shame of your country.’ ” Crébillon had made the
subject a weariness and a foolishness in “Catilina.” How could a Voltaire
better avenge France and himself—particularly himself—than by turning
the same subject into a masterpiece and a furore?
The pages of “Rome Sauvée” were still wet, when he took another dull
play of Crébillon’s—“Électre”—and turned it into “Oreste.”
He called together a few friends at the house of his “angels,” the
d’Argentals, and a few of the chief actors and actresses, for a reading of
“Rome Sauvée”; and read them “Oreste” instead. The truth was the actors
were in want of a play to act immediately, at the end of a week. If M. de
Voltaire could not give them one—well, there were other playwrights who
could! M. de Voltaire considered that his “Rome Sauvée” would require at
least six weeks’ rehearsal; so he read “Oreste.” He went in person to obtain
the censor’s permission for it, and did obtain it. “Oreste” appeared in public
on January 12, 1750, to a house equally crowded with the author’s friends
and with the faction of Crébillon, headed by Piron as usual. Voltaire had
written an opening speech in which, with a touching innocence, he
disclaimed all idea of being the rival of Crébillon and “Électre.” Half the
house received the play with applause which had nothing to do with its
merits, and the other half with hisses which had nothing to do with its
defects. The impulsive author, who was in the d’Argentals’ box and
supposed to be incognito, forgot all about that, and leant over the side,
crying, to encourage a burst of applause, “Courage, brave Athenians! This is
pure Sophocles.” For a few nights the vivid energy of Voltaire
FREDERICK THE GREAT
From an Engraving by Cunejo, after
the Painting by Cunningham

kept the piece going. He was improving and correcting it the whole time.
“Voltaire is a strange man,” said Fontenelle. “He composes his pieces
during their representation.” He kept the actors and actresses to their work
with a dreadful determination. He was always altering and adding to their
parts. Mademoiselle Clairon received at least four notes from him, full of
the handsomest compliments and of apologies for making so many changes;
but making them all the same. Mademoiselle Desmares at last totally
declined to have her lines changed any more, or even to receive Voltaire.
So, never baffled, on a day when she was giving a dinner-party he sent her a
pâté of partridges—and behold! each partridge had a little note in its beak
containing emendations to her rôle.
If the story be true or not, the fact remains that Voltaire was a very
exigeant manager. He had dedicated “Oreste” to the Duchesse du Maine;
and took the pains to write her a very long letter to reproach her for not
having attended the first performance. But in spite of all pains “Oreste” was
hardly a success. It was exceedingly tragic and had no love interest. It was
revived, after being withdrawn for a time, which the author spent in
rewriting it, and on its revival it was acted nine times. Its last performance
took place on February 7, 1750.
Voltaire’s grief was certainly by this time on the high road to a cure. He
had to fight so hard there was no time to sit at home, dull and wretched. He
did not realise at first the strength of his enemy, Crébillon. The truth is, the
Court was afraid of the Voltairian pen, and meant to stand by Crébillon and
applaud his dulness to the echo, only because he was Voltaire’s rival. The
Comédie Française—good, loyal toady—must needs think like the King.
When Voltaire realised the nature of the conflict, he resolved to fight the
enemy by a new method of warfare.
At Christmas, 1749, Madame Denis had come to live with him. A plump
widow of forty, not at all disinclined to try matrimony again, was Madame
Denis by this time. She had attempted to be a playwright when Voltaire was
at Lunéville; and her dear uncle had written with dreadful plainness of
language to d’Argental that to write mediocre plays was the worst of careers
for a man and “the height of degradation for a woman.”
Not the less, he saw his niece as a rule through very kindly spectacles,
and let his good nature so far warp his judgment as to make him think, or at
any rate say, that if she was no playwright she was an actress of the highest
ability. It is true that she was very fond of that amusement, having a vast
appetite for pleasure of any kind. At the beginning of the year 1750 both she
and her sister, Madame de Fontaine, were in the Rue Traversière; and
Madame Denis was making a very goodnatured, easy-going hostess for her
uncle’s guests.
Voltaire had begun to go out and about again, too. It was at some very
inferior amateur theatricals one night that he discovered an uncommonly
good amateur actor: sent for him, and received the trembling and delighted
youth the next morning. He embraced him, and thanked God for having
created a person who could be moved, and moving, even in speaking such
uncommonly bad verses. The pair drank chocolate together, mixed with
coffee. Lekain—that was the youth’s obscure name—announced his
intention of joining the King’s troupe. Voltaire offered to lend him ten
thousand francs to start on his own account. Eventually, he received the
young actor and his company into his house, and paid all his expenses for
six months—“and since I have belonged to the stage I can prove that he has
given me more than two thousand crowns,” says the famous Lekain in his
“Memoirs.”
There was plenty of space in the house in the Rue Traversière now the
Marquis du Châtelet no longer shared it. Voltaire turned the second floor
into a theatre capable of holding a hundred and twenty persons, and in a
very short time had there a playhouse, players, and plays which were the
height of the mode and made Court and Comédie, with all their hopes
pinned on poor old Crébillon of seventy-six, green with jealousy.
The Voltairian amateurs began with “Mahomet.” There were only half a-
dozen intimates, and a few of the servants, as spectators. Lekain was in the
title rôle, and the heroine was played by a shy little girl of fifteen, who—
thanks, partly at least, to the energetic coaching of M. de Voltaire—became
a pleasing actress. Actors and audience all stayed to supper; and, after it, M.
de Voltaire produced the parts of “Rome Sauvée,” distributed them, and
begged the actors to learn them as soon as they could. He coached and
rehearsed his company himself. He superintended the scenery. He saw
personally to the smallest details. Nothing was too much trouble if Voltaire
could but outvie Crébillon, and “Rome Sauvée” “Catilina.” The audacious
playwright actually had the coolness to make Richelieu get him the loan of
the gorgeous costumes in which “Catilina” had been played at the Comédie.
“Rome Sauvée” appeared on the boards of the theatre of the Rue
Traversière before an audience composed almost exclusively of the greatest
literary men of the age and country. Here were d’Alembert, the prince of
mathematicians, and, to be, perpetual secretary of the Academy; Hénault,
President of the Chambre des Enquêtes, and of at least two of the most
famous salons in Paris; young Marmontel, rising in the world; Diderot, the
encyclopædist of unclean lips; gallant and accommodating friend Richelieu;
and schoolmaster d’Olivet. The performance was a brilliant success. “Rome
Sauvée” was worthy of its author.
At a second representation that untiring person himself played the part of
Cicero, and excited the enthusiasm of the audience.
The fame and ability of the troupe of the Rue Traversière reached the
ears of Court and Comédie of course. They had players as good; but where
were they to find such plays?
One of the aims of the performance of “Rome Sauvée” in the Rue
Traversière was attained when on February 28th, “after long hesitations,”
that shifty Pompadour—a little bit to oblige Voltaire and chiefly because no
other play so suitable could be found—had “Alzire” acted by a
distinguished company of amateurs in the royal apartments.
Madame de Pompadour herself played “Alzire.” The Queen was not
present; nor her daughters; nor the Dauphin; nor the playwright himself.
But on March 6th “Alzire” was repeated: with Voltaire in the audience.
The King was well pleased with “Alzire,” but not with its author.
When the play was over he said loudly that he was astonished that the
author of so good a play as “Alzire” could also have written “Oreste”; and
the writer of “Oreste” had to swallow that royal rebuff in silence.
It was in this same March of the year 1750 that Voltaire was stung to
fresh action by the attacks of Fréron, enemy and journalist, the tool of
Boyer, and the acknowledged foe of all the light and knowledge in France.
Fréron had written an unsuccessful poem on the victory of Fontenoy, and
had never forgiven Voltaire for winning where he had failed. All the
aggressions seem to have been on the part of Fréron. Voltaire was only
aggravatingly successful and good-humoured. Fréron had not found it an
easy task to goad him to anger. But he had done it at last. “That worm from
the carcase of Desfontaines” was Voltaire’s vigorous epithet for him now.
And when in this March there was question of this “worm” being made
Parisian correspondent to Frederick the Great—“to send him the new books
and new follies of our country”—Voltaire flung on to paper a warm
remonstrance to his King against any such appointment; and then
recommended in writing to Darget, Frederick’s friend, the Abbé Raynal for
the post instead. Raynal was not appointed; but then neither was Fréron. For
many years, Fréron was to Voltaire the wasp who stung, and stung, and
stung again—with a sting not deadly indeed, but infinitely annoying and
malicious.
The death of Madame du Châtelet had, not unnaturally, been the signal
for King Frederick to renew his pressing invitations to Voltaire to visit him.
In the November of 1749 this most persistent of monarchs and of men had
written to reproach his friend for making excuses for not coming. They
must be excuses now! And Voltaire was so apt in them! In December the
King wrote again. In the January of 1750, more persistently still. In
February—“well, I will not press an immediate visit: but I will hold you
bound to come when the weather is better and Flora has beautified this
climate of mine.”
It was all very flattering. Voltaire felt it to be so. He was in the not
uncommon position of the man who likes to be asked but does not want to
go. There were many reasons against his going. He had just settled into his
house in Paris. Niece Denis had come to look after it for him. All his friends
lived hard by. The feverish events of the past year had made rest and quiet
peculiarly desirable. His health made them almost necessary. Travelling was
exceedingly expensive. But if these were all good reasons for remaining in
the Rue Traversière-Saint-Honoré, there were better ones for leaving it.
Running now through Paris were those gay satirical contes of his which
ridiculed every vice of the old régime and made King, Court, and confessor
supremely ridiculous. The graceless old Duchesse du Maine, sitting up in
bed at three o’clock in the morning, had laughed to hear her order
burlesqued in “Zadig.” But all her class had not her saving sense of humour.
The satire was too keen not to cut—the portraits too lifelike to be
unrecognised.
If he had stopped at “Zadig,” at “Barbouc,” at “Scarmentado,” there was
no reason in the world why Voltaire should be a popular member of the

You might also like