Skip to main content

Classifies English iambic pentameter poetry by period

Project description

Premodern Iambic Pentameter Period Classifier

Overview

ipclassifier accepts a text file, which should be lines of pre-modern English iambic pentameter, and outputs the period/style classification. It only uses features derived from prosody to make a classification.

Installation

pip install ipclassifier

NOTE: The relevant nltk datasets are included in the module, in order to avoid having to download additional required files.

Usage

ipclassifier can be run either as a script or as a module.

my_poem.txt:

First was the World as one great Cymbal made,
Where Jarring Windes to infant Nature plaid.
All Musick was a solitary sound,
To hollow Rocks and murm'ring Fountains bound.
Jubal first made the wilder Notes agree;
And Jubal tun'd Musicks Jubilee:
He call'd the Ecchoes from their sullen Cell,
And built the Organs City where they dwell.
Each sought a consort in that lovely place;
And Virgin Trebles wed the manly Base.
From whence the Progeny of numbers new
Into harmonious Colonies withdrew.
Some to the Lute, some to the Viol went,
And others chose the Cornet eloquent.
These practising the Wind, and those the Wire,
To sing Mens Triumphs, or in Heavens quire.
Then Musick, the Mosaique of the Air,
Did of all these a solemn noise prepare:
With which She gain'd the Empire of the Ear,
Including all between the Earth and Sphear.
Victorious sounds yet here your Homage do
Unto a gentler Conqueror then you;
Who though He flies the Musick of his praise,
Would with you Heavens Hallelujahs raise.

NOTE: Accuracy is best with 100 or more lines.

From the command line

python -m ipclassifier -f my_poem.txt
>>> processing starting...
>>> Your text is probably 17th-Century

As a module

my_file.py:

from ipclassifier.runners import classify_ip

my_filename = "my_poem.txt"
classification = classify_ip(my_filename)
# classification = "17th-Century"

Credit

Aside from explicit dependencies,ipclassifier uses code from the following projects:

Methodology

After ipclassifier cleans and tokenizes the input text, lines are scanned. A set of transformations are applied until either the line can be made to conform to ideal iambic pentameter (WSWSWSWSWS) or the line is determined to be "invalid." Here are the sequence of transformations:

  1. No transformation necessary (scans as is)
  2. Demote compound stresses (mostly an artifact of the initial processing--some compounds are processed as two words, with the result that a single word has two primary stresses)
  3. Demote stressed monosyllables
  4. Promote unstressed monosyllables
  5. Promote unstressed syllables in polysyllabic words (the primary stress is not altered)
  6. Demote primary stress in polysyllabic words
  7. “invalid line” (if we assume that all input lines are valid, this is basically a measure of the scanner's error rate)

For a set of lines, features are then extracted. Here are the features:

  1. A one-hot encoded array of words whose primary stress had to be altered (rule 6 above)
  2. The average of the sample's transformation rules (ex: 4.2)
  3. The average words per line
  4. The average syllables per line
  5. The individual ratios of each sample's transformation rules

These features are then fed into two models. The primary model is a Multinomial Naive Bayes. This is supplemented by a second model, (Complement Naive Bayes).

The model is trained on approximately 15,000 lines from each category

  • 15th Century (Chaucer, Gower, Henryson)
  • 16th Century (Marlowe, Raleigh, Shakespeare, Sidney, Skelton, Spencer, Surrey, Wyatt)
  • 17th Century (Donne, Dryden, Jonson, Milton, Vaughan)
  • 18th Century (Akenside, Cowper, Johnson, Pope, Swift)
  • 19th Century, Romantic (Byron, Coleridge, Shelley, Wordsworth)
  • 19th Century, Victorian (Arnold, Browning, Swinburne, Tennyson, Wilde)

using groups of 100 lines.

The trained model's accuracy is in the upper 90s.

There is an /OUT_OF_SAMPLE folder for demonstration purposes. None of these poets are found in the train/test data.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ipclassifier-1.0.0.tar.gz (33.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ipclassifier-1.0.0-py3-none-any.whl (33.5 MB view details)

Uploaded Python 3

File details

Details for the file ipclassifier-1.0.0.tar.gz.

File metadata

  • Download URL: ipclassifier-1.0.0.tar.gz
  • Upload date:
  • Size: 33.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for ipclassifier-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e5d39f50d483d50466f4ba4f79da30deb0a58783207a8fd73e7640b4dd8e26c5
MD5 025a9dfd83397762af2a23c187fc431c
BLAKE2b-256 66194fb493010add485dcaad2c7d84886360dfab04e09973799cd72cad733a6e

See more details on using hashes here.

File details

Details for the file ipclassifier-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ipclassifier-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 33.5 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for ipclassifier-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d8c3fd7a985f9cb0caf676679ddac1c9a838629a528dab79cc9d5128d892ad20
MD5 e6f97f93e3e52d541cc4ee285495bd04
BLAKE2b-256 da44ffbbb92d35924da5161f3ba69ac7bb34730a121ad58ec12717ec4954181f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page