Fine-tuned
Qwen3-0.6B for
real-time turn-end detection in Malaysian multilingual call center conversations.
1import torch
2import math
3import torch.nn.functional as F
4from transformers import AutoTokenizer, AutoModelForCausalLM
5
6model_id = "Scicom-intl/Malaysian-Turn-Detector-Qwen3-0.6B"
7tokenizer = AutoTokenizer.from_pretrained(model_id)
8model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16).cuda().eval()
9
10IM_END_ID = tokenizer.convert_tokens_to_ids("<|im_end|>")
11
12def get_turn_end_prob(text):
13 """Returns probability that the speaker's turn is complete."""
14 # Strip trailing <|im_end|> so the model predicts whether to emit it
15 if text.endswith("<|im_end|>"):
16 text = text[:-len("<|im_end|>")]
17 inputs = tokenizer(text, return_tensors="pt").to("cuda")
18 with torch.no_grad():
19 logits = model(**inputs).logits
20 prob = F.softmax(logits[0, -1], dim=-1)[IM_END_ID].item()
21 return prob
22
23# Complete turn - should be high probability
24text = "<|im_start|>user\nHello, saya nak tanya pasal bil saya.<|im_end|>\n<|im_start|>assistant\nBoleh, sila berikan nombor akaun anda."
25prob = get_turn_end_prob(text)
26print(f"P(turn complete) = {prob:.4f}") # ~0.74
27
28# Incomplete turn - should be low probability
29text = "<|im_start|>user\nHello, saya nak tanya pasal bil saya.<|im_end|>\n<|im_start|>assistant\nBoleh, sila berikan nombor"
30prob = get_turn_end_prob(text)
31print(f"P(turn complete) = {prob:.4f}") # ~0.00