<?xml version="1.0" encoding="UTF-8"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
    <teiHeader>
        <fileDesc>
            <titleStmt>
                <title type="full">
                    <title type="main">A Hybrid Approach to Stanza Classification in Spanish Poetry</title>
                    <title type="sub"/>
                </title>
                <author>
                    <persName>
                        <surname>De la Rosa</surname>
                        <forename>Javier</forename>
                    </persName>
                    <affiliation>UNED, Spain</affiliation>
                    <email>versae@linhd.uned.es</email>
                </author>
                <author>
                    <persName>
                        <surname>Pérez</surname>
                        <forename>Álvaro</forename>
                    </persName>
                    <affiliation>UNED, Spain</affiliation>
                    <email>alvaro.perez@linhd.uned.es</email>
                </author>
                <author>
                    <persName>
                        <surname>Hernández</surname>
                        <forename>Laura</forename>
                    </persName>
                    <affiliation>UNED, Spain</affiliation>
                    <email>laura.hernandez@scc.uned.es</email>
                </author>
                <author>
                    <persName>
                        <surname>De Sisto</surname>
                        <forename>Mirella</forename>
                    </persName>
                    <affiliation>UNED, Spain</affiliation>
                    <email>mdesisto@scc.uned.es</email>
                </author>
                <author>
                    <persName>
                        <surname>Ros</surname>
                        <forename>Salvador</forename>
                    </persName>
                    <affiliation>UNED, Spain</affiliation>
                    <email>sros@scc.uned.es</email>
                </author>
                <author>
                    <persName>
                        <surname>González-Blanco</surname>
                        <forename>Elena</forename>
                    </persName>
                    <affiliation>IE School of Human Science and Technology, Spain</affiliation>
                    <email>egonzalezblanco@faculty.ie.edu</email>
                </author>
            </titleStmt>
            <editionStmt>
                <edition>
                    <date>2021-06-10T17:38:59.854613438</date>
                </edition>
            </editionStmt>
            <publicationStmt>
                <publisher>Elisabeth Burr, University of Leipzig</publisher>
                <address>
                    <addrLine>Beethovenstr. 15</addrLine>
                    <addrLine>04107 Leipzig</addrLine>
                    <addrLine>Germany</addrLine>
                    <addrLine>Elisabeth Burr</addrLine>
                </address>
            </publicationStmt>
            <sourceDesc>
                <p>Converted from an OASIS Open Document</p>
            </sourceDesc>
        </fileDesc>
        <encodingDesc>
            <appInfo>
                <application ident="DHCONVALIDATOR" version="1.22">
                    <label>DHConvalidator</label>
                </application>
            </appInfo>
        </encodingDesc>
        <profileDesc>
            <textClass>
                <keywords scheme="ConfTool" n="category">
                    <term>Paper</term>
                </keywords>
                <keywords scheme="ConfTool" n="subcategory">
                    <term>Long paper</term>
                </keywords>
                <keywords scheme="ConfTool" n="keywords">
                    <term>poetry</term>
                    <term>stanza classification</term>
                    <term>natural language processing</term>
                    <term>word embeddings</term>
                    <term>language models</term>
                    <term>neural networks</term>
                </keywords>
                <keywords scheme="ConfTool" n="topics">
                    <term>Gathering</term>
                    <term>Programming</term>
                    <term>Annotating</term>
                    <term>Content Analysis</term>
                    <term>Structural Analysis</term>
                    <term>Stylistic Analysis</term>
                    <term>Modeling</term>
                    <term>Identifying</term>
                    <term>Sharing</term>
                    <term>Text</term>
                    <term>Language</term>
                    <term>Methods</term>
                    <term>Literature</term>
                    <term>Data</term>
                    <term>not applicable</term>
                    <term>English</term>
                </keywords>
            </textClass>
        </profileDesc>
    </teiHeader>
    <text>
        <body>
            <div type="div1" rend="DH-Heading1">
                <head>Introduction</head>
                <p>An important aspect of the analysis of poetry relies on the extraction of
                    information from the different structures found in a poem. To a certain degree,
                    identifying these structures automatically with the help of a computer is
                    partially possible now and such tools already exist for many languages such as
                    Spanish (Gervás 2000), Portuguese (Araújo / Mamede 2002), French (McAleese
                    2007), English (Heuser / Antiila 2010), Czech (Ibrahim / Plecháč 2011), Euskara
                    (Agirrezabal 2016), or Dutch (De Sisto 2020). Most approaches use rule-based
                    systems (Gervás 2000; McAleese 2007; Heuser / Antiila 2010; Ibrahim / Plecháč
                    2011; De la Rosa et al. 2020), while only a few make use of neural networks
                    techniques (Agirrezabal 2016; De Sisto 2020). Remarkably, the automatic
                    identification of stanza types remains understudied. In this work, we framed the
                    problem of stanza type identification as a classification task.</p>
            </div>
            <div type="div1" rend="DH-Heading1">
                <head>Classification of stanzas</head>
                <p>A stanza is the minimal structural unit of a poem that usually also encapsulates
                    themes or ideas (Kirszner 2003). Stanzas are formed by verses, and as such they
                    are shaped by authorial styles and historic preferences. In the Spanish
                    tradition, three aspects determine how a stanza is identified: metrical length,
                    rhyme type, and rhyme scheme (Domínguez Caparrós 2014; Jauralde 2020; Quilis
                    2000; Torre 2000). Therefore, stanza classification can be formulated as a three
                    stages process (Domínguez Caparrós 2014) (see Table 1 for an example):</p>
                <list type="ordered">
                    <item>Calculation of per verse metrical length. This step usually involves counting the number of syllables and checking for rhetorical devices that may alter this count (e.g., syneresis, synalephas).</item>
                    <item>Determining the rhyme type. A pair of verses rhyme in consonance when all the sounds after the last stressed syllable of each verse match. On the other hand, assonance only pertains to the matching of vocalic sounds, ignoring the consonantal ones.</item>
                    <item>Extraction of the rhyme scheme. The rhyme scheme is determined by what verses rhyme with each other.</item>
                </list>
                <table rend="frame" xml:id="Table1">
                    <row role="label">
                        <cell>Stanza</cell>
                        <cell>Length</cell>
                        <cell>Type</cell>
                        <cell>Scheme</cell>
                    </row>
                    <row>
                        <cell>Escribí en el aren
                            <hi rend="bold">a</hi>l
                        </cell>
                        <cell>8</cell>
                        <cell>-a</cell>
                        <cell>a</cell>
                    </row>
                    <row>
                        <cell>los tres nombres de la vida:</cell>
                        <cell>8</cell>
                        <cell>-</cell>
                        <cell>-</cell>
                    </row>
                    <row>
                        <cell>vida, muerte, am
                            <hi rend="bold">o</hi>r.
                        </cell>
                        <cell>6</cell>
                        <cell>-o</cell>
                        <cell>b</cell>
                    </row>
                    <row>
                        <cell>Una ráfaga de m
                            <hi rend="bold">a</hi>r,
                        </cell>
                        <cell>8</cell>
                        <cell>-a</cell>
                        <cell>a</cell>
                    </row>
                    <row>
                        <cell>tantas claras veces d
                            <hi rend="bold">a</hi>,
                        </cell>
                        <cell>8</cell>
                        <cell>-a</cell>
                        <cell>a</cell>
                    </row>
                    <row>
                        <cell>vino y nos borr
                            <hi rend="bold">ó</hi>.
                        </cell>
                        <cell>6</cell>
                        <cell>-o</cell>
                        <cell>b</cell>
                    </row>
                </table>
                <p>Table 1. Example of a 6 verses stanza by poet Miguel Hernández with assonant rhyme showing metrical lengths, rhyme type, and rhyme scheme. Rhyming sound of the ending word in bold.</p>
                <p>Once these three aspects are identified (verse lengths, rhyme types, and rhyme scheme), the expert has to match their characteristics against the different definitions of stanza types given by the poetic tradition and make a decision about the best match.</p>
            </div>
            <div type="div1" rend="DH-Heading1">
                <head>Methods and Evaluation</head>
                <p>In order to test automatic approaches to stanza classification, we first
                    collected a corpus of 5005 stanzas from 1600 poems ranging from the early 15th
                    century to contemporary poems, containing a balanced number of stanzas for each
                    of the 45 stanza types considered plus an extra category for stanzas with no
                    type known. The corpus was manually reviewed by three experts to ensure texts
                    were written in modern Spanish (computer tools tend to struggle with old
                    Spanish) with no spelling or orthotypographic mistakes (Pérez Pozo et al.,
                    2021). Based on the 3-stages of stanza classification aforementioned, we created
                    a knowledge base with the appropriate rules for each type of stanza, and had the
                    same group of experts decide on the order they should be applied and how
                    ambiguities should be resolved. We then incorporated these rules to a baseline
                    expert system built on top of Rantanplan (De la Rosa et al. 2020), a scansion
                    tool for Spanish that reports state of the art results for metrical pattern
                    extraction. Using the metrical information extracted by Rantanplan from the
                    plain text of a stanza, and the set of manually crafted rules by the experts,
                    our baseline was able to predict a stanza type with an accuracy of 78.63% when
                    evaluated on the corpus. Once the baseline was established, we tested different
                    techniques in an attempt to improve the classification results.</p>
                <p>From a machine learning point of view, the problem is a pure multiclass classification task. Decision trees come as a natural fit to our problem for their capacity to encode rules and their priorities, and their ability to produce explainable and interpretable models. To carry out the training, we split the 5005 stanzas in our corpus into stratified training and testing sets of 4004 stanzas (80%) and 1001 stanzas (20%), respectively. Each stanza was vectorized and transformed into a feature vector containing information about what independent rules in the knowledge base were triggered according to the metrical information extracted by Rantanplan. That is, we ignored the experts’ knowledge on the order and subsumption of rules and gave the activations as inputs to the classifier. Tree-based methods were able to improve our baseline by almost 13% (see Table 2).</p>
                <table rend="frame" xml:id="Table2">
                    <row role="label">
                        <cell>Method </cell>
                        <cell>Accuracy(%) </cell>
                    </row>
                    <row>
                        <cell>Baseline</cell>
                        <cell rend="end">78.63</cell>
                    </row>
                    <row>
                        <cell>Decision Tree </cell>
                        <cell rend="end">88.21</cell>
                    </row>
                    <row>
                        <cell>Random Forests </cell>
                        <cell rend="end">88.51</cell>
                    </row>
                    <row>
                        <cell>GloVe</cell>
                        <cell rend="end">66.72</cell>
                    </row>
                    <row>
                        <cell>BERT</cell>
                        <cell rend="end">42.12</cell>
                    </row>
                    <row>
                        <cell>BERT + features</cell>
                        <cell rend="end bold">91.91</cell>
                    </row>
                </table>
                <p>Table 2. Tree-based evaluation results expressed in accuracy percentages on the test set. Best result in bold.</p>
                <p>We did not cross-validate the training and testing sets since the same splits
                    were used to train computationally expensive neural networks. We expected that
                    the networks would learn most of the rules necessary to classify the different
                    stanza types without manually encoding the rules. Since embeddings have
                    demonstrated to be highly effective in a number of NLP tasks (Chen et al. 2013),
                    we relied on word embeddings and language models to extract the feature vectors
                    from the plain text of each stanza in the corpus. The architecture was based on
                    stacked bi-directional LSTM layers, dropout, and a fully connected linear layer
                    acting as a classifier. The input to the neural networks was the plain text of
                    each stanza. We then tested both GloVe (Pennington et al. 2014) and BERT (Devlin
                    et al. 2019) text embeddings as inputs to the networks. After a small grid
                    search, we found that GloVe performed better with 3 LSTM layers, dropout of 0.2,
                    learning rate of 1.25e-5, and trained for 325 epochs. While BERT, with the same
                    LSTM settings but a learning rate of 1e-4, plateau at 5 epochs. We also tested a
                    hybrid approach in which we combined a BERT model with the vector of features
                    extracted by Rantanplan (same vector used as input to the tree-based models). In
                    this case, the model performed better with 20 LSTM layers, a dropout of 0.1,
                    learning rate of 1e-3, and trained for 100 epochs. The models were trained using
                    the same 80/20 split, but reserving 20% of the training set for evaluation
                    purposes. Table 2 shows that this approach performed better than any other.</p>
            </div>
            <div type="div1" rend="DH-Heading1">
                <head>Discussion</head>
                <p>While notably better than a random classifier, our baseline expert system
                    suffered from a series of limitations: the use of Old Spanish in some poems,
                    which confused the underlying scansion tool; the relaxation of some rules
                    related to verse length allowing a small fluctuation in the fixed length of
                    verses (Domínguez Caparrós 2014; Jauralde 2020; Quilis 2000; Torre 2000); and
                    the presence of hemistiches, verses split in two halves with independent
                    metrical lengths that affect that of the verse as a whole. Tree-based solutions
                    were capable of learning the right order in which rules needed to be applied and
                    boost the accuracy by 13%. On the other hand, neither contextual (BERT) nor
                    contextually-aware (GloVe) embeddings produced better results than our baseline.
                    However, the combination of the contextual embeddings with prior domain-specific
                    knowledge seems to perform over 15% better than our baseline. The embedding
                    layers seem to carry insufficient structural information for this task, but it
                    complements very well the feature set obtained from the 3-stage rules of each
                    stanza type.</p>
            </div>
            <div type="div1" rend="DH-Heading1">
                <head>Conclusions</head>
                <p>In this work, we have framed the problem of stanza identification as a classification task prone to be approached using machine learning techniques, including those based on recent natural language processing methods such as word embeddings and language models. In the process, we have contributed with a novel corpus of more than 5000 stanzas of 45 types in Spanish, a knowledge base with rules for each stanza type, and a baseline classifier soon to be released as part of an existing scansion tool. We have shown that powerful language models trained on billions of words are not yet capable to outperform simple methods such as decision trees, since the amount of structural information encoded in their dense vectors is not sufficient to perform stanza classification. Finally, we have proven that combining both expert knowledge and contextual embeddings performs best, producing a system that assigns a correct stanza type over 91% of the time. This result is both somewhat expected, since stanza classification is a very nuanced task, and challenging, since it might hinder our future plans to create models that perform well in several languages without explicitly encoding their rules. Moreover, a proper error analysis needs to be conducted to examine where the differences in performance are coming from.</p>
            </div>
            <div type="div1" rend="DH-Heading1">
                <head>Software</head>
                <p>All the source code and corpus are available at GitHub repository: 
                    <ref target="https://github.com/linhd-postdata/stanza-detection-evaluation">https://github.com/linhd-postdata/stanza-detection-evaluation</ref>.
                </p>
            </div>
            <div type="div1" rend="DH-Heading1">
                <head>Acknowledgements</head>
                <p>This work was supported by the Starting Grant research project ‘Poetry Standardization and Linked Open Data: POSTDATA (ERC-2015-STG-679528), funded by the European Research Council (ERC) under the European Union’s Horizon 2020 research and innovation program.</p>
            </div>
        </body>
        <back>
            <div type="bibliogr">
                <listBibl>
                    <head>Bibliography</head>
                    <bibl>
                        <hi rend="bold">Agirrezabal, </hi>
                        <hi rend="bold">Manex </hi>(2016): “ZeuScansion: A Tool for Scansion of
                        English Poetry”, in: <hi rend="italic">Journal of Language Modelling</hi> 4,
                        1: 3 DOI: https://doi.org/10.15398/jlm.v4i1.102 .</bibl>
                    <bibl>
                        <hi rend="bold">Araújo, Paulo</hi> / <hi rend="bold">Mamede, Nuno</hi>
                        (2002): <hi rend="italic">Classificador de Poemas</hi>. Lisbon: CCTE. </bibl>
                    <bibl>
                        <hi rend="bold">Chen, Yanqing</hi> / <hi rend="bold">Perozzi, Bryan</hi> /
                            <hi rend="bold">Al-Rfou, Rami</hi> / <hi rend="bold">Skiena, Steven
                        </hi>(2013): "The Expressive Power of Word Embeddings", in: <hi
                            rend="italic">ArXiv</hi> 1301.3226 [Cs, Stat] &lt;<ref
                            target="http://arxiv.org/abs/1301.3226"
                            >http://arxiv.org/abs/1301.3226</ref>&gt; </bibl>
                    <bibl>
                        <hi rend="bold">De la Rosa, </hi>
                        <hi rend="bold">Javier</hi> / <hi rend="bold">Pérez, Álvaro</hi> / <hi
                            rend="bold"> Hernández, Laura</hi> / <hi rend="bold">Ros, Salvador</hi>
                        / <hi rend="bold">González-Blanco, Elena</hi> (2020): “Fast and Accurate
                        Syllabification and Scansion of Spanish Poetry”, in: <hi rend="italic">
                            Revista de Procesamiento del Lenguaje Natural</hi> 65. </bibl>
                    <bibl>
                        <hi rend="bold">De Sisto, Mirella</hi> (2020): <hi rend="italic">The
                            interaction between phonology and metre</hi>. Approaches to Romance and
                        West-Germanic metre (= LOT Publications). Nijmegen: Radboud University. </bibl>
                    <bibl>
                        <hi rend="bold">Domínguez-Caparrós, José</hi> (2014): <hi rend="italic"
                            >Métrica española</hi>. Madrid: Editorial UNED. </bibl>
                    <bibl>
                        <hi rend="bold">Domínguez-Caparros, José</hi> (2006): <hi rend="italic"
                            >Métrica Española</hi>. Sintesis. </bibl>
                    <bibl>
                        <hi rend="bold">Gervás, Pablo</hi> (2000): “A Logic Programming Application
                        for the Analysis of Spanish Verse”, in: <hi rend="italic">International
                            Conference on Computational Logic</hi>. Berlin / Heidelberg: Springer. </bibl>
                    <bibl>
                        <hi rend="bold">Hartman, Charles</hi> (2017): <hi rend="italic"
                            >Scandroid</hi> &lt;<ref
                            target="http://oak.conncoll.edu/cohar/Programs.htm"
                            >http://oak.conncoll.edu/cohar/Programs.htm</ref>&gt;
                        [01.06.2021].</bibl>
                    <bibl>
                        <hi rend="bold">Heuser, Ryan</hi> / <hi rend="bold">Anttila, Arto</hi>
                        (2010): <hi rend="italic">Prosodic</hi> &lt;<ref
                            target="http://prosodic.stanford.edu"
                        >http://prosodic.stanford.edu</ref>&gt; [01.06.2021]. </bibl>
                    <bibl>
                        <hi rend="bold">Ibrahim, Robert</hi> / <hi rend="bold"> Plecháč, Petr</hi>
                        (2011): “Towards the automatic analysis of Czech verse”, in: <hi
                            rend="italic">Formal Methods in Poetics</hi> 295–305. RAM. </bibl>
                    <bibl>
                        <hi rend="bold">Jauralde, Pablo </hi> (2020): <hi rend="italic">Métrica
                            Española</hi>. Catedra. </bibl>
                    <bibl>
                        <hi rend="bold">Kirszner, Laurie G.</hi> / <hi rend="bold">Mandell, Stephen
                            R.</hi> (2003): <hi rend="italic">Literature: Reading, Reacting,
                            Writing</hi>. Thomson / Heinle. </bibl>
                    <bibl>
                        <hi rend="bold">McAleese, Gareth </hi>(2007): <hi rend="italic">Improving
                            scansion with syntax: an investigation into the effectiveness of a
                            syntactic analysis of poetry by computer using phonological scansion
                            theory</hi>. PhD thesis, Open University. </bibl>
                    <bibl>
                        <hi rend="bold">Moretti, Franco</hi> (2013): <hi rend="italic">Distant
                            Reading</hi>. Verso. </bibl>
                    <bibl>
                        <hi rend="bold">Pérez Pozo, Álvaro</hi> / <hi rend="bold"> de la Rosa,
                            Javier</hi> / <hi rend="bold">Ros, Salvador</hi> / <hi rend="bold"
                            >González-Blanco, Elena</hi> / <hi rend="bold">Hernández, Laura</hi> /
                            <hi rend="bold">De Sisto, Mirella</hi> (2021): “A bridge too far for
                        artificial intelligence? Automatic classification of stanzas in Spanish
                        poetry”, in : <hi rend="italic">Journal of the Association for Information
                            Science and Technology</hi> 1– 10. </bibl>
                    <bibl>
                        <hi rend="bold">Pennington, Jeffrey</hi> / <hi rend="bold">Socher,
                            Richard</hi> / <hi rend="bold">Manning, Christopher D.</hi> (2014):
                        “GloVe: Global Vectors for Word Representation”, in: <hi rend="italic"
                            >Proceedings of the 2014 Conference on Empirical Methods in Natural
                            Language Processing (EMNLP) </hi>1532–1543. </bibl>
                    <bibl>
                        <hi rend="bold">Quilis, Antonio</hi> (2000): <hi rend="italic">Métrica
                            española</hi>. Grupo Planeta (GBS). </bibl>
                    <bibl>
                        <hi rend="bold">Torre, Esteban</hi> (2000): <hi rend="italic">Métrica
                            española comparada</hi> 48. Sevilla: Universidad de Sevilla. </bibl>
                </listBibl>
            </div>
        </back>
    </text>
</TEI>
