Views
No views yet
1from transformers import pipeline, AutoTokenizer
2from unsloth import FastLanguageModel
3
4# Load model
5model, tokenizer = FastLanguageModel.from_pretrained(
6 "aminLo/merged_model_run-v2-02052025-llama-3B",
7 max_seq_length=2048,
8 load_in_4bit=True,
9)
10
11# Format prompt
12instruction = """
13Tu es un assistant chargé d'extraire des informations clés depuis un texte administratif.
14Analyse le texte suivant et retourne les informations au format JSON.
15"""
16
17input_text = """
18[Your administrative text here]
19"""
20
21# Create pipeline
22pipe = pipeline(
23 "text-generation",
24 model=model,
25 tokenizer=tokenizer,
26 max_new_tokens=512,
27 temperature=0.1,
28)
29
30# Format as chat
31messages = [
32 {"role": "user", "content": f"
33Tu es un assistant chargé d'extraire des informations clés depuis un texte administratif.
34
35Analyse le texte suivant et retourne les informations au format JSON en respectant la structure suivante :
36
371. Si l'événement est un **avancement d'échelon** :
38{
39"Agent": "NOM PRÉNOM",
40"Etablissement": "Ville ou organisme concerné",
41"Evenement": "avancement d'échelon",
42"Echelon": "Numéro d'échelon",
43"Date": "AAAA-MM-JJ"
44}
45
462. Si l'événement est un **passage à temps partiel** (y compris thérapeutique ou sous autorisation) :
47{
48"Agent": "NOM PRÉNOM",
49"Etablissement": "Ville ou organisme concerné",
50"Evenement": "passage à temps partiel",
51"TempsHebdomadaire": "Nombre d'heures/semaine",
52"Pourcentage": "XX%",
53"Durée": "Durée si précisée",
54"Date": "AAAA-MM-JJ"
55}
56
573. Pour les autres événements (nomination, fin de contrat, etc.) :
58{
59"Agent": "NOM PRÉNOM",
60"Etablissement": "Ville ou organisme concerné",
61"Evenement": "type d'événement",
62"Date": "AAAA-MM-JJ",
63"Durée": "si précisée"
64}
65
66Texte à analyser :
67\n\n'input_text'"}
68]
69prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
70
71# Generate response
72output = pipe(prompt, return_full_text=False)
73generated_text = outputs[0]['generated_text']
74print(generated_text)