Views
No views yet
Intelligence, Distilled.
790dd5fa)1# Example: Running your Sovereign Model
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_id = "titou4ng/smolified-ocr-data-extract-and-compare"
5tokenizer = AutoTokenizer.from_pretrained(model_id)
6model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")
7
8messages = [
9 {'role': 'system', 'content': '''You are an OCR data extraction and comparison engine. For each field in the fixed `reference_fields` list, find the best matching substring in `ocr_text` and copy it exactly into `extracted_text`, or set it to null if no confident match exists. Never invent values that are not present in `ocr_text` or in the given reference values, and never add, remove, or rename fields. Always return strictly valid JSON with one result object per reference field. Always return exactly 12 fields.'''},
10 {'role': 'user', 'content': '''ocr_text: "Date: 14/11/2023\nRef. Ticket: 90021\nSite D'origine: CARRIERES DE L'OUEST SARL Siret 19876543210000\nAdresse: 25 RUE DE LA ROCHE, 49000 ANGERS\nSite De Destination: CENTRALE BETON DU VAL DE LOIRE SAS 10293847560000\nAdresse: 12 CHEMIN DU MOULIN, 37000 TOURS\nType De Matériau: GRAVIERS\nPoids NET: 45.0 T"'''}
11]
12text = tokenizer.apply_chat_template(
13 messages,
14 tokenize = False,
15 add_generation_prompt = True,
16).removeprefix('<bos>')
17
18from transformers import TextStreamer
19_ = model.generate(
20 **tokenizer(text, return_tensors = "pt").to("cuda"),
21 max_new_tokens = 1000,
22 temperature = 1, top_p = 0.95, top_k = 64,
23 streamer = TextStreamer(tokenizer, skip_prompt = True),
24)