Appendix A — Quickstart

Author

Patrick J. Burns

Open In Colab

Patrick J. Burns | Getting Started with LatinCy

This quickstart introduces LatinCy through the opening sentences of Ritchie’s Fabulae Faciles (1884), a beginner’s Latin reader based on mythological stories. In a few minutes you will install the library, load a model, annotate a text, and run a lemma-based search to find all grammatical forms of a Latin word across a passage — useful for close reading, concordance work, and textual analysis.

The examples use the small model (la_core_web_sm). No prior NLP experience is assumed.

A.1 Setup

The cell below installs spaCy and the LatinCy small model automatically when run in Google Colab. If you are working in a local environment, see the Installing LatinCy models chapter for installation instructions.

import sys
if 'google.colab' in sys.modules:
    !pip install -U spacy -q
    !pip install -q "la-core-web-sm @ https://huggingface.co/latincy/la_core_web_sm/resolve/main/la_core_web_sm-3.9.4-py3-none-any.whl"
import spacy

nlp = spacy.load('la_core_web_sm')
print(f"Loaded pipeline: {nlp.meta['name']} v{nlp.meta['version']}")
Loaded pipeline: core_web_sm v3.9.4

A.2 Working with Latin text

We will work with the opening sentences of Ritchie’s Fabulae Faciles. The passage introduces the myth of Perseus:

Haec narrantur a poetis de Perseo. Perseus filius erat Iovis, maximi deorum. Avus eius Acrisius appellabatur.

Passing the text to nlp() runs it through the full LatinCy pipeline: tokenization, lemmatization, part-of-speech tagging, morphological analysis, dependency parsing, and named entity recognition.

text = (
    "Haec narrantur a poetis de Perseo. "
    "Perseus filius erat Iovis, maximi deorum. "
    "Avus eius Acrisius appellabatur."
)

doc = nlp(text)
print(doc)
Haec narrantur a poetis de Perseo. Perseus filius erat Iouis, maximi deorum. Auus eius Acrisius appellabatur.

A.3 Token annotations

Once a text is processed, every token in the Doc carries a set of linguistic annotations. The most commonly used are:

Attribute Description
token.text The surface form (after any pipeline normalization)
token.lemma_ The dictionary headword
token.pos_ Coarse part-of-speech tag (NOUN, VERB, ADP, …)
token.morph Full morphological feature bundle

LatinCy’s normalization component converts vu and ji directly in token.text, so the input Iovis is stored as Iouis and Avus as Auus — visible in the Token column below:

print(f"{'Token':<14} {'Lemma':<14} {'POS':<8} Morphology")
print("-" * 64)
for token in doc:
    if not token.is_punct and not token.is_space:
        print(f"{token.text:<14} {token.lemma_:<14} {token.pos_:<8} {token.morph}")
Token          Lemma          POS      Morphology
----------------------------------------------------------------
Haec           hic            DET      Case=Nom|Gender=Neut|Number=Plur
narrantur      narro          VERB     Aspect=Imp|Mood=Ind|Number=Plur|Person=3|Tense=Pres|VerbForm=Fin|Voice=Pass
a              ab             ADP      
poetis         poeta          NOUN     Case=Abl|Gender=Fem|Number=Plur
de             de             ADP      
Perseo         Perseus        PROPN    Case=Abl|Gender=Masc|Number=Sing
Perseus        Perseus        PROPN    Case=Nom|Gender=Masc|Number=Sing
filius         filius         NOUN     Case=Nom|Gender=Masc|Number=Sing
erat           sum            AUX      Aspect=Imp|Mood=Ind|Number=Sing|Person=3|Tense=Past|VerbForm=Fin
Iouis          Iuppiter       PROPN    Case=Gen|Gender=Masc|Number=Sing
maximi         magnus         ADJ      Case=Gen|Gender=Masc|Number=Sing
deorum         deus           NOUN     Case=Gen|Gender=Masc|Number=Plur
Auus           Auus           PROPN    Case=Nom|Gender=Masc|Number=Sing
eius           is             PRON     Case=Gen|Gender=Fem|Number=Sing
Acrisius       Acrisius       PROPN    Case=Nom|Gender=Masc|Number=Sing
appellabatur   appello        VERB     Aspect=Imp|Mood=Ind|Number=Sing|Person=3|Tense=Past|VerbForm=Fin|Voice=Pass

A.4 Visualizing annotations

DisplaCy renders annotations directly in the notebook. The dependency visualizer shows the parse as an arc diagram; the span visualizer highlights noun chunks in running text; the entity visualizer color-codes named entity spans by type.

from spacy import displacy

sents = list(doc.sents)
displacy.render(sents[0], style="dep", jupyter=True)
Haec DET narrantur VERB a ADP poetis NOUN de ADP Perseo. PROPN nsubj:pass case obl case obl

A.4.1 Noun chunks

selection = doc
selection.spans['NP'] = [chunk for chunk in doc.noun_chunks if len(chunk) > 1]

colors = {'NP': '#85C1E9'}
options = {'spans_key': 'NP', 'colors': colors}
displacy.render(selection, style="span", jupyter=True, options=options)
Haec narrantur a poetis de Perseo . Perseus filius erat Iouis , maximi NP deorum . Auus NP eius Acrisius appellabatur .

A.4.2 Named entities

ent_doc = nlp("Iason et Medea e Thessalia expulsi ad urbem Corinthum venerunt, cuius urbis Creon quidam regnum tum obtinebat.")
displacy.render(ent_doc, style="ent", jupyter=True)
Iason PERSON et Medea PERSON e Thessalia LOC expulsi ad urbem Corinthum LOC uenerunt, cuius urbis Creon PERSON quidam regnum tum obtinebat.

A.5 Finding words with the Matcher

Latin inflection means the same word can appear in many surface forms — Perseus in the nominative becomes Perseo in the ablative, Perseum in the accusative. A lemma-based search finds all of them at once.

spaCy’s Matcher lets you search by annotation attributes. Matching on LEMMA finds every surface form the model has traced back to a given headword:

from spacy.matcher import Matcher

matcher = Matcher(nlp.vocab)
matcher.add('PERSEUS', [[{'LEMMA': 'Perseus'}]])

matches = matcher(doc)
print(f"{'Form':<12} {'POS':<8} Morphology")
print("-" * 52)
for match_id, start, end in matches:
    token = doc[start]
    print(f"{token.text:<12} {token.pos_:<8} {token.morph}")
Form         POS      Morphology
----------------------------------------------------
Perseo       PROPN    Case=Abl|Gender=Masc|Number=Sing
Perseus      PROPN    Case=Nom|Gender=Masc|Number=Sing

The same approach works for any set of terms. Searching for three key words from the passage — the hero, his divine father, and the family relationship — maps each match back to its lemma:

matcher = Matcher(nlp.vocab)
key_terms = ['Perseus', 'deus', 'filius']
for term in key_terms:
    matcher.add(term.upper(), [[{'LEMMA': term}]])

matches = matcher(doc)
print(f"{'Lemma':<10} {'Form':<14} Morphology")
print("-" * 56)
for match_id, start, end in matches:
    token = doc[start]
    print(f"{token.lemma_:<10} {token.text:<14} {token.morph}")
Lemma      Form           Morphology
--------------------------------------------------------
Perseus    Perseo         Case=Abl|Gender=Masc|Number=Sing
Perseus    Perseus        Case=Nom|Gender=Masc|Number=Sing
filius     filius         Case=Nom|Gender=Masc|Number=Sing
deus       deorum         Case=Gen|Gender=Masc|Number=Plur

A.6 Next steps

This quickstart covers the basics. The full book works through each pipeline component in detail: