Due Tuesday, October 13: Python and Natural Language Processing
Of all the kinds of data we examine, unstructured text is among the most interesting and difficult. Websites, social media, research, journalism, and literature contain language whose meaning depends on grammar, context, culture, irony, and knowledge of the world. Natural language processing asks how computational methods can bring structure to that language and what becomes visible—or disappears—when words become data.
Some of the earliest computational approaches were surprisingly simple. Concordances used word frequencies to study an author or text, while stylometry analyzed patterns of style and helped address disputed authorship, including the Federalist Papers. Markov used patterns in Pushkin’s Eugene Onegin to show how local probabilities could produce larger regularities. More recent methods use machine learning, sentiment analysis, and large language models, but they inherit the same basic problem: a measurable pattern is not automatically the same thing as meaning.
Simple word frequencies can still surface patterns in large texts, even though they ignore syntax and context. Sentiment analysis makes a stronger claim by assigning emotional values to language and tracing how those values change across a text. This can reveal a large-scale narrative shape, but it can also misread negation, irony, ambiguity, unusual diction, or culturally specific expression.
Your own knowledge of a novel therefore matters. In class, we will use Voyant Tools to explore what computational analysis makes visible in a familiar text—and what it misses.
October Break: No class Thursday, October 8. If you received an email about missing DataCamp assignments, make them up by the end of fall break.
1. Finish Introduction to Python
Complete the final two chapters of DataCamp’s Introduction to Python:
This completes the introductory Python course begun for October 6. Focus on how functions package reusable behavior, how libraries extend Python, and how NumPy represents and operates on numerical data. You are still learning the basics: notice the difference between a Python list and a NumPy array, and practice predicting an operation’s result before running it.
2. Choose and check your novel
Choose a novel that you have already read and know well. You will need enough familiarity with its plot, characters, tone, and major turning points to judge what a computational analysis captures—and what it misses.
Your copy must be a plain-text file ending in .txt. You may start with a PDF, EPUB, or Word document and try converting it with Google Docs or another converter, but the file you bring must be a clean .txt file. Scanned PDFs may require optical character recognition (OCR), and conversion can introduce errors.
- Browse Project Gutenberg Australia and choose a novel, or locate a legal digital copy from another source.
- On the book’s download page, choose the TEXT or Plain Text UTF-8 version. If the text opens in your browser, save the page as a file whose name ends in
.txt. - Open the saved file in a plain-text editor and check the actual contents. On a Mac: press Command + Space, type TextEdit, and press Return; you can also find it in Finder → Applications → TextEdit. Use File → Open to open your file. If you are saving a converted document, choose Format → Make Plain Text and save it with a
.txtextension. On Windows: open Start, type Notepad, and open the app; then use File → Open to select your file. If it is not listed, change the file-type filter to All files. When saving, choose UTF-8 encoding. - Inspect passages near the beginning, middle, and end. Look for spaces inserted inside words, missing spaces between words, broken paragraphs, repeated page numbers or headers, and unexpected symbols such as
�or garbled sequences. Compare a passage with the original. Accented letters, curly quotation marks, and other legitimate Unicode characters are fine; the problem is conversion errors, not Unicode itself. If the text is badly garbled, try another converter or find a cleaner digital copy. - Make sure the file contains the complete novel and is long enough for analysis—roughly 100 pages or more.
- Rename it clearly using the title and author, for example
woolf_mrs_dalloway.txt, and save it somewhere you can find easily.
If you use the U.S. Project Gutenberg instead, select Plain Text UTF-8. You may also use another lawful source, provided that you can download or export a clean .txt file. It is okay to try converting a PDF using Google Docs or another converter. Export or save the result as plain text (.txt), then check it before bringing it to class.
Bring the clean .txt file to class on Tuesday, October 13. We will upload it to Voyant Tools during class.
3. Introduction to NLP
- What Is NLP (Natural Language Processing)? (9:37), IBM Technology.
Questions to prepare for Tuesday
- What makes human language harder to analyze than a list of numbers? Give an example involving context, ambiguity, or irony.
- What could counting words tell you about your novel? What would it miss?
- How might patterns of writing style help distinguish authors without explaining what their writing means?
- Which characters, themes, or changes in language would you expect to notice in your familiar novel? How would you check whether a word-frequency pattern fits your reading?
- What does a Python function let you reuse? What is a package, and how is a NumPy array different from a list?
Coming next: text processing and sentiment analysis
Thursday, October 15’s work introduces DataCamp’s Natural Language Processing (NLP) in Python, Chapters 1–2, and the Python Sentiment Analysis Tutorial. See Work Ahead for the full assignment. The Shapes of Stories, Section 1 (“The Birth of a Field”), and a hand-drawn prediction of your novel’s emotional arc are saved for the following Tuesday, October 20. They are not part of October 13’s homework.
