Views
No views yet
1[id→en]
2{input text}
3→1[en→id]
2{input text}
3→1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch, re
3
4model_id = "Sandroeth/cali-id-en-translate"
5
6tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
7model = AutoModelForCausalLM.from_pretrained(
8 model_id,
9 trust_remote_code=True,
10 device_map="auto"
11)
12model.eval()
13
14def translate(text, locale):
15 direction = "[id→en]" if locale == "id" else "[en→id]"
16 prompt = f"{direction}\n{text}\n→"
17
18 inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
19
20 with torch.no_grad():
21 out = model.generate(
22 **inputs,
23 max_new_tokens=64,
24 do_sample=False,
25 repetition_penalty=1.5,
26 no_repeat_ngram_size=3,
27 pad_token_id=tokenizer.eos_token_id,
28 use_cache=False,
29 )
30
31 gen = out[0][inputs["input_ids"].shape[1]:]
32 result = tokenizer.decode(gen, skip_special_tokens=True).strip()
33
34 return re.split(r'(?<=[.!?])\s+', result)[0]
35
36print(translate("Dia pergi ke pasar setiap pagi.", "id"))
37print(translate("The weather is very cold today.", "en"))| Input | Direction | Output |
|---|---|---|
| Saya makan nasi. | id→en | I eat rice. |
| Dia pergi ke pasar setiap pagi. | id→en | He goes to the market every morning. |
| She is happy. | en→id | Dia bahagia. |
| The weather is very cold today. | en→id | Cuacanya sangat dingin hari ini. |
| Pemerintah sedang membangun infrastruktur baru. | id→en | The government is building new infrastructure. |
1@article{cali2026,
2 title = {CALI 0.1B},
3 author = {Sandroeth},
4 year = {2026},
5 publisher = {Hugging Face},
6 url = {https://huggingface.co/Sandroeth/cali-0.1B}
7}