Skip to main content

Transformers-based narrative sentiment/emotion arcs for literature (syuzhet-like).

Project description

Fabula-fr

fabula-fr est une bibliothèque Python pour analyser l’évolution du sentiment et/ou des émotions dans un texte et produire des arcs narratifs lissés.

Le package fournit :

  • une API Python (Fabula),
  • une CLI (fabula score / fabula arc),
  • des utilitaires de segmentation,
  • des fonctions de resampling + lissage,
  • des helpers de visualisation.

Installation

pip install fabula-fr

Pour le développement local :

pip install -e .[dev]

Démarrage rapide

API Python

from fabula.core import Fabula
from fabula.scorer import TransformersScorer

scorer = TransformersScorer(model="cmarkea/distilcamembert-base-sentiment")
fb = Fabula(scorer=scorer, analysis="sentiment")

text = "Bonjour. C'est une belle journée. Je suis triste."

# Scores par segment
scores = fb.score(text)
print(scores[["idx", "rel_pos", "label", "score"]])

# Arc narratif lissé
arc = fb.arc(text, n_points=100, smooth_window=7)
print(len(arc.x), len(arc.y))

CLI

# Scoring par segments (JSON)
fabula score mon_texte.txt --format json

# Scoring par segments (CSV)
fabula score mon_texte.txt --format csv

# Arc narratif
fabula arc mon_texte.txt --n-points 120 --smooth-window 9 --format csv

Lecture depuis stdin :

cat mon_texte.txt | fabula score - --format json

Segmentation

Segmenters disponibles

  • RegexSentenceSegmenter : segmentation par ponctuation terminale.
  • ParagraphSegmenter : segmentation par paragraphes (\n\n).
  • SlidingWindowTokenSegmenter : fenêtres glissantes sur tokens.
  • DocumentChunkTokenSegmenter : chunks de document par tokens.

Choix via CLI

Actuellement la CLI expose :

  • --segment sentence
  • --segment paragraph

Scoring et modèles

Mode standard

Par défaut, la CLI utilise TransformersScorer avec le modèle :

  • cmarkea/distilcamembert-base-sentiment

Vous pouvez le changer :

fabula score mon_texte.txt --model astrosbd/french_emotion_camembert

Mode sans téléchargement (--dummy)

Pour des tests rapides sans dépendre de Hugging Face :

fabula score mon_texte.txt --dummy
fabula arc mon_texte.txt --dummy

Arcs narratifs

Fabula.arc(...) :

  1. récupère les scores segmentés,
  2. interpole vers n_points (resample_to_n),
  3. applique un lissage (smooth_series).

Vous pouvez aussi générer des arcs multi-séries avec score_col="probs" dans l’API Python.


Visualisation

Le module fabula.plot expose :

  • plot_arc(...) pour un arc scalaire,
  • plot_arc_series(...) pour plusieurs séries.

Exemple :

from fabula.plot import plot_arc

fig, ax = plot_arc(arc, title="Arc narratif", save_path="arc.png")

Tests

Exécuter les tests :

python -m pytest -q

Citation

Si vous utilisez fabula, merci de citer :

Cafiero, Florian, et Alexandre Lionnet. Des émotions au fil du récit : fabula, un package pour analyser les textes francophones par Transformers. Communication présentée à Humanistica 2026 (Paris), à paraître dans Anthology of Computers and the Humanities.

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

fabula_fr-0.1.4.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

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

fabula_fr-0.1.4-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file fabula_fr-0.1.4.tar.gz.

File metadata

  • Download URL: fabula_fr-0.1.4.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fabula_fr-0.1.4.tar.gz
Algorithm Hash digest
SHA256 2a9b8b25830ffae866952fd2860f37fd38be4dc650e7c861b2b8bd295162d45b
MD5 75c866de860d47917939e40afd674cc5
BLAKE2b-256 a02a3422eed98f0d417c435c5f4c9ed6f81badc801bc5a5c85e917836ec40ae1

See more details on using hashes here.

Provenance

The following attestation bundles were made for fabula_fr-0.1.4.tar.gz:

Publisher: python-publish.yml on floriancafiero/fabula-fr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fabula_fr-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: fabula_fr-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fabula_fr-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5184127eff38b627d9b9bb08c651e2f13904ad185a11bb5ac333dcb7a982489c
MD5 f46fed9a77e620b2c92e05b5169adf51
BLAKE2b-256 745aa16d7a91093afe7d4b2d8ce57f3e524edc5b0f5168399080b8a921384753

See more details on using hashes here.

Provenance

The following attestation bundles were made for fabula_fr-0.1.4-py3-none-any.whl:

Publisher: python-publish.yml on floriancafiero/fabula-fr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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