<?xml version="1.0" encoding="UTF-8"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
    <teiHeader>
        <fileDesc>
            <titleStmt>
                <title>An Approach to the Automatic Search of Formulas in Old Norse-Icelandic Saga Corpus</title>
                <author>
                    <persName>
                        <surname>Glebova</surname>
                        <forename>Daria</forename>
                    </persName>
                    <affiliation>Higher School of Economics, Russian Federation</affiliation>
                    <email>kashalotdar@gmail.com</email>
                </author>
                <author>
                    <persName>
                        <surname>Kostyanitsyna</surname>
                        <forename>Anastasiya</forename>
                    </persName>
                    <affiliation>Higher School of Economics, Russian Federation</affiliation>
                    <email>anastasiya.kost98@gmail.com</email>
                </author>
                <author>
                    <persName>
                        <surname>Glazunov</surname>
                        <forename>Evgenii</forename>
                    </persName>
                    <affiliation>Higher School of Economics, Russian Federation</affiliation>
                    <email>e.glznv@yandex.ru</email>
                </author>
            </titleStmt>
            <editionStmt>
                <edition>
                    <date>2021-06-15T15:09:00Z</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 a Word 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>Short Paper</term>
                </keywords>
                <keywords scheme="ConfTool" n="keywords">
                    <term>formula</term>
                    <term>NLP</term>
                    <term>automatic search</term>
                </keywords>
                <keywords scheme="ConfTool" n="topics">
                    <term>DataRecognition</term>
                    <term>Programming</term>
                    <term>Annotating</term>
                    <term>Editing</term>
                    <term>Content Analysis</term>
                    <term>Network Analysis</term>
                    <term>Theorizing</term>
                    <term>Identifying</term>
                    <term>Communicating</term>
                    <term>Publishing</term>
                    <term>Sharing</term>
                    <term>Meta: Assessing</term>
                    <term>Meta: CommunityBuilding</term>
                    <term>Meta: Teaching/Learning</term>
                    <term>DigitalHumanities</term>
                    <term>Projects</term>
                    <term>Text</term>
                    <term>Tools</term>
                    <term>Language</term>
                    <term>Literature</term>
                    <term>English</term>
                </keywords>
            </textClass>
        </profileDesc>
    </teiHeader>
    <text>
        <body>
            <div type="div1" rend="DH-Heading1">
                <head>Introduction</head>
                <p>Developed around epic poetry, the oral formulaic theory described the <hi
                        rend="italic">formula</hi> as a building block of oral composition that was
                    strictly connected to meter (Parry 1930; Lord 1960). However, recently there
                    have been several studies discussing <hi rend="italic">formulas</hi> in prose
                    traditional narratives (Lamb 2015; Sävborg 2018) and showing that in such prose
                    corpora formulas are used without metrical conditions. This theoretic direction
                    creates a ground for an automatic search for formulas in medieval prose texts.
                    Such an experiment is the main goal of this project focused on formulas and
                    meaningful repetitions in Old Norse-Icelandic sagas (corpus information see in
                    Eiríkur Rögnvaldsson / Sigrún Helgadóttir 2011).  </p>
            </div>
            <div type="div1" rend="DH-Heading1">
                <head>Methods and Problems</head>
                <p>The main idea of the algorithm is the compilation of a list of ngrams, its further filtration, and application of NLP methods to determine repeating semantically significant word sequences. Formulas have at least two important features that are problematic for an automatic search:</p>
                <list type="ordered">
                    <item>A formula can be not only closed (word for word repetition) but also open
                        or semi-open (some of the slots in the word sequence can be variable; the
                        word order can change) (Lamb 2015: 228-231);</item>
                    <item>Certain formulas and their variants can appear rarely in the corpus.</item>
                </list>
                <p>Therefore, the entity filtering based on frequency is not applicable. Special heuristics were designed to gradually filter examples and combine contextual synonyms in groups. The algorithm consists of four main stages:</p>
                <list type="ordered">
                    <item>Ngram list formation</item>
                    <item>Ngram grouping</item>
                    <item>Syntactic grouping</item>
                    <item>Semantic clustering </item>
                </list>
                <div type="div2" rend="DH-Heading2">
                    <head>Ngram list compilation</head>
                    <p>To begin with, the list of ngrams has to be compiled (4 to 8 words). To get
                        only meaningful phrases, each ngram was tested on compliance with the
                        following criteria: 1) Presence of a verb, 2) Syntactic integrity, 3) Part
                        of speech (POS) significance of at least 90%. The phrasal syntactic
                        integrity was validated based on the POS and word cases (i.e. there are no
                        violations of agreement and government). The POS significance score was
                        calculated according to the formula: </p>
                    <figure>
                        <graphic n="1001" width="5.506861111111111cm" height="0.8043333333333333cm" url="Pictures/ac3be447c33a6811eac34a07249d983e.png" rend="inline"/>
                    </figure>
                    <p>Significance - the significance of a POS (each POS was assigned a number
                        reflecting its semantic significance in the process of phrase formation, see
                        Appendix); </p>
                    <p>
                        Frequency - frequency of a POS in an ngram;
                    </p>
                    <p>
                        <hi rend="italic">nwords</hi> - number of words in an ngram. </p>
                    <p>Thus, the ngram was skipped if its score is less than 0.9 (the threshold was determined by a test sample analysis), if it does not have syntactic integrity and if it does not have a verb. As a result, a list of 663,775 phrases was compiled. </p>
                </div>
                <div type="div2" rend="DH-Heading2">
                    <head>Ngram grouping</head>
                    <p>Then the ngrams should be grouped. The grouping consists of three stages: 1) the ngrams were normalised (e.g. adjectives and adverbs were omitted as modifiers may vary within the same structure or pronouns and proper nouns were transformed into POS and case tag, e.g. PrpNom, etc.); 2) resulting representations with the same word content but different word order were combined; 3) all phrases were grouped by their syntactic constituents, e.g. all sequences consisting of a verb, a pronoun in dative and a noun in nominative were grouped together. </p>
                </div>
                <div type="div2" rend="DH-Heading2">
                    <head>Semantic clustering</head>
                    <p>As the ngram groups should be semantically similar, each syntactic group was
                        clustered using the <hi rend="bold">spectral clustering algorithm</hi> (von
                        Luxburg 2007). This algorithm was adjusted for the current research purposes
                        as a graph of phrases was created for each syntactic group where each two
                        semantically similar nodes had a connection added. To find semantic
                        similarity between the nodes, the following operation was designed: 1) each
                        phrase was represented as a list of fastText vectors (Joulin et al. 2016);
                        2) the cosine similarities between words in the same position in
                        construction were calculated; 3) the similarity scores for phrases were
                        computed based on the average values of words they consist of. The resulting
                        scores were used as weights for connections between graph nodes; the
                        connection was added if the semantic similarity between the two phrases was
                        more than 0.85. </p>
                </div>
                <div type="div2" rend="DH-Heading2">
                    <head>Topic Modelling and Metrics Evaluation</head>
                    <p>As formulas in Old Icelandic sagas are usually used in similar situations
                        (see Sävborg 2018: 58-59), the last step was to find clusters that occur in
                        similar contexts. For this, a topic model for the whole corpus was built and
                        each sentence received a vector of topic distribution in the surrounding
                        fragment (5 sentences before and after). To evaluate the thematic similarity
                        of phrases within the clusters special metrics were created: <hi rend="bold"
                            >sparseness coefficient</hi> (how thematically sparse a certain cluster
                        is) and <hi rend="bold">cluster core</hi> (share of a strongly connected
                        group of entries). To calculate sparseness coefficient community unfolding
                        using greedy modularity maximization algorithm (Clauset et al. 2004) was
                        performed on cluster graphs that were beforehand reduced by calculating
                        median vectors of thematically similar ngram entries. The formula goes as
                        follows: </p>
                    <figure>
                        <graphic n="1002" width="6.5140416666666665cm" height="0.8801805555555555cm" url="Pictures/9eaddf4280773caee735008560a15365.png" rend="inline"/>
                    </figure>
                    <p>Nbiggest - the biggest community size</p>
                    <p>Nnodes - cluster size</p>
                    <p>𝜎 - standard deviation of community sizes
                    </p>
                    <p>To calculate the cluster core, outliers are omitted on each step and the average pairwise cosine similarity is computed until it reaches 0.9; the coefficient is the share of entries left.</p>
                </div>
            </div>
            <div type="div1" rend="DH-Heading1">
                <head>Discussion and Conclusions</head>
                <p>Finally, 1270 word sequences were collected. As there is no ‘golden standard’, it is impossible to use accuracy or recall, so precision was chosen as an evaluation metric. We used random samples (with different parameters; 100 ngrams in each sample) evaluated manually by the expert.</p>
                <table rend="rules">
                    <row role="label">
                        <cell style="text-align: center;">Filter</cell>
                        <cell style="text-align: center;">Precision
                        </cell>
                        <cell style="text-align: center;" cols="2">Confidence interval</cell>
                    </row>
                    <row>
                        <cell style="text-align: left;"/>
                        <cell style="text-align: left;"/>
                        <cell style="text-align: center;">Lower bound</cell>
                        <cell style="text-align: center;">Upper bound</cell>
                    </row>
                    <row>
                        <cell style="text-align: left;">Exact repetitions</cell>
                        <cell style="text-align: center;">12%</cell>
                        <cell style="text-align: center;">5,6%</cell>
                        <cell style="text-align: center;">18,4%</cell>
                    </row>
                    <row>
                        <cell style="text-align: left;">Sparseness coefficient &lt;= 0.15</cell>
                        <cell style="text-align: center;">13%</cell>
                        <cell style="text-align: center;">6,4%</cell>
                        <cell style="text-align: center;">19,6%</cell>
                    </row>
                    <row>
                        <cell style="text-align: left;">Cluster core &gt;= 0.9</cell>
                        <cell style="text-align: center;">18%</cell>
                        <cell style="text-align: center;">10,5%</cell>
                        <cell style="text-align: center;">25,5%</cell>
                    </row>
                    <row>
                        <cell style="text-align: left;">
                            <p style="text-align: left;">Sparseness coefficient &lt;= 0.15 &amp;</p>
                            <p style="text-align: left;">Cluster core &gt;= 0.9</p>
                        </cell>
                        <cell style="text-align: center;">11%</cell>
                        <cell style="text-align: center;">4,9%</cell>
                        <cell style="text-align: center;">17,1%</cell>
                    </row>
                    <row>
                        <cell style="text-align: left;">All</cell>
                        <cell style="text-align: center;">15%</cell>
                        <cell style="text-align: center;">8,00%</cell>
                        <cell style="text-align: center;">22,00%</cell>
                    </row>
                </table>
                <p>While the search gives good examples (e.g. variants for famous "X hét maður" (A man called X) or beginnings like "var það á einni nótt að/ það var á einni nótt þar sem…"), the precision shows low general results. In future the filtering algorithm could be improved and other semantic models could be used. However, although it is still work-in-progress, the presented algorithm can narrow down the list of all possible ngrams to several hundred that can be then evaluated manually. </p>
            </div>
            </body>
        <back>
            <div type="bibliogr">                
                <listBibl>
                    <head>Bibliography</head>
                    <bibl>
                        <hi rend="bold">Clauset, Aaron</hi> / <hi rend="bold">Newman, Mark E.
                            J.</hi> / <hi rend="bold">Moore, Clauset</hi> (2004): "Finding community
                        structure in very large networks", in: <hi rend="italic">Physical Review
                            E</hi> 70, 6 DOI: 10.1103/PhysRevE.70.066111. </bibl>
                    <bibl>
                        <hi rend="bold">Rögnvaldsson, Eiríkur</hi> / <hi rend="bold">Helgadóttir,
                            Sigrún</hi> (2011): "Morphosyntactic Tagging of Old Icelandic Texts and
                        Its Use in Studying Syntactic Variation and Change", in: Sporleder, Caroline
                        / van den Bosch, Antal / Zervanou, Kalliopi (eds.): <hi rend="italic"
                            >Language Technology for Cultural Heritage</hi>. Selected Papers from
                        the LaTeCH Workshop Series. Berlin: Springer 63–76 DOI:
                        10.1007/978-3-642-20227-8_4. </bibl>
                    <bibl>
                        <hi rend="bold">Joulin, Armand</hi> / <hi rend="bold">Grave, Edouard</hi> /
                            <hi rend="bold">Bojanowski, Piotr</hi> / <hi rend="bold">Douze,
                            Matthijs</hi> / <hi rend="bold">Jégou,  Hérve</hi> / <hi rend="bold"
                            >Mikolov, Tomas</hi> (2016): <hi rend="italic">FastText.zip: Compressing
                            text classification models</hi>. arXiv preprint:1612.03651 &lt;<ref
                            target="https://arxiv.org/abs/1612.03651"
                            >https://arxiv.org/abs/1612.03651</ref>&gt; [31.08.2021]. </bibl>
                    <bibl>
                        <hi rend="bold">Lamb, William</hi> (2015): "Verbal Formulas in Gaelic
                        Traditional Narrative: Some Aspects of their Form and Function", in: Agha,
                        Asif / Frog (eds.): <hi rend="italic">Registers of Communication.
                        </hi>Helsinki: Finnish Literature Society 225–246.  </bibl>
                    <bibl>
                        <hi rend="bold">Newman, Mark E. J. </hi>(2011): <hi rend="italic">Networks:
                            An Introduction.</hi> Oxford: Oxford University Press.</bibl>
                    <bibl>
                        <hi rend="bold">Parry, Milman</hi> (1930): "Studies in the Epic Technique of
                        Oral Verse-Making. I. Homer and Homeric Style", in: <hi rend="italic"
                            >Harvard Studies in Classical Philology </hi>41: 73–148.  </bibl>
                    <bibl>
                        <hi rend="bold">Sävborg, Daniel</hi> (2018): "The Formula in Icelandic Saga
                        Prose", in: <hi rend="italic">Saga-Book</hi> 42: 51-86. </bibl>
                    <bibl>
                        <hi rend="bold">von Luxburg, Ulrike</hi> (2007): "A Tutorial on Spectral
                        Clustering", in: <hi rend="italic">Statistics and computing</hi> 17, 4:
                        395-416.  </bibl>
                </listBibl>
            </div>
        </back>
     </text>
</TEI>
