100% found this document useful (3 votes)
110 views

Natural Language Processing Recipes: Unlocking Text Data with Machine Learning and Deep Learning Using Python 2nd Edition Akshay Kulkarni - Download the ebook now for an unlimited reading experience

The document promotes the book 'Natural Language Processing Recipes: Unlocking Text Data with Machine Learning and Deep Learning Using Python 2nd Edition' by Akshay Kulkarni, which provides practical solutions for implementing NLP techniques using Python. It covers various NLP applications, including text classification, sentiment analysis, and advanced preprocessing methods, aimed at helping readers unlock insights from unstructured textual data. The book is designed for intermediate Python programmers with some knowledge of machine learning, offering hands-on projects and code examples throughout.

Uploaded by

kalajboukaf
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
110 views

Natural Language Processing Recipes: Unlocking Text Data with Machine Learning and Deep Learning Using Python 2nd Edition Akshay Kulkarni - Download the ebook now for an unlimited reading experience

The document promotes the book 'Natural Language Processing Recipes: Unlocking Text Data with Machine Learning and Deep Learning Using Python 2nd Edition' by Akshay Kulkarni, which provides practical solutions for implementing NLP techniques using Python. It covers various NLP applications, including text classification, sentiment analysis, and advanced preprocessing methods, aimed at helping readers unlock insights from unstructured textual data. The book is designed for intermediate Python programmers with some knowledge of machine learning, offering hands-on projects and code examples throughout.

Uploaded by

kalajboukaf
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 72

Read Anytime Anywhere Easy Ebook Downloads at ebookmeta.

com

Natural Language Processing Recipes: Unlocking


Text Data with Machine Learning and Deep Learning
Using Python 2nd Edition Akshay Kulkarni

https://ebookmeta.com/product/natural-language-processing-
recipes-unlocking-text-data-with-machine-learning-and-deep-
learning-using-python-2nd-edition-akshay-kulkarni/

OR CLICK HERE

DOWLOAD EBOOK

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


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

Natural Language Processing Recipes: Unlocking Text Data


with Machine Learning and Deep Learning Using Python 2nd
Edition Akshay Kulkarni
https://ebookmeta.com/product/natural-language-processing-recipes-
unlocking-text-data-with-machine-learning-and-deep-learning-using-
python-2nd-edition-akshay-kulkarni/
ebookmeta.com

Time Series Algorithms Recipes: Implement Machine Learning


and Deep Learning Techniques with Python 1st Edition
Akshay Kulkarni
https://ebookmeta.com/product/time-series-algorithms-recipes-
implement-machine-learning-and-deep-learning-techniques-with-
python-1st-edition-akshay-kulkarni/
ebookmeta.com

Natural Language Processing Projects: Build Next-


Generation NLP Applications Using AI Techniques Akshay
Kulkarni
https://ebookmeta.com/product/natural-language-processing-projects-
build-next-generation-nlp-applications-using-ai-techniques-akshay-
kulkarni/
ebookmeta.com

Virtual Training Basics 2nd Edition Cindy Huggett

https://ebookmeta.com/product/virtual-training-basics-2nd-edition-
cindy-huggett/

ebookmeta.com
Developing Comprehensive School Safety and Mental Health
Programs An Integrated Approach 1st Edition Jeffrey C.
Roth
https://ebookmeta.com/product/developing-comprehensive-school-safety-
and-mental-health-programs-an-integrated-approach-1st-edition-jeffrey-
c-roth/
ebookmeta.com

Gingerbread Man A Man of the Month Club Novella A small


town grumpy and sunshine age gap romance 1st Edition Karla
Doyle
https://ebookmeta.com/product/gingerbread-man-a-man-of-the-month-club-
novella-a-small-town-grumpy-and-sunshine-age-gap-romance-1st-edition-
karla-doyle-2/
ebookmeta.com

To Reject a Mate Redwood University 1 1st Edition Poppy


Ireland

https://ebookmeta.com/product/to-reject-a-mate-redwood-
university-1-1st-edition-poppy-ireland/

ebookmeta.com

Cross Sectional Atlas of Human Brainstem With 0 06 mm


Pixel Size Color Images Park

https://ebookmeta.com/product/cross-sectional-atlas-of-human-
brainstem-with-0-06-mm-pixel-size-color-images-park/

ebookmeta.com

Age of Deception 1st Edition T A White

https://ebookmeta.com/product/age-of-deception-1st-edition-t-a-white/

ebookmeta.com
The Truth About Bears (The Truth About Your Favorite
Animals) 1st Edition Maxwell Eaton Iii

https://ebookmeta.com/product/the-truth-about-bears-the-truth-about-
your-favorite-animals-1st-edition-maxwell-eaton-iii/

ebookmeta.com
Akshay Kulkarni and Adarsha Shivananda

Natural Language Processing Recipes


Unlocking Text Data with Machine Learning and
Deep Learning Using Python
2nd ed.
Akshay Kulkarni
Bangalore, Karnataka, India

Adarsha Shivananda
Bangalore, Karnataka, India

ISBN 978-1-4842-7350-0 e-ISBN 978-1-4842-7351-7


https://doi.org/10.1007/978-1-4842-7351-7

© Akshay Kulkarni and Adarsha Shivananda 2021

Apress Standard

The use of general descriptive names, registered names, trademarks,


service marks, etc. in this publication does not imply, even in the
absence of a specific statement, that such names are exempt from the
relevant protective laws and regulations and therefore free for general
use.

The publisher, the authors and the editors are safe to assume that the
advice and information in this book are believed to be true and accurate
at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, expressed or implied, with respect to the
material contained herein or for any errors or omissions that may have
been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.

This Apress imprint is published by the registered company APress


Media, LLC part of Springer Nature.
The registered company address is: 1 New York Plaza, New York, NY
10004, U.S.A.
To our families
Introduction
According to industry estimates, more than 80% of the data being
generated is in an unstructured format in the form of text, images,
audio, or video. Data is being generated as we speak, write, tweet, use
social media platforms, send messages on messaging platforms, use
ecommerce to shop, and do various other activities. The majority of this
data exists in textual form.

So, what is unstructured data? Unstructured data is information that


doesn’t reside in a traditional relational database. Examples include
documents, blogs, social media feeds, pictures, and videos.
Most of the insights are locked within different types of
unstructured data. Unlocking unstructured data plays a vital role in
every organization wanting to make improved and better decisions.
This book unlocks the potential of textual data.
Textual data is the most common and comprises more than 50% of
unstructured data. Examples include tweets/posts on social media, chat
conversations, news, blogs, articles, product or services reviews, and
patient records in the healthcare sector. Recent examples include voice-
driven bots like Siri and Alexa.
To retrieve significant and actionable insights from textual data and
unlock its potential, we use natural language processing coupled with
machine learning and deep learning.
But what is natural language processing? Machines and algorithms
do not understand text or characters, so it is very important to convert
textual data into a machine-understandable format (like numbers or
binary) to analyze it. Natural language processing (NLP) allows
machines to understand and interpret the human language.
If you want to use the power of unstructured text, this book is the
right starting point. This book unearths the concepts and
implementation of natural language processing and its applications in
the real world. NLP offers unbounded opportunities for solving
interesting problems in artificial intelligence, making it the latest
frontier for developing intelligent, deep learning–based applications.
What Does This Book Cover?
Natural Language Processing Recipes is a handy problem/solution
reference for learning and implementing NLP solutions using Python.
The book is packed with lots of code and approaches that help you
quickly learn and implement both basic and advanced NLP techniques.
You will learn how to efficiently use a wide range of NLP packages,
implement text classification, and identify parts of speech. You also
learn about topic modeling, text summarization, text generation,
sentiment analysis, and many other NLP applications.
This new edition of Natural Language Processing Recipes focuses on
implementing end-to-end projects using Python and leveraging cutting-
edge algorithms and transfer learning.
The book begins by discussing text data collections, web scraping,
and different types of data sources. You learn how to clean and
preprocess text data and analyze it using advanced algorithms.
Throughout the book, you explore the semantic as well as syntactic
analysis of text. It covers complex NLP solutions that involve text
normalization, various advanced preprocessing methods, part-of-
speech (POS) tagging, parsing, text summarization, sentiment analysis,
topic modeling, named-entity recognition (NER), word2vec, seq2seq,
and more.
The book covers both fundamental and state-of-the-art techniques
used in machine learning applications and deep learning natural
language processing. This edition includes various advanced techniques
to convert text to features, like GloVe, ELMo, and BERT. It also explains
how transformers work, using Sentence-BERT and GPT as examples.
The book closes by discussing some of the advanced industrial
applications of NLP with a solution approach and implementation, also
leveraging the power of deep learning techniques for natural language
processing and natural language generation problems, employing
advanced RNNs, like long short-term memory, to solve complex text
generation tasks. It also explores embeddings—high-quality
representations of words in a language.
In this second edition, few advanced state-of-art embeddings and
industrial applications are explained along with end-to-end
implementation using deep learning.
Each chapter includes several code examples and illustrations.
By the end of the book, you will have a clear understanding of
implementing natural language processing. You will have worked on
multiple examples that implement NLP techniques in the real world.
Readers will be comfortable with various NLP techniques coupled with
machine learning and deep learning and its industrial applications,
making the NLP journey much more interesting and improving your
Python coding skills.
Who This Book Is For
This book explains various concepts and implementations to get more
clarity when applying NLP algorithms to chosen data. You learn about
all the ingredients you need to become successful in the NLP space.
Fundamental Python skills are assumed, as well as some knowledge of
machine learning and basic NLP. If you are an NLP or machine learning
enthusiast and an intermediate Python programmer who wants to
quickly master natural language processing, this learning path will do
you a lot of good.
All you need to know are the basics of machine learning and Python
to enjoy the book.

What You Will Learn


The core concepts of implementing NLP, its various approaches, and
using Python libraries such as NLTK, TextBlob, spaCy, and Stanford
CoreNLP
Text preprocessing and feature engineering in NLP along with
advanced methods of feature engineering
Information retrieval, text summarization, sentiment analysis, text
classification, and other advanced NLP techniques solved leveraging
machine learning and deep learning
The problems faced by industries and how to implement them using
NLP techniques
Implementing an end-to-end pipeline of NLP life cycle projects,
which includes framing the problem, finding the data, collecting,
preprocessing the data, and solving it using cutting-edge techniques
and tools

What Do You Need for This Book?


To perform all the recipes in this book successfully, you need Python 3.x
or higher running on any Windows- or Unix-based operating system
with a processor of 2.0 GHz or higher and a minimum of 4 GB RAM. You
can download Python from Anaconda and leverage a Jupyter notebook
for coding purposes. This book assumes you know Keras basics and
how to install the basic machine learning and deep learning libraries.
Please make sure you upgrade or install the latest version of all the
libraries.
Python is the most popular and widely used tool for building NLP
applications. It has many sophisticated libraries to perform NLP tasks,
from basic preprocessing to advanced techniques.
To install any library in a Python Jupyter notebook, use ! before the
pip install.
NLTK is a natural language toolkit and is commonly called “the
mother of all NLP libraries.” It is one of the primary resources when it
comes to Python and NLP.

!pip install nltk


nltk.download()

spaCy is a trending library that comes with the added flavors of a


deep learning framework. Although spaCy doesn’t cover all NLP
functionalities, it does many things well.

!pip install spacy


#if above doesn't work, try this in your terminal/
command prompt
conda install spacy
python -m spacy.en.download all
#then load model via
spacy.load('en')

TextBlob is one of data scientists’ favorite libraries when it comes


to implementing NLP tasks. It is based on both NLTK and Pattern.
TextBlob isn’t the fastest or most complete library, however.

!pip install textblob

CoreNLP is a Python wrapper for Stanford CoreNLP. The toolkit


provides robust, accurate, and optimized techniques for tagging,
parsing, and analyzing text in various languages.
!pip install CoreNLP
There are hundreds of other NLP libraries, but these are the widely
used and important ones.
There is an immense number of NLP industrial applications that are
leveraged to uncover insights. By the end of the book, you will have
implemented many of these use cases, from framing a business
problem to building applications and drawing business insights. The
following are some examples.
Sentiment analysis—a customer’s emotions toward products offered
by the business
Topic modeling extracts the unique topics from the group of
documents.
Complaint classifications/email classifications/ecommerce product
classification, and so on
Document categorization/management using different clustering
techniques.
Résumé shortlisting and job description matching using similarity
methods
Advanced feature engineering techniques (word2vec and fastText) to
capture context
Information/document retrieval systems, for example, search
engines
Chatbots, Q&A, and voice-to-text applications like Siri, Alexa
Language detection and translation using neural networks
Text summarization using graph methods and advanced techniques
Text generation/predicting the next sequence of words using deep
learning algorithms
Acknowledgments
We are grateful to our families for their motivation and constant
support.
We want to express our gratitude to out mentors and friends for
their input, inspiration, and support. A special thanks to Anoosh R.
Kulkarni, a data scientist at Quantziq, for his support in writing this
book and his technical input. A big thanks to the Apress team for their
constant support and help.
Finally, we would like to thank you, the reader, for showing an
interest in this book and making your natural language processing
journey more exciting.
Note that the views and opinions expressed in this book are those of
the authors.
Table of Contents
Chapter 1:​Extracting the Data
Introduction
Client Data
Free Sources
Web Scraping
Recipe 1-1.​Collecting Data
Problem
Solution
How It Works
Recipe 1-2.​Collecting Data from PDFs
Problem
Solution
How It Works
Recipe 1-3.​Collecting Data from Word Files
Problem
Solution
How It Works
Recipe 1-4.​Collecting Data from JSON
Problem
Solution
How It Works
Recipe 1-5.​Collecting Data from HTML
Problem
Solution
How It Works
Recipe 1-6.​Parsing Text Using Regular Expressions
Problem
Solution
How It Works
Recipe 1-7.​Handling Strings
Problem
Solution
How It Works
Recipe 1-8.​Scraping Text from the Web
Problem
Solution
How It Works
Chapter 2:​Exploring and Processing Text Data
Recipe 2-1.​Converting Text Data to Lowercase
Problem
Solution
How It Works
Recipe 2-2.​Removing Punctuation
Problem
Solution
How It Works
Recipe 2-3.​Removing Stop Words
Problem
Solution
How It Works
Recipe 2-4.​Standardizing Text
Problem
Solution
How It Works
Recipe 2-5.​Correcting Spelling
Problem
Solution
How It Works
Recipe 2-6.​Tokenizing Text
Problem
Solution
How It Works
Recipe 2-7.​Stemming
Problem
Solution
How It Works
Recipe 2-8.​Lemmatizing
Problem
Solution
How It Works
Recipe 2-9.​Exploring Text Data
Problem
Solution
How It Works
Recipe 2-10.​Dealing with Emojis and Emoticons
Problem
Solution
How It Works
Problem
Solution
How It Works
Problem
Solution
How It Works
Problem
Solution
How It Works
Problem
Solution
How It Works
Recipe 2-11.​Building a Text Preprocessing Pipeline
Problem
Solution
How It Works
Chapter 3:​Converting Text to Features
Recipe 3-1.​Converting Text to Features Using One-Hot
Encoding
Problem
Solution
How It Works
Recipe 3-2.​Converting Text to Features Using a Count
Vectorizer
Problem
Solution
How It Works
Recipe 3-3.​Generating n-grams
Problem
Solution
How It Works
Recipe 3-4.​Generating a Co-occurrence Matrix
Problem
Solution
How It Works
Recipe 3-5.​Hash Vectorizing
Problem
Solution
How It Works
Recipe 3-6.​Converting Text to Features Using TF-IDF
Problem
Solution
How It Works
Recipe 3-7.​Implementing Word Embeddings
Problem
Solution
How It Works
Recipe 3-8.​Implementing fastText
Problem
Solution
How It Works
Recipe 3-9.​Converting Text to Features Using State-of-the-Art
Embeddings
Problem
Solution
ELMo
Sentence Encoders
Open-AI GPT
How It Works
Chapter 4:​Advanced Natural Language Processing
Recipe 4-1.​Extracting Noun Phrases
Problem
Solution
How It Works
Recipe 4-2.​Finding Similarity Between Texts
Solution
How It Works
Recipe 4-3.​Tagging Part of Speech
Problem
Solution
How It Works
Recipe 4-4.​Extracting Entities from Text
Problem
Solution
How It Works
Recipe 4-5.​Extracting Topics from Text
Problem
Solution
How It Works
Recipe 4-6.​Classifying Text
Problem
Solution
How It Works
Recipe 4-7.​Carrying Out Sentiment Analysis
Problem
Solution
How It Works
Recipe 4-8.​Disambiguating Text
Problem
Solution
How It Works
Recipe 4-9.​Converting Speech to Text
Problem
Solution
How It Works
Recipe 4-10.​Converting Text to Speech
Problem
Solution
How It Works
Recipe 4-11.​Translating Speech
Problem
Solution
How It Works
Chapter 5:​Implementing Industry Applications
Recipe 5-1.​Implementing Multiclass Classification
Problem
Solution
How It Works
Recipe 5-2.​Implementing Sentiment Analysis
Problem
Solution
How It Works
Recipe 5-3.​Applying Text Similarity Functions
Problem
Solution
How It Works
Recipe 5-4.​Summarizing Text Data
Problem
Solution
How It Works
Recipe 5-5.​Clustering Documents
Problem
Solution
How It Works
Recipe 5-6.​NLP in a Search Engine
Problem
Solution
How It Works
Recipe 5-7.​Detecting Fake News
Problem
Solution
How It Works
Recipe 5-8.​Movie Genre Tagging
Problem
Solution
How It Works
Chapter 6:​Deep Learning for NLP
Introduction to Deep Learning
Convolutional Neural Networks
Data
Architecture
Convolution
Nonlinearity (ReLU)
Pooling
Flatten, Fully Connected, and Softmax Layers
Backpropagation:​Training the Neural Network
Recurrent Neural Networks
Training RNN:​Backpropagation Through Time (BPTT)
Long Short-Term Memory (LSTM)
Recipe 6-1.​Retrieving Information
Problem
Solution
How It Works
Recipe 6-2.​Classifying Text with Deep Learning
Problem
Solution
How It Works
Recipe 6-3.​Next Word Prediction
Problem
Solution
How It Works
Recipe 6-4.​Stack Overflow question recommendation
Problem
Solution
How It Works
Chapter 7:​Conclusion and Next-Gen NLP
Recipe 7-1.​Recent advancements in text to features or
distributed representations
Problem
Solution
Recipe 7-2.​Advanced deep learning for NLP
Problem
Solution
Recipe 7-3.​Reinforcement learning applications in NLP
Problem
Solution
Recipe 7-4.​Transfer learning and pre-trained models
Problem
Solution
Recipe 7-5.​Meta-learning in NLP
Problem
Solution
Recipe 7-6.​Capsule networks for NLP
Problem
Solution
Index
About the Authors
Akshay Kulkarni
is a renowned AI and machine learning
evangelist and thought leader. He has
consulted several Fortune 500 and global
enterprises on driving AI and data
science–led strategic transformation.
Akshay has rich experience in building
and scaling AI and machine learning
businesses and creating significant
impact. He is currently a data science
and AI manager at Publicis Sapient,
where he is part of strategy and
transformation interventions through AI.
He manages high-priority growth
initiatives around data science and
works on various artificial intelligence engagements by applying state-
of-the-art techniques to this space.
Akshay is also a Google Developers Expert in machine learning, a
published author of books on NLP and deep learning, and a regular
speaker at major AI and data science conferences.
In 2019, Akshay was named one of the top “40 under 40 data
scientists” in India.
In his spare time, he enjoys reading, writing, coding, and mentoring
aspiring data scientists. He lives in Bangalore, India, with his family.

Adarsha Shivananda
is a lead data scientist at Indegene Inc.’s product and technology team,
where he leads a group of analysts who enable predictive analytics and
AI features to healthcare software products. These are mainly
multichannel activities for pharma products and solving the real-time
problems encountered by pharma sales reps. Adarsha aims to build a
pool of exceptional data scientists within the organization to solve
greater health care problems through
brilliant training programs. He always
wants to stay ahead of the curve.
His core expertise involves machine
learning, deep learning,
recommendation systems, and statistics.
Adarsha has worked on various data
science projects across multiple domains
using different technologies and
methodologies. Previously, he worked
for Tredence Analytics and IQVIA.
He lives in Bangalore, India, and loves
to read, ride, and teach data science.
About the Technical Reviewer
Aakash Kag
is a data scientist at AlixPartners and is a
co-founder of the Emeelan application.
He has six years of experience in big data
analytics and has a postgraduate degree
in computer science with a specialization
in big data analytics. Aakash is
passionate about developing social
platforms, machine learning, and
meetups, where he often talks.
© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2021
A. Kulkarni, A. Shivananda, Natural Language Processing Recipes
https://doi.org/10.1007/978-1-4842-7351-7_1

1. Extracting the Data


Akshay Kulkarni1 and Adarsha Shivananda1
(1) Bangalore, Karnataka, India

This chapter covers various sources of text data and the ways to extract it. Textual data can act as
information or insights for businesses. The following recipes are covered.
Recipe 1. Text data collection using APIs
Recipe 2. Reading a PDF file in Python
Recipe 3. Reading a Word document
Recipe 4. Reading a JSON object
Recipe 5. Reading an HTML page and HTML parsing
Recipe 6. Regular expressions
Recipe 7. String handling
Recipe 8. Web scraping

Introduction
Before getting into the details of the book, let’s look at generally available data sources. We need to identify
potential data sources that can help with solving data science use cases.

Client Data
For any problem statement, one of the sources is the data that is already present. The business decides
where it wants to store its data. Data storage depends on the type of business, the amount of data, and the
costs associated with the sources. The following are some examples.
SQL databases
HDFS
Cloud storage
Flat files

Free Sources
A large amount of data is freely available on the Internet. You just need to streamline the problem and start
exploring multiple free data sources.
Free APIs like Twitter
Wikipedia
Government data (e.g., http://data.gov)
Census data (e.g., www.census.gov/data.html)
Health care claim data (e.g., www.healthdata.gov)
Data science community websites (e.g., www.kaggle.com)
Google dataset search (e.g., https://datasetsearch.research.google.com)

Web Scraping
Extracting the content/data from websites, blogs, forums, and retail websites for reviews with permission
from the respective sources using web scraping packages in Python.
There are a lot of other sources, such as news data and economic data, that can be leveraged for analysis.

Recipe 1-1. Collecting Data


There are a lot of free APIs through which you can collect data and use it to solve problems. Let’s discuss the
Twitter API.

Problem
You want to collect text data using Twitter APIs.

Solution
Twitter has a gigantic amount of data with a lot of value in it. Social media marketers make their living from
it. There is an enormous number of tweets every day, and every tweet has some story to tell. When all of this
data is collected and analyzed, it gives a business tremendous insights about their company, product,
service, and so forth.
Let’s now look at how to pull data and then explore how to leverage it in the coming chapters.

How It Works
Step 1-1. Log in to the Twitter developer portal
Log in to the Twitter developer portal at https://developer.twitter.com.
Create your own app in the Twitter developer portal, and get the following keys. Once you have these
credentials, you can start pulling data.
consumer key: The key associated with the application (Twitter, Facebook, etc.)
consumer secret: The password used to authenticate with the authentication server (Twitter, Facebook,
etc.)
access token: The key given to the client after successful authentication of keys
access token secret: The password for the access key

Step 1-2. Execute query in Python


Once all the credentials are in place, use the following code to fetch the data.

# Install tweepy
!pip install tweepy
# Import the libraries
import numpy as np
import tweepy
import json
import pandas as pd
from tweepy import OAuthHandler
# credentials
consumer_key = "adjbiejfaaoeh"
consumer_secret = "had73haf78af"
access_token = "jnsfby5u4yuawhafjeh"
access_token_secret = "jhdfgay768476r"
# calling API
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
# Provide the query you want to pull the data. For example, pulling data for
the mobile phone ABC
query ="ABC"
# Fetching tweets
Tweets = api.search(query, count =
10,lang='en',exclude='retweets',tweet_mode='extended')
This query pulls the top ten tweets when product ABC is searched. The API pulls English tweets since the
language given is 'en'. It excludes retweets.

Recipe 1-2. Collecting Data from PDFs


Most of your data is stored in PDF files. You need to extract text from these files and store it for further
analysis.

Problem
You want to read a PDF file.

Solution
The simplest way to read a PDF file is by using the PyPDF2 library.

How It Works
Follow the steps in this section to extract data from PDF files.

Step 2-1. Install and import all the necessary libraries


Here are the first lines of code .

!pip install PyPDF2


import PyPDF2
from PyPDF2 import PdfFileReader

Note You can download any PDF file from the web and place it in the location where you are running
this Jupyter notebook or Python script.

Step 2-2. Extract text from a PDF file


Now let’s extract the text.

#Creating a pdf file object


pdf = open("file.pdf","rb")
#creating pdf reader object
pdf_reader = PyPDF2.PdfFileReader(pdf)
#checking number of pages in a pdf file
print(pdf_reader.numPages)
#creating a page object
page = pdf_reader.getPage(0)
#finally extracting text from the page
print(page.extractText())
#closing the pdf file
pdf.close()

Please note that the function doesn’t work for scanned PDFs.

Recipe 1-3. Collecting Data from Word Files


Next, let’s look at another small recipe that reads Word files in Python.

Problem
You want to read Word files .

Solution
The simplest way is to use the docx library.

How It Works
Follow the steps in this section to extract data from a Word file.

Step 3-1. Install and import all the necessary libraries


The following is the code to install and import the docx library.

#Install docx
!pip install docx
#Import library
from docx import Document

Note You can download any Word file from the web and place it in the location where you are running a
Jupyter notebook or Python script.

Step 3-2. Extract text from a Word file


Now let’s get the text .

#Creating a word file object


doc = open("file.docx","rb")
#creating word reader object
document = docx.Document(doc)
#create an empty string and call this document. #This document variable
stores each paragraph in the Word document.
#We then create a "for" loop that goes through each paragraph in the Word
document and appends the paragraph.
docu=""
for para in document.paragraphs.
docu += para.text
#to see the output call docu
print(docu)

Recipe 1-4. Collecting Data from JSON


JSON is an open standard file format that stands for JavaScript Object Notation. It’s often used when data is
sent to a webpage from a server. This recipe explains how to read a JSON file/object.

Problem
You want to read a JSON file/object.

Solution
The simplest way is to use requests and the JSON library.

How It Works
Follow the steps in this section to extract data from JSON.

Step 4-1. Install and import all the necessary libraries


Here is the code for importing the libraries.

import requests
import json
Step 4-2. Extract text from a JSON file
Now let’s extract the text .

#extracting the text from "https://quotes.rest/qod.json"


r = requests.get("https://quotes.rest/qod.json")
res = r.json()
print(json.dumps(res, indent = 4))
#output
{
"success": {
"total": 1
},
"contents": {
"quotes": [
{
"quote": "Where there is ruin, there is hope for a
treasure.",
"length": "50",
"author": "Rumi",
"tags": [
"failure",
"inspire",
"learning-from-failure"
],
"category": "inspire",
"date": "2018-09-29",
"permalink":
"https://theysaidso.com/quote/dPKsui4sQnQqgMnXHLKtfweF/rumi-where-there-is-
ruin-there-is-hope-for-a-treasure",
"title": "Inspiring Quote of the day",
"background":
"https://theysaidso.com/img/bgs/man_on_the_mountain.jpg",
"id": "dPKsui4sQnQqgMnXHLKtfweF"
}
],
"copyright": "2017-19 theysaidso.com"
}
}
#extract contents
q = res['contents']['quotes'][0]
q
#output
{'author': 'Rumi',
'background': 'https://theysaidso.com/img/bgs/man_on_the_mountain.jpg',
'category': 'inspire',
'date': '2018-09-29',
'id': 'dPKsui4sQnQqgMnXHLKtfweF',
'length': '50',
'permalink': 'https://theysaidso.com/quote/dPKsui4sQnQqgMnXHLKtfweF/rumi-
where-there-is-ruin-there-is-hope-for-a-treasure',
'quote': 'Where there is ruin, there is hope for a treasure.',
'tags': ['failure', 'inspire', 'learning-from-failure'],
'title': 'Inspiring Quote of the day'}
#extract only quote
print(q['quote'], '\n--', q['author'])
#output
It wasn't raining when Noah built the ark....
-- Howard Ruff

Recipe 1-5. Collecting Data from HTML


HTML is short for HyperText Markup Language. It structures webpages and displays them in a browser.
There are various HTML tags that build the content. This recipe looks at reading HTML pages .

Problem
You want to read parse/read HTML pages.

Solution
The simplest way is to use the bs4 library.

How It Works
Follow the steps in this section to extract data from the web.

Step 5-1. Install and import all the necessary libraries


First, import the libraries .

!pip install bs4


import urllib.request as urllib2
from bs4 import BeautifulSoup

Step 5-2. Fetch the HTML file


You can pick any website that you want to extract. Let’s use Wikipedia in this example.

response =
urllib2.urlopen('https://en.wikipedia.org/wiki/Natural_language_processing')
html_doc = response.read()

Step 5-3. Parse the HTML file


Now let’s get the data.

#Parsing
soup = BeautifulSoup(html_doc, 'html.parser')
# Formating the parsed html file
strhtm = soup.prettify()
# Print few lines
print (strhtm[:1000])
#output
<!DOCTYPE html>
<html class="client-nojs" dir="ltr" lang="en">
<head>
<meta charset="utf-8"/>
<title>
Natural language processing - Wikipedia
</title>
<script>
document.documentElement.className = document.documentElement.className.rep
</script>
<script>
(window.RLQ=window.RLQ||[]).push(function()
{mw.config.set({"wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"
processing","wgCurRevisionId":860741853,"wgRevisionId":860741853,"wgArticleId"
["*"],"wgCategories":["Webarchive template wayback links","All accuracy disput
identifiers","Natural language processing","Computational linguistics","Speech

Step 5-4. Extract a tag value


You can extract a tag’s value from the first instance of the tag using the following code.

print(soup.title)
print(soup.title.string)
print(soup.a.string)
print(soup.b.string)
#output
<title>Natural language processing - Wikipedia</title>
Natural language processing - Wikipedia
None
Natural language processing

Step 5-5. Extract all instances of a particular tag


Here we get all the instances of the tag that we are interested in.

for x in soup.find_all('a'): print(x.string)


#sample output
None
Jump to navigation
Jump to search
Language processing in the brain
None
None
automated online assistant
customer service
[1]
computer science
artificial intelligence
natural language
speech recognition
natural language understanding
natural language generation

Step 5-6. Extract all text from a particular tag


Finally, we get the text .

for x in soup.find_all('p'): print(x.text)


#sample output
Natural language processing (NLP) is an area of computer science and
artificial intelligence concerned with the interactions between computers
and human (natural) languages, in particular how to program computers to
process and analyze large amounts of natural language data.
Challenges in natural language processing frequently involve speech
recognition, natural language understanding, and natural language
generation.
The history of natural language processing generally started in the 1950s,
although work can be found from earlier periods.
In 1950, Alan Turing published an article titled "Intelligence" which
proposed what is now called the Turing test as a criterion of intelligence.
Note that the p tag extracted most of the text on the page.

Recipe 1-6. Parsing Text Using Regular Expressions


This recipe discusses how regular expressions are helpful when dealing with text data. Regular expressions
are required when dealing with raw data from the web that contains HTML tags, long text, and repeated text.
During the process of developing your application, as well as in output, you don’t need such data.
You can do allsorts of basic and advanced data cleaning using regular expressions.

Problem
You want to parse text data using regular expressions.

Solution
The best way is to use the re library in Python.

How It Works
Let’s look at some of the ways we can use regular expressions for our tasks.
The basic flags are I, L, M, S, U, X.
re.I ignores casing.
re.L finds a local dependent.
re.M finds patterns throughout multiple lines.
re.S finds dot matches.
re.U works for Unicode data.
re.X writes regex in a more readable format.
The following describes regular expressions’ functionalities .
Find a single occurrence of characters a and b: [ab]
Find characters except for a and b: [^ab]
Find the character range of a to z: [a-z]
Find a character range except a to z: [^a-z]
Find all the characters from both a to z and A to Z: [a-zA-Z]
Find any single character: []
Find any whitespace character: \s
Find any non-whitespace character: \S
Find any digit: \d
Find any non-digit: \D
Find any non-words: \W
Find any words: \w
Find either a or b: (a|b)
The occurrence of a is either zero or one
Matches zero or not more than one occurrence: a? ; ?
The occurrence of a is zero or more times: a* ; * matches zero or more than that
The occurrence of a is one or more times: a+ ; + matches occurrences one or more
than one time
Match three simultaneous occurrences of a: a{3}
Match three or more simultaneous occurrences of a: a{3,}
Match three to six simultaneous occurrences of a: a{3,6}
Start of a string: ^
End of a string: $
Match word boundary: \b
Non-word boundary: \B
The re.match() and re.search() functions find patterns, which are then processed according to
the requirements of the application.
Let’s look at the differences between re.match() and re.search().
re.match() checks for a match only at the beginning of the string. So, if it finds a pattern at the
beginning of the input string, it returns the matched pattern; otherwise, it returns a noun.
re.search() checks for a match anywhere in the string. It finds all the occurrences of the pattern in the
given input string or data.
Now let’s look at a few examples using these regular expressions.

Tokenizing
Tokenizing means splitting a sentence into words. One way to do this is to use re.split.

# Import library
import re
#run the split query
re.split('\s+','I like this book.')
['I', 'like', 'this', 'book.']

For an explanation of regex, please refer to the main recipe.

Extracting Email IDs


The simplest way to extract email IDs is to use re.findall.
1. Read/create the document or sentences.

doc = "For more details please mail us at: [email protected], [email protected]"

2. Execute the re.findall function.

addresses = re.findall(r'[\w\.-]+@[\w\.-]+', doc)


for address in addresses.
print(address)
#Output
[email protected]
[email protected]

Replacing Email IDs


Let’s replace email IDs in sentences or documents with other email IDs. The simplest way to do this is by
using re.sub.
1. Read/create the document or sentences.

doc = "For more details please mail us at [email protected]"

2. Execute the re.sub function.

new_email_address = re.sub(r'([\w\.-]+)@([\w\.-]+)', r'[email protected]', doc)


print(new_email_address)
#Output
For more details please mail us at [email protected]
For an explanation of regex, please refer to Recipe 1-6.
If you observe in both instances when dealing with email using regex, we have implemented a very basic
one. We state that words separated by @ help capture email IDs. However, there could be many edge cases;
for example, the dot (.) incorporates domain names and handles numbers, the + (plus sign), and so on,
because they can be part of an email ID.
The following is an advanced regex to extract/find/replace email IDs.

([a-zA-Z0-9+._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)

There are even more complex ones to handle all the edge cases (e.g., “.co.in” email IDs). Please give it a
try.

Extracting Data from an eBook and Performing regex


Let’s solve a case study that extracts data from an ebook by using the techniques you have learned so far.
1. Extract the content from the book.

# Import library
import re
import requests
#url you want to extract
url = 'https://www.gutenberg.org/files/2638/2638-0.txt'
#function to extract
def get_book(url).
# Sends a http request to get the text from project Gutenberg
raw = requests.get(url).text
# Discards the metadata from the beginning of the book
start = re.search(r"\*\*\* START OF THIS PROJECT GUTENBERG EBOOK .*
\*\*\*",raw ).end()
# Discards the metadata from the end of the book
stop = re.search(r"II", raw).start()
# Keeps the relevant text
text = raw[start:stop]
return text
# processing
def preprocess(sentence).
return re.sub('[^A-Za-z0-9.]+' , ' ', sentence).lower()
#calling the above function
book = get_book(url)
processed_book = preprocess(book)
print(processed_book)
# Output
produced by martin adamson david widger with corrections by andrew sly
the idiot by fyodor dostoyevsky translated by eva martin part i i. towards
the end of november during a thaw at nine o clock one morning a train on
the warsaw and petersburg railway was approaching the latter city at full
speed. the morning was so damp and misty that it was only with great
difficulty that the day succeeded in breaking and it was impossible to
distinguish anything more than a few yards away from the carriage windows.
some of the passengers by this particular train were returning from abroad
but the third class carriages were the best filled chiefly with
insignificant persons of various occupations and degrees picked up at the
different stations nearer town. all of them seemed weary and most of them
had sleepy eyes and a shivering expression while their complexions
generally appeared to have taken on the colour of the fog outside. when da
2. Perform an exploratory data analysis on this data using regex.

# Count number of times "the" is appeared in the book


len(re.findall(r'the', processed_book))
#Output
302
#Replace "i" with "I"
processed_book = re.sub(r'\si\s', " I ", processed_book)
print(processed_book)
#output
produced by martin adamson david widger with corrections by andrew sly
the idiot by fyodor dostoyevsky translated by eva martin part I i. towards
the end of november during a thaw at nine o clock one morning a train on
the warsaw and petersburg railway was approaching the latter city at full
speed. the morning was so damp and misty that it was only with great
difficulty that the day succeeded in breaking and it was impossible to
distinguish anything more than a few yards away from the carriage windows.
some of the passengers by this particular train were returning from abroad
but the third class carriages were the best filled chiefly with
insignificant persons of various occupations and degrees picked up at the
different stations nearer town. all of them seemed weary and most of them
had sleepy eyes and a shivering expression while their complexions
generally appeared to have taken on the colour of the fog outside. when da
#find all occurance of text in the format "abc--xyz"
re.findall(r'[a-zA-Z0-9]*--[a-zA-Z0-9]*', book)
#output
['ironical--it',
'malicious--smile',
'fur--or',
'astrachan--overcoat',
'it--the',
'Italy--was',
'malady--a',
'money--and',
'little--to',
'No--Mr',
'is--where',
'I--I',
'I--',
'--though',
'crime--we',
'or--judge',
'gaiters--still',
'--if',
'through--well',
'say--through',
'however--and',
'Epanchin--oh',
'too--at',
'was--and',
'Andreevitch--that',
'everyone--that',
'reduce--or',
'raise--to',
'listen--and',
'history--but',
'individual--one',
'yes--I',
'but--',
't--not',
'me--then',
'perhaps--',
'Yes--those',
'me--is',
'servility--if',
'Rogojin--hereditary',
'citizen--who',
'least--goodness',
'memory--but',
'latter--since',
'Rogojin--hung',
'him--I',
'anything--she',
'old--and',
'you--scarecrow',
'certainly--certainly',
'father--I',
'Barashkoff--I',
'see--and',
'everything--Lebedeff',
'about--he',
'now--I',
'Lihachof--',
'Zaleshoff--looking',
'old--fifty',
'so--and',
'this--do',
'day--not',
'that--',
'do--by',
'know--my',
'illness--I',
'well--here',
'fellow--you']

Recipe 1-7. Handling Strings


This recipe discusses how to handle strings and deal with textual data. You can do all sorts of basic text
explorations using string operations.

Problem
You want to explore handling strings.

Solution
The simplest way is to use the following string functionality.
s.find(t) is an index of the first instance of string t inside s (–1 if not found)
s.rfind(t) is an index of the last instance of string t inside s (–1 if not found)
s.index(t) is like s.find(t) except it raises ValueError if not found
s.rindex(t) is like s.rfind(t) except it raises ValueError if not found
s.join(text) combines the words of the text into a string using s as the glue
s.split(t) splits s into a list wherever a t is found (whitespace by default)
s.splitlines() splits s into a list of strings, one per line
s.lower() is a lowercase version of the string s
s.upper() is an uppercase version of the string s
s.title() is a titlecased version of the string s
s.strip() is a copy of s without leading or trailing whitespace
s.replace(t, u) replaces instances of t with u inside s

How It Works
Now let’s look at a few of the examples.

Replacing Content
Create a string and replace the content. Creating strings is easy. It is done by enclosing the characters in
single or double quotes. And to replace, you can use the replace function.
1. Create a string.

String_v1 = "I am exploring NLP"


#To extract particular character or range of characters from string
print(String_v1[0])
#output
"I"
#To extract the word “exploring”
print(String_v1[5:14])
#output
exploring

2. Replace "exploring" with "learning" in the preceding string.

String_v2 = String_v1.replace("exploring", "learning")


print(String_v2)
#Output
I am learning NLP

Concatenating Two Strings


The following is simple code.

s1 = "nlp"
s2 = "machine learning"
s3 = s1+s2
print(s3)
#output
'nlpmachine learning'

Searching for a Substring in a String


Use the find function to fetch the starting index value of the substring in the whole string.

var="I am learning NLP"


f= "learn"
var.find(f)
#output
5

Recipe 1-8. Scraping Text from the Web


This recipe discusses how to scrape data from the web.

Caution Before scraping any websites, blogs, or ecommerce sites, please make sure you read the site’s
terms and conditions on whether it gives permissions for data scraping. Generally, robots.txt contains the
terms and conditions (e.g., see www.alixpartners.com/robots.txt) and a site map contains a
URL’s map (e.g., see www.alixpartners.com/sitemap.xml).

Web scraping is also known as web harvesting and web data extraction. It is a technique to extract a large
amount of data from websites and save it in a database or locally. You can use this data to extract
information related to your customers, users, or products for the business’s benefit.
A basic understanding of HTML is a prerequisite.

Problem
You want to extract data from the web by scraping. Let’s use IMDB.com as an example of scraping top
movies.

Solution
The simplest way to do this is by using Python’s Beautiful Soup or Scrapy libraries. Let’s use Beautiful Soup
in this recipe.

How It Works
Follow the steps in this section to extract data from the web.

Step 8-1. Install all the necessary libraries


!pip install bs4
!pip install requests

Step 8-2. Import the libraries


from bs4 import BeautifulSoup
import requests
import pandas as pd
from pandas import Series, DataFrame
from ipywidgets import FloatProgress
from time import sleep
from IPython.display import display
import re
import pickle

Step 8-3. Identify the URL to extract the data


url = 'http://www.imdb.com/chart/top?ref_=nv_mv_250_6'

Step 8-4. Request the URL and download the content using Beautiful Soup
result = requests.get(url)
c = result.content
soup = BeautifulSoup(c,"lxml")
Exploring the Variety of Random
Documents with Different Content
FOURTH BOOK—continued

SECOND PART
TIME OF LORENZO THE MAGNIFICENT.
CHAPTER VI.

LORENZO AS A POET.

In April 1465, as already stated, Federigo of Aragon, Prince of


Naples, and Lorenzo de’ Medici, then seventeen years old, met at
Pisa. A letter addressed by the young Florentine to his royal friend,
probably in the following year, begins thus:[1] ‘When thou, illustrious
Federigo, didst visit the most ancient city of Pisa, thou didst turn our
conversation to the subject of those who have written poetry in the
Tuscan language, and didst manifest a laudable desire to see all
their works collected by my care. Endeavouring to fulfil thy wishes, I
had a diligent search made for all the old manuscripts, and chose
from them the least imperfect, which I now present to your
Highness, arranged in order in a book which I earnestly desire thee
approvingly to accept, as a token of especial goodwill. Let no one
despise this Tuscan tongue as poor and rude, for he who can rightly
estimate its value will find it rich and well cultivated. There is,
indeed, nothing vigorous or graceful, impressive or ingenious, witty,
harmonious, or majestic, of which examples may not be found in our
two greatest poets, Dante and Petrarca; and after them, by those
whom thou, Prince, hast recalled to life.
‘Petrarca shows in one of his letters that the ancient Romans
were acquainted with rhyme which, after a long interval, revived in
Sicily, spread through France, and was restored to Italy, its original
home. The first who gave our modern poetry its peculiar form of
verse were Guittone of Arezzo and his Bolognese contemporary
Guido Guinicello. They were both well versed in philosophy, and
wrote profoundly; but the first is somewhat harsh and rude, deficient
in ornament and eloquence. The latter, who is far more clear and
elegant, was called by Dante “his father,” and the father of all who
write sweet and graceful love songs. He was unquestionably the first
to impress on our beautiful language that attractive colouring which
the bard of Arezzo had but faintly indicated. After these shone Guido
Cavalcanti, one of the keenest dialecticians and most admirable
philosophers of his time. He was handsome in person, and his
writings are to me in the highest degree attractive; his imagination is
rich and wonderfully grand; his reasoning is weighty; his tone
extremely dignified. These qualities are heightened by the rich
charm of a style that sets them off like a resplendent robe. He
needed but a wider field to have attained the highest honours.
‘Bonagiunta of Lucca and the notary of Lentino must not be
overlooked; but though earnest and weighty writers, they were so
destitute of refined taste, that they must be content to find a place
in this collection of honoured names. Another contemporary of
Guittone was Pier delle Vigne, of whom Dante said that “he had both
the keys of Frederick’s heart.” Only a few short pieces by him
remain, and they are not wanting in depth or earnestness.
‘And now come the two glorious suns that have illuminated our
language—Dante, and he who stands hardly below him, Francesco
Petrarca. In praise of them, silence, to use the words of Sallust
concerning Carthage, is better than halting speech. Greatly in need
of their polish stood Onesto, and the Sicilians who in order of time
preceded them, and who were not without spirit or purpose. Cino of
Pistoja, tender and full of feeling, deserves his reputation. He was
the first, in my opinion, who thoroughly surmounted the antique
roughness which Dante, so admirable in other respects, could not
entirely avoid. A host of writers follow, ranking far below those I
have named. All these of the past, and some of our own time, owe
lasting thanks to thee, O Prince, who hast bestowed on them life,
and light, and fame, acquiring for thyself a claim to greater renown
than that of the Athenian Peisistratos, who rescued from oblivion the
lays of Homer. He restored life to one; thou hast revived a whole
host. At the end of the book, as it seemed not unpleasing to thee, I
have added some sonnets and canzoni of my own, that when thou
readest them, my goodwill and affection may be vividly recalled to
thy mind. Though in themselves unworthy of a place beside the
admirable works of the past, it may be useful to set them side by
side for a comparison which can but enhance the perfections of the
latter. Pray take then, O Prince, not only into thine house, but into
thy heart and mind, both them and me, even as thou abidest a
welcome guest in my heart and soul.’
Thus wrote Lorenzo de’ Medici apparently in 1466. On a
subsequent occasion, in a gloss on his own poems such as it was the
custom then for an author himself or some of his friends to write, he
gave his opinion on the much-disputed question of the value of the
vulgar tongue as the language of poetry. ‘If we want,’ he wrote, ‘to
prove the worth of our language, we need only apply this test: does
it express with ease all our thoughts and all our feelings? Nothing
can be more satisfactory than the answer given us by experience.
Our countrymen Dante, Petrarca, and Boccaccio, have in their verses
and discourses, whether grave or gay, proved clearly that every
thought and feeling finds easy and natural expression in this tongue
of ours. Whoever reads the “Commedia” sees various questions of
theology and nature discussed with as much skill as success. He
finds there the three degrees of style specified by orators—the
simple, the florid, and the sublime, nay, more—Dante in himself
presents a union of all the qualities which Greek and Latin writers
display separately. Who again can deny the warmth, tenderness, and
gaiety of Boccaccio? In his love poems he shows a mingled grace
and fervour that neither Ovid, Tibullus, Propertius nor Catullus have
equalled. Dante’s pithy sonnets and canzoni are scarcely surpassed
by anything in prose or verse, and the readers of Boccaccio, whose
learning was as great as the polish of his style, must admit that in
him the faculty of invention contends with the variety and eloquence
of his language. Any one who examines his “Decameron” with its
endless diversity of subject, its descriptions of every conceivable
situation produced by love and hate, hope or fear; its exhibition of
countless intrigues and artifices; its characteristic representation of
diverse natures, and its expression of every passion, will be
convinced that for all this no language can be better adapted than
our own. It is not the language that has been unfavourable to
writers, but there has been a dearth of authors who could use it. To
any one with a little practice, it is full of power, harmony, and grace.
It appears to me richly endowed with all that constitutes the
excellence of a language, and I am persuaded that a knowledge of
what has been written in it is not only useful but necessary—more
especially the works of Dante, which are both solid and profound.
The commentaries of learned men on the “Commedia” bear witness
to this no less than the allusions made to the work from the pulpit.
We may look forward to the appearance of other excellent works in
this language, which still preserves its freshness and is growing in
elegance and copiousness. A prospect of still greater perfection is
before it, should the dominion of Florence be extended, a thing not
merely to be hoped but to be striven for by our gallant citizens with
all their energies of body and mind. Though such a consummation
cannot positively be predicted, since it depends on fate and the will
of God, yet it is within the limits of possibility. For the present the
following conclusion is enough. Our native speech has all the
excellencies of a language in abundance, and we ought not to be
dissatisfied with it, nor ought any one to blame me for writing in a
tongue to which I was born and in which I was educated. Hebrew
and Latin originally were no more than vulgar tongues, yet those
who hold an honoured place in literature cultivated them to a degree
of perfection that was never attained by the mass of the people.’
These remarks, which are followed by others on the sonnet and
on Tuscan rhythm and metre, show that from his youth up Lorenzo
de’ Medici thought much of the nature and history of the language
of his country. His poems opened out no new path, but served with
those of many among his contemporaries to give more freedom and
grace of movement to the language, more facility for applying it to
manifold aims and objects, and a richer variety of idiomatic forms.
His masterly handling of the language was equalled by his command
of versification. Harshness he has, and that force which will not
avoid a difficulty. Nor is he wanting in archaic forms and illegitimate
turns of expression, while he has echoes of the artificial manner
which in the poet’s youth was regarded as modern classicism. We do
not always meet with the refinement of ear, accuracy of taste, and
fulness of harmony, which give such importance to his contemporary
Poliziano, and mark him as the true leader of the great literary
movement of the fifteenth century, a movement which, in its last
decade, put an end to a state of things in which it is hard to say
whether stagnation or perverted energy was the worst feature.
Nevertheless, Lorenzo de’ Medici takes a conspicuous and peculiar
place in this movement. Had he been only a literary man, he would
have shone as such. As in his whole character, so also as a poet, is
he the true representative of his time, a time that strove with pious
care to restore the old, while it joyfully if doubtfully anticipated the
opening of new vistas and formed the threshold between two great
epochs, the blending of the sunset and the dawn. Lorenzo de’
Medici, while rightly estimating the character of the literature of
Dante’s age, and perceiving that it and not the pedantry of the
humanistic poets contained life and hope for the future, was,
nevertheless, still influenced by the great fact of the first half of his
century, the revival of classical culture. Even when he most nearly
approaches the lyric poets who preceded him, it is not in imitation,
like Bembo’s imitation of Petrarca. Even when Dante or Guido
Cavalcanti, with their subtle dissection of feelings, partaking
somewhat of the character of scholasticism, and their habit of
treating even earthly things with a certain unearthly solemnity of
tone, have been most evidently his guiding lights—still, through all,
there pierces a spirit which could only have been aroused by the
contact of modes of thought derived from the antique with modern
life and experience, and by a direct knowledge of the creations of
Hellenic genius, which to the fathers of Italian poetry were sealed
books, whose very titles were unknown to most of them.
Lorenzo de’ Medici is no imitator of Petrarca, although echoes of
Petrarca and even, through the latter, of the poetry of the
Troubadours occur frequently in his compositions. But, apart from
other details, he has one conspicuous trait in common with Petrarca
—a quick sense of the beauties of nature. The hermit of Vaucluse
and Arquà is, of all modern poets, the first to whom nature seems to
have been especially revealed in her inner life and in the impression
which she makes on the feelings; for in Dante it is rather the
historical character of the landscape and the plasticity of sharply
defined individual phenomena which come out most strongly. Like
Petrarca, he who dwelt in the Tuscan villas and among the wooded
Apennines found in nature an inexhaustible fountain whence flowed
forth an ever-fresh stream of forms and images clothed in the most
varied and brilliant colours. The richness and freshness of his
treatment proves how quick were his eyes to receive and his mind to
realise such impressions. He delighted to consecrate to the mental
and moral refreshment of a residence in the country the hours and
days which he could steal from his varied and often vexatious cares
and occupations. If his poetic descriptions did not sufficiently declare
it, his whole life would furnish a proof that there was in him not
merely an active fancy, but an actual need, as well as a true and
quick apprehension of nature. He has shown in the ‘Selve d’amore,’
and in the idyl of ‘Ambra,’ what were his powers of describing
nature, not merely in the illustration of thoughts and feelings, but as
an independent picture complete in itself.
The greater part of his sonnets and canzoni consists, as may be
imagined, of love poems. But the individualising characteristics of his
poetry save them from the monotony usually inseparable from this
style; for where there is no variety of tone, there is a variety of
situation and colouring. The lover and poet is with Lorenzo always a
disciple of philosophy, and the subject of his poems, decked in all
the brilliant colours of fancy, retreats into the background infinitely
more than with the great poets of the Trecento. In reading Lorenzo’s
poems, one gives little more than a passing thought to Lucrezia
Donati, whose name even is revealed to us only by the poet’s
friends. Beatrice and Madonna Laura have been the objects of
careful historical research—scarcely any one has troubled himself
about the fair Florentine, sprung from a race whose name filled the
history of the city when that of Medici was still unknown. The reason
is not merely that Lucrezia’s bard was no Dante or Petrarca, and that
his poetry, however fresh and genuine, and however important as
completing a character unique in its way, yet held but a secondary
place in the mind and life of Lorenzo de’ Medici; but the ideal
creation threatens to swallow up the personality. The story
connected with the beautiful girl lying on the bier, in which the poet
sets forth how he sought and found a worthy object for his affection,
sufficiently indicates that he rather transferred to this object what
had already assumed a living shape in his own mind than received
his impulse from it. To the greatest of Italy’s poets the angel-bride of
his early youth became the ideal in which all his thoughts and
feelings were wrapt up; the ideal stood before the eyes of Lorenzo
de’ Medici before he knew her whose form he clothed in the magic
of spiritualised desire.
The disciple of the Platonic philosophy, giving a description of his
beloved one in the commentary on his sonnets,[2] thus declares
himself in his definition of the nature of love. ‘Whoever seeks the
true definition of love, will find that it consists in the desire for
beauty. This being so, whatever is ugly repels him who truly and
worthily loves. The beauty of the countenance and soul of our
beloved one impels us to seek beauty in other things; to rise to that
virtue which is beauty on earth as in heaven, and to reach at length
the highest beauty—the Divinity, our final goal and resting-place.
The necessary conditions of a true, worthy, and elevated love,
appear to me to be two: first, that the object shall be one, then that
the love shall be constant. It is not given to all to fulfil these
conditions, seeing that but few women possess the lofty power of
attaching men so entirely to themselves that they shall never offend
against the two conditions without which there is no true love.’ But
his philosophical view of life and human happiness is contained in a
longer poem in terza rima, (‘L’Altercazione’), in which Marsilio Ficino
is personally introduced as teacher, and decides between the poet
and his interlocutor. The former has left the tumult of the city, the
confusion of party politics, the throng of the market, to bring his soul
to a haven of rest, a life free and secure from anxiety, in the solitude
of the country. He describes what he seeks and hopes to find in this
retreat to the shepherd whom he meets; the latter points out to him
the toils and troubles of his humble lot, and how he drags on day
after day beneath ever-renewing cares. Then Marsilio comes to place
in their true light the worth and the worthlessness of sublunary
things; to show how happiness depends neither on the high position
of the one nor the lowly station of the other, but is to be found in
the knowledge and love of the Author of all things. As may be seen
from this sketch of its contents, the poem contains nothing original,
but it is pleasing from its life-like description of contrasts, and
interesting as a token of the earnest self-introspection of a richly and
variously endowed mind.[3]
The three idyls which we possess of Lorenzo de’ Medici are so
many witnesses to the many-sidedness of his genius. The first,
‘Corinto’ (the name of the shepherd who sings his love), resembles
the eclogues of the ancients, which were soon to become the
models of so many writers, and especially of Sannazaro. Following
the precedent of Boccaccio, it is in terza rima, a metre better suited
to a series of narratives and descriptions than to a subject in which
the lyrical element preponderates. ‘Nencia da Barberino’ is pure
nature—in some parts severe nature, with a rich vein of quaint
humour and a charming local colour. It is an idyl in eight-lined
stanzas, redolent of Tuscan soil, describing the Tuscan people, their
manners and modes of speech, with a succession of apostrophes,
eulogies, and comparisons, including some that are strange enough.
Such are the so-called rispetti,—those songs of the people,
especially country people, which sometimes in their fantastic flights
soar up to the sun and stars, and sometimes borrow their similes
from the humblest things. Lorenzo has, in fact, here put together a
whole poem of rispetti, in which the serious and the comic alternate,
and through the mouth of a lover has applied to one rustic beauty
what would have sufficed for a whole bevy of maidens. These
rispetti are evidently learned from the people, who to this day
produce thousands of these half-lyric, half-epigrammatic songs,
particularly in the hill-country of Pistoja, for, as an old proverb says,
‘the mountaineers have thick shoes and fine brains.’[4] They are to
be heard also in other parts of the Florentine and Sienese
dominions, as far as the Maremma, from whence they extend into
the Roman Campagna. Some of the rustic verses are peculiar to the
poet, who exercises himself freely in a style that permits great
variety, and who rivals the people among whom he mingles in
fantastic flights and quaint similes, producing a somewhat motley
but richly coloured and life-like picture. Luigi Pulci has furnished a
companion piece to ‘Nencia.’ Poliziano, without confining himself to a
special subject, has also tried his hand at these little songs, which
seem to flow spontaneously from Tuscan pens, and form a branch of
literature highly important in its relation to the character of the
people.
While in ‘Nencia’ the popular and burlesque element prevails, the
third of these idyls, ‘Ambra,’ belongs to the province of mythology.
Its importance lies far less in the story itself—one of the oft-told
tales after the Ovidian pattern—than in the grand descriptions of
nature to which the fable gives rise. The scene is the villa of Poggio
a Cajano, on the decoration of which the princely owner bestowed
so much trouble and expense, the results of his work being
repeatedly destroyed by the overflow of the Ombrone in its descent
from the Pistojan mountains to the level ground around the low hill
on which Cajano stood. A small islet in the river bore the name of
Ambra, which was transferred to the villa itself. The dykes raised for
its defence did not fulfil Poliziano’s hope that the stream would spare
the flower-garden. In the poem, Ambra is the nymph beloved by the
shepherd Lauro. Her charms, seen when bathing, attract the river
god, and she only escapes from his wild pursuit by the help of
Diana, who, at her entreaty, changes her into a rock, on which the
villa is then built. As in ‘Nencia’ the ottava rima adapts itself to a
burlesque and popular subject, so here it developes a surprising
power in descriptions of the natural occurrences that caused the
destruction of the pleasant rustic dwelling, and of the events which
are made to precede them.
As ‘Ambra’ inclines to the descriptive, so does another little poem
in eight-line stanzas called ‘The Hawking Party’ (‘La Caccia con
Falcone’), a lively picture of a universally favourite pastime to which
our poet was almost passionately addicted. The fresh morning on
which the party sets out, the adventures and intermezzos on the
way, the rivalry and excitement of the huntsmen, the manœuvres of
the chase, with the birds and dogs, carefully trained, yet not always
to be relied on, the return in midday heat, and the cheerful meal,
which reconciles the tired disputants and brings the day to a close,—
all this is described with the most vivid reality, and with an amount
of detail that could only come from an initiated sportsman. We are in
the midst of the cheerful company that crowded around the gay and
stately young man. For the poem dates some time before the year
1478, as is proved by the circumstance that Lorenzo’s brother-in-law,
Guglielmo de’ Pazzi, is one of the chief persons present, together
with Luigi Pulci, Foglia Amieri, Dionigi Pucci, and several others less
easy to distinguish by name. A whole stanza is taken up with the
names of the falcons, the number of which shows that this was
indeed a princely hunt, such as often took place at Pisa or Poggio a
Cajano.
The poem in terza rima which bears the name of ‘I Beoni’ (‘The
Drinkers’), or ‘Simposio,’ resembles the ‘Nencia’ and the ‘Hawking
Party’ in so far as it describes Florentine and Tuscan manners. In
rhythm, tone, and manner, it is very different from the others; for
although in ‘Nencia’ peasant life sometimes receives a burlesque
covering, the poem never becomes satire, nor sinks to that degree
of low comedy which degenerates into vulgarity. This, however, is
the case in the ‘Beoni,’ a series of chapters in which the poet
describes the manners and adventures of a company of jolly fellows,
whom he meets near Porta Faenza as he is returning from Careggi,
at the moment when they are setting out for Ponte a Rifredi, a little
place about a mile away from the town, and which takes its name
from a bridge over the little stream Terzolle. The business of the
company is to taste a cask of wine which they have heard highly
praised. The poem is not wanting in humour, and offers a lively
picture of convivial rather than social manners, such as long existed
in Tuscany, and of which we possess many literary monuments.
Although unfinished, it is long, and monotonous in spite of the
variety of its situations; its dry comedy often degenerates into
downright coarseness, such as might lead to very unfavourable
conclusions with regard to the morals even of the higher classes and
the clergy, who in part are represented here. ‘I Beoni’ makes an
unpleasant impression from another point of view. Not only is the
metre that of the most sublime poems in the Italian language; the
outward arrangement of the poem, as well as a number of particular
turns, are burlesque imitations of the great poets. This is a proof of
keen observation, of wonderful and many-sided power; but it has a
darker side. If we are to recognise in this production the beginning
of Italian satire, we can all the more justly measure the distance
between these ‘chapters’ and those brilliant mirrors of the time
which immediately followed that of Lorenzo de’ Medici—the satires
of Lodovico Ariosto.
Like the ‘Beoni,’ the dance-songs (‘Canzoni a ballo’) and the
songs of the carnival (‘Canti carnascialeschi’), especially the latter,
often pass the limits which separate social gaiety from burlesque and
satire. Yet the nature and object of these songs demand the
predominance of the lyrical element. The dance songs are explained
by the old traditional customs of the Tuscan people, and Lorenzo did
but follow examples furnished by the age of Dante; examples
differing in character of all degrees, from the grave and sententious
to the popular and comic. The musical accompaniment, in which
popular old tunes alternate with later compositions, naturally
influences the form of these songs; but the poet handles the form
with the greatest ease, and knows how to give to metre and rhyme
a variety that corresponds with the changes of mood, and prevents
the monotony which the matter and subject might produce. For the
subject is love and its enjoyments, in which the sensual and
humorous preponderate. Here prevails the sway of that
epicureanism which sees in the material satisfaction of our desire for
enjoyment the solution of the problem of life, which regards as lost
the time spent on all else, snaps its fingers at a severe moral
judgment, and ends in outspoken nihilism, mocking even at love and
happiness. The sum of worldly wisdom here taught is—enjoy
yourself as much as you can, and lose no time about it; it is not the
action that matters, but only that it should not reach the ears of
those who would be sure to give it a bad name; ill-will and the
conflict of interests bring blame, not things in themselves. Even
more clearly than in the dance-songs is this cynicism seen in the
‘Lays of the Carnival,’ which, like the former, are intended for
choruses, mostly with alternate parts.
The following pages, which treat of the manners of the time, will
describe the bacchanals, which were not new in Florence, but which
Lorenzo de’ Medici increased, and not merely for the humour of the
thing, to a degree that has cast on his memory a reflection which an
exact comparison of the poet’s circumstances with the past would
hardly justify. The abundant imagination and many-sided wit of
these gay compositions may be admired, but, even were the licence
less, it would be impossible to take real pleasure in them when once
the purpose underlying them is perceived. Such songs were
traditional in Florence and other places, as were also the people’s
carnival societies, of which Lorenzo made use for his popular
festivals, and for which he wrote even in the days of his highest
authority—perhaps even more especially then. To these songs the
accomplished choir-master of San Giovanni, the German Heinrich
Isaak, commonly called Arrigo Tedesco, composed melodies for
three voices. Even before the event which exercised so great and
injurious an influence on life and morals—the plague of 1348—songs
were openly sung, the levity and revolting coarseness of which
contrasted strangely with the pious canticles which resounded in the
evening before the image of the Madonna and other shrines. The
‘Decameron’ refers to them, and the Chronicles of Modena give us
the beginning of a drinking-song which bears witness to the
confusion of tongues that had arisen, probably among the
mercenary bands: ‘Trinche gote Malvasie—mi non biver oter vin.’ The
poems destined for singing increase in number from the fourteenth
century onwards.[5] Lorenzo only perfected in form, rendered more
significant, and finally turned to account for other purposes, what he
found ready in the life of the people. A greater contrast to these
frivolous productions than even his wanderings on the heights of
speculation, his effusions of philosophic poetry and tender aspiring
sentiment, is offered by the poems on religious subjects, of which
Lorenzo found examples in his own family. The mystery-play,
‘Rappresentazione dei SS. Giovanni e Paolo,’ composed, according to
the prologue spoken by the angel of the Annunciation, for the
brotherhood of San Giovanni, is said to have been acted at the
festivities which celebrated the marriage of Maddalena de’ Medici. It
is certain that Lorenzo’s son, Giuliano, then just ten, and perhaps
also Piero, took part with other youths and boys of noble houses in
the representation held by the said company in 1489. The legend of
Constantia, daughter of Constantine the Great, who was said to have
been cured of leprosy at the tomb of St. Agnes on the Nomentan
Way, and that of the martyrs John and Paul, who suffered death in
Rome on the Cœlian, are here blended with the story of the division
of the empire among Constantine’s sons, of the reign of Julian the
Apostate, and his death in the Parthian war, and formed into a whole
in which strange confusion and leaps from one subject to another do
not prevent much poetical beauty and moral and political teaching.
Like other earlier and contemporary pieces of this kind, it is more
lyric than dramatic; in particular it has no dramatic unity. But if the
dramatic element is weak, the historical character of one of the two
chief persons, the Emperor Julian, shows an accuracy of conception
which, with regard to this prince, must have been rare at that
period. In this respect Lorenzo’s drama commands an interest far
superior to that which we take in most productions of this class.
Since the statue of Victory was taken away from the Curia—so
speaks the Emperor—success no longer crowns the Roman arms,
which once subdued the world. Only by returning to our old gods
can we recall victory to our standards. But the object is not to be
attained by this alone, or by taking from the Christians wealth and
goods which should be forbidden them by the teachings of their own
faith. The head of the empire must again command the old
reverence, and this cannot be if the ruler hands over the cares of
government to others, while he heaps up treasure and thinks only of
amusement. If he is rich, his riches are but lent him to share with his
people, and relieve necessity wherever he finds it. Power and
property belong not to him, but to the community; he is the steward
who has the satisfaction and the glory of distributing to others what
fate has placed in his hands.
Julian is a man of energy, conscious of the extent and difficulty of
his task; Constantine in his old age is the representative of the
melancholy which overcomes him, who feels that the burden of
government has become too heavy for his shoulders. Who knows
whether the poet is not drawing from the experience of his own
heart when he puts into the mouth of his hero the description of the
labours and dangers of sovereignty, which wear out body and soul,
while others see in it the height of happiness, never reflecting that
they can sleep while one is watching who holds the scales in his
hand, to whom all eyes are turned; who lives not for himself, but for
others, who must be the servant of servants:
How often does the man that envies me
Not know that happier far than I is he.

Strange contrasts of height and depth there were in this man—


contradictions in his life as well as in his poetry. Like his mother, he
tried his hand on spiritual songs, and his hymns of praise display an
individuality and fulness of conception wanting to other compositions
of this kind which perhaps surpass his in freshness and simplicity.
Besides songs in which the teachings of Platonism give a peculiar
colouring to the faith of the Church, we find others in which the tone
of the older hymns to Mary has been successfully adopted. If these
lauds have not the same ardently soaring strain as those of
Benivieni; still we can well imagine that they were sung alternately
with the latter when the opposition to the worldly spirit encouraged
by their author had gained the victory. This, too, is one of the
contrasts which abound in the history of Lorenzo de’ Medici. The
lauds give us a deep insight into his mind. They are, in some degree,
the agonised cry of a soul which, instead of finding satisfaction in
the glory and splendour, the wealth and enjoyments of the world, is
repelled by its emptiness, and feels driven further and further away
from the highest good, of which the love once kindled within it had
grown cold amid the cares and pleasures of this life:
Thou seekest life where nought hath living breath;
Thou seekest joy where nought avails save death.
CHAPTER VII.

MARSILIO FICINO AND CRISTOFORO LANDINO.

In order to gain a complete view both of Lorenzo de’ Medici’s own


life and of his influence on the scientific progress of his time, it is
necessary to contemplate the circle in which he was placed in his
youth, and which, though greatly modified in the course of years,
preserved the same character in essentials to the end. The persons
of whom it was composed carry us back to the time of Cosimo. The
first we meet are Marsilio Ficino and Cristoforo Landino. Both owed
their rise to the house of Medici; both contributed to its glory.
The last twenty-five years at least of Ficino’s life were occupied
with the endeavour to reconcile Platonism and Christianity, to make
the one expand within the other. At the end of 1473, when forty
years old, he entered holy orders, after seriously weighing the duties
and obligations of that sacred office, and after coming to the
conclusion that there is nothing on earth nobler than a good priest,
nothing more vile than an unworthy one. At the same time he held
counsel with his own mind as to the direction of his philosophical
studies. The example of St. Augustine, who, after he became a
Christian, inclined to the Platonics of the Christian era, decided him
the more easily, because it confirmed the direction of his whole
previous life. When he became aware how Platonism recognises
Christian dogma on account of the analogies which the latter
presents to its own doctrines, he thanked God, and felt himself
confirmed in his Christian faith. He did not, however, long remain
free from a suspicion of the divergence which Platonism had caused
in the mediæval development of Christian teaching from the
Aristotelian system, which was the standing-ground of scholasticism,
in its efforts to reconcile the faith of the Church with the researches
of reason. He had started from the view that religion and philosophy
are sisters. As true philosophy, he says, is the loving study of truth
and wisdom—as God alone is truth and wisdom—so true philosophy
is nothing but genuine religion, and genuine religion nothing but true
philosophy. Religion is innate in every man; every religion is good, in
so far as it turns to God, but Christianity is the only true one,
inspired by the divine power which dwelt in its Founder. For himself,
he declares he needs nothing but the teaching of Christ. He would
rather believe divine things than know human ones; for divine faith
is more secure than human knowledge, and what proceeds from it is
confirmed by true science. But there are spirits for whom the
authority of the divine law is not enough, and who require the
arguments of reason. Divine Providence has ordained that the
teachings of Platonism should agree in many things with those of
Christianity, in order to bring such spirits to Christ; for, as Augustine
said, with the exception of a few things the Platonists were
Christians. As Plato always connects religion with philosophy, and
does not merely disclose to us the principles and order of natural
things, like Aristotle, but teaches us our duty towards Him who
orders all things by number, measure, and weight; so he himself has
no other object than to make this intimate connection clear, so far as
his weak powers permit.
Any one who puts together his numerous remarks on Christianity,
dogma, and morality, although he may deem some of his views
peculiar, cannot reproach him with constructing a Christianity of his
own. Though he found such an agreement between Moses and Plato
that he saw in the latter only a Moses writing in the Attic tongue,
and though he compared the life of Socrates with the life of Jesus,
yet he acknowledged in the Socratic doctrines only a confirmation of
the Christian, and guarded himself against seeing in the Greek
philosopher a shadow of the Saviour, and from interpreting the
Christian mysteries by Platonic writings. Strange was the position of
the thinkers of that time, placed as they were between Christianity
and the strongly-reviving influences of heathen antiquity, and we
should do them great injustice did we not consider the spirit which
governed the whole of that period. Giovanni Pico della Mirandola
believed he had found in the Cabala the foundation of the faith and
the explanation of the Christian mysteries; both he and Marsilio held
confidential evening discussions with learned Jewish doctors on the
divine inspiration of the Prophecies, and plunged deep into both
ancient and mediæval Hebrew lore. By a gradual enlightenment of
his mind, filled with the fantastic images of the later Platonism and
the half rationalistic mysticism founded on it, Pico came back to the
pure Christian faith, which finds in Holy Scripture a living heavenly
force whose wonderful power raises man to the height of divine
love. Marsilio Ficino’s mysticism, increased by his strong tendency to
astrology, assumed in more than one of his writings a colouring
which made his friends uneasy. In 1489 he was even accused of
magic before Pope Innocent VIII., but was cleared of the charge
partly by his own apology, partly by his friends, Francesco Soderini,
Ermolao Barbaro, and the archbishop Rinaldo Orsini, who was then
at Rome.
Marsilio Ficino always keeps in view the connection between
Christianity and philosophy, both in his speculations and in the
practical application of his principles and their corollaries. If we are
astonished at the fantastic flights which seem to lead him far away
from the course he had traced out for himself, we yet gain a clear
and comprehensive development of the aim of his whole teaching,
the attainment of the highest happiness by the individual as well as
by the community, the end for which God created us. In the
harmony between the spirit of government and the divine law,
whence the written law is derived, he recognises the essential
element of general well-being. As regards forms of government, he
decides that many are good, if rightly administered—aristocracy, if
its limits are not too narrow; democracy, if it produces respect for
law. Mob rule is a polypus, all limbs and no head; tyranny has no
legal ground and no legitimate limits. Monarchy would be preferable,
if it could be maintained according to Plato’s ideal, by power and
wisdom united. But the true end of all forms of government and civil
constitutions, both in theory and practice, can be reached neither by
the few nor by the many, but only by the co-operation of the united
forces of the human race, by the maintaining and enforcing of
uniform laws by a ruler who is raised above all enmity, ambition, and
envy, because he is acknowledged and loved by all. The Christian
Platonist, who lived to see the beginning of the new era, the dawn
of which had been heralded by the school to which he attached
himself, arrived at the summit of his philosophical and political
speculations exactly at the same standpoint which the greatest poet
of the middle ages had reached more than a century and a half
before him, amid the conflict of parties in the State. Wide as was the
difference between their positions and experiences of life, and
between the civil and political conditions both of their own
immediate home and of a large part of Italy, this is a remarkable
circumstance, which explains the interest felt by Marsilio Ficino in
that book, so diversely judged, in which Dante Alighieri developes
his theory of monarchy—a work well-nigh forgotten, despised by the
learned on account of its style, and sealed to the generality, till the
Platonist of the Medicean times made it accessible to his
contemporaries by a translation.
Numerous works were composed by Marsilio Ficino, who
occupied himself not only with philosophy but with theology,
medicine, and music, and was wont to say that they belonged to
each other like body, soul, and spirit in nature. His book on Christian
doctrine, begun after his entrance into the priesthood, seems to
have been finished in the beginning of 1475, and appeared in the
following year, with a declaration that the author submitted himself
in all things to the judgment of the Church. He presented his work to
Lorenzo de’ Medici. Rather more than two years later he seems to
have finished his translation of Plato’s works from the manuscripts
given him by Cosimo and by Amerigo Benci. These he submitted to
the revision of Demetrius Chalcondylas, Antonio Vespucci, and
Giovan Battista Buoninsegni, and also sought advice from Angelo
Poliziano, Landino and Bartolommeo Scala. Filippo Valori bore the
expenses of the printing, which seems to have been completed at
the end of 1482—a proof how men of high Florentine families
assumed the character of Mæcenas. Meanwhile, the industrious
writer had concluded his great work on the Platonic doctrine of
immortality (‘Theologia Platonica de immortalitate animarum’), which
came out at the same time with the translation of the writings on
which it was founded. The Laurentian library possesses the
parchment manuscript which was given to Lorenzo. It contains ideas
new and old blended together, and comprising the philosophic
system of its author and the defence of the supernatural against
Materialism and Pantheism, which at that time numbered many
disciples, in opposition to the Platonic school. The scientific value of
this work, in which the doctrines of Plato and the teachings of his
most dissimilar scholars in ancient and modern times are not easy to
distinguish, must rest on its own merits, as must the validity of
Lorenzo’s remark that the Materialists, for whom there is no life in
the next world, are already dead in this. But we cannot deny the
importance of Ficino’s great work in the history of civilisation, nor
question its beneficial influence on the time.
Then followed a series of smaller writings on separate questions
of philosophy, translations connected with them, and a life of Plato.
Cosimo de’ Medici wished to see the works of Plotinus translated by
Ficino, an undertaking to which the latter only devoted himself long
after the death of its originator, and to which he was chiefly
encouraged by Pico della Mirandola. According to his own words, he
recognised in this new task a leading of Providence. As the Latin
nations had learned to know Plato, the collector of the traditions of
religious philosophy, so they should also learn to know Plotinus, who
first drew forth from darkness the theology of the ancients and
searched into its mysteries. This work was finished in 1486, and a
detailed commentary on it in the summer of 1491. Lorenzo had
undertaken to defray the cost of printing, and promised to do the
same for a new edition of Plato’s works, the former one being
inadequate. But the printing was only completed a month after the
death of the generous patron—‘magnifico sumptu Laurentii patriæ
servatoris.’ After this came a translation of the mystic theology of the
writer calling himself Dionysius the Areopagite. Lorenzo Valla, who
surpassed most of his contemporaries in keenness of criticism and
knowledge of antiquity, had already raised a doubt as to its
genuineness, as had also other writers. But this work, perhaps that
of a Platonist of the fifth century, fitted in with Marsilio’s system too
well not to be accepted by him as valid testimony; another example
showing how, like the Alexandrian school, these later disciples
wandered from their original models without knowing or intending it;
with this difference, that the Neoplatonism of old ran in sharp
contradiction to Christianity, while that of more modern times aimed
at a union with it.
The philosophic ‘Macrobioticon,’ an original work, was finished in
1490, and dedicated to Lorenzo de’ Medici and King Matthias
Corvinus. Far more interest attaches to Marsilio’s correspondence,
which embraces the twenty years between 1474 and 1494—the only
product of his literary activity that has a real value at the present
time. In these letters his opinions and motives are mirrored with life-
like originality, and they afford much information as to his life, his
occupations, his social relations, and his friends. The twelve books
(which he, following the example of many contemporaries, arranged
himself, because apocryphal writings were in circulation) are all
dedicated to men of high position or friends of the author: Giuliano
de’ Medici, Federigo of Montefeltro, Matthias Corvinus, Bernardo
Bembo, Filippo and Niccolò Valori, and others.
Marsilio’s extraordinary literary activity, the more astonishing in a
man of delicate health, did not interfere with the performance of his
duties as a priest or as a secular teacher. He preached often, not
only in his own parish church at Nevoli, but also in Florence, at the
church of the Angeli and in the cathedral. His personal relations, to
which his correspondence bears witness, were very numerous. Paol’
Antonio Soderini, Giovanni Cavalcanti, Carlo Marsuppini the younger,
Piero and Giovanni Guicciardini, Bernardo Canigiani, Bernardo Dovizj
of Bibiena, afterwards cardinal; Lorenzo’s nephew Cosimo de’ Pazzi,
Bernardo Rucellai, Pier Filippo Pandolfini, Francesco Sassetti, Ugolini
Verini, and many others, were his pupils and remained attached to
him; while from Leon Battista Alberti and Cristoforo Landino
downwards, all the learned men whom Florence or Italy possessed
were in communication with him. At an important moment of his life
he called three of these, namely, Piero Soderini (afterwards
Gonfaloniere for life), Piero del Nero, and Piero Guicciardini, his three
brothers in the search after truth; and on March 6, 1482, he stood
sponsor to Guicciardini’s son, afterwards the famous statesman and
historian. Foreign lands as well as Italy sent their sons to hear his
lectures, and more than one of these foreigners remained gratefully
attached to him. Among others he became acquainted with several
Germans; Johannes Reuchlin and Ludwig Wergenhans (Nauclerus),
provost of Stuttgart, who with Gabriel Biel, professor of scholastic
philosophy at Tübingen, and the learned theologian Peter Jacobi, of
Arlon in Luxemburg, accompanied Count Eberhard of Würtemberg
when in the spring of 1482 he undertook the expedition to Rome,
which will be mentioned hereafter. Marsilio maintained the most
intimate personal relations with Martin Preninger, chancellor of the
bishopric of Constance, and afterwards professor of canon law at
Tübingen. This man was twice in Italy in the year 1492 on business
of Eberhard’s, and his correspondence with Marsilio bears witness to
a friendship and agreement of opinions rare to meet with. Marsilio
was wont to say that he possessed two friends, one in Germany, the
other in Italy, who represented the alliance between philosophy and
jurisprudence, namely, Martinus Uranius (Preninger’s literary name)
and Giovan Vittorio Soderini. He had Greek manuscripts copied for
his Swabian friend, and kept him informed of what was going on in
the field of science, as well as of what he was doing himself. Another
of his German correspondents was Georg Herwart of Augsburg, who
made his acquaintance in Florence; Reuchlin’s younger brother
Dionysius and Johann Strehler of Ulm also received introductions to
him, when being sent by the Count of Würtemberg to study in Italy
they enjoyed the notice of Lorenzo de’ Medici and were received into
the house of Giorgio Antonio Vespucci. Numerous princes, temporal
and spiritual, beginning with Matthias Corvinus, who tried vainly to
attract him to Ofen like Argyropulos, were in regular correspondence
with him, asked his advice on points of theology and philosophy, and
sought his criticism on various works.
Amid all these unsought testimonies of honour and confidence,
Marsilio Ficino remained simple, unpretending, easily satisfied. His
delicate health compelled him to lead a quiet life, and suffices to
explain the melancholy humour that often stole over him when
alone. Yet in company which he liked, and which afforded food for
his mind in unrestrained intercourse, he was cheerful and
sympathetic. His musical talents, bringing change and refreshment
from serious studies, helped to season his conversation. With his
plectrum, an instrument which he himself perfected, he resembled
the poet-sages of the mythic age. He was seldom absent from
Platonic banquets, and had been an habitual guest of Lorenzo’s
grandfather when the latter invited learned men to his house. He
loved a country life above all things, and passed a great part of his
time on the little estate of Montevecchio. In later years he often
went to see Pico della Mirandola and Poliziano, when they were
staying in his neighbourhood—the one at Querceto, the other at
Fiesole; and still oftener to Lorenzo, when he was living at Careggi.
He was received as a welcome guest at the villas of Valori, Canigiani,
Cavalcanti, and others. At Montevecchio he instituted a peculiar
yearly festival. On SS. Cosmo and Damian’s day he assembled the
old tenants (‘coloni’) of his first and greatest patron and entertained
them with music and singing. His independence of mind was in no
way diminished by intercourse with those who, through birth or a
successful career, held a higher position in life. He once wrote thus
to Lorenzo de’ Medici, whose fondness for pleasure in his earlier,
perhaps also in his later days, appeared to Ficino excessive, and
caused him anxiety: ‘In the name of the eternal God I intreat thee,
my dearest Prince, to economise every moment of this brief life, lest
there come over thee vain remorse for dissipation and irreparable
harm. The consciousness of lost time drew deep sighs from the
great Cosimo in my presence, when he had reached the age of
seventy. Trifling occupations and empty pastimes rob thee of thy
true self; they make thee a slave, who art born to be a ruler. Free
thyself while thou canst from this miserable servitude; only to-day
canst thou do so, for only to-day is thine own; to-morrow it will be
too late.’
When the young Raffaelle Riario was made a cardinal, he
addressed to him warnings and counsels similar to those given in a
like case, fourteen years later, by Lorenzo to his son, who was
departing for Rome. He reminded him that, since he owed his high
rank not to his own merits, he was the more bound to justify by his
manner of life the preference bestowed on him. His memorable
appeal to Pope Sixtus IV. during the war of 1478[6] shows how he
could combine outspokenness with reverence for the head of the
Church, which the Bishop of Arezzo, a far higher dignitary than he,
and Francesco Filelfo made light of. His was the frankness of a lover
of truth whose soul was filled with grief for the evils which had
befallen the flock, and no less for the blots which in an unhappily
complicated affair had fallen on the reputation of a supreme pastor
who ought to be revered for his wisdom and goodness.
Like a true philosopher, Marsilio Ficino never strove after outward
splendour. His income was most modest. Besides his little farm, he
received from Lorenzo two benefices of which the revenue was
small, as he was obliged to entrust them to curates, but which would
have sufficed for his modest requirements had he not been besieged
in his later years by a swarm of needy relatives. Without the aid of
rich friends, the publication of his works would have been
impossible. Amid the restlessness and discontent of the learned men
of his time, who were rushing breathlessly after wealth and honours;
amid the greediness for ecclesiastical benefices, even among those
who were not priests like himself, Marsilio Ficino, contented and
devoted to science, is a fine example of the realisation of those
philosophic doctrines which in the case of so many were only
spiritual luxuries or a means of making money. It is this that gives
interest to his character and work, though his writings have lost their
value except in their connection with the history of learning.
Lorenzo’s attachment to him remained unchanged till his last hour; it
shows itself in his poems as vividly as in his letters. ‘Write to me,’ he
says in a letter addressed to him from Pisa, about 1473,[7] ‘whatever
occurs to your mind, for nothing ever comes from you that is not
good; you never have an unworthy thought, so that you can never
write me anything that will not be useful or agreeable. What makes
me long for your letters is that in them you combine elegance of
expression with solidity of contents, so that in both respects they
leave nothing to be desired.’ And in the philosophic poem mentioned
above, on the independence of happiness from outward position, he
thus describes Marsilio’s appearance, with a touch of the warm
feeling that inspired Dante on meeting his master Brunetto, at the
sight of the ‘dear, good, fatherly face:’
Marsilio is this, of Montevecchio,
Whom heaven has filled with its own special grace,
That to the world its mirror he may be?
This is that faithful follower of the Muses,
In whom are grace and wisdom aye united,
And never separated one from other;
From us and all worthy of highest honour.[8]

Cristoforo Landino stands far below Marsilio Ficino in scientific


importance. But both as a professor and in the learned circle of the
Medici he held a peculiar position; and by one of his literary works
he opened out a path which hundreds trod after him without taking
away the relative value of his labours. His life was not like that of his
contemporary and friend, dedicated solely to literature. As
Chancellor of the Magistracy of the Guelphic party, and one of the
secretaries of the Republic, he was concerned in public affairs till a
late period of his life.[9] During the lifetime of Pope Eugene IV. he
passed some time in Rome, and studied those antiquities the decay
of which made a painful impression on him, as on other Florentines
of his time. But when complaining, like others, that the travertine of
the amphitheatre is broken up and burnt for chalk, and that the
antique sculptures lie about mutilated, he exaggerates strangely
when he says:[10]
Though round the mighty city thy gaze contemplative wanders,
Vainly around does it look for monuments vanished and gone.

In January, 1458, he accepted the professorship of eloquence


and poetry at the University, and gathered round him a continually
renewed circle of hearers, his influence being equalled by that of no
contemporary save Ficino. In 1460 he began to lecture on the Italian
poems of Petrarca, being desirous to stem the tide of contempt for
the vulgar tongue which still existed in learned circles. Though in
this respect he deserves all praise, yet his remarks on
contemporaries, on Bruni, Alberti, Palmieri, show how he was
himself still prejudiced in his view of the philological treatment of the
language. His labours in the field of classical philology have no great
weight. He wrote a commentary on Horace and one on Virgil, the
former of which he dedicated to Guidobaldo of Montefeltro, and the
latter to the young Piero de’ Medici. He also translated Pliny’s
‘Natural History,’ and undertook translations of modern Italian works,
such as Giovanni Simonetta’s Latin ‘History of Francesco Sforza,’
which was published at Milan in 1490. He composed a letter-writer
and a formulary for speeches, which was printed two years later,
with a dedication to Duke Ercole d’Este. But the true centre of his
activity and its importance lies elsewhere—in his relation to and
share in that intellectual movement amid which the Medici lived, and
in his position as a leader of the revival of the study of Dante. In
illustration of the first point, his ‘Disputationes Camaldulenses,’ which
belong to the history of Lorenzo’s youth, deserve especial
consideration.
Amidst the fir and beech woods which still cover the Casentino
hills, where they rise towards the Apennines, lies the convent which
gave its name to the order of St. Romuald. For nearly a thousand
years countless pilgrims and travellers have rested within the
hospitable walls of Camaldoli, which now seem threatened with
abandonment and desolation. The Medici had long kept up intimate

You might also like