This model was trained on the official French government open dataset
"Liste des expériences partagées par les usagers" from data.gouv.fr.
-
Geographic information (department, region)
-
Service channels (phone, email, in-person, online, etc.)
-
Service categories and administrative structures
-
Response tracking and follow-up actions
-
Base Model: camembert-base
-
Language: French (fr)
-
Task: Text Classification (Sentiment Analysis)
-
Domain: Public services user feedback
-
Model Type: CamemBERT (RoBERTa-like for French)
-
License: MIT
-
Authors: Olivier Caron
1from transformers import pipeline
2
3# Initialize the sentiment analysis pipeline
4classifier = pipeline(
5 "text-classification",
6 model="oliviercaron/fr-camembert-spplus-sentiment",
7 device_map="auto",
8 top_k=None # Return scores for all classes
9)
10
11# Example texts
12texts = [
13 "Accueil très aimable, explications claires, je suis satisfait.",
14 "Je n'ai pas d'avis particulier sur la question.",
15 "Très déçu, aucune réponse à mes emails depuis des semaines.",
16 "Le service était correct, sans plus."
17]
18
19# Get predictions
20results = classifier(texts)
21
22# Display results
23for text, result in zip(texts, results):
24 print(f"Text: {text}")
25 for prediction in result:
26 print(f" {prediction['label']}: {prediction['score']:.4f}")
27 print()
28
29# Expected output:
30# Text: Accueil très aimable, explications claires, je suis satisfait.
31# Positif: 0.9990
32# Neutre: 0.0007
33# Négatif: 0.0002
34#
35# Text: Je n'ai pas d'avis particulier sur la question.
36# Neutre: 0.9790
37# Négatif: 0.0128
38# Positif: 0.0082
39#
40# Text: Très déçu, aucune réponse à mes emails depuis des semaines.
41# Négatif: 0.9873
42# Neutre: 0.0117
43# Positif: 0.0010
44#
45# Text: Le service était correct, sans plus.
46# Neutre: 0.9695
47# Positif: 0.0199
48# Négatif: 0.0106
1import torch
2from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
4# Load model and tokenizer
5model_name = "oliviercaron/fr-camembert-spplus-sentiment"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
9# Set device
10device = "cuda" if torch.cuda.is_available() else "cpu"
11model.to(device)
12model.eval()
13
14# Example text
15text = "Le personnel était compétent et à l'écoute."
16
17# Tokenize and predict
18inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
19inputs = {k: v.to(device) for k, v in inputs.items()}
20
21with torch.no_grad():
22 outputs = model(**inputs)
23 predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
24
25# Get results
26labels = ["Négatif", "Neutre", "Positif"]
27for i, (label, score) in enumerate(zip(labels, predictions[0])):
28 print(f"{label}: {score:.4f}")