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.3.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.3-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fabula_fr-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 5aa7fb7e367f47e0f5b7517a50fc8c3b3c045e1ae49c816dec9e36cdb8583c9f
MD5 86f8827c37cff0dbc7906dcd03b21659
BLAKE2b-256 2e0565145ae630e3962361480eddbc5e2da5b64a91667f6c810e3f443fe4cfbd

See more details on using hashes here.

Provenance

The following attestation bundles were made for fabula_fr-0.1.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: fabula_fr-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 10.7 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5a4408e7fd05c4c90b7a4317d9640f7cb8d6b2cfe52d59f3debe77a1e103ca2c
MD5 b0e92719682a7c797e94c094f1d843b2
BLAKE2b-256 55871f62605d86b981250701f1fdade7b244136b2ac5f2dd65ae9d5d83080821

See more details on using hashes here.

Provenance

The following attestation bundles were made for fabula_fr-0.1.3-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