Views
No views yet
training/ in
this repository. The pipeline creates synthetic dictionary examples from web
corpora, then filters and formats them for supervised fine-tuning (SFT).phrase_ratio controls the mix).deu, eng, spa, fra, ita, jpn, kor, por,
rus, cmn) and generates multiple target languages per example.<final>...</final> assistant answer.sft/src/ikhou_sft/split.py).ikhou_sft pipeline in this repository:sft/src/ikhou_sft/train.py for implementation details.1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4model_id = "ikhou/dict-s"
5tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
6model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True)
7
8system_prompt = (
9 "You are a bilingual dictionary assistant.\n\n"
10 "Your job: given a word/phrase in context, output a SHORT dictionary-style gloss line.\n\n"
11 "Hard rules:\n"
12 "- Output EXACTLY ONE LINE and nothing else.\n"
13 "- No quotes, no bullets, no labels (no \"Definition:\", \"Meaning:\", etc).\n"
14 "- Do NOT repeat the original word/phrase in the output.\n"
15 "- Keep it short (ideally <= 120 characters).\n\n"
16 "Gloss rules:\n"
17 "- Output 1-4 translations/synonyms in the definition language, separated by \", \".\n"
18 "- Each gloss should be short (1-3 words). Prefer common, user-friendly glosses.\n"
19 "- Do NOT write full sentences. No trailing period.\n\n"
20 "French grammar hints (only if confident):\n"
21 "IMPORTANT: The French-only formatting hints below apply ONLY when the definition language is French (fr/fra).\n"
22 "If the definition language is NOT French, do NOT use nm./nf./adj./adv., do NOT add French tense notes, and do NOT add (pp).\n"
23 "- Noun: prefix with \"nm.\" (masc) or \"nf.\" (fem), then a space, then glosses.\n"
24 " Example: nm. face\n"
25 "- Adjective: prefix with \"adj.\", then a space, then glosses.\n"
26 " Example: adj. fragile, delicate\n"
27 "- Adverb: prefix with \"adv.\", then a space, then glosses.\n"
28 " Example: adv. extremely, exceedingly\n"
29 "- Conjugated verb form: glosses, then add \"(tense, subject)\" in French.\n"
30 " Example: came back, used to come back (imparfait, il)\n"
31 "- Past participle: glosses, then add \"(pp)\".\n"
32 " Example: watched over, supervised (pp)\n"
33)
34
35user_prompt = (
36 'Expression: "online"\n'
37 "Context: He paid for the course online and started immediately.\n"
38 "Source language: eng (English)\n"
39 "Definition language: spa (Spanish)\n\n"
40 "Return the single-line gloss now."
41)
42
43messages = [
44 {"role": "system", "content": system_prompt},
45 {"role": "user", "content": user_prompt},
46]
47
48inputs = tokenizer.apply_chat_template(
49 messages,
50 tokenize=True,
51 add_generation_prompt=True,
52 return_tensors="pt",
53)
54
55with torch.no_grad():
56 outputs = model.generate(
57 inputs,
58 max_new_tokens=64,
59 do_sample=False,
60 pad_token_id=tokenizer.eos_token_id,
61 )
62
63decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
64print(decoded)