<figure><img src="image_1.png" /></figure>

HAL
open science

# Renard: A Modular Pipeline for Extracting Character Networks from Narrative Texts

Arthur Amalvy, Vincent Labatut, Richard Dufour

<figure><img src="image_2.png" /></figure>

## To cite this version:

Arthur Amalvy, Vincent Labatut, Richard Dufour. Renard: A Modular Pipeline for Extracting Character Networks from Narrative Texts. Journal of Open Source Software, 2024, 9 (98), pp.6574. 10.21105/joss.06574. [hal-04611122v2](https://hal.science/hal-04611122v2)

HAL Id: hal-04611122

https://hal.science/hal-04611122v2

Submitted on 24 Jun 2024

HAL is a multi-disciplinary open access archive for the deposit and dissemination of scientific research documents, whether they are published or not. The documents may come from teaching and research institutions in France or abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est destinée au dépôt et à la diffusion de documents scientifiques de niveau recherche, publiés ou non, émanant des établissements d'enseignement et de recherche français ou étrangers, des laboratoires publics ou privés.

<figure><img src="image_3.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
# Renard: A Modular Pipeline for Extracting Character Networks from Narrative Texts

Arthur Amalvy, Vincent Labatut, Richard Dufour

<figure><img src="image_1.png" /></figure>

## To cite this version:

Arthur Amalvy, Vincent Labatut, Richard Dufour. Renard: A Modular Pipeline for Extracting Character Networks from Narrative Texts. Journal of Open Source Software, 2024, 9 (98), pp.6574. 10.21105/joss.06574. [hal-04611122v2](https://hal.science/hal-04611122v2)

HAL Id: hal-04611122

https://hal.science/hal-04611122v2

Submitted on 24 Jun 2024

HAL is a multi-disciplinary open access archive for the deposit and dissemination of scientific research documents, whether they are published or not. The documents may come from teaching and research institutions in France or abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est destinée au dépôt et à la diffusion de documents scientifiques de niveau recherche, publiés ou non, émanant des établissements d'enseignement et de recherche français ou étrangers, des laboratoires publics ou privés.

<figure><img src="image_2.png" /></figure>
# Renard: A Modular Pipeline for Extracting Character Networks from Narrative Texts

Arthur Amalvy¹, Vincent Labatut¹, and Richard Dufour²

1 Laboratoire Informatique d'Avignon, France 2 Laboratoire des Sciences du Numérique de Nantes, France

DOI: 10.21105/joss.06574

## Software

- Review ⚙️

- Repository ⚙️

- Archive ⚙️

Editor: Tristan Miller ⚙️ ID

## Reviewers:

- @tellarin

- @LCB0B

Submitted: 18 March 2024

Published: 20 June 2024

## License

Authors of papers retain copyright and release the work under a Creative Commons Attribution 4.0 International License (CC BY 4.0).

## Summary

Renard (*Relationships Extraction from NARRative Documents*) is a Python library that allows users to define custom natural language processing (NLP) pipelines to extract character networks from narrative texts. Contrary to the few existing tools, Renard can extract *dynamic* networks, as well as the more common static networks. Renard pipelines are modular: users can choose the implementation of each NLP subtask needed to extract a character network. This allows users to specialize pipelines to particular types of texts and to study the impact of each subtask on the extracted network.

## Statement of Need

Character networks (i.e., graphs where vertices represent characters and edges represent their relationships) extracted from narrative texts are useful in a number of applications, from visualization to literary analysis (Labatut & Bost, 2019). There are different ways of modeling relationships (co-occurrences, conversations, actions, etc.), and networks can be static or dynamic (i.e., series of networks representing the evolution of relationships through time). This variety means one can extract different kinds of networks depending on the targeted applications. While some authors extract these networks by relying on manually annotated data (Park, Kim, & Cho, 2013; Park, Kim, Hwang, et al., 2013; Rochat, 2014, 2015; Rochat & Triclot, 2017), it is a time-costly endeavor, and the fully automatic extraction of these networks is therefore of interest. Unfortunately, there are only a few existing software packages and tools that can extract character networks (Métrailler, 2023; Sparavigna & Marazzato, 2015), but none of these can output dynamic networks. Furthermore, automatically extracting a character network requires solving several successive natural language processing tasks, such as named entity recognition (NER) or coreference resolution, and algorithms carrying these tasks are bound to make errors. To our knowledge, the cascading impact of these errors on the quality of the extracted networks has yet to be studied extensively. This is an important issue since knowing which tasks have more influence on the extracted networks would allow prioritizing research efforts.

Renard is a fully configurable pipeline that can extract static and dynamic networks from narrative texts. We base Renard on the generic character network extraction framework highlighted by the survey of Labatut & Bost (2019). We design it so that it is as modular as possible, which allows the user to select the implementation of each extraction step as needed. This has several advantages:

1. Depending on the input text, the user can choose the most relevant series of steps and configure each of them as needed. Therefore, the pipeline can be specialized for different types of texts, allowing for better performance.
# Renard: A Modular Pipeline for Extracting Character Networks from Narrative Texts

Arthur Amalvy¹, Vincent Labatut¹, and Richard Dufour²

1 Laboratoire Informatique d'Avignon, France 2 Laboratoire des Sciences du Numérique de Nantes, France

DOI: 10.21105/joss.06574

## Software

- Review ⚗

- Repository ⚗

- Archive ⚗

Editor: Tristan Miller ⚗

## Reviewers:

- @tellarin

- @LCB0B

Submitted: 18 March 2024

Published: 20 June 2024

## License

Authors of papers retain copyright and release the work under a Creative Commons Attribution 4.0 International License (CC BY 4.0).

## Summary

Renard (*Relationships Extraction from NARRative Documents*) is a Python library that allows users to define custom natural language processing (NLP) pipelines to extract character networks from narrative texts. Contrary to the few existing tools, Renard can extract *dynamic* networks, as well as the more common static networks. Renard pipelines are modular: users can choose the implementation of each NLP subtask needed to extract a character network. This allows users to specialize pipelines to particular types of texts and to study the impact of each subtask on the extracted network.

## Statement of Need

Character networks (i.e., graphs where vertices represent characters and edges represent their relationships) extracted from narrative texts are useful in a number of applications, from visualization to literary analysis (Labatut & Bost, 2019). There are different ways of modeling relationships (co-occurrences, conversations, actions, etc.), and networks can be static or dynamic (i.e., series of networks representing the evolution of relationships through time). This variety means one can extract different kinds of networks depending on the targeted applications. While some authors extract these networks by relying on manually annotated data (Park, Kim, & Cho, 2013; Park, Kim, Hwang, et al., 2013; Rochat, 2014, 2015; Rochat & Triclot, 2017), it is a time-costly endeavor, and the fully automatic extraction of these networks is therefore of interest. Unfortunately, there are only a few existing software packages and tools that can extract character networks (Métrailler, 2023; Sparavigna & Marazzato, 2015), but none of these can output dynamic networks. Furthermore, automatically extracting a character network requires solving several successive natural language processing tasks, such as named entity recognition (NER) or coreference resolution, and algorithms carrying these tasks are bound to make errors. To our knowledge, the cascading impact of these errors on the quality of the extracted networks has yet to be studied extensively. This is an important issue since knowing which tasks have more influence on the extracted networks would allow prioritizing research efforts.

Renard is a fully configurable pipeline that can extract static and dynamic networks from narrative texts. We base Renard on the generic character network extraction framework highlighted by the survey of Labatut & Bost (2019). We design it so that it is as modular as possible, which allows the user to select the implementation of each extraction step as needed. This has several advantages:

1. Depending on the input text, the user can choose the most relevant series of steps and configure each of them as needed. Therefore, the pipeline can be specialized for different types of texts, allowing for better performance.
2. The pipeline can easily incorporate new advances in NLP, by simply implementing a new step when necessary.

3. One can study the impact of the performance of each step on the quality of the extracted networks.

We intend for Renard to be used by digital humanities researchers as well as NLP researchers and practitioners. The former category of users can use Renard to quickly extract character networks for literary analysis. Meanwhile, the latter can use Renard to easily represent textual content using networks, which can be used as inputs for downstream NLP tasks (classification, recommendation...).

## Design and Main Features

Renard is centered about the concept of a *pipeline*. In Renard, a pipeline is a series of sequential *steps* that are run one after the other in order to extract a character network from a text. When using Renard, the user simply *describes* this pipeline in Python by specifying this series of steps, and can apply it to different texts afterwards. The following code block exemplifies that philosophy:

```python
from renard.pipeline import Pipeline
from renard.pipelineesteelseization import NLTKřokenizer
from renard.pipeline.ner import NLTKNamedEntityRecognizer
from renard.pipeline character_unification import GraphRulesCharacterUnifier
from renard.pipeline graph_extraction import CoOccurrencesGraphExtractor
```

```python
with open("./my_doc.txt") as f:
    text = f.read()
```

```groovy
pipeline = Pipeline(
    [
        NLTKřokenizer(),
        NLTKNamedEntityRecognizer(),
        GraphRulesCharacterUnifier(min_appearance=10),
        # users can pass 'dynamic=True' and specify the
        # 'dynamic_windows' argument to extract a dynamic network
        # instead of a static one.
        CoOccurrencesGraphExtractor(
            coNERoccurrences_dist=10, dynamic=False
        )
    ]
)
```

```groovy
out = pipeline(text)
```
2. The pipeline can easily incorporate new advances in NLP, by simply implementing a new step when necessary.

3. One can study the impact of the performance of each step on the quality of the extracted networks.

We intend for Renard to be used by digital humanities researchers as well as NLP researchers and practitioners. The former category of users can use Renard to quickly extract character networks for literary analysis. Meanwhile, the latter can use Renard to easily represent textual content using networks, which can be used as inputs for downstream NLP tasks (classification, recommendation...).

## Design and Main Features

Renard is centered about the concept of a *pipeline*. In Renard, a pipeline is a series of sequential *steps* that are run one after the other in order to extract a character network from a text. When using Renard, the user simply *describes* this pipeline in Python by specifying this series of steps, and can apply it to different texts afterwards. The following code block exemplifies that philosophy:

```python
from renard.pipeline import Pipeline
from renard.pipelineesteelseization import NLTKřflyncizer
from renard.pipeline.ner import NLTKNamedEntityRecognize
from renard.pipeline character_unification import GraphRulesCharacterUnifier
from renard.pipeline graph_extraction import CooccurrencesGraphExtractor
```

```python
with open("./my_doc.txt") as f:
    text = f.read()
```

```groovy
pipeline = Pipeline(
    [
        NLTKřflyncizer(),
        NLTKNamedEntityRecognize(),
        GraphRulesCharacterUnifier(min_appearance=10),
        # users can pass 'dynamic=True' and specify the
        # 'dynamic_windows' argument to extract a dynamic network
        # instead of a static one.
        CooccurrencesGraphExtractor(
            coNER occurrences dist=10, dynamic=False
        )
    ]
)
```

```groovy
out = pipeline(text)
```
<figure><img src="image_4.png" /><figcaption>**Figure 1:** Co-occurrence character network of Jane Austen's "Pride and Prejudice", extracted automatically using Renard. Vertex size and color denote degree, while edge thickness and color denote the number of co-occurrences between two characters.</figcaption></figure>

As an example, Figure 1 shows the co-occurrence character network of Jane Austen's 1813 novel "Pride and Prejudice", extracted using the Renard pipeline above. While this network is static, users can also extract a dynamic network by passing the `dynamic=True` argument to the last step of the pipeline, and specifying the `dynamic_windows` argument: in that case, Renard outputs a list of graphs corresponding to a dynamic network instead of a single network<fnref n="1" />. Renard uses the NetworkX Python library (Hagbert et al., 2008) to manipulate graphs, ensuring compatibility with a wide array of tools and formats.

To allow for custom needs, we design Renard to be very flexible. If a step is not available in Renard, we encourage users to either:

* Externally perform the computation corresponding to the desired step, and inject the results back into the pipeline at runtime,

* Implement their own step to integrate their custom processing into Renard by subclassing the existing `PipelineStep` class. If necessary, this `PipelineStep` can act as an adapter to an external process that may or may not be written in Python.

The flexibility of this approach introduces the possibility of creating invalid pipelines because steps often require information computed by previously run steps: for example, solving the NER task requires a tokenized version of the input text. To counteract this issue, each step therefore declares its requirements and the new information it produces, which allows Renard to check whether a pipeline is valid, and to explain at runtime to the user why it may not be<fnref n="2" />.

<table><caption>**Table 1:** Existing steps and their supported languages in Renard.</caption><thead><tr><td>Step</td><td>Supported Languages</td></tr></thead><tbody><tr><td>StanfordCoreNLPPipeline</td><td>eng</td></tr><tr><td>CustomSubstitutionPreprocessor</td><td>any</td></tr><tr><td>NLTKTokenizer</td><td>eng, fra, rus, ita, spa... (12 other)</td></tr><tr><td>QuoteDetector</td><td>any</td></tr><tr><td>NLTKNamedEntity Recognizer</td><td>eng, rus</td></tr></tbody></table>

<footnote n="1">¹See the documentation on dynamic networks for more details.</footnote>

<footnote n="2">²See the documentation for more details on steps requirements.</footnote>
<figure><img src="image_3.png" /><figcaption>**Figure 1:** Co-occurrence character network of Jane Austen's "Pride and Prejudice", extracted automatically using Renard. Vertex size and color denote degree, while edge thickness and color denote the number of co-occurrences between two characters.</figcaption></figure>

As an example, Figure 1 shows the co-occurrence character network of Jane Austen's 1813 novel "Pride and Prejudice", extracted using the Renard pipeline above. While this network is static, users can also extract a dynamic network by passing the `dynamic=True` argument to the last step of the pipeline, and specifying the `dynamic_windows` argument: in that case, Renard outputs a list of graphs corresponding to a dynamic network instead of a single network<fnref n="1" />. Renard uses the NetworkX Python library (Hagbert et al., 2008) to manipulate graphs, ensuring compatibility with a wide array of tools and formats.

To allow for custom needs, we design Renard to be very flexible. If a step is not available in Renard, we encourage users to either:

* Externally perform the computation corresponding to the desired step, and inject the results back into the pipeline at runtime,

* Implement their own step to integrate their custom processing into Renard by subclassing the existing `PipelineStep` class. If necessary, this `PipelineStep` can act as an adapter to an external process that may or may not be written in Python.

The flexibility of this approach introduces the possibility of creating invalid pipelines because steps often require information computed by previously run steps: for example, solving the NER task requires a tokenized version of the input text. To counteract this issue, each step therefore declares its requirements and the new information it produces, which allows Renard to check whether a pipeline is valid, and to explain at runtime to the user why it may not be<fnref n="2" />.

<table><caption>**Table 1:** Existing steps and their supported languages in Renard.</caption><thead><tr><td>Step</td><td>Supported Languages</td></tr></thead><tbody><tr><td>StanfordCoreNLPPipeline</td><td>eng</td></tr><tr><td>CustomSubstitutionPreprocessor</td><td>any</td></tr><tr><td>NLTKTokenizer</td><td>eng, fra, rus, ita, spa... (12 other)</td></tr><tr><td>QuoteDetector</td><td>any</td></tr><tr><td>NLTKNamedEntity Recognizer</td><td>eng, rus</td></tr></tbody></table>

<footnote n="1">¹See the documentation on dynamic networks for more details.</footnote>

<footnote n="2">²See the documentation for more details on steps requirements.</footnote>
<table><thead><tr><td>Step</td><td>Supported Languages</td></tr></thead><tbody><tr><td>BertNamedEntity Recognizer</td><td>eng, fra</td></tr><tr><td>BertCoreferenceResolver</td><td>eng</td></tr><tr><td>SpacyCorefereeCoreferenceResolver</td><td>eng</td></tr><tr><td>NaiveCharacterUnifier</td><td>any</td></tr><tr><td>GraphRulesCharacterUnifier (inspired from Vala et al. (2015))</td><td>eng, fra</td></tr><tr><td>BertSpeakerDetector</td><td>eng</td></tr><tr><td>CoOccurencesGraphExtractor</td><td>any</td></tr><tr><td>ConversationalGraphExtractor</td><td>any</td></tr></tbody></table>

Renard lets users select the targeted language of its their custom pipelines. A pipeline can be configured to run in any language, as long as each of its steps supports it. Table 1 shows all the currently available steps in Renard and their supported languages.

## References

Hagbert, A. A., Schult, D. A., & Swart, P. J. (2008). Exploring network structure, dynamics and function using NetworkX. 7th Python in Science Conference (SciPy 2008). https://www.osti.gov/biblio/960616

Labatut, V., & Bost, X. (2019). Extraction and analysis of fictional character networks: A survey. ACM Computing Surveys, 52, 89. https://doi.org/10.1145/3344548

Métrailleur, C. (2023). Charnetto. https://gitlab.com/maned_wolf/charnetto

Park, G., Kim, S., & Cho, H. (2013). Structural analysis on social network constructed from characters in literature texts. Journal of Computers, 8. https://doi.org/10.4304/jcp.8.9.2442-2447

Park, G., Kim, S., Hwang, H., & Cho, H. (2013). Complex system analysis of social networks extracted from literary fictions. International Journal of Machine Learning and Computing, 107–111. https://doi.org/10.7763/IJMLC.2013.V3.282

Rochat, Y. (2014). Character networks and centrality [PhD thesis, Université de Lausanne]. https://serval.unil.ch/resource/serval:BIB_663137B68131.P001/REF.pdf

Rochat, Y. (2015). Character network analysis of Émile Zola's Les Rougon-Macquart. Digital Humanities 2015. https://infoscience.epfl.ch/record/210573?ln=en

Rochat, Y., & Triclot, M. (2017). Les réseaux de personnages de science-fiction : Échantillons de lectures intermédiaires. ReS Futurae, 10, 1183. https://doi.org/10.4000/resf.1183

Sparavigna, A. C., & Marazzato, R. (2015). Analysis of a play by means of CHAPLIN, the characters and places interaction network software. International Journal of Sciences, 4(3), 60–68. https://doi.org/10.18483/ijSci.662

Vala, H., Jurgens, D., Piper, A., & Ruths, D. (2015). Mr. Bennet, his coachman, and the archbishop walk into a bar but only one of them gets recognized: On the difficulty of detecting characters in literary texts. Conference on Empirical Methods in Natural Language Processing, 769–774. https://doi.org/10.18653/v1/D15-1088
<table><thead><tr><td>Step</td><td>Supported Languages</td></tr></thead><tbody><tr><td>BertNamedEntity Recognizer</td><td>eng, fra</td></tr><tr><td>BertCoreferenceResolver</td><td>eng</td></tr><tr><td>SpacyCorefereeCoreferenceResolver</td><td>eng</td></tr><tr><td>NaiveCharacterUnifier</td><td>any</td></tr><tr><td>GraphRulesCharacterUnifier (inspired from Vala et al. (2015))</td><td>eng, fra</td></tr><tr><td>BertSpeakerDetector</td><td>eng</td></tr><tr><td>CoOccurencesGraphExtractor</td><td>any</td></tr><tr><td>ConversationalGraphExtractor</td><td>any</td></tr></tbody></table>

Renard lets users select the targeted language of its their custom pipelines. A pipeline can be configured to run in any language, as long as each of its steps supports it. Table 1 shows all the currently available steps in Renard and their supported languages.

## References

Hagbert, A. A., Schult, D. A., & Swart, P. J. (2008). Exploring network structure, dynamics and function using NetworkX. 7th Python in Science Conference (SciPy 2008). https://www.osti.gov/biblio/960616

Labatut, V., & Bost, X. (2019). Extraction and analysis of fictional character networks : A survey. ACM Computing Surveys, 52, 89. https://doi.org/10.1145/3344548

Métrailier, C. (2023). Charnetto. https://gitlab.com/maned_wolf/charnetto

Park, G., Kim, S., & Cho, H. (2013). Structural analysis on social network constructed from characters in literature texts. Journal of Computers, 8. https://doi.org/10.4304/jcp.8.9.2442-2447

Park, G., Kim, S., Hwang, H., & Cho, H. (2013). Complex system analysis of social networks extracted from literary fictions. International Journal of Machine Learning and Computing, 107-111. https://doi.org/10.7763/IJMLC.2013.V3.282

Rochat, Y. (2014). Character networks and centrality [PhD thesis, Université de Lausanne]. https://serval.unil.ch/resource/serval:BIB_663137B68131.P001/REF.pdf

Rochat, Y. (2015). Character network analysis of Émile Zola's Les Rougon-Macquart. Digital Humanities 2015. https://infoscience.epfl.ch/record/210573?ln=en

Rochat, Y., & Triclot, M. (2017). Les réseaux de personnages de science-fiction : Échantillons de lectures intermédiaires. ReS Futurae, 10, 1183. https://doi.org/10.4000/resf.1183

Sparavigna, A. C., & Marazzato, R. (2015). Analysis of a play by means of CHAPLIN, the characters and places interaction network software. International Journal of Sciences, 4(3), 60-68. https://doi.org/10.18483/ijSci.662

Vala, H., Jurgens, D., Piper, A., & Ruths, D. (2015). Mr. Bennet, his coachman, and the archbishop walk into a bar but only one of them gets recognized: On the difficulty of detecting characters in literary texts. Conference on Empirical Methods in Natural Language Processing, 769-774. https://doi.org/10.18653/v1/D15-1088