100% found this document useful (5 votes)
64 views84 pages

Software Engineering For Data Scientists (MEAP V2) Andrew Treadway Download

The document discusses the MEAP V2 edition of 'Software Engineering for Data Scientists' by Andrew Treadway, which aims to teach data scientists how to apply software engineering principles to improve their coding practices. It covers topics such as source control, scaling code, testing, deployment, and monitoring, providing hands-on experience with code examples and downloadable datasets. The book is structured into four parts, focusing on getting started, scaling, production readiness, and monitoring code in production.

Uploaded by

carvobunns30
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 (5 votes)
64 views84 pages

Software Engineering For Data Scientists (MEAP V2) Andrew Treadway Download

The document discusses the MEAP V2 edition of 'Software Engineering for Data Scientists' by Andrew Treadway, which aims to teach data scientists how to apply software engineering principles to improve their coding practices. It covers topics such as source control, scaling code, testing, deployment, and monitoring, providing hands-on experience with code examples and downloadable datasets. The book is structured into four parts, focusing on getting started, scaling, production readiness, and monitoring code in production.

Uploaded by

carvobunns30
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/ 84

Software Engineering for Data Scientists (MEAP

V2) Andrew Treadway install download

https://ebookmeta.com/product/software-engineering-for-data-
scientists-meap-v2-andrew-treadway/

Download more ebook from https://ebookmeta.com


We believe these products will be a great fit for you. Click
the link to download now, or visit ebookmeta.com
to discover even more!

Data Analytics for Drilling Engineering Theory


Algorithms Experiments Software Information Fusion and
Data Science Qilong Xue

https://ebookmeta.com/product/data-analytics-for-drilling-
engineering-theory-algorithms-experiments-software-information-
fusion-and-data-science-qilong-xue/

Bash for Data Scientists 1st Edition Oswald Campesato

https://ebookmeta.com/product/bash-for-data-scientists-1st-
edition-oswald-campesato/

Data Analysis for Scientists and Engineers Edward L.


Robinson

https://ebookmeta.com/product/data-analysis-for-scientists-and-
engineers-edward-l-robinson/

Fokker Aircraft of WWI Volume 5 1918 Designs Part 2


Production Fighters 1st Edition Jack Herris

https://ebookmeta.com/product/fokker-aircraft-of-wwi-
volume-5-1918-designs-part-2-production-fighters-1st-edition-
jack-herris/
Demon Slayer Kimetsu No Yaiba Volume 14 Chapters 117
120 Koyoharu Got■ge

https://ebookmeta.com/product/demon-slayer-kimetsu-no-yaiba-
volume-14-chapters-117-120-koyoharu-gotoge/

Greene s Infectious Diseases of the Dog and Cat Fifth


Edition Jane E Sykes

https://ebookmeta.com/product/greene-s-infectious-diseases-of-
the-dog-and-cat-fifth-edition-jane-e-sykes/

A Nation of Provincials Celia Applegate

https://ebookmeta.com/product/a-nation-of-provincials-celia-
applegate/

Conceptual Physical Chemistry part 1 upto Gaseous


Liquid State pg 235 IIT JEE main advanced 9th Edition
Prabhat Kumar

https://ebookmeta.com/product/conceptual-physical-chemistry-
part-1-upto-gaseous-liquid-state-pg-235-iit-jee-main-
advanced-9th-edition-prabhat-kumar/

Deployable Machine Learning for Security Defense Second


International Workshop MLHat 2021 Virtual Event August
15 2021 Proceedings Communications in Computer and
Information Science Gang Wang (Editor)
https://ebookmeta.com/product/deployable-machine-learning-for-
security-defense-second-international-workshop-
mlhat-2021-virtual-event-august-15-2021-proceedings-
Wearable Communication Systems and Antennas Design
efficiency and miniaturization techniques 2nd Edition
Albert Sabban

https://ebookmeta.com/product/wearable-communication-systems-and-
antennas-design-efficiency-and-miniaturization-techniques-2nd-
edition-albert-sabban/
MEAP Edition
Manning Early Access Program
Software Engineering for Data Scientists
Version 2

Copyright 2023 Manning Publications

For more information on this and other Manning titles go to


manning.com

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
welcome
Thank you for purchasing the MEAP for Software Engineering for Data Scientists. This book is written for readers
looking to learn how to apply software engineering concepts to data science.

The book is split into four parts:

Part 1 – Getting started


This part will cover topics such as source control, exception handling, better structuring your code,
object-oriented programming (OOP) for data science, and monitoring the progress of your code
(such as model training or data extraction)
Part 2 – Scaling
Part 2 covers scaling your code effectively. For example – how do you deal with larger datasets?
We’ll cover both the computational and memory components of scaling

Part 3 – Scheduling, testing, and deployment into production


Part 3 details how to rigorously test your code, protecting your credentials (for example when
connecting to a database to query data, scheduling models and data pipelines to run automatically,
and packaging data analytics code into a portable library that can be shared with and downloaded
by others
Part 4 – Monitoring your data processing and modeling code

Lastly, Part 4 will teach you how to effectively monitor your code in production. This is especially
relevant when you deploy a machine learning model to make predictions on a recurring or
automated basis. We’ll cover logging, automated reporting, and how to build dashboards with
Python.

In addition to the direct topics we cover in the book, you’ll also get hands-on experience with the code examples.
The code examples in the book are meant to be runnable on your own with downloadable datasets, and you’ll find
corresponding files available in the Github repository. Besides the examples laid out in the book, you’ll also find
Practice on your own sections at the end of most chapters so that you can delve further into the material in a
practical way.

The book covers an extensive set of topics, and I hope you find it helpful in your technical journey. If you have any
questions, comments, or suggestions, please share them in Manning’s liveBook Discussion forum.

— Andrew Treadway

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
brief contents
PART 1: GETTING STARTED

1 Introducing software engineering principles


2 Source control for data scientists
3 How to write robust code
4 Object-oriented programming for data scientists
5 Creating progress bars and time-outs in Python

PART 2: SCALING PYTHON

6 Making your code faster and more efficient


7 Memory management with Python
8 Scaling Python code – Alternatives to pandas

PART 3: EVERYTHING YOU NEED TO PUT PYTHON IN PRODUCTION


9 Making your code production-ready
10 Testing pipeline
11 How to auto-schedule your Python code
12 How to package your code

PART 4: MONITORING YOUR PYTHON CODE


13 Reporting and logging with Python
14 Intro to web development and dashboarding for data science

APPENDIXES

A Setting up your environment for this book


B Setting up SQLite

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
1

Introducing engineering principles

This chapter covers


1
What data scientists need to know about software engineering
Why data pipelines are important
How machine learning (ML) pipelines are used
Putting models into production

Suppose you’re working on a project with several others (could be data scientists, software
engineers, etc.). How do you handle modifying the same code files? What about testing out new
features or modeling techniques? What’s the best way to track these experiments or to revert
changes? Often times, data scientists will use tools like Jupyter Notebook (a software tool that
for writing code and viewing its results in a single integrated environment). Because Jupyter
Notebook allows for easy viewing of code results (such as showing charts or other visuals, for
example), it’s a popular tool for data scientists. However, working on these notebook files can
often get messy quickly (you may hear the term spaghetti code). This is generally because part of
being a data scientist is experimentation and exploration - trying out various ideas, creating
visualizations, and searching for answers in data. Applying software engineering principles, such
as reducing redundancies, making code more readable, or using object-oriented programming (a
topic we’ll introduce later), can vastly improve your workflow even if your direct involvement
with software engineers is limited. These principles make your code easier to maintain and to
understand (especially if you’re looking at it some length of time after you’re written it).

Additionally, being able to pass your code to someone else (like a software engineer, or even
another data scientist) can be very important when it comes to getting your code or model to be
used by others. Having messy code spread across Jupyter Notebook files, or perhaps scattered
across several programming languages or tools makes transitioning a code base to someone else

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
2

much more painful and frustrating. It can also cost more time and resources in order to re-write a
data scientist’s code into something that is more readable, maintainable, and able to be put into
production. Having a greater ability to think like a software engineer can greatly help a data
scientist minimize these frustrations.

The diagram in Figure 1.1 shows an example of a codebase where a data scientist’s code may be
scattered across several notebooks, potentially in multiple languages. This lack of a cohesive
structure makes it much more difficult to integrate the code (for example, a model) into another
codebase. We’ll revisit this diagram later in the chapter within an updated, improved codebase
example.

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
3

Figure 1.1 For data scientists, the state of their codebase is often a scattered collection of files. These
might be across multiple languages, like Python or R. The code within each file might also have little
structure, forming what is commonly known as spaghetti code.

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
4

Next, let’s delve into what data scientists need to know about software engineering.

1.1 What do data scientists need to know about software


engineering?
Before we go further, it may be helpful to briefly define software engineering. Software
engineering is the application of engineering principles to developing software applications. Just
like a civil engineer helps to ensure the reliability and effectiveness of bridges or other
constructs, a software engineer develops applications that are reliable, scalable, and efficient. A
few of the key principles of software engineering as applied to data science are below:

Better-structured code to minimize errors (both in terms of bugs in the code, but also in
terms of inputs into code functions, such as the features being fed into a model)
Collaboration among co-workers is a key part of any data science team. Software
engineering principles can and should be applied to make collaboration and working
together on the same code base seamless and effective
Scaling code to be able to process large datasets efficiently and effectively is also very
important in modern data science.
Putting models into production (as mentioned above)
Effectively testing your code to reduce future issues

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
5

We’ll cover each of these points in more detail in the next section. First, let’s briefly discuss the
intersection of data science and software engineering.

Josh Wills (a former director of data engineering at Slack) once said that to be a data scientist,
you need to be better at statistics than a software engineer, and better at software engineering
than a statistician. One thing is for certain - the skills that a data scientist is expected to have has
grown much over the years. This greater skillset is needed as both technology and business needs
have evolved. For example, there’s no recommending posts or videos to users if there’s no
internet. Platforms, like Facebook, TikTok, Spotify, etc. also benefit from advanced technology
and hardware available in modern times that allow them to process and train models on massive
datasets in relatively short periods of time. Models like predicting customer churn or potential
fraud are much more prevalent nowadays because more data being collected, and more
companies looking to data scientists to provide solutions for these problems.

Additionally, if you’re interviewing for a data scientist position nowadays, chances are you’ll run
into questions around programming, deploying models, and model monitoring. These are in
addition to being tested on more traditional statistics and machine learning questions. This makes
the interview process more challenging, but also creates more opportunities for those
knowledgeable in both data science and software engineering. Data scientists need to have a
solid knowledge of several areas in software engineering in their day-to-day work. For example,
one key area where software engineering comes into play is around implementation. The
example models we’ve mentioned so far, like recommendation systems, customer churn
prediction, or fraud models all need to be implemented in production in order to provide value.
Otherwise, those models are just existing in a data scientist’s code files, never making
predictions on new data.

Before we delve more deeply in the engineering principles mentioned above, let’s walk through
a few more examples of common issues in a data scientist’s work where software engineering
can help!

1.2 When do we need software engineering principles?


Let’s walk through a few real-life scenarios for a data scientist. These scenarios will highlight
several key issues data scientists face in their work. The motivation for walking through these
problems is to illustrate the usefulness of incorporating software engineering knowledge, which
we’ll further introduce as we go through this chapter.

Better stuctured code

We covered this point already earlier in the chapter, so we’ll just briefly rehash that improving
the structure of your code can greatly help for several key reasons, including sharing your code
with others, and integrating the code into other applications.

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
6

Improving coding collaboration

Extending on the earlier scenario, collaborating on the same code base with others is crucial
across almost any data science organization or team. Applying software engineering principles
through source control allows you to track code changes, revert to previous code file versions,
and (importantly) allows for multiple people to easily change the same code files without threat
of losing someone else’s changes. These benefits of source control can also be useful even if
you’re working a on a project alone because it makes it much easier to keep track of the changes
or experiments that you may have tried.

Figure 1.2 Collaboration is an important part of coding in many companies. Data scientists, data
engineers, and software engineers are three common roles that often interact with each other, and
share code with each other. Working effectively with a shared codebase across multiple (or many) users
is a topic we’ll delve into in the next chapter.

Scaling your code to handle more data efficiently

Another common scenario involves scaling. Scaling involves improving your code’s ability to
handle larger amounts of data from both a memory perspective, as well as an efficiency point of
view. Scaling can come up in many different scenarios. For instance, even reading in a large file
might take precious time when your compute resources are constrained. Data processing and
cleaning, such as merging datasets together, transforming variables, etc. can also take up a lot of
©Manning Publications Co. To comment go to liveBook
https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
7

time and potentially memory. Luckily, there exists many techniques for handling these problems
on a large scale, which we’ll cover in more detail later in this book. It is quite common for data
science code to be initially written inefficiently. Again, this is often because data scientists spend
a lot of time exploring data and experimentally trying out new features, models, etc. By applying
software engineering concepts and tools available, you can transform your code to run on a more
robust basis, scaling to larger numbers of observations much more efficiently.

Putting models into production to make them usable by others

Once you’ve developed a model, you need to put it to use in order to provide value for your team
or company. This is where putting your model into production comes into play, which as
mentioned above, essentially means scheduling your model to make predictions on a recurring
(or potentially real-time) basis. Putting code in production has long been a software engineering
task. It’s the heart of software engineering work at many different companies. For example,
software engineers are heavily involved in creating and putting apps on your phone into
production, which allows you to use the apps in the first place. The same principles behind doing
this can also be applied to data science in order to put models into production, making them
usable by others, operating anywhere from a small number of users to billions (like predicting
credit card fraud), depending on the use case.

Effectively testing code to reduce future issues

So you’ve created a model and it’s soon going to be making new predictions. Maybe it’s a model
to predict which customers are going to churn in the next month. Maybe it’s predicting how
much new insurance claims will cost. Whatever it is, how do you know the model will continue
to perform adequately? Even before that, how can you ensure the code base extracting,
processing, and inputting data into the model doesn’t fail at some point? Or how can you
mitigate the results of the code base failing? Variations of these issues are constantly faced by
software engineers with respect to code they’re writing. For example, an engineer developing a
new app for your phone is going to be concerned with making sure the app is rigorously tested to
make sure it performs like it is supposed to. Similarly, by thinking as a software engineer, you
can develop tests for your data science code to make sure it runs effectively and is able to handle
potential errors.

In Figure 1.3, we show an example of inputting features into a customer churn prediction model.
Here, we might add tests to ensure the inputs to the model, like customer age or number of
transactions over last 30 days, are valid values within pre-defined ranges.

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
8

Figure 1.3 This snapshot shows a sample of tests that could be performed when deploying a customer
churn model. For example, if the model has two inputs - customer age and number of transactions over
the last 30 days, we could perform checks to make sure those inputs values are within set ranges prior
to inputting into the model.

Let’s summarize these principles in a table.

Engineering Advantages
principle
Better structured Makes code more easily integratable, easier to maintain, and helps improve coding collaboration.
code
Improving code In addition to better structured code, we can use additional tools - such as source control - to make it
collaboration easy to work together on the same codebase across many users or teams.
Scaling your code Making your code robust enough to handle large volumes of data and generalizable enough to deal
with new variations of inputs, data, or various errors that may occur.
Deploying models Make the application of your code usable or accessible by others. This can be anything from a
into production customer churn model making predictions to an app on your phone tracking your fitness goals.
Effective testing Any model or application that will be handling data or being used by others needs to be rigorously
tested to ensure it can handle potential issues.

Next, let’s go through a sample data science workflow using a specific example. This will help to
tie the above scenarios to a common data science use case.

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
9

1.2.1 Sample data science workflow


Suppose you’re working for an e-commerce company and you want to predict whether a
customer will churn in the next 30 days. Oftentimes, a data scientist working on a problem like
this would roughly follow these steps:

Gather data
Data can be collected in several ways:
Writing SQL to extract data from various tables / databases (MySQL, SQL Server, etc.).
Scraping data from documents (e.g. CSV, excel files, or even PDF / Word documents in
some cases)
Extracting data from webpages or through web APIs
Exploratory data analysis (EDA) / data validation
EDA involves steps like checking the distributions of key variables, investigating missing
values, looking at correlation plots, and checking descriptive statistics (such as the
median values for numeric variables or most common value for categorical features).
Data validation might involve checking the results of EDA against domain knowledge or
across multiple data sources to ensure that the data is accurate and reasonable to use for
analysis and modeling.
Data cleaning
Data cleaning involves minimizing the number of issues in a dataset, including the
following:
Replacing missing values
Removing highly correlated variables
Treating highly skewed variables (potentially transforming certain features)
Dealing with an imbalanced dataset (think about predicting ad clicks, for example, where
the vast majority of users never click on an ad)
Feature engineering
Feature engineering is the process of developing new features from existing variables.
This is generally done in an effort to improve model performance. For example, certain
machine learning models will perform better when the inputs follow a normal
distribution, so there are existing techniques that make these transformations. In other
instances, feature engineering is absolutely necessary to get anything useful out of a
variable. This is typical of date variables, for instance. For example, in the credit fraud
use case, transaction date could be a raw variable, but cannot be input directly into a
machine learning model. Instead, we parse out new features, such as the day of the week,
hour of the day, month, etc.
Model training
Model training involves inputting data into machine learning algorithms like logistic
regression, random forests, etc. so that the algorithm can learn the patterns in the data in
order to be able to make predictions on new data. This process may involve testing out
several different models, performing fine-tuning the parameters of the models, and
perhaps selecting a subset of the more important features relevant to a model.

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
10

Model evaluation
Model evaluation is a key component where data scientists need to check how well the
model performs. This is usually done by evaluating the model on a fresh, or hold-out,
dataset that was not used for model development. There are a variety of metrics that may
be used to assess performance, such as accuracy (number of examples where the model
was correct / total number of predictions) or correlation score (sometimes used to
evaluate models outputting a continuous prediction).

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
11

Figure 1.4 A sample data science workflow, as described above. Data science workflows involve key
steps like gathering data, exploring and cleaning the data, feature engineering, and model
development. The model evaluation piece is also a highly important step, that we will cover in detail
when we discuss model monitoring later in this book.

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
12

1.2.2 How does software engineering come into the picture?


The process above presents several potential problems from a software engineering perspective.

How do we allow easier coding collaboration between data scientists, data engineers,
software engineers, and whomever else may be working on the project?
While data scientists ultimately use data to perform analysis and modeling, data
engineers are more heavily involved in creating new tables, managing databases, and
developing workflows that bring data from some source (like raw logging on a website)
to a more easily ingestible place where data scientists can query a table - or small number
of tables - in order to get the data needed for modeling or analysis. Software engineers, as
mentioned above, help to create reliable applications that might be used either by internal
employees or external consumers. These three roles often work closely together, and their
exact responsibilities may overlap depending on different companies.
How do we use the developed model to predict churn for customers on an ongoing basis?
We can think of this question as an extension of the last point in our data science
workflow concerning model evaluation. Once we’re satisfied with a model’s
performance, how do we go from a trained model to one that is making predictions on a
regular cadence? This heavily involves one of the main topics of this book, which is
putting models into production.
How can we have fresh data ready for the model to use in production?
This question is partially related to the first piece of the data science workflow -
gathering data. Essentially, ensuring fresh data is available in production involves
automating the gathering data process and hardening it to reduce the possibility of errors
or data issues.
How do we handle invalid inputs into the model or other errors?
Handling invalid inputs into the model is often needed once the model is developed and
ready to be deployed into production. In a production environment with new data coming
in, we may need to create checks like making sure the data types of each feature input is
correct (for example, no character inputs when a numeric value is expected) or that
numeric values are in an expected range (such as avoiding negative values when a
positive number is expected). Other types of errors may also occur in the workflow above
when we are automating those steps for fresh incoming data. For instance, whatever code
is being used to extract the new data may fail or some reason (such as the server hosting a
database going down), so you could develop logic to retry running the code after a few
minutes.

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
13

How can we effectively monitor the model’s performance once it’s making predictions
on a recurring basis?
Model monitoring can be thought of as an extension of the model evaluation step in our
data science workflow above. Effective monitoring of a model is necessary to ensure
confidence in a model’s performance over time. The exact way we monitor a model will
depend upon what the model is actually doing. In our example above, we would know
after 30 days whether a customer actually churned. We could use this to then chart the
accuracy of the model over time, along with other metrics like precision and recall
(which may actually be more important depending on the balance of the dataset). These
metrics can be tracked using a dashboard. Additionally, we might monitor information
like the distributions of the features in the model. This can help to debug potential issues,
such as dips in model performance. We will discuss Python tools for introductory web
development and dashboarding later in this book.
Do we need to re-train the model on an ongoing schedule?
Re-training a model on a recurring cadence is tied to the performance of the model over
time. The short response to this question is…it depends. If the model performance is
dropping a week after you’ve trained it, then you might need to re-train the model
frequently (or consider different features). If the model performance is stable over time,
you might not need to re-train the model very often, though it’s a must to monitor the
model to ensure it is meeting the standards expected.
How can we scale the model to millions of users?
Scaling can be a fairly in-depth topic, but we can broadly think of it in terms of memory
and efficiency. Many machine learning applications can be extremely intensive in terms
of both CPU (or GPU) cycles, as well as memory. Enabling ML and data workflows to
handle larger-scale data is an important task, and one that is likely to grow in importance
as datasets get larger and more diverse. Scaling code is heavily a software engineering
topic. When applied to data science, it can involve areas like parallelizing code or using
advanced data structures.

We will dive into more detailed approaches to each of these concerns in later chapters, but for
now let’s introduce a few summary points. Broadly speaking, software engineering provides
solutions to these issues. Software engineering helps to fortify our modeling code to reduce
errors and increase reliability. It can integrate a model trained in a data scientist’s development
environment into a robust application making predictions on millions of observations.
There are a few software engineering concepts we can apply to make our data science workflow
more robust and to handle these issues.

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
14

Source control
Source control (sometimes called version control) refers to a set of practices to manage
and monitor changes to a collection of code files.
Exception handling
Exception handling involves developing logic to handle errors or cases where a piece of
code may fail. For instance, this would come up in the example mentioned earlier where
a section of code retrieving data from a database might fail and exception handling logic
could be implemented to retry retrieving the data after several minutes. A few examples
of exception handling can be seen in Figure 1.5.

Figure 1.5 Exception handling can take many forms. A few examples are shown in this figure. For
example, we may need to query data on a regular basis for model training (for instance, updating the
customer churn model). What happens if the query returns zero rows one day? There could be multiple
solutions, but one could be sending an alert/email to an oncall data scientist (or engineer) about the
problem. Or what if you’re scraping data from a collection of webpages and a request fails due to a
non-existing webpage? We might want to skip over the webpage without ending the program in error.
We’ll delve into exception handling more fully in Chapter Three.

Putting a model into production


As mentioned earlier, putting a model in production involves enabling the model to make
predictions on an automated basis, perhaps on a recurring schedule or in real-time.
Object-oriented programming (OOP)
©Manning Publications Co. To comment go to liveBook
https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
15

Object-oriented programming (OOP) is a type of coding paradigm that revolves around


objects which have corresponding functions and features known as attributes. To take a
real-life analogy, consider a car as an object. A car has many attributes like a make and
model, color, number of doors, etc. It also has associated functions, such as starting,
stopping, driving, etc.
Automated testing
Automated testing refers to rigorously checking each component of code that will need to
run in production to ensure there are no issues - all in an as automated a way as possible.
This might involve validating a model’s predictions on test inputs, for example.
Scale
Scale generally refers to data size and is usually thought of in terms of memory or
efficiency. Larger scale problems might have millions (or billions) of observations and
thousands of columns.
These software engineering concepts are not utilized in a vacuum. Any ML model or data
science workflow (even basic analysis) involves data. Where do we get the data from? How do
we make sure the data source and any aggregations, data merging, or pre-processing done prior
to being ingested by a model is reliable? The key idea is to construct a data pipeline, which we’ll
introduce shortly. Another key concept when it comes to deploying machine learning models is a
machine learning pipeline, which we’ll discuss after data pipelines. Before we dive into data
pipelines, however, let’s summarize what we’ve learned in this section.
Software engineering involves applying engineering principles to software in order to
make it more scalable, reliable, and efficient. These same principles can also be applied
to make data science applications have improved reliability, able to scale to larger
datasets, and more efficient.
These principles include well-structured code, which helps make debugging and
collaboration much easier. They also involve dealing with larger and larger datasets in a
world where data is continually growing. Depending on your data science application,
engineering principles can also be applied to put your code into production (such as a
model that can run on millions - even billions - of observations).
A typical data science workflow involves several steps, including gathering data, data
cleaning, and model training / evaluation.
There are several key components of software engineering that can enhance the data
science workflow. These include exception handling, source control, object-oriented
programming (OOP), and scale (among others).

Now, let’s dive into data pipelines!

1.3 What are the components of a data pipeline?


A data pipeline is a set of actions to process data. Processing data means any action taken to a
collection of data such as the following:
Extracting the data from some source (database, webpage, set of documents, etc.)
Merging and aggregating features (i.e. columns) of data from different sources (e.g.
customer-level vs. transaction-level data)
Logging a model’s predictions to a new table
©Manning Publications Co. To comment go to liveBook
https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
16

In the workplace, data pipelines are often created by data engineers. However, depending on a
company’s structure, data scientists may also write data pipelines. In general, if you’re a data
scientist, it’s recommended to know about data pipelines and understand the source of the data
you’re using for your modeling or analysis projects. This is important for several reasons, but
especially because it helps you to build confidence in knowing where the data you’re using is
coming from. Software engineers can also be involved in data pipelines. For example, at tech
companies, it is common for software engineers to write the code that logs data from a particular
web application (a simple example would be logging whether someone clicks on an ad).

Data pipelines are necessary because they ensure that data is served reliably for a variety of data
science applications. Even if you’re working on an insight analysis, rather than a model, for
example, you need to be able to retrieve reliable data. Data pipelines are used in these cases to
bring data from between different tables and sources. They can also be used for logging data,
such as storing predictions from a model.

Sometimes you may see data pipelines referred in the context of reporting and analytics, as well,
in addition to being used for machine learning models. The main summary point to keep in mind
is that data pipelines are ultimately used to flow data from a source (or collection of sources) into
finalized outputs, usually in the form of structured tables with collections of rows and columns.
The exact application of ultimately using the data can vary. Let’s give a real-world example of a
data pipeline.

1.3.1 Real-world example: Building a model to predict customer churn


Taking the example mentioned earlier, suppose you’re building a model to predict whether an
e-commerce customer will churn in the next 30 days. Sample inputs into the model might
include:

Total amount of transactions over last 3 months


Number of times customer logged onto the e-commerce website
Length of time since customer first registered
Number of times customer has deactivated account in last 12 months

The data points above may be derived from several different tables. Let’s list those out below:

Table 1.1 Transaction table

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
17

Table 1.2 Login record table

Table 1.3 Customer information table (e.g. dim_customers)

In order to train a model in the first place, we need to have a method of combining and
aggregating the data inputs we need from the above tables. This process might involve multiple
sources of data and in some cases, may involve using various languages or frameworks. A
common language used in extracting data from tabular sources is SQL. SQL, or Structured
Query Language, is basically a programming language designed to extract data from databases.

The final dataset may include additional pre-processing and feature engineering prior to the
actual model development. Depending on the setup, some of these components may be handled
in the data pipeline or in the modeling code component, which we’ll cover next. For instance,
suppose that a person’s age is being used as a feature in predicting customer churn. Rather than
inputting age directly into a model, we might want to apply a transformation to age, like
bucketing it into different groups (for instance, under 18, 18 - 24, 25 - 30, 31 - 40, etc.). This
bucketing could be handled directly in a data pipeline by creating a table that has a column (
bucketed_age) with those categories, or it could be handled after the data (including the age
variable) has been passed to the model, with some pre-processing code to create that bucketed
feature prior to inputting it into a model.

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
18

Figure 1.6 An example flow of data from several source tables to a final output dataset used for
predicting customer churn.

Now that we’ve covered the flow of data from several potential sources to a finalized dataset,
what happens to the data? This is where machine learning pipelines come into the picture, as we
will discuss next.

1.4 Deploying models with machine learning pipelines


A machine learning pipeline is essentially a setup for automating and hardening a workflow to
deploy a machine learning (ML) model. In this context, an ML pipeline can be thought of as an
extension of (or encompassing) a data pipeline. A data pipeline is necessary to have a scheduled
and fortified (minimizing errors) workflow for providing the data for an ML model. The rest of
the ML pipeline feeds the data into an algorithm (think random forest, logistic regression, etc.).
We can break the model structure component into several sub-components, which we break out
below. Before we dive into the details, let’s take a look at an overview of an ML pipeline, as you
can see in the below diagram. Here, we show how an ML pipeline is connected to a data
pipeline. All ML pipelines start with and depend upon data. This data typically comes as the
result of a data pipeline. Additionally, the data must undergo processing, such as createing new
features for a machine learning model, selecting which features to use in a model, evaluation of a
model’s performance, and more.
©Manning Publications Co. To comment go to liveBook
https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
19

Figure 1.7 A sample workflow of a machine learning pipeline extending from a data pipeline. This
diagram shows an outline of a typical machine learning pipeline. Keep in mind that the starting point is
data. Data is always needed for any machine learning pipeline. The final part is monitoring the model to
validate its performance on an ongoing basis. These and the in-between components are covered in
detail below.

Now, let’s dive into the details of the ML pipline components displayed above.

1.4.1 Data ingestion


Data ingestion involves ingesting the data needed for the machine learning model. This data can
be ingested from the last step of a corresponding data pipeline, which outputs a table with the
columns needed for the model. There are a variety of ways the data ingestion component can be
setup, including fetching features from a key-value store (think of a key-value store has a fast
lookup table to map a key - such as a customer ID - to a set of features for that customer, such as
age or account history information), writing SQL to pull the needed data, and many more, which
will be further discussed later in this book. Once data is ingested, there may be additional
processing that needs to be done prior to using the data for model training. We’ll explain what
this processing involves next.

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
20

1.4.2 Pre-processing
Pre-processing, broadly speaking, involves performing any additional cleaning or feature
engineering prior to model training. For example, the cleaning component might involve
replacing missing values or capping outliers. As stated earlier, feature engineering could be
implemented in the data pipeline by creating the new features directly into table columns, which
are ingested by a model. Alternatively, feature engineering could be done as part of the
pre-processing step after the data has already been extracted. When the pre-processing step is
complete, the next component involves training a model on the data.

1.4.3 Model training


There are two main types of model training when it comes to ML pipelines, regardless of the
type of model you’re using.

Train a model once, and use the static model for fetching predictions on an ongoing basis.
This type of model structure is useful in cases where the data does not change very
rapidly. For instance, building a model to predict insurance claim cost from the time a
claim is filed might be an example where the underlying data doesn’t change from week
to week (the relationship of the variables in the model vs. actual claim cost could be
relatively static for shorter durations), but rather it might only need to be updated every
6-12 months.
Re-train the model on a periodic basis, such as monthly, weekly, or even more frequently
if needed. This setup is useful when the performance of the model drops by a
high-enough margin over shorter time periods to warrant updating it on an ongoing basis.
This is related to the topic of model monitoring, which we’ll cover in a later chapter. An
example of this might be a recommendation system, for instance, where new and more
varied types of content are frequently being made available, and the relationships
between the inputs and the target that is being predicted changes fairly rapidly, requiring
more frequent re-training.

After a model is trained, we need to evaluate the performance of the model. The main reason for
this is that is we need to be confident that the model is performing adequately for our standards,
which we’ll discuss next.

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
21

1.4.4 Model evaluation


Model evaluation comes after a model has been trained on a dataset. There may be a variety of
evaluation metrics and breakdowns to help ensure confidence in the model performance. The
evaluation of the model will often be monitored on an ongoing basis. For instance, in the
customer churn example, we should be able find out in the available data whether a customer
actually churned i.e. whether our model prediction was correct. This ground truth could be
compared to our model prediction to calculate metrics like precision or recall. In this case,
precision would be the proportion of cases where the model predicted a customer would churn
and that the model was successful in that prediction. Recall would be the proportion of customers
that actually churned which were successfully captured by the model. The model monitoring
component may consist of dashboards and potentially a notification system to alert if the
performance of the model drops by a significant amount. Model evaluation is highly important to
any business use case because if a model is not performing adequately, then it could end up
costing a company money, wasting resources, or having a negative impact on customers relying
on the model predictions (such as credit card users depending on accurate predictions preventing
malicious actors from secretly using their credit).

Once we are confident in a model’s performance, it is time for putting the model into production
order to make predictions on an ongoing basis.

1.4.5 Model prediction / deployment


On the model prediction side, there are also two main model structures (again, this is regardless
of the underlying model being used).

Real-time models
Real-time models return predictions in real-time. Predicting whether a credit card
transaction is fraudulent is a high-impact example where a real-time model can be
critical. These predictions are often fetched via an API call, which we’ll discuss in more
detail later in this book.
Offline models
Offline models make predictions on a scheduled basis, such as daily, weekly, hourly, etc.
Our example of predicting customer churn could potentially be an offline model, running
daily.

After the model is deployed and able to make predictions on new data, it is important to monitor
the model’s performance on an ongoing basis. This allows us to be alerted if there are any issues
that arise in terms of the model’s performance or changes in the data being used for the model.

Before we go into model monitoring, let’s summarize a few examples based on real-time vs.
offline prediction and recurring training vs. single (or infrequent) model training.

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
22

Model prediction Training frequency Prediction type


Customer churn Evaluate based on need, but potentially monthly, or every Offline - update model prediction
several months based on data ingested each day
Ad click prediction Patterns related to ad clicks can change very fast, so training Real-time
might be done on a weekly, daily, or even real-time basis
Credit card fraud The factors used to identify fraud may change relatively Real-time
prediction rapidly, so training frequency should account for this
Property insurance Potentially every few months unless there are major changes Offline - update predictions with
claim cost that will impact the model’s predictive power new information daily
Music genre prediction Depending on how often new genres are added, this could be Could be real-time or offline
(for example, Spotify) every few weeks/months or on more frequent basis

Now, let’s discuss model monitoring.

1.4.6 Model monitoring


As just mentioned, it is important to monitor a model in order to ensure its performance is
adequate. This was briefly discussed earlier in the chapter, and to re-iterate, usually involves
tracking model performance metrics and potentially feature distributions.

Before we close out the chapter, let’s revisit Figure 1. Since we now know about data pipelines
and ML pipelines, we can think about restructuring the scattered notebooks/files shown in Figure
1 into a more sequential collection of files. Ideally, these would be standardized across languages
as much as possible (for example, keeping code files only in Python rather than across Python,
R, Julia, etc.). For example, this might look like the following table:

Sample file name Description


1_fetch_dataset.py Python script to extract data needed for model training
2_clean_dataset.py A Python file to clean the raw dataset
3_feature_engineering.py Perform feature engineering, such as calculating number of transactions over last 30
days
4_feature_selection.py Reduce the features to only those needed
5_train_model.py Train the model and store the model object
6_generate_evaluation_metrics.py Generate a collection of evaluation metrics to measure the model’s performance

This tables show a few sample code files corresponding to different steps in the ML pipeline.
There could be additional code files as well. For example - feature engineering might be divided
into several components in different files. We’ll go further into the possible structure of files in
the data science workflow when we get to Chapter Three. Now, let’s close out this chapter with a
summary of what we’ve we covered.

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
23

1.5 Summary
In this chapter, we discussed data pipelines, ML pipelines, and provided an overview of putting
models into production.

Data scientists need software engineering concepts in order to make code easier to
maintain, allow for more seamless collaboration, implement models into production,
scaling, and rigorously testing your code.
Data pipelines are used for merging, aggregating, and extracting data from some
underlying source into a final output (typically a table or collection of tables).
Machine learning (ML) pipelines are used to deploy machine learning models to make
predictions on an automated basis. This might be making predictions in real-time or
recurring on a schedule, such as daily or weekly predictions.
Key software engineering concepts that are used in fortifying data pipelines and ML
pipelines include source control, object-oriented programming, scale, and exception
handling.
Putting a model in production requires fortification of code like handling errors /
exceptions, scaling as necessary, and structuring code to be more readable and allow for
easier collaboration

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
24

This chapter covers


Source control for data scientists
2
What is source control
Why do data scientists need to know source control
What is git
What are the main git commands you need to know as a data scientist

In the last chapter, we introduced several key software engineering concepts that will improve
your life as a data scientist. These included:

Source control
Exception handling
Putting a model into production
Object-oriented programming (OOP)
Automated testing
Scale

In this chapter, we’re going to delve deeper into the first of these - namely, source control.
Source control (also called version control) is basically a way of tracking changes to a codebase.
As the number and size of codebases has grown indescribably over the years, the need for
monitoring code changes, and making it easier for various developers to collaborate is absolutely
crucial. Because software engineering has existed longer than modern data science, source
control has been a software engineering concept longer than a data science one. However, as
we’ll demonstrate in this chapter, source control is an important tool to learn for any data
scientist. Before we delve into using source control for data science, however, let’s discuss how

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
25

source control fits into the picture of applying software engineering to data science. Recall in the
last chapter, we discussed several key concepts of software engineering, such as better structured
code, object-oriented programming, exception handling, etc.

Source control can (and should) be used from the very beginning and throughout a project. That
project could be a purely software engineering application, a data science project, or some
combination. For example, the project could be developing a new machine learning model, like
our example in the last chapter around predicting customer churn. It could also be a purely
engineering project, like code to create a new app for your phone. There is a consistent theme
between source control, better structured code, and object-oriented programming (explained in a
later chapter) in that each of these software engineering concepts make collaboration between
developers (or data scientists) much easier. This chapter will focus specifically on common
software for using source control.

Next, let’s explore how source control will help you in your projects. Going back to the customer
churn example from the first chapter, suppose you and a colleague are working on a data science
project together to predict whether a customer will churn. To make this concrete, we will use the
customer churn dataset available from Kaggle here:
www.kaggle.com/competitions/customer-churn-prediction-2020/data. This dataset involves
predicting whether a customer from a Telecom company will churn. The workflow of this project
can be structured similarly to the data science life cycle that we discussed in the first chapter. As
a refresher, we’ve repeated the chapter one diagram showing the combined data pipeline/ML
pipeline view in Figure 2.1.

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
26

Figure 2.1 Adding to what we covered in the previous chapter, we can use source code at almost any
step of of a data pipeline or ML pipeline. This is especially useful when multiple coworkers are
collaborating together on the same codebase, but can also be helpful for tracking changes in a
codebase even if you are the only one working on it.

In the following steps, we tie the pipeline components to our specific Kaggle dataset:

Gathering data
Fetch the data needed to build the customer churn model. In the Kaggle dataset we’ll be
using, this includes information like length of account (account age), number of day calls,
area code, etc.
Exploratory data analysis (EDA) / data validation
Analyzing the data for patterns, distributions, correlations, missing values, etc. For
example, what’s the proportion of churn to non-churn? What’s the association with total
day minutes used (total_day_minutes) and churn? Etc.
Data cleaning
Handle issues, such as missing values, outliers, dirty data, etc.
Feature engineering
Create new features for the models you both will build. For example, you could create a
new feature based on the average total day charge for the state the user resides in.
Model training
Develop models, such as logistic regression or random forest to predict churn.
Model evaluation.

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
27

Evaluate the performance of the models. Since churn vs. non-churn is a classification
problem, we might use metrics like precision or recall here.
Model deployment
Make the finalized model accessible to others. For this case, that might mean prioritizing
individuals predicted to churn for marketing or lower price incentives.

Each of these steps might involve collaboration between you and your colleague. Consider a few
example scenarios:

When gathering data, you might write code to extract data from the last year. Your
colleague, wishing to get more data, modifies the codebase to extract data from the last
three years.
Your colleague adds code that creates several visualizations of the data, like the
distribution of daytime calls. You find a bug in your colleague’s code and want to correct
it, so you modify the shared codebase.
The two of you are working on cleaning the data. One colleague adds code to replace
missing values and handle outliers. The other one realizes that one of the fields has a mix
of numeric and string values, and writes code to clean this issue. Both sets of changes go
into the same file.
One of you works on developing an logistic regression model, while the other wants to
try out a random forest. But you both want to share code with each other and potentially
make modifications (like use different parameters or features)

Source control makes these types of collaborations much easier and trackable. Next, let’s dive
into how source control would help you and your colleague in this situation, or in general for any
data science project you may work on.

2.1 What is source control?


Source control, as mentioned above, is a system for tracking code changes across a collection of
users (though that collection of users could also just be a single individual). Source control has
long been used by software engineers, though as we’ll see below is also invaluable for data
scientists, as well. When speaking about source control, you’ll often encounter the term
repository (or repo for short). A repository is simply a collection of files, often hosted on a
remote server. Typically, the source control workflow involves multiple people contributing to
the same repository. Each person will download a copy of the repository’s codebase to a local
directory. By local, we mean whatever server or personal environment someone is using to
create and write new code files. You may hear the term local repository to refer your copy of the
collection of files. A developer can then make whatever changes needed to the codebase, such as
creating new files (like a new Python script, for example) or modifying existing files. After
changes are made, the updates can be pushed to the repository so that other users can download
the most up-to-date code. Additionally, any changes pushed to the remote repository can be
tracked, so that you can trace who made particular changes.

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
28

Figure 2.2 Source control enables easier coding collaboration between different developers of the same
codebase, often stored on a shared remote repository

An alternative to using source control would be to simply use a shared network directory where
different developers could add or modify files to a centralized location. However, this has several
key problems:

How do we track changes based by different users? In other words, how can I easily tell
who made what change? With the methodology above, this is very difficult.
Difficult to revert changes. This can be especially important in cases where a new change
causes an issue, like an app to crash, for instance.
Easy to overwrite others' changes.
Merging changes from different users working on the same code file is a challenge
Taking our customer churn dataset example, suppose you write code that creates a
collection of new features for the churn model. Your colleague wants to modify the same
code file(s) that you created. This process is called merging. Let’s look at an example
below.

Merging example:

Data scientist (DS) #1 changes

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
29

Listing 2.1 DS #1 creates a new Python file


import pandas as pd

p50_account_length_by_state = train.groupby("state").\
median()["account_length"]

Import pandas package


Calculate the median account length by state

Data scientist (DS) #2 changes

Listing 2.2 DS #2 modifies the same file DS #1 created.


import pandas as pd

p50_account_length_by_state = train.groupby("state").\
median()["account_length"]

p50_day_minutes_by_state = train.groupby("state").\
median()["total_day_minutes"]

Import pandas package


Calculate the median account length by state
Calculate the median day minutes by state

In the first code snippet, DS #1 creates a code file that calculates median account length values
by state. Another data scientist (DS #2) changes the code to calculate median total daytime
minutes by state (adding an extra line of code). DS #2 can now merge the changes made into a
shared repository where DS #1 can downloaded DS #1’s contributions. Now, let’s move into
how source control helps with the above-mentioned problems.

Broadly speaking, source control offers many benefits, including:

Tracking who changed what. Source control makes it easy to track who created or
modified any file in a repository.
Undoing changes to the repository is straightforward. Depending on the specific software
you’re using for source control, this may even be as simple as executing one line of code
to revert the changes.
Provides a system for merging changes together from multiple users.
Provides a backup for the codebase. This can be useful even if you’re the only person
contributing code. It’s all too easy to accidentally overwrite a file or potentially lose work
if a system crashes. Source control helps to mitigate these issues, in addition to delivering
the benefits listed above.
Code consistency. Too often, different members of a team may follow various styles or
have different sets of functions, which may perform overlapping or similar actions.
Source control allows for easier code-sharing among team members, enabling greater
consistency in the codebase used across team members.
©Manning Publications Co. To comment go to liveBook
https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
30

The benefits of using source control can be applied to any codebase, regardless of the
application, environment, company, etc. Though source control has long been used by software
engineers, it is also an important tool for data scientists to learn, as we’ll explain below.

2.2 Why do data scientists need to know source control?


As data science projects scale in terms of the code base, as well as the number of people working
together on the code, source control is crucial in keeping track of all the changes that are made.
Almost any software engineer should be familiar with using source control for projects.
However, with data science, there can be a tendency to write spaghetti code. This phrase
generally refers to code that is disorganized, contains redundancies, and is difficult to track
changes or contributions from different people working on the code base. A core reason for this
is that data science tends to be more experimental in the way code is written vs. pure software
engineering. For example, when you’re working on a project to develop a model, you might try
out various combinations of features, different treatments of the data (like replacing missing
values, capping outliers, etc.), or different types of models. Source control offers several benefits
for this type of scenario:

Easily track any experimental changes done by either an individual or a group of data
scientists working on the same project
Enables data scientists, software engineers, data engineers, etc. to modify the same code
base in parallel, without fear of overwriting anyone’s changes
Allows for more easily packaging of the code base and hand-off to software engineers.
This can be very important for putting models, data pipelines, etc. into production
Makes it easier to merge changes to the same underlying files

To make the concept of source control less abstract, let’s use a concrete example of a version
control software called Git.

2.3 Introducing git


Git is an open source version control tool, which is also freely available. Git is the software
behind popular sites like Github and Gitlab. Because it is free and open source, in addition to
being straightforward to use, Git is popular not only for software engineers, but is also used for
many data science projects. We will be using git throughout this book for version control, so we
will give an overview of how git works in the following sections.

Git can be used via the command line (terminal) or through a UI, like Github’s web UI
(SourceTree and GitKraken are other UI’s for Git). We can think of a typical Git workflow as
shown in the below diagram.

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
31

Figure 2.3 This diagram is an extension of the one shown earlier. Developers push and pull code to and
from, respectively, a remote repository. Each user must first commit his or her code to a local repository
before pushing the code to the remote repo.

Next, let’s get hands-on experience using Git so that this workflow will become more clear.

2.3.1 Basic git commands


Installing Git

If you’re using a Mac, Git comes pre-installed. On Windows, you’ll need to install Git. A
common way to get Git setup on Windows is to go to Git’s website (git-scm.com/) and download
the installer for Windows.

Once you have Git installed, you can get started with it by opening a terminal. Any Git command
you use will be comprised of git followed by some keyword or other parameters. Our first
example of this is using Git to download a remote repo for the first time.

Downloading a repository

To download an existing remote repository, we can use the git clone command, like this:

Listing 2.3 git clone command


git clone [URL of repository]

git clone is a command to download a remote repository to local storage.

In this command, we just need to write git clone followed by the URL of the repository we want
to download. For example, suppose you want to download the popular Python requests library
repository from Github. On Github, you can find the link you need to use by going to the repo’s
©Manning Publications Co. To comment go to liveBook
https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
32

main page on Github.

Figure 2.4 Snapshot of Github repo page.

Clicking on Code should bring up a view like below, where you can see and copy the HTTPS
URL (github.com/psf/requests.git in this case).

Figure 2.5 Snapshot of Github repo page.

Next, you can download the contents of the repo like this:

Listing 2.4 git clone command


git clone https://github.com/kennethreitz-archive/requests3.git

Using git clone here to download (or clone) a repository from Github

A benefit of using git clone is that it automatically links to the downloaded repo to being tracked
©Manning Publications Co. To comment go to liveBook
https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
33

by git for you. For example, running the above command will download a folder (in this case,
called requests3) from the Github repository. But now, any changes you make in this folder will
be automatically tracked. For example, let’s suppose we create a new file within the downloaded
directory called test_file.txt. Then, running git status in the terminal shows the following
message:

Figure 2.6 Running ls -a in the terminal will show the newly created hidden git files

From this message we can see that there is one file (the one we just created) that is currently
untracked. Additionally, we can see our local repository is up-to-date with the remote repository
on Github. This means no else has made any changes to the remote repository since we’ve
downloaded the local repository.

git clone is a useful command when there’s an already-existing remote repository that you’re
planing to modify. However, what if a remote repository doesn’t exist? That’s where git init
comes in handy, which we’ll discuss next.

Downloading the repo for this book!

Now that we walked through how to clone the repository for a sample repo, let’s download the
repo for this book!

Listing 2.5 git clone command


git clone https://github.com/atreadw1492/software_engineering_for_data_scientists.git

Using git clone here to download the repository for this book

Now, you should have all the files from the book’s repository in whatever directory you selected
in your computer.

2.4 Git workflow from scratch


Creating a new repository

What if you want to version control a local collection of files? For instance, let’s go through how
we created the book repository in the first place. To start with, we will use the git init command.
If you enter git init in the terminal, a new local repository will be created in the current working
©Manning Publications Co. To comment go to liveBook
https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
34

directory. As an example, if you’re currently in the /this/is/an/example/folder, simply running git


init will create a local repository in /this/is/an/example/folder.

Listing 2.6 git init is a command to create a new local repository


git init

Use git init to create a new local repository

To create a repository in another folder, you just need to specify the name of the that directory,
like in the example below, where we create a repository in /some/other/folder.

Listing 2.7 Use git init [directory name] to create a new repository in another folder
git init /some/other/folder

Running git init /some/other/folder will create a new local repository in


/some/other/folder

When you use the git init command, git will create several hidden files in the input directory. If
you’re using a Mac or Linux, you can see this by running ls -a in the terminal. Similarly, you can
use the same command in Bash on Windows, as well.

Figure 2.7 Running ls -a in the terminal will show the newly created hidden git files

git init can be run in a directory either before or after you’ve created files that you want to
backup via version control. Let’s suppose you’ve already setup a collection of sub-directories
and files corresponding to what you can see in this book’s remote repository.

ch2/…
ch3/…
ch4/…
Etc.

Next, we need to tell git to track the files we’ve created. We can do that easily enough by
running git add . The period at the end of this line tells git to track all of the files within the
directory.

Listing 2.8 Use git add . to tell Git to track all files that were changed
git add .

Now, we can commit our changes. This means that we want to save a snapshot of our changes.
We do this by writing git commit followed by a message that is associated with the commit. To
©Manning Publications Co. To comment go to liveBook
https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
35

specify the message, you need to type the parameter -m followed by the message in quotes.

Listing 2.9 git commit saves the changes you’ve made as a snapshot of the repo. The
parameter -m is used to include a message / description for the commit.
git commit -m "upload initial set of files"

Running this git commit command will save the changes we’ve made to the repo
(in this case, creating the 1_process_data.py file)

Now that we’ve committed our changes, we need to create a remote repository in order to upload
our committed changes. This remote repository will be where other users can download or view
your changes.

2.4.1 Uploading local repository changes to a remote repository


There’s several sites for hosting remote repositories, but a popular one (as mentioned above) is
Github. To create a remote repo on Github, you should be able to follow these steps:

Create a Github account if you don’t already have one


On most Github pages, you should see a plus sign that you can click to create a new repo

Figure 2.8 To create a new repo on Github, look for the plus sign (top right corner of the webpage) to
click and create a new repo.

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
36

Give a name to your new repository. It’s recommended that this name matches the name
of the folder you’re storing the local copies of the files you’re dealing with. For example,
if sample_data_science_project is the name of your local folder, then you could also
name your repository sample_data_science_project. For the book’s codebase, our
repository name is software_engineering_for_data_scientists.
Next, you’re ready to push the local repository to the remote one you just created.

To actually push your local repository to the one on Github, you can run a command similar to
this:
Listing 2.10 Use _git remote add origin [remote repo URL] to enable pushing your changes
to a remote repository.
git remote add origin https://github.com/USERNAME/sample_data_science_project.git

Running this command will allow us to push our changes to the remote repo at this
URL: github.com/USERNAME/sample_data_science_project.git

USERNAME will be replaced with your username, while sample_data_science_project will be


replaced with whatever name you choose for the repository (like
software_engineering_for_data_scientists, for example).

Next, run the line below to tell git that you want to use the main branch. Usually, the main
branch is called master or main. This branch should be considered the source of truth. In other
words, there might be other branches that deal with experimental code (for instance, feature_x
branch), but the main branch should use code that has closer to being production-ready, or at
least passed off to software engineers for production. In some cases, if the codebase is small, or
there are only a few contributers, you might decide to just use a single main branch. However, as
codebases get larger, and more people get involved in contributing code to the repository, then
creating separate branches can help keep the main branch clean from messy spaghetti code that
frequently changes.

Listing 2.11 git branch -M main tells Git that you want to use the main branch when you
push or pull changes.
git branch -M main

Tell git that you want to use the main branch

Lastly, you can run git push -u origin main to push your local repo changes to the remote
repository. After running this line, you should be able to see the changes in the remote
repository.

Listing 2.12 git push -u origin main will push your local changes to the remote repo.
git push -u origin main

Push the changes in the local repo to the main remote repository
©Manning Publications Co. To comment go to liveBook
https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
37

As you and your potential colleagues make changes to the same repo, it is convenient to be able
to easily tell who made which changes. Fortunately, there’s a straightfoward way to do this,
which we’ll cover next.

Modifying a Git repo

Let’s suppose now that we want to add a new file to our working directory called
1_process_data.py. This file could be a Python script that reads in data from a database and
performs basic processing / cleaning of the data. As a naming convention, we might add "1_" to
the front of the script name in order to convey that this is the first script in a collection of
potential files that needs to be run. For now, though, let’s suppose we’ve just created this
1_process_data.py file. In order to backup our new file via git’s source control system, we’ll
need to commit the file (more on this in just a moment). First, however, let’s run git status. This
command, as described above, is a simple way of checking what files have been modified or
created, but are not currently being tracked in git’s version control system.

Listing 2.13 Use git status to check the status of the current directory, which will show any
files that have been created or modified, but not yet committed.
git status

Running git status will tell you what files have been created or modified, but not
yet committed

Figure 2.9 Running git status shows what files, if any, are not currently being tracked via git

Next, let’s tell Git to track our new file, 1_process_data.py. Again, we can do that easily enough
by running git add . to add all changed/new files for tracking.

Listing 2.14 Use git add [file_name] to tell git to track a specific file. In this case, we will
track our new file, 1_process_data.py.
git add 1_process_data.py

Add 1_process_data.py to a staging area so that we can track its changes

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
38

You can also add multiple files by running the git add command separately. For example, after
running the command above, you could run git add 2_generate_features.py and Git will prepare
2_generate_features.py to be committed. This sample file is available in the Git repo, along with
1_process_data.py, so that you can practice on your own.

Now, we can commit our new file. The -m parameter adds a message in the commit providing a
short description.

Listing 2.15 git commit saves the changes you’ve made as a snapshot of the repo. The
parameter -m is used to include a message / description for the commit.
git commit -m "create 1_process_data.py for processing data"

Running this git commit command will save the changes we’ve made to the repo
(in this case, creating the 1_process_data.py file)

Lastly, we can push the changes to our remote repo.

Listing 2.16 git push -u origin main will push your local changes to the remote repo.
git push -u origin main

Push the changes in the local repo to the main remote repository

Next, let’s a take a look at how we can see who made commits.

2.4.2 How to see who made commits


We stated previously that Git helps with tracking who made specific changes. To actually see
who made specific changes, you can run the git log command.

Listing 2.17 git log will print out what commits have been made in the repo.
git log

Print a log of what commits have been made in the repo

Figure 2.10 Running git log will show the commit history for the repo

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
39

The long combination of digits and characters after commit is the commit hash ID. It’s a unique
identifier for a specific commit. You can also see the contents of the commit (the actual code
change) by using git show, followed by the a hash commit ID.

Listing 2.18 Use git show to see the contents of a commit


git show 2793446df81f27980c4bbbf96ede45ce929a5c93

Print the contents of a specific commit

Figure 2.11 Running git show will show the contents of a specific commit, as can be seen in thie
example snapshot.

In this case, git show doesn’t display any code because our sample file we created was empty.
But, let’s suppose we have created and committed another file for feature creation. If we run git
show for this other commit, we might get something like the snapshot below showing lines of
code that have been added to a file.

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
40

Figure 2.12 This time git show displays the code changes to a specific file

In addition to committing your own changes, it is important to be able to get the latest updates
from the remote repository. Let’s dive into how to get the latest changes from the remote
repository next!

2.5 Getting the latest changes from a remote repository


As you collaborate on your data science project, it’s important to keep up to date with the latest
code changes. For example, a member of your team might add a new file for cleaning a
collection of features. To get the latest changes, you can use the git pull command. git pull will
fetch the remote changes and automatically try to merge them with your local repository. If there
are no conflicts between the remote repo and your own, Git will merge the remote repository’s
updates into your local repo. However, if there are conflicts, they will need to be handled
separately, as we’ll discuss in the next section.

Listing 2.19 Use the git pull command to get the latest changes from a repo
git pull origin

Use git pull to get the latest changes from a repository.

In the above command, origin refers the remote repository (you can think of it as the original
repo). Alternatively, you can just run git pull, which will pull the changes from the same remote
repository by default.

Listing 2.20 We can also omit the "origin" snippet in our previous git pull command.
git pull

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
41

Use git pull to get the latest changes from a repository.


Next, let’s show how to deal with conflicts that can arise when merging.

2.6 Conflicts and merging changes from different users


Let’s go back to our example of two data scientists (you are your colleague) working on the
customer churn project. What happens if you and your colleague make changes to the exact same
line of code in the same file? This can lead to a conflict. Let’s walk through an example.

Conflict example

Suppose the 1_process_data.py file mentioned previously contains a simple Python function, like
this:

Listing 2.21 Sample Python function to demonstrate what happens when two users update
the same line of code
def read_data(file_name):

df = pd.read_csv(file_name)

return df

Create a function to read data from a file

Let’s say that you change the name of the function to read_file. However, your colleague
changed the name to read_info in a local repo and then pushed those changes to the remote
repository that both of you are working with. In this case, running git pull will result in an error
message that looks like this:

Listing 2.22 Run git diff to show the conflict differences between your repo vs. the remote
one.
Automatic merge failed; fix conflicts and then commit the result.

Merge conflict message

©Manning Publications Co. To comment go to liveBook


https://livebook.manning.com/book/software-engineering-for-data-scientists/discussion
Another Random Scribd Document
with Unrelated Content
and I could not but express my approbation of them all. “What do
you tell me?” said he, interrupting me hastily while I was speaking of
one of them; “and yet I gave him so bad a reception at the Tuileries
on my return! Ah! I fear I have committed some involuntary acts of
injustice! This comes of being obliged to take for granted the first
story that is told, and of not having a single moment to spare for
verification! I fear too that I have left many debts of gratitude in
arrear! How unfortunate it is to be incapable of doing every thing
one’s self!”
I replied—“Sire, it is true that, if blame be attached to the officers
of your household, it must be shared equally by all; a fact, however,
which must humble us strangely in the eyes of foreign nations. As
soon as the King appeared, all hastened to him, not as to the
sovereign whom your abdication had left us, but as to one who had
never ceased to be our sovereign; not with the dignity of men proud
of having always fulfilled their duties, but with the equivocal
embarrassment of unskilful courtiers. Each sought only to justify
himself: your Majesty was from that instant disavowed and abjured;
the title of Emperor was dropped. The Ministers, the Nobles, the
intimate friends of your Majesty, styled you simply 'Buonaparte,’ and
blushed not for themselves or their nation. They excused themselves
by saying that they had been compelled to serve; that they could
not do otherwise, through dread of the treatment they might have
experienced.” The Emperor here recognised a true picture of our
national character. He said we were still the same people as our
ancestors the Gauls: that we still retained the same levity, the same
inconstancy, and, above all, the same vanity. “When shall we,” said
he, “exchange this vanity for a little pride?”
“The officers of your Majesty’s household,” said I, “neglected a
noble opportunity of acquiring both honour and popularity. There
were above one hundred and fifty officers of the household; a great
number of them belonged to the first families, and were men of
independent fortune. It was for them to set an example, which,
being followed by others, might have given another impulse to the
national attitude, and afforded us a claim on public esteem.”[24]
—“Yes,” said the Emperor, “if all the upper classes had acted in that
way, affairs might have turned out very differently. The old editors of
the public journals would not then have indulged in their chimeras of
the good old times; we should not then have been annoyed with
their dissertations on the straight line and the curve line; the King
would have adhered honestly to his charter; I should never have
dreamed of quitting the Island of Elba; the head of the nation would
have been recorded in history with greater honour and dignity; and
we should all have been gainers.”
THE EMPEROR’S IDEA OF RESERVING CORSICA.—HIS OPINION OF
ROBESPIERRE.—HIS IDEAS RESPECTING PUBLIC OPINION.—
EXPIATORY INTENTION OF THE EMPEROR WITH REGARD TO
THE VICTIMS OF THE REVOLUTION.
18th.—After the accustomed occupation of the day, I accompanied
the Emperor to the garden about four o’clock. He had just completed
his dictation on the subject of Corsica. Having concluded every thing
he had to say relative to that island, and to Paoli, he adverted to the
interest which he himself excited there, while yet so young, at the
time of his separation from Paoli. He added that latterly he might to
a certainty have united in his favour the wishes, the sentiments, and
the efforts of the whole population of Corsica; and that, had he
retired to that island on quitting Paris, he would have been beyond
the reach of any foreign power whatever. He had an idea of doing so
when he abdicated in favour of his son. He was on the point of
reserving to himself the possession of Corsica during his life. No
obstacle at sea would have obstructed his passage thither. But he
abandoned that design for the sake of rendering his abdication the
more sincere and the more advantageous to France. His residence in
the centre of the Mediterranean, in the bosom of Europe, so near
France and Italy, might have furnished a lasting pretext to the Allies.
He even preferred America to England, from the same motive and
the same idea. It is true that, in the sincerity of his own measures,
he neither did, nor could foresee, his unjust and violent banishment
to St. Helena.
The Emperor, next proceeding to take a review of different points
of the Revolution, dwelt particularly on Robespierre, whom he did
not know, but whom he believed to be destitute of talent, energy, or
system. He considered him, notwithstanding, merely as the
scapegoat of the Revolution, sacrificed as soon as he endeavoured
to arrest it in its course:—the common fate, he observed, of all who,
before himself (Napoleon) had ventured to take that step. The
Terrorists and their doctrine survived Robespierre; and if their
excesses were not continued, it was because they were obliged to
bow to public opinion. They threw all the blame on Robespierre; but
the latter declared shortly before his death, that he was a stranger
to the recent executions, and that he had not appeared in the
Committees for six weeks previously. Napoleon confessed that, while
he was with the army of Nice, he had seen some long letters
addressed by Robespierre to his brother, condemning the horrors of
the Commissioners of the Convention, who, as he expressed it, were
ruining the Revolution by their tyranny and atrocities. “Cambaceres,
who,” observed the Emperor, “must be a good authority on subjects
relating to that period, answered an enquiry which I one day
addressed to him respecting the condemnation of Robespierre, in
these remarkable words: ‘Sire, that was a sentence without a trial;’
adding that Robespierre had more foresight and conception than
was generally imagined; and that his intention was, after subduing
the unbridled factions which he had to oppose, to restore a system
of order and moderation. ‘Some time previously to his fall,’ added
Cambaceres, ‘he delivered a most admirable speech on this subject;
it was not thought proper to insert it in the Moniteur, and all trace of
it is now lost.’”
This is not the first instance I have heard of omissions and want of
accuracy in the Moniteur. In the reports inserted in that journal
relative to the proceedings of the Assembly, there must be a period
remarkable for incorrectness; as the minutes of those proceedings
were for a time arbitrarily drawn up by one of the Committees.
Those who are induced to believe that Robespierre was at once
wearied, satiated, and alarmed by the Revolution, and had resolved
on checking it, affirm that he would not take any decided step until
after he had read his famous speech. He considered it so fine that
he had no doubt of its effect on the Assembly. If this be true, his
mistake or his vanity cost him dear. Those who think differently
assert that Danton and Camille-des-Moulins had precisely the same
views; and yet that Robespierre sacrificed them. To these it is replied
that Robespierre sacrificed them to preserve his popularity, because
he judged that the decisive moment had not yet arrived; or because
he did not wish to resign to them the glory of the enterprise.
Be this as it may, it is certain that the nearer we approach to the
instruments and the agents in that catastrophe, the greater
obscurity and mystery we find; and this uncertainty will but increase
with time. Thus the page of history will, on this point as on many
others, become the record, not so much of the events which really
occurred, as of the statements which are given of them.
In the course of our conversation relative to Robespierre, the
Emperor said that he had been very well acquainted with his brother,
the younger Robespierre, the representative to the Army of Italy. He
said nothing against this young man, whom he had led into action
and inspired with great confidence and considerable enthusiasm for
his person; so much so, that previously to the 9th of Thermidor,
young Robespierre, being recalled by his brother, who was then
secretly laying his plans, insisted on Napoleon’s accompanying him
to Paris. The latter experienced the greatest difficulty in ridding
himself of the importunity, and, at length, only escaped it by
requesting the interference of the General-in-chief Dumerbion,
whose entire confidence he possessed, and who represented that it
was absolutely necessary he should remain where he was. “Had I
followed young Robespierre,” said the Emperor, “how different might
have been my career! On what trivial circumstances does human
fate depend!—Some office would doubtless have been assigned to
me; and I might at that moment have been destined to attempt a
sort of Vendemiaire. But I was then very young; my ideas were not
yet fixed. It is probable, indeed, that I should not have undertaken
any task that might have been allotted to me; but supposing the
contrary case, and even admitting that I had been successful, what
results could I have hoped for? In Vendemiaire the revolutionary
fever was totally subdued; in Thermidor it was still raging in its
utmost fury and at its greatest height.”
“Public opinion,” said the Emperor, on another occasion, when
conversing on another subject, “is an invisible and mysterious power
which it is impossible to resist: nothing is more unsteady, more
vague, or more powerful; and capricious as it may be, it is,
nevertheless, just and reasonable more frequently than is supposed.
On becoming Provisional Consul, the first act of my administration
was the banishment of fifty anarchists. Public opinion, which had at
first been furiously hostile to them, suddenly turned in their favour,
and I was forced to retract. But some time afterwards, these same
anarchists, having shewn a disposition to engage in plots, were
again overthrown by that very public opinion, which had now
returned to support me. Thus, through the errors that were
committed at the time of the restoration, popularity was secured to
the regicides, who but a moment before had been proscribed by the
great mass of the nation.
“It belonged to me only,” continued the Emperor, “to shed a lustre
over the memory of Louis XVI. in France, and to purify the nation of
the crimes with which it had been sullied by frantic acts and
unfortunate fatalities. The Bourbons, being of the royal family, and
coming from abroad, merely avenged their own private cause, and
augmented the national opprobrium. I, on the contrary, being one of
the people, should have raised the character of the nation, by
banishing from society, in her name, those whose crimes had
disgraced her. This was my intention, but I proceeded prudently in
the fulfilment of it. The three expiatory altars at St. Denis were but a
prelude to my design. The Temple of Glory, on the site of the
Magdelaine, was to have been devoted to this object with still
greater solemnity. There, near the tomb and over the very bones of
the political victims of our revolution, monuments and religious
ceremonies would have consecrated their memory in the name of
the French people. This is a secret that was not known to above ten
individuals: though it had been found necessary to communicate a
hint of the design to those who were intrusted with the arrangement
of the edifice. I should not have executed my scheme in less than
ten years; but what precautions had I not adopted; how carefully
had I smoothed every difficulty, and removed every obstruction! All
would have applauded my design, and no one would have suffered
from it. So much depends on circumstances and forms,” added he,
“that in my reign, Carnot would not have dared to write a memorial,
boasting of the death of the King, though he did so under the
Bourbons. I should have leagued with public opinion in punishing
him; while public opinion sided with him in rendering him
unassailable.”

CASCADE AT BRIARS.

19th.—My son and I rose very early. Our task had been finished
on the preceding day; and as the Emperor could not want me for
some time, we availed ourselves of the fineness of the morning to
explore the neighbourhood of our abode.
Passing through the valley of James-Town, on the right of our little
level height at Briars, was a deep ravine, the sides of which were
intersected by numerous perpendicular cliffs. We descended into the
ravine, not without difficulty, and found ourselves at the edge of a
little limpid streamlet, beside which grew abundance of cresses. We
amused ourselves by gathering them as we passed along; and after
a few windings we soon reached the extremity of the valley and the
streamlet, which are closed transversely by a huge pointed mass of
rock, from the summit of which issues a pretty cascade, produced
from the waters of the surrounding-heights. This water-fall
descending into the valley forms the streamlet along which we had
just passed, and which rolls sometimes in a rapid stream to the sea.
The water of the cascade was at this moment dispersed above our
heads in small rain or light vapour; but in stormy weather it rushes
forth in a torrent, and furiously dashes through the ravine till it
reaches the sea. To us the scene presented a gloomy, solitary, and
melancholy aspect; though it was altogether so interesting that we
quitted it with regret.
To-day was Sunday, and we all dined with the Emperor; he good
humouredly observed that we composed his state party. After dinner
the circle of our amusements was not very extensive: he asked us
whether we would have a comedy, an opera, or a tragedy. We
decided in favour of a comedy, and he himself read a portion of
Moliere’s Avare, which was continued by other individuals of the
party. The Emperor had a cold, and was slightly feverish. He
withdrew early from his walk in the garden, and desired me to see
him again that evening, if he should not have gone to bed. My son
and I accompanied the rest of the gentlemen to the town; and on
our return, the Emperor had retired to rest.

FIRST AND ONLY EXCURSION DURING OUR ABODE AT


BRIARS. THE ADMIRAL’s BALL.

20th.—The Emperor, after dictating as usual to one of the


gentlemen, called me about five o’clock. He was alone; the rest of
the gentlemen and my son having gone to the town, where the
Admiral was that evening to give a ball. The Emperor and I walked
along the road leading to the town, until we came within sight of the
sea and the shipping. On the left, in the depth of the valley, was a
pretty little house. The Emperor stood for a considerable time with
his glass at his eye, examining the garden, which appeared to be
very well cultivated, and in which a group of beautiful children were
at play, attended by their mother. We were informed that this house
belonged to Major Hudson, a resident in the island, the same
gentleman who had lent me the Annual Register. The house was
situated at the bottom of the ravine which commences in the vicinity
of Briars, and near the curious cascade which I have already noticed.
The Emperor took a fancy to go down to the house, though it was
now nearly six o’clock. The road was extremely steep: we found it
longer and more difficult of descent than we had expected; and we
reached the bottom of the ravine quite out of breath. We took a
survey of the little domain, which had evidently been laid out as the
residence of a permanent occupant, and not as the mere temporary
abode of a traveller passing to a foreign land; and, after receiving
the attentions of the master of the house, and paying a few
compliments to the mistress, the Emperor took his leave.
But the evening was already far advanced, and we were very
much fatigued; we therefore accepted the horses that were offered
us, and speedily returned to our hut and our dinner. This little
excursion, and the exercise of riding on horseback, which had been
so long relinquished, seemed to do the Emperor good.
He desired that I would go to the Admiral’s ball, in spite of my
reluctance to leave him. At half-past eight o’clock he observed that
the night was dark, the road bad, and that it was time I had set out.
He insisted on my leaving him, and he entered his room, where I
saw him undress and retire to bed. He again desired me to go, and I
unwillingly obeyed. I left him alone; and thus, for the first time,
violated a custom which had become most dear to me.
I proceeded on foot to the town. The Admiral had given great
éclat to his ball. It had been talked of for a considerable time before.
He wished it to be understood that the entertainment was given
solely on our account, and we had been formally invited. Was it
most advisable to accept or to decline the invitation? Something
might be said on both sides. Political misfortunes did not require that
we should assume the appearance of domestic sorrow; it might be
proper, and even useful, to mingle cheerfully in company with our
jailors. We might, therefore, adopt either resolution indifferently. We
determined to go. But what sort of conduct were we to observe?
Should we assume pride, or employ address? The first might be
attended with inconvenience; in our situation every wounded
pretension became an insult. In the second there could be no
impropriety: to receive marks of politeness as though we were
accustomed to them, and as though they were our due, and to
overlook any little want of respect, was certainly the wisest course. I
arrived at the ball very late, and left it very early. I was much
pleased with the entertainment in every respect.

MY CONDUCT WHILE THE EMPEROR WAS AT ELBA.

21st—22nd. The Emperor, who had often questioned me on the


line of conduct pursued by many of his ministers, members of his
Council, and officers of his Household, during his residence at the
Island of Elba, at length called me to account in my turn, saying:
—“But you yourself, Las Cases, what did you do after the arrival of
the King? What happened to you all that time? Come, sir, make a
report on that subject: you know this is my way; and it is the only
plan by which we can properly classify what we say, or what we wish
to learn. Besides, it will furnish you with another article for your
Journal. And, don’t you see?“ added he, jokingly, “your biographers
will only have the trouble of extracting; the thing will be all ready
written to their hands.”
“Sire,” I replied, “you shall have a literal statement of every thing;
though I have but little to say. I commanded, on the 31st of March,
the 10th legion of the National Guard of Paris, that of the Legislative
Body. We lost, during the day, a considerable number of men. At
night I heard of the capitulation; I wrote to the officer next in rank
to myself, and transferred to him the command of my legion,
informing him that, though in my quality of member of the Council
of State I had previously received orders to proceed elsewhere, yet I
had not wished to abandon my legion at the moment of danger; but
that the event which had just occurred having changed the aspect of
affairs, I must now proceed forthwith to fulfil new duties.
“At day-break I set out on the road to Fontainebleau, and found
myself in the midst of the wrecks of Marmont’s and Mortier’s
detachments. I was on foot, but I doubted not I should be able to
purchase a horse. I soon, however, discovered that soldiers in
retreat are neither just nor civil. At that disastrous moment, my
uniform of a National Guard was insulted, and I was myself ill-
treated.
“After an hour’s walk, overpowered by the fatigue of the journey,
joined to the want of rest which I had experienced for two or three
nights previously; seeing around me no face that I knew, and having
no hope of procuring a horse, I determined, with a sorrowful heart,
to return to the capital.
“The National Guard was ordered out to assist in the triumphant
entry of the enemy: there was even a probability of its being
selected as a guard of honour to the Sovereigns who had conquered
us. I determined to be absent from my home. I had conveyed my
wife and children safely out of Paris a week or two before, and for a
few days had recourse to the hospitality of a friend. I never went out
of doors but in a shabby great coat, visiting the coffee-houses and
public places, and joining the different groups which were formed in
the streets. My object was to make observations on persons and
things, and above all, to learn the real feeling of the people. How
many extraordinary occurrences did I not witness in the course of
my rambles!
“I saw in front of the residence of the Emperor of Russia, men
distinguished by their rank, and calling themselves Frenchmen,
exerting their utmost endeavours to induce the rabble to call out
‘Long live Alexander, our deliverer!’
“I saw, Sire, your monument on the Place Vendôme resist the
efforts of a few wretches, belonging to the lowest dregs of the
people, who had been hired by persons of note.
“Finally, in one of the comers of the Place Vendôme, before the
hotel of the Commandant of the place, I saw one of the officers of
your household trying, on the first evening after your departure, to
prevail on young conscripts to enter another service than yours; but
he received from them a lesson that might have made him blush for
his own conduct, had he been capable of feeling shame.
“Doubtless, those to whom I here allude will exclaim that I
mingled with the rabble; and yet it may with justice be affirmed that
the acts of baseness which then disgraced France did not originate
with the rabble. These acts were far from obtaining the countenance
of the lower classes of the people; on the contrary, they were
decidedly censured by the uprightness, generosity, and nobleness of
sentiment, manifested in the public streets. What reproaches might I
not convey, were I to repeat all that I heard on this subject!
“Your Majesty abdicated. I had refused my signature to the act of
adherence of the Council of State; but I thought I might make
amends for this by an additional act of adherence. The Moniteur was
every day filled with articles of this kind; mine however was not
deemed worthy the honour of insertion.
“At length the King arrived: he was henceforth our sovereign. He
appointed a day for the reception of those individuals who had been
presented to Louis XVI. I proceeded to the Tuileries to avail myself
of this prerogative.—What were my reflections on entering those
apartments which had so lately been filled with your glory and
power! And yet I presented myself to the King sincerely and in good
faith; my foresight never led me even to think of your return.
“Deputations to the King were multiplied beyond number: a
meeting of the officers of the naval establishment was proposed. To
the person who communicated this fact to me I replied that nothing
could be more gratifying to my heart than to join my old comrades,
none of whom could entertain sentiments purer than I did; but that
the offices I had filled placed me in a peculiar and delicate situation,
and that motives of prudence must deter me from appearing where
the zeal of a president might lead him to employ expressions which I
neither could nor would sanction by my opinion or presence.
“Subsequently, however, in spite of my mortification and disgust, I
determined, at the solicitation of some friends, to think of something
for myself. The Council of State was re-composed; several members
of the last Council assured me, in spite of my recent conjectures on
that point, that nothing was easier than to retain my office; that
they had succeeded merely by an application to the Chancellor of
France. I had not courage to venture a moment’s encroachment on
his Lordship’s time: and therefore contented myself with writing to
acquaint him that I had been Master of Requests to the last Council
of State; and that, if that circumstance were not sufficient to exclude
me from becoming a member of the new assembly, I begged him to
recommend me to the King as a Councillor of State. I observed that
I would not advance as claims to favour my eleven years’ emigration
or the loss of my patrimony in the King’s cause. At that period I had
only done what I then considered to be my duty; which I had at all
times, to the best of my knowledge, fulfilled faithfully and to the last
moment. This phrase, as may well be supposed, deprived me even
of the honour of a reply.
“Meanwhile the new situation of Paris, the sight of the foreign
troops, the acclamations of every kind, were more than I could
endure; and I adopted the determination of going for a short time to
London, where I should meet with old friends, who might afford me
all the consolation of which I was susceptible. Then, again, I
recollected that I might find in London the same tumult and the
same exultation that had driven me from Paris; this proved to be the
fact. London was the scene of festivity and rejoicing, to celebrate the
triumphs of the English and our humiliation.
“During my stay in London, the marine establishment was re-
modelled at Paris, and the Chevalier de Grimaldi, one of my old
comrades, whom I had not seen or heard of for a length of time,
was appointed a member of the Committee. He called on my wife,
and expressed his surprise that I had not put in my claims;
observing that I was entitled, by law, to return to the corps, or to
retire on a certain pension. He advised my wife to bring me to a
decision on the subject, and to rely on his friendship; adding that
there was no time to be lost. I attached higher value to this mark of
attention than to the favour which it was intended to procure me.
However, I wrote to the Committee, requesting that, as I was
desirous of wearing a uniform to which I had become attached, I
might be allowed to enjoy the honorary title of Capitaine de
Vaisseau; while at the same time I renounced the pension, to which
I did not conceive myself entitled.
“I returned to Paris. The diversity of opinions and the irritation of
the public mind were extreme. I had for a long time lived in the
greatest retirement. I now confined myself entirely to the domestic
circle of my wife and children. Never at any former period of my life
did I prove myself a better husband or a better father; and never,
perhaps, was I more physically happy.
“As I was one day reading, in the Journal des Debats, an account
of a work of M. Beauchamp, I found mentioned the names of several
gentlemen who were stated to have assembled on the Place Louis
XV. on the 31st March, to excite sentiments in favour of royalty; and
my name was among the number. It was in good company, no
doubt; but at the same time the statement was untrue; and I should
have been considerably lowered in the estimation of many if it had
been believed. I wrote to request a correction of the error, which
was calculated to render me the subject of congratulations to which
I was in no way entitled.
“I observed that it was out of my power at the time to act in the
way described, whatever might have been my inclination. As the
commander of a legion of the National Guard, I had contracted
obligations from which no consideration on earth could free me, &c.
I sent my letter to the deputy Chabaud-Latour, one of the
proprietors of the Journal des Debats, a man for whom I entertained
a great esteem. He declined publishing my letter, purely from good
intentions towards me. I then addressed it to the editor; but he
refused to insert it on account of difference of opinion.
“Meanwhile, the state of the public mind indicated an inevitable
and speedy catastrophe. Every thing foreboded that the Bourbons
would share the fate of the Stuarts. My wife and I used every
evening to amuse ourselves in reading Hume’s History of England.
We began at Charles I., and your Majesty arrived before we had got
to James II.” (Here the Emperor could not repress a laugh.)
“Your Majesty’s advance and arrival,” continued I, “were to us a
subject of the greatest astonishment and anxiety. I was far from
foreseeing the honourable voluntary exile which it would gain for me
in the end; for I was then little known to your Majesty; and
circumstances arising out of that event alone brought me here. Had
I filled the most trivial post under the King; had I even been a
frequent attendant at the Tuileries, which would have been very
natural and consistent with propriety, I should not have appeared for
a length of time in your Majesty’s presence. Not, indeed, that I
should have had any thing to reproach myself with, or that my
attachment to you would have been the less sincere; but because I
should not have wished to pass for a piece of court furniture, or to
seem always ready to offer incense at the shrine of power. I should
have awaited an appointment, instead of pressing forward to solicit
one. But as it was, I felt myself so much at liberty, every thing about
me was in such perfect harmony, that I seemed to form a part of the
great event. I therefore eagerly hastened to meet the first glance of
your Majesty; I felt as though I had claims on your kindness and
favour. On your return from Waterloo, the same sentiments brought
me immediately and spontaneously near your person, which I have
never since quitted. If I was then attracted by your public glory, I am
now attached by your private virtues; and if it be true that the
gratification of my feelings then cost me some sacrifice, I now find
myself repaid a hundred-fold, by the happiness I enjoy in being able
to tell you so.
“It would however be difficult to describe the extreme disgust I
felt at every thing during the ten months of your absence. I felt an
utter contempt for mankind and worldly vanities. Every illusion was
destroyed, all interest had vanished. Every thing appeared to be at
an end, or to be undeserving of the smallest value. During my
emigration, I had received the cross of St. Louis; an ordinance
decreed that it was to be legitimated by a new brevet. I had not
spirit to put in my claim. Another ordinance directed that the titles
bestowed by your Majesty should be sent in to be confirmed; but I
felt indifferent with regard to compromising those which I had
obtained during the Empire. In fine, I received a letter from the
Marine department, informing me that my captain’s commission had
just been forwarded thither, and there it still remains.
“Your Majesty’s absence was to me a widowhood, the affliction
and grief of which I concealed from no one. But on your return I
was repaid for all by the testimony borne by those who surrounded
you, and to whom I had previously been scarcely known. At your
Majesty’s first levee, the individual who was ad interim at the head
of the department of foreign affairs, coming from the presence, took
me aside to a window, and told me to go home and prepare, as I
should probably have to set out on a journey. He had just, he said,
proposed me to your Majesty, adding that he had represented me as
a madman, but mad for love of you. I wished to know whither I was
to be sent; but that, he said, he neither would nor could tell me. I
never heard any thing more of the matter.
“M. Regnault de Saint-Jean d’Angeli placed me on the list of the
Imperial Commissioners whom your Majesty sent to the
departments, I assured him that I was ready to do any thing; but I
observed that I was a noble and an emigrant, and that these two
words pronounced by the first comer would be sufficient to
annihilate me, in case of necessity, at any time or in any place. He
acknowledged the justice of my observation, and relinquished his
intention.
“A Senator next solicited that your Majesty would appoint me to
the prefecture of Metz, his native town. He requested me to make
this sacrifice for only three months, in order, as he said, to conciliate
the popular mind, and set things to rights. At length Decrés and the
Duke of Bassano proposed me as a Councillor of State; and, the
third day after your arrival, your Majesty signed my appointment.”
23rd.—The Emperor was still indisposed: he confined himself to
his room, and would see nobody. He sent for me at 9 o’clock in the
evening. I found him very low-spirited and melancholy. He scarcely
spoke to me, and I did not dare to say anything to him. If I regarded
his illness as merely physical, it grieved me sincerely:—if he laboured
under mental affliction, how much more was I grieved that I could
not employ all the resources of consolation with which the heart
naturally overflows for those whom we truly love. The Emperor
dismissed me in about half an hour.
24th.—The Emperor continued indisposed, and still declined seeing
any body. He sent for me to dine with him at a late hour. Dinner was
served on a little table beside the sofa on which he was lying. He ate
heartily. He said that he stood in need of some sudden revulsion of
the constitution, which he should soon obtain; so well did he
understand his own temperament. After dinner he took up the
Memoirs of Marshal de Villars, which amused him. He read aloud
many passages, which revived former recollections, and gave rise to
many anecdotes.

THE EMPEROR’S TEMPERAMENT.—RIDING.—NOTIONS


OF MEDICINE.

25th.—The Emperor still continued unwell: he had passed a bad


night. At his desire I dined with him beside the sofa, which he was
unable to leave. He was, however, evidently much better. After
dinner he wished to read. He had a heap of books scattered around
him on the sofa. The rapidity of his imagination, the fatigue of
dwelling always on the same subject, or of reading what he already
knew, caused him to take up and throw down the books one after
the other. At length he fixed on Racine’s Iphigenia, and amused
himself by pointing out the beauties, and discussing the few faults,
to be found in that work. He dismissed me at an early hour.
Contrary to the general opinion, in which I myself once
participated, the Emperor is far from possessing a strong
constitution. His limbs are large, but his fibres are relaxed. With a
very expanded chest, he is constantly labouring under the effects of
cold. His body is subject to the influence of the slightest accidents.
The smell of paint is sufficient to make him ill; certain dishes, or the
slightest degree of damp, immediately take a severe effect on him.
His body is far from being a body of iron, as is generally supposed:
all his strength is in his mind. His prodigious exertions abroad and
his incessant labours at home are known to every one. No sovereign
ever underwent so much bodily fatigue. The most remarkable
instance of the Emperor’s activity and exertion was his riding post
from Valladolid to Burgos, (a distance of thirty-five Spanish leagues)
in five hours and a half; that is to say, upwards of seven leagues an
hour.[25] The Emperor had set out accompanied by a numerous
escort, in case of danger from the Guerillas; but at every yard he left
some of his company behind him, and he arrived at Burgos with but
few followers. His ride from Vienna to the Simmering, a distance of
eighteen or twenty leagues, is also frequently talked of. The Emperor
rode to breakfast at the Simmering, and returned to Vienna
immediately after. Napoleon often hunted to the distance of thirty-
eight leagues, and never less than fifteen. One day a Russian officer,
who had come as a courier from St. Petersburg in the space of
twelve or thirteen days, arrived at Fontainebleau at the moment
when the Emperor was about to set out on a hunt. By way of a rest,
the officer had the honour to be invited to join the hunting-party. He
of course accepted the invitation; but he dropped down in the forest,
overcome by fatigue, and was not found until after considerable
search had been made for him.
I have known the Emperor to be engaged in business in the
Council of State for eight or nine hours successively, and afterwards
rise with his ideas as clear as when he sat down. I have seen him at
St. Helena peruse books for ten or twelve hours in succession, on
the most abstruse subjects, without appearing in the least fatigued.
He has suffered, unmoved, the greatest shocks that ever man
experienced. On his return from Moscow or Leipsic, after he had
communicated the disastrous event in the Council of State, he said:
—“It has been reported in Paris that this misfortune turned my hair
grey; but you see it is not so (pointing to his head); and I hope I
shall be able to support many other reverses.” But these prodigious
exertions are made only, as it were, in despite of his physical
powers, which never appear less susceptible than when his mind is
in full activity.
The Emperor eats very irregularly, but generally very little. He
often says that a man may hurt himself by eating too much, but
never by eating too little. He will remain four-and-twenty hours
without eating, only to get an appetite for the ensuing day. But if he
eats little, he drinks still less. A single glass of Madeira or Champaign
is sufficient to restore his strength, and to produce cheerfulness of
spirits. He sleeps very little and very irregularly, generally rising at
daybreak to read or write, and afterwards lying down to sleep again.
The Emperor has no faith in medicine, and never takes any. He
had adopted a peculiar mode of treatment for himself. Whenever he
found himself unwell, his plan was to run into an extreme, the
opposite of what happened to be his habit at the time. This he calls
restoring the equilibrium of nature. If, for instance, he had been
inactive for a length of time, he would suddenly ride about sixty
miles, or hunt for a whole day. If, on the contrary, he had been
harassed by great fatigues, he would resign himself to a state of
absolute rest for twenty-four hours. These unexpected shocks
infallibly brought about an internal crisis, and instantly produced the
desired effect: this remedy, he observed, never failed.
The Emperor’s lymphatic system is deranged, and his blood
circulates with difficulty. Nature, he said, had endowed him with two
important advantages: the one was the power of sleeping whenever
he needed repose, at any hour, and in any place; another was that
he was incapable of committing any injurious excess either in eating
or drinking. “If,” said he, “I go the least beyond my mark, my
stomach instantly revolts.” He is subject to nausea from very slight
causes; a mere tickling cough is sufficient to produce that effect on
him.

OUR MODE OF LIVING AT BRIARS.—MY FIRST VISIT TO


LONGWOOD.—INFERNAL MACHINE; ITS HISTORY.

26th—28th. On the 26th the Emperor dressed very early: he found


himself quite recovered. He wished to walk out, as the weather was
very fine; and, besides, his room had not been put in order for three
days. We went into the garden, and he chose to breakfast under the
arbour. He was in good spirits, and his conversation turned upon
many different subjects and persons.
The Emperor’s health being now perfectly restored, he resumed
his usual occupation, which, indeed, was his only source of
amusement. Reading, dictating, and walking in the garden, filled up
all his time during the day. He still occasionally resorted to his
favourite path, though the turn of the season, and the change of the
moon, had nearly put a stop to our evening walks. The numerous
visitors who came to Mr. Balcombe’s house, attracted by the hope of
meeting the Emperor, annoyed him very much, and, indeed,
compelled him to withdraw himself altogether. We therefore
remained shut up in our little dwelling. We at first understood that
we should remain at Briars only a few days; but six weeks had
passed away, and we had yet heard nothing respecting our removal.
All this time the Emperor had been as much confined as he had
been on board of the vessel. He had taken only one excursion, which
was when he visited Major Hudson; and we afterwards learned that
this circumstance had occasioned alarm. It had been whispered
about at the Admiral’s ball, and had reached the ears of our high
authorities, who were thrown into great consternation by the event.
The workmen continued their labours at Longwood, which was to
be our new residence. The troops who had come with us from
England were encamped in the neighbourhood. The Colonel gave a
ball, to which we were invited. The Emperor wished me to go, and
that I should, at the same time, take the opportunity of inspecting
our future abode. I went with Madame Bertrand, in a carriage drawn
by six oxen. In this Merovingian equipage we proceeded to
Longwood. This was the first opportunity I had had of seeing any
part of the island, except the neighbourhood of Briars. The whole
road along which we passed presented continued evidences of a
great natural convulsion. We saw nothing but huge masses of rock,
totally destitute of vegetation. If, at every change of the horizon, we
perceived a trace of verdure or a few clusters of trees, yet on a
nearer approach, all vanished like the creations of a poet’s fancy; we
found only a few marine plants and wild shrubs; or, what was still
worse, some wretched gum-trees. These were the only ornaments
of Longwood. I returned on horseback about six o’clock. The
Emperor put many questions to me concerning our new residence.
Finding that I did not speak of it very enthusiastically, he asked at
once whether he should gain or lose by the change? I told him what
I thought in one sentence. “Sire,” said I, “we are here in a cage;
there we shall be in a fold.”
28th.—The Emperor changed his military uniform, which he had
put on to go on board the Bellerophon, for a fancy dress coat. In the
course of conversation this day the Emperor adverted to the
numerous conspiracies which had been formed against him. The
infernal machine was mentioned in its turn. This diabolical invention,
which gave rise to so many conjectures, and caused the death of so
many victims, was the work of the Royalists, who obtained the first
idea of it from the Jacobins.
The Emperor stated that a hundred furious Jacobins, the real
authors of the scenes of September, the 10th of August, &c., had
resolved to get rid of the First Consul, for which purpose they
invented a 15 or 16-pound howitzer, which, on being thrown into the
carriage, would explode by its own concussion, and hurl destruction
on every side. To make sure of their object, they proposed to lay
chevaux de frise along a part of the road, which, by suddenly
impeding the horses, would of course render it impossible for the
carriage to move on. The man who was employed to lay down the
chevaux de frise, entertaining some suspicions of the job which he
had been set upon, as well as of the morality of his employers,
communicated the business to the police. The conspirators were
soon traced, and were apprehended near the Jardin des Plantes, in
the act of trying the effect of the machine, which made a terrible
explosion. The First Consul, whose policy it was not to divulge the
numerous conspiracies of which he was the object, did not give
publicity to this, but contented himself with imprisoning the
criminals. He soon relaxed his orders for keeping them in close
confinement, and they were allowed a certain degree of liberty. In
the same prison in which these Jacobins were confined, some
Royalists were also imprisoned for an attempt to assassinate the
First Consul, by means of air-guns. These two parties formed a
league together; and the Royalists transmitted to their friends out of
prison the idea of the infernal machine, as being preferable to any
other plan of destruction.
It is very remarkable that, on the evening of the catastrophe, the
Emperor expressed an extreme repugnance to go out. Madame
Buonaparte and some intimate friends absolutely forced him to go to
an Oratorio. They roused him from a sofa where he was fast asleep;
one fetched him his sword, and another his hat. As he drove along in
the carriage, he fell asleep again, and awoke suddenly, saying that
he had dreamed he was drowning in the Tagliamento. To explain
what he alluded to, it is necessary to mention that some years
previously, when he was General of the army of Italy, he passed the
Tagliamento in his carriage during the night, contrary to the advice
of every one about him. In the ardour of youth, and heedless of
every obstacle, he crossed the river surrounded by a hundred men
armed with poles and torches. His carriage was, however, soon set
afloat; Napoleon incurred the most imminent danger, and for some
time gave himself up for lost. At the moment when he now awoke,
on his way to the Oratorio, he was in the midst of a conflagration,
the carriage was lifted up, and the passage of the Tagliamento came
fresh upon his mind. The illusion, however, was but momentary; a
dreadful explosion immediately ensued. “We are blown up!”
exclaimed the First Consul to Lannes and Bessieres, who were in the
carriage with him. They were for stopping the carriage, but the First
Consul enjoined them not to do it on any account. He arrived safe,
and appeared at the Opera as though nothing had happened. He
was preserved by the desperate driving of his coachman. The
machine injured only one or two individuals who closed the escort.
The most trivial circumstances often lead to the most important
results. The coachman was intoxicated, and there is no doubt that
this proved the means of saving the life of the First Consul. The
man’s intoxication was so great that it was not until next morning he
could be made to comprehend what had happened. He had taken
the explosion for the firing of a salute. Immediately after this event,
measures were adopted against the Jacobins, who had been
convicted of meditating the crime: and a considerable number were
banished. They, however, were not the real criminals, whose
discovery was brought about by another very singular chance.
Three or four hundred drivers of fiacres subscribed a louis or
twelve francs each to give a dinner to the First Consul’s coachman,
who had become the hero of the day and the boast of his
profession. During the feast, one of the guests drinking to the health
of the First Consul’s coachman, observed that he knew who had
played him the trick, alluding to the explosion of the machine. He
was immediately arrested, and it appeared that, on the very night,
or the night preceding the explosion, he had drawn up his fiacre
beside a gate, whence had issued the little cart that had done all the
mischief. The police proceeded to the place, and it was found to be a
coach-yard, where all kinds of vehicles were lent on hire. The
keepers of the yard did not deny the fact; they pointed out the stall
in which the cart stood; it still presented traces of gunpowder. The
proprietors declared that they were given to understand the cart had
been hired by some Bretons who were concerned in smuggling. The
man who had sold the horse, together with every individual who had
participated in the affair, were easily traced out; and it was proved
that the plot had been formed by the Chouan Royalists. Some active
and intelligent men were despatched to their head-quarters in
Morbihan. They took no pains to conceal their share in the
transaction, and only regretted that it had not succeeded. Some of
them were apprehended and brought to punishment. It is said that
the chief conspirator afterwards turned Trappist, and sought to
expiate his crime by religious austerities.

CONSPIRACY OF GEORGES, PICHEGRU, &C.—THE DUKE D’ENGHIEN.—THE SLAVE


TOBY.—CHARACTERISTIC REFLECTIONS OF NAPOLEON.

29th—30th. I find in this part of my manuscript some important


particulars respecting the conspiracy of Georges, Pichegru, Moreau,
and the trial of the Duke d’Enghien; but, as these subjects recur
repeatedly in the course of my Journal, I transfer to another part
what occurred here, in order to bring all my information on the
above points at once under the eye of the reader.
Mr. Balcombe’s little garden, in which we so often walked, was
superintended by an old negro. The first time we saw him, the
Emperor, according to his usual custom, desired me to put some
questions to him respecting his history; and his answers strongly
excited our interest. He was a Malay Indian, and had been forced
from his home by the crew of an English vessel, and sold at St.
Helena, where he had continued ever since in slavery. His story bore
every mark of truth. His countenance had a frank and benevolent
expression; his eyes were animated and sparkling. In short his
appearance was by no means abject; but, on the contrary, truly
prepossessing.
The history of the poor fellow’s misfortunes filled us with,
indignation; and a few days after, the Emperor expressed a wish to
purchase him and send him back to his own country. He mentioned
the subject to the Admiral. The latter, at first, defended his
countrymen, and declared that old Toby (which was the name of the
unfortunate slave) must be an impostor; for the thing was
impossible. He, however, enquired into the matter, and, finding that
the story was but too true, he participated in the indignation which
we expressed, and promised to exert his best endeavours for the
fulfilment of our design. When we left Briars for Longwood, poor
Toby, sharing the common fate of all earthly things, was soon
forgotten; I know not what became of him.
When we were in the garden, the Emperor generally stopped near
Toby’s hut, and made me question him respecting his country, the
days of his youth, his family, his present situation, &c.: one would
have supposed that he wished to study the feelings of the old slave.
By the Emperor’s desire, I invariably closed the conversation by
giving him a Napoleon.
Toby was very much attached to us; our presence always seemed
to fill him with joy. When we entered the garden, he immediately
suspended his work, and, resting on his spade, gazed on us with an
air of satisfaction. He understood not a word of the conversation
that passed between the Emperor and myself; but he always
seemed to anticipate, with a smile, the first words I translated to
him. He called the Emperor the Good Gentleman: this was the only
name he ever applied to him, and he knew him by no other.
I have mentioned the above particulars, because our meetings
with Toby were always followed by novel, spirited, and characteristic
reflections on the part of the Emperor. The versatility of his mind is
well known. Whenever he adverted to the poor slave’s misfortunes,
he always took a new view of the subject. I shall content myself with
noting down the following remarks:—
“Poor Toby,” said he one day, “has been torn from his family, from
his native land, and sold to slavery: could any thing be more
miserable to himself, or more criminal in others! If this crime be the
act of the English captain alone, he is doubtless one of the vilest of
men; but if it be that of the whole of the crew, it may have been
committed by men, perhaps, not so base as might be imagined; for
vice is always individual, and scarcely ever collective. Joseph’s
brethren could not bring themselves to slay him; while Judas, a cool,
hypocritical, calculating villain, betrayed his Master. A philosopher
has affirmed that men are born wicked: it would be both difficult and
idle to attempt to discover whether the assertion be true. This, at
least, is certain, that the great mass of society is not wicked; for if
the majority were determined to be criminal and to violate the laws,
who would have the power to restrain or prevent them? This is the
triumph of civilization; for this happy result springs from its bosom,
and arises out of its nature. Sentiments are for the most part
traditionary; we feel them because they were felt by those who
preceded us: thus we must look to the development of human
reason and of the faculties of mankind for the only key to social
order, the only secret of the legislator. It is only those who wish to
deceive the people and rule them for their own personal advantage
that would desire to keep them in ignorance; for the more they are
enlightened, the more will they feel convinced of the utility of laws,
and of the necessity of defending them; and the more steady, happy,
and prosperous will society become. If, however, knowledge should
ever be dangerous in the multitude, it can only be when the
Government, in opposition to the interests of the people, drives
them into an unnatural situation, or dooms the lower classes to
perish for want. In such a case, knowledge would inspire them with
spirit to defend themselves, or to become criminal.
“My code alone, from its simplicity, has been more beneficial to
France than the whole mass of laws which preceded it. My schools
and my system of mutual instruction are preparing generations yet
unknown. Thus, during my reign, crimes were rapidly diminishing;
while, on the contrary, with our neighbours in England, they have
been increasing to a frightful degree. This alone is sufficient to
enable any one to form a decisive judgment of the respective
governments![26]
“Look at the United States, where, without any apparent force or
effort, every thing goes on prosperously; every one is happy and
contented: and this is because the public wishes and interests are in
fact the ruling power. Place the same government at variance with
the will and interests of its inhabitants, and you would soon see
what disturbance, trouble, and confusion, and above all, what an
increase of crimes, would ensue.
“When I acquired the supreme direction of affairs, it was wished
that I might become a Washington. Words cost nothing; and no
doubt those who were so ready to express the wish did so without
any knowledge of times, places, persons, or things. Had I been in
America, I would willingly have been a Washington, and I should
have had little merit in so being; for I do not see how I could
reasonably have acted otherwise. But had Washington been in
France, exposed to discord within, and invasion from without, I
would have defied him to have been what he was in America; at
least, he would have been a fool to attempt it, and would only have
prolonged the existence of evil. For my own part, I could only have
been a Crowned Washington. It was only in a congress of kings, in
the midst of kings, yielding or subdued, that I could become so.
Then and there alone, I could successfully display Washington’s
moderation, disinterestedness, and wisdom. I could not reasonably
attain to this but by means of the universal Dictatorship. To this I
aspired; can that be thought a crime? Can it be believed that to
resign this authority would have been beyond the power of human
nature? Sylla, glutted with crimes, dared to abdicate, pursued by
public execration! What motive could have checked me, who would
have been followed only by blessings?——But it remained for me to
conquer at Moscow!—How many will hereafter regret my disasters
and my fall!—But to require prematurely of me that sacrifice, for
which the time had not arrived, was a vulgar absurdity; and for me
to have proclaimed or promised it, would have been taken for
hypocrisy and quackery: that was not my way.——I repeat, it
remained for me to conquer at Moscow!——”
On another occasion, pausing before Toby, he said:—“What, after
all, is this poor human machine? There is not one whose exterior
form is like another, or whose internal organisation resembles the
rest! And it is by disregarding this truth that we are led to the
commission of so many errors! Had Toby been a Brutus, he would
have put himself to death: if an Æsop, he would now, perhaps, have
been the Governor’s adviser; if an ardent and zealous Christian, he
would have borne his chains in the sight of God, and blessed them.
As for poor Toby, he endures his misfortunes very quietly; he stoops
to his work, and spends his days in innocent tranquillity.” Then, after
looking at him for a few moments in silence, he turned away and
said: “Certainly it is a great step from poor Toby to a King Richard!
——And yet,” continued he, as he walked along, “the crime is not the
less atrocious; for this man, after all, had his family, his happiness,
and his liberty; and it was a horrible act of cruelty to bring him here
to languish in the fetters of slavery,” Then, suddenly stopping short,
he added:—“But I read in your eyes that you think he is not the only
example of the sort at St. Helena!” And whether he felt offended at
being placed on a parallel with Toby, whether he thought it
necessary to raise my spirits, or whatever else might be his reason,
he went on with dignity and animation: “My dear Las Cases, there is
not the least resemblance here: if the outrage is of a higher class,
the victims also possess very different resources. We have not been
exposed to corporeal sufferings; or if that had been attempted, we
have souls to disappoint our tyrants! Our situation may even have its
charms! The eyes of the universe are fixed upon us! We are martyrs
in an immortal cause! Millions of human beings are weeping for us:
our country sighs, and glory mourns our fate! We here struggle
against the oppression of the gods, and the prayers of nations are
for us!”—After a pause of a few seconds, he continued:—“Besides,
this is not the source of my real sufferings! If I considered only
myself, perhaps I should have reason to rejoice! Misfortunes are not
without their heroism and their glory! Adversity was wanting to my
career! Had I died on the throne, enveloped in the dense
atmosphere of my power, I should to many have remained a
problem; but now misfortune will enable all to judge of me without
disguise.“

ORIGIN OF THE CORPS OF GUIDES.—ANOTHER DANGER


INCURRED BY NAPOLEON.—THE GERMAN OFFICER.

December 1st—3rd. Many incidents fill up this interval: some I


reject as unnecessary, some it is proper I should withhold. I here
note down only a few anecdotes of the General-in-chief of the Army
of Italy.
After the passage of the Mincio, Napoleon, having concerted all his
plans, and pursued the enemy in every direction, entered a castle on
the left bank of the river. He was troubled with the head-ache, and
he used a foot-bath. A large detachment of the enemy, in great
confusion, arrived, having ascended the river as far as the castle.
Napoleon had only a few persons with him; the sentinel on duty at
the gate had just time to close it, exclaiming, “To arms!” and the
General of the Army of Italy, in the hour of victory, was compelled to
escape through the back gates of the garden, with but one boot on.
Had he been made prisoner, before his reputation was established,
the acts of genius which had marked the commencement of his
career would, perhaps, by the common run of mankind, have been
considered merely as fortunate and blameable enterprises. The
danger which the French General had just escaped (a circumstance
which, through his method of operations, was likely often to recur)
was the origin of the guides appointed to guard his person. These
guides have since been introduced in other armies.
In the same campaign, Napoleon incurred another imminent risk:
—Wurmser, who had been compelled to throw himself into Mantua,
and who was debouching suddenly on an open plain, learned from
an old woman, that, only a few moments before his arrival, the
French General, with but a few followers, had stopped at her door,
and that he had fled within sight of the Austrians. Wurmser
immediately despatched parties of cavalry in every direction,
calculating with certainty on the precious capture. “But,” said the
Emperor, “I must do him this justice, he gave particular orders that I
should not be killed or harmed in any way.” Fortunately for the
young General, his happy star and the swiftness of his horse
preserved him.
The new system of military operations practised by Napoleon
disconcerted every one. The campaign was scarcely opened, when
Lombardy was inundated with troops in every direction, and the
French approached Mantua pell-mell with the enemy. The General-
in-chief, when in the neighbourhood of Pizzighitone, met a great fat
German Captain or Colonel, who had been made prisoner. Napoleon
took a fancy to question him, without being known, and enquired
how affairs were going on. “Very badly,” replied the officer; “I know
not how it will end; but no one seems to understand what is doing;
we have been sent to fight a young blockhead, who attacks you on
the right and the left, in front and in rear, so that there is no
knowing how to proceed. This mode of carrying on war is
intolerable; and for my part, I am very glad to have done with it....”
Napoleon used to relate that, after one of his great actions in
Italy, he passed over the field of battle with two or three other
persons, before the dead bodies had been interred. “In the deep
silence of a beautiful moonlight night,” said the Emperor, “a dog,
leaping suddenly from beneath the clothes of his dead master,
rushed upon us, and then immediately returned to his hiding-place,
howling piteously. He alternately licked his master’s face, and again
flew at us; thus, at once soliciting aid and seeking revenge. Whether
owing to my own particular turn of mind at the moment,” continued
the Emperor, “the time, the place, or the action itself, I know not;
but certainly no incident on any field of battle ever produced so deep
an impression on me. I involuntarily stopped to contemplate the
scene. This man, thought I, perhaps has friends in the camp or in
his company; and here he lies forsaken by all except his dog! What a
lesson Nature here presents through the medium of an animal! What
a strange being is man! and how mysterious are his impressions; I
had, without emotion, ordered battles which were to decide the fate
of the army; I had beheld, with tearless eyes, the execution of those
operations, by which numbers of my countrymen were sacrificed;
and here my feelings were roused by the mournful howling of a dog!
Certainly at that moment I should have been easily moved by a
suppliant enemy; I could very well imagine Achilles yielding up the
body of Hector at the sight of Priam’s tears.”

WAR.—PRINCIPLES.—APPLICATION.—OPINIONS ON
SEVERAL GENERALS.

4th—5th. My eyes had become so bad that I was obliged to


suspend my occupation: I had nearly lost my sight in the Campaign
in Italy.
For some time past a sensible change had taken place in the
weather. We knew nothing about the order of the seasons. As the
sun passed twice over our heads in the course of the last year, we
said we ought, at least, to have two summers. Every thing was
totally different from what we had been accustomed to; and, to
complete our embarrassments, we were obliged, being now in the
southern hemisphere, to make all our calculations in a manner quite
the reverse of that which we had practised in Europe. It rained
frequently, the air was very damp, and it grew colder than before.
The Emperor could no longer go out in the evening; he was
continually catching cold and did not sleep well. He was obliged to
give up taking his meals beneath the tent, and he had them served
up in his own chamber. Here he found himself better; but he could
not stir from his seat.
Our conversation continued after the dinner was removed from
table. To-day the Emperor attacked General Gourgaud on the
elements and first exercises of artillery. The General had recently
belonged to that department of the service, and all his professional
science was quite fresh. The discussion was very curious, and was
maintained with great spirit. Napoleon never proved himself to be
the weaker party: one might have been tempted to believe that he
had just passed his examination at the academy.
The conversation then turned on war and great commanders.
“The fate of a battle,” observed the Emperor, “is the result of a
moment—of a thought: the hostile forces advance with various
combinations, they attack each other and fight for a certain time;
the critical moment arrives, a mental flash decides, and the least
reserve accomplishes the object.” He spoke of Lützen, Bautzen, &c.;
and afterwards, alluding to Waterloo, he said, that had he followed
up the idea of turning the enemy’s right, he should easily have
succeeded; he, however, preferred piercing the centre, and
separating the two armies. But all was fatal in that engagement; it
even assumed the appearance of absurdity: nevertheless, he ought
to have gained the victory. Never had any of his battles presented
less doubt to his mind; nor could he now account for what had
happened. Grouchy, he said, had lost himself; Ney appeared
bewildered, and his countenance at once expressed the remorse he
felt for the transactions of Fontainebleau and of Lons-le-Saunier;
d’Erlon was useless; in short, the generals were no longer
themselves. If, in the evening, he had been aware of Grouchy’s
position, and could have thrown himself upon it, he might, in the
morning, with the help of that fine reserve, have repaired his ill
success, and perhaps, even have destroyed the allied forces by one
of those miracles, those turns of Fortune, which were familiar to
him, and which would have surprised no one. But he knew nothing
of Grouchy; and besides, it was not easy to act with decision
amongst the wrecks of the army. It would be difficult to imagine the
condition of the French army on that disastrous night; it was a
torrent dislodged from its bed, sweeping away every thing in its
course.
Turning to another subject, he said that the dangers incurred by
the military commanders of antiquity were not to be compared with
those which attend the generals of modern times. There is, he
observed, no position in which a general may not now be reached by
artillery; but anciently a general ran no risk, except when he himself
charged, which Cæsar did only twice or thrice.
“We rarely,” said he, “find, combined together, all the qualities
necessary to constitute a great general. The object most desirable is
that a man’s judgment should be in equilibrium with his personal
courage; that raises him at once above the common level.” This is
what the Emperor termed being well squared, both by the base and
perpendicular.
“If,” continued he, “courage be a general’s predominating quality,
he will rashly embark in enterprises above his conceptions; and, on
the other hand, he will not venture to carry his ideas into effect, if
his character or courage be inferior to his judgment.”
He then cited the example of the Viceroy, whose sole merit
consisted in this equilibrium of character, which, however, sufficed to
render him a very distinguished man.
Physical and moral courage then became the subject of discourse.
“With respect to physical courage,” the Emperor said, “it was
impossible for Murat and Ney not to be brave, but no men ever
possessed less judgment; the former in particular. As to moral
courage,” observed he, “I have very rarely met with the two o’clock
in the morning courage. I mean, unprepared courage, that which is
necessary on an unexpected occasion, and which, in spite of the
most unforeseen events, leaves full freedom of judgment and
decision.” He did not hesitate to declare that he was himself
eminently gifted with this two o’clock in the morning courage, and
that, in this respect, he had met with but few persons who were at
all equal to him. He remarked that an incorrect idea was generally
formed of the strength of mind necessary to engage in one of those
great battles on which depends the fate of an army or nation, or the
possession of a throne. “Generals,” added he, “are rarely found
eager to give battle; they choose their positions; establish
themselves; consider their combinations; but then commences their
indecision: nothing is so difficult, and at the same time so important,
as to know when to decide.”
He next proceeded to notice several generals, and condescended
to reply to some questions that were asked him. “Kleber,” said he,
“was endowed with the highest talent; but he was merely the man
of the moment: he pursued glory as the only road to enjoyment; but
he had no national sentiment, and he could, without any sacrifice,
have devoted himself to foreign service.” Kleber had commenced his
youthful career among the Prussians, to whom he continued much
attached. Dessaix possessed, in a very superior degree, the
important equilibrium above described. Moreau scarcely deserved to
be placed in the first rank of generals; in him nature had left her
work unfinished; he possessed more instinct than genius. In Lannes,
courage at first predominated over judgment; but the latter was
every day gaining ground, and approaching the equilibrium. He had
become a very able commander at the period of his death. “I found
him a dwarf,” said the Emperor, “but I lost him a giant.” In another
general, whom he named, judgment was, on the contrary, superior
to courage; it could not be denied that he was a brave man; but he,
like many others, did not forget the chance of the cannon-ball.
Speaking of military ardour and courage, the Emperor said, “I
know the depth, or what I call the draught of water, of all my
generals. Some,” added he, joining action to his words, “will sink to
the waist, some to the chin, others over head; but the number of
the latter is very small, I assure you.” Suchet, he said, was one
whose courage and judgment had been surprisingly improved.
Massena was a very superior man, and, by a strange peculiarity of
temperament, he possessed the desired equilibrium only in the heat
of battle; it was created in the midst of danger. “The generals,”
finally observed the Emperor, “who seemed destined to rise to future
distinction were Gerard, Clausel, Foy, Lamarque, &c. These were my
new marshals.”

SITUATION OF THE SPANISH PRINCES AT VALENCEY.—THE


POPE AT FONTAINEBLEAU.—REFLECTIONS, &C.

6th.—The Emperor, after dictating to me this morning, was


successively engaged with the other gentlemen, with whom he
prolonged his walk for some time. When they withdrew, I followed
him into the lower path: he was dull and silent, and his countenance
appeared somewhat harsh and ruffled. “Well,” said he, as we were
returning to dinner, “we shall have sentinels under our windows at
Longwood. They wished to force me to have a foreign officer at my
table and in my drawing-room. I cannot mount my horse without
being accompanied by an officer; in short, we cannot stir a step
under pain of being insulted!...” I replied that this was another drop
of sorrow added to the bitter cup which we were doomed to drink to
his past glory and power; but that his philosophy was sufficient to
defy the malice of his enemies, and to make them blush for their
brutality in the face of the whole world. I ventured to remark that
the Spanish Princes at Valencey, and the Pope at Fontainebleau, had
never experienced such treatment. “Certainly not,” resumed he; “the
Princes hunted and gave balls at Valencey, without being physically
aware of their chains; they experienced respect and courtesy at all
hands. Old King Charles IV. removed from Compiegne to Marseilles,
and from Marseilles to Rome, whenever he wished. And yet how
different are those places from this! The Pope at Fontainebleau,
whatever may have been the reports circulated in the world, was
treated in the same manner. And yet how many persons, in spite of
all the indulgences he enjoyed, refused to be appointed to guard
him!—a circumstance which gave me no offence, for I thought it
perfectly natural. Such employments are subject to the influence of
delicacy of feeling; and our European manners require that power
should be limited by honour.” He observed that, for his own part, as
a private man and an officer, he should without hesitation have
refused to guard the Pope, whose removal to France, he added, had
never been ordered by him.—I manifested great surprise.—“You are
astonished,” said he: “you did not know this? But it is nevertheless
true, as well as many other similar facts, which you will learn in
course of time. But, with reference to the subject on which we have
just been speaking, it is necessary to distinguish the conduct of the
sovereign, who acts collectively, from that of the private man, whose
sentiments are without constraint. Policy permits, nay, frequently
demands, from the one, what would be unpardonable in the other.”
The hour of dinner, by introducing various subjects of conversation,
diverted his melancholy, and cheerfulness finally prevailed.
Meanwhile the Emperor seriously determined to quit his present
wretched abode, whatever inconvenience his new residence might
present. On going to pass the remainder of the evening with our
host, the Emperor directed me to present him a box bearing his
cypher, and to tell him he was sorry for all the trouble he had
occasioned to him.
ON THE NOUVELLE HÉLOÏSE, AND ON LOVE.
7th.—The Emperor summoned me to attend him at an early hour.
He began to read the Nouvelle Héloïse, frequently remarking on the
ingenuity and force of the arguments, the elegance of the style and
expressions: he read for upwards of two hours. This reading made a
powerful impression on me; it produced a deep melancholy—a
mingled feeling of tenderness and sorrow. I had always been fond of
the work; and it now awakened happy recollections, and excited
deep regret: the Emperor frequently smiled at me. During breakfast
the Nouvelle Héloïse was the topic of conversation.
“Jean-Jacques has overcharged his subject,” said the Emperor; “he
has painted madness: love should be a source of pleasure, not of
misery.” I alleged that Jean-Jacques had described nothing which a
man might not feel, and that even the misery to which the Emperor
alluded was, in reality, happiness.—“I see,” said he, “you have a little
touch of the romantic: has Love’s misery rendered you happy?”—“I
do not complain of my fate, Sire,” replied I; “were I to begin life
again, I should wish to retrace the course I have already pursued.”
The Emperor resumed his reading after breakfast; but he paused
occasionally: the enchantment seemed to seize him in his turn. He at
length laid down the book, and we went out to the garden. “Really,”
said he, as we walked along, “this work is not without fire; it moves,
it rouses the feelings.” We discussed the subject deeply; we were
very prolix in our remarks, and we at length agreed that perfect love
is like ideal happiness; that both are equally airy, fugitive,
mysterious, and inexplicable; and that, finally, love is the business of
the idle man, the recreation of the warrior, and the ruin of the
sovereign.
We were joined by the Grand Marshal and M. Gourgaud, who had
just come from Longwood. The admiral had for some days past been
urgent for our removal thither; and the Emperor was not less
anxious to go, the accommodation at Briars being so very bad.
However, before he removed, it was necessary that the smell of the
paint should be entirely gone, for, owing to his peculiar organization,
he could not possibly endure it. In the Imperial palaces, care had
been taken never to expose him to it. In his different journeys, the
slightest smell of paint frequently rendered it necessary to change
the apartments that had been prepared for him; and on board of the
Northumberland the paint of the ship had made him very ill. He had
been informed on the preceding evening that all was ready at
Longwood, and that the disagreeable effect of the paint was entirely
gone. He accordingly determined to remove on the Saturday
following, as he would thus be rid of the annoyance of the workmen
on Sunday; but the Grand Marshal and M. Gourgaud now came to
say that they had visited the place, and that it was not habitable.
The Emperor expressed much vexation at the first account he had
received, and the resolution which it had led him to adopt. The two
gentlemen withdrew, and we entered the lower walk. The Emperor
was much out of humour. M. de Montholon now arrived, very mal-a-
propos, from Longwood, declaring that all was ready, and that the
Emperor might remove as soon as he wished. These two accounts,
so contradictory and so close upon each other, strongly excited his
displeasure. Fortunately, dinner was announced, which diverted his
attention from the subject. The cloth was laid in the Emperor’s

You might also like