Skip to content

Détecteur v1 de mentions de collaboration externe + table amendement_mentions#6

Closed
DavidNO wants to merge 6 commits into
add-amendements-modelfrom
detect-mentions-poc
Closed

Détecteur v1 de mentions de collaboration externe + table amendement_mentions#6
DavidNO wants to merge 6 commits into
add-amendements-modelfrom
detect-mentions-poc

Conversation

@DavidNO

@DavidNO DavidNO commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

Objectif

Première brique d'une partie du POC : détecter les amendements déclarés « travaillés avec » / « inspirés par » une entité externe (lobby, syndicat, association, entreprise…).

Version v1 exploratoire, utilisant uniquement un LLM : chaque amendement est soumis à un LLM pour détecter ce type de déclaration.

Contenu

Détecteur (analysis/detect_mentions.py)

  • Envoie l'exposé sommaire de chaque amendement à une API OpenAI-compatible et extrait les mentions de collaboration externe sous forme structurée.
  • Agnostique du provider et du modèle via les variables LLM_* (LLM_API_KEY / LLM_BASE_URL / LLM_MODEL), à créer localement…
  • Échantillonnage déterministe (paginable) ou aléatoire (--random) sur tout le corpus.
  • Parsing JSON défensif : aucune dépendance au mode json_object ( à changer si le modèle définitif le supporte).
  • Gestion du rate-limit : throttle configurable (--delay) + backoff exponentiel sur 429.
  • Sortie brute en JSONL (analysis/output/, gitignoré) + récap des formulations rencontrées.

Table d'analyse (models/amendement_mention.pyamendement_mentions)

  • Une ligne par mention : amendementUid, citation, formulation, entite, typeEntite, externe, modele, createdAt.
  • Table d'analyse (hors ETL_TABLES) : survit aux rebuilds via create_all, pendant que amendements/dossiers sont recréées.
  • amendementUid est une référence molle (pas de ForeignKey) vers amendements.uid, sur le modèle des RefUid existants : évite qu'une contrainte référentielle bloque le drop de la table ETL.

Persistance (--persist)

  • Écrit les mentions dans amendement_mentions en plus du JSONL.
  • Idempotent par amendement (delete-puis-insert), commit par ligne (une interruption conserve l'acquis).

Formulations observées (run de 100 amendements aléatoires)

travaillé avec, travaillé en lien avec, en lien avec, en concertation avec, rédigé en collaboration avec, réalisé avec le concours de, issu d'une proposition de, reprend ainsi la demande de, inspirée de, proposé par

Entités réelles détectées : FNSEA, Coordination Rurale, CFDT Défense, SER, Amorce, APPS… Le flag externe distingue les acteurs privés des organes publics (AID, AMIAD, DGA).

Screenshot de la table amendement_mentions

image

Note

Branche empilée sur add-amendements-model (#4) : à merger après celle-ci.

DavidNO added 6 commits July 12, 2026 10:50
Exploratory detector (no pre-filter) that sends each amendment's
exposé sommaire to an OpenAI-compatible API (Scaleway, OpenRouter...)
and extracts declared collaborations with external entities.

- Provider-agnostic via LLM_* env vars (base_url/model/key)
- Random or deterministic sampling over the amendements table
- Defensive JSON parsing (no reliance on json_object mode)
- Rate-limit handling: throttle + exponential backoff on 429
- Writes raw results to analysis/output/ (gitignored), prints a
  frequency summary of the formulations encountered
Stores external-collaboration mentions detected in amendments' exposé
sommaire. Analysis table (not in ETL_TABLES): survives rebuilds via
create_all while amendements/dossiers are dropped and reloaded.

amendementUid is a soft reference to amendements.uid (no ForeignKey),
matching the RefUid pattern in the Amendement model, so the referential
constraint never blocks the drop of the ETL-managed amendements table.
One row per mention; provenance kept via modele/createdAt.
Add --persist flag to the detector: on top of the JSONL output it writes
each mention to the amendement_mentions table via SQLAlchemy. Idempotent
per amendment (delete-then-insert), commit per row so a partial run keeps
what it found. The just recipe now forwards extra flags (--random/--persist).
- Add the missing setup steps (.env copy, starting Postgres via docker compose)
- Document the external-collaboration mention detector: LLM_* env config,
  detect-mentions usage and flags, JSONL/DB outputs
- Explain that amendement_mentions is an analysis table that survives rebuilds
- Fix the stale Dossier model example (was still named User)
@DavidNO

DavidNO commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator Author

Remplacée par #7 : approche regex retenue pour cette itération (déterministe, sans coût d'API). La branche detect-mentions-poc est conservée comme référence — elle a servi à calibrer les motifs et à construire le jeu d'évaluation.

@DavidNO DavidNO closed this Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant