murat commited on
Commit
f8cbe3c
·
verified ·
1 Parent(s): 9d9e4f8

Fix repeating model output

Browse files
Files changed (1) hide show
  1. README.md +44 -4
README.md CHANGED
@@ -14,12 +14,52 @@ language:
14
  ## Quick start
15
 
16
  ```python
17
- from transformers import pipeline
 
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  incorrect_text = "омур бою иштеген адамдар чынында бактылуу деп ойлойсунбу?"
20
- generator = pipeline("text-generation", model="murat/kyrgyz_umlaut_corrector", device="cuda")
21
- output = generator([{"role": "user", "content": incorrect_text}], max_new_tokens=128, return_full_text=False)[0]
22
- print(output["generated_text"])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  ```
24
 
25
  ## Training procedure
 
14
  ## Quick start
15
 
16
  ```python
17
+ import torch
18
+ from transformers import pipeline, AutoTokenizer
19
 
20
+ # 1. Моделдин ID'син көрсөтөбүз
21
+ model_id = "murat/kyrgyz_umlaut_corrector"
22
+
23
+ # 2. Токенайзерди жүктөйбүз. Бул бизге атайын токендерди алууга керек.
24
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
25
+
26
+ # 3. Pipeline'ды түзөбүз
27
+ # Эгер токенайзерди өзүнчө жүктөсөк, pipeline аны туура колдонот.
28
+ generator = pipeline(
29
+ "text-generation",
30
+ model=model_id,
31
+ tokenizer=tokenizer,
32
+ device="cpu", # cuda
33
+ # torch_dtype=torch.bfloat16 # uncomment this line if you are using cuda
34
+ )
35
+
36
+ # 4. Токтотуучу токендин ID'син алабыз
37
+ # Gemma чат модели үчүн ар бир жооптун аягы ушул токен менен белгиленет.
38
+ stop_token_id = tokenizer.convert_tokens_to_ids("<end_of_turn>")
39
+
40
+ # 5. Текстти даярдайбыз
41
  incorrect_text = "омур бою иштеген адамдар чынында бактылуу деп ойлойсунбу?"
42
+ chat_prompt = [{"role": "user", "content": incorrect_text}]
43
+
44
+ # 6. Моделди керектүү параметрлер менен чакырабыз
45
+ output = generator(
46
+ chat_prompt,
47
+ max_new_tokens=128,
48
+ return_full_text=False,
49
+ # Бул эң маанилүү параметр: ушул токенге жеткенде генерацияны токтот
50
+ eos_token_id=stop_token_id,
51
+ # Так оңдоо үчүн do_sample=False койгон жакшы.
52
+ # Бул моделди эң ыктымалдуу жоопту тандоого мажбурлайт.
53
+ do_sample=False
54
+ )
55
+
56
+ # 7. Жыйынтыкты чыгарабыз
57
+ # .strip() методу ашыкча боштуктарды же саптарды тазалайт
58
+ corrected_text = output[0]["generated_text"].strip()
59
+ print(corrected_text)
60
+
61
+ # Күтүлгөн жыйынтык:
62
+ # өмүр бою иштеген адамдар чынында бактылуу деп ойлойсуңбу?
63
  ```
64
 
65
  ## Training procedure