File size: 6,419 Bytes
d640b95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
---

language:
- th
license: apache-2.0
tags:
- token-classification
- ner
- temporal-extraction
- wangchanberta
- roberta
- thai-nlp
base_model: airesearch/wangchanberta-base-att-spm-uncased
datasets:
- DuckerMaster/Thai-Natural-DateTime-Dataset
pipeline_tag: token-classification
metrics:
- f1
- precision
- recall
- accuracy
model-index:
- name: DuckerTime-Normalize-Thai
  results:
  - task:
      type: token-classification
      name: Named Entity Recognition
    dataset:
      name: Thai Natural DateTime Dataset (v1.1)
      type: DuckerMaster/Thai-Natural-DateTime-Dataset
    metrics:
    - name: In-Distribution F1
      type: f1
      value: 1.0000
    - name: Out-of-Distribution F1
      type: f1
      value: 0.9692
    - name: Out-of-Distribution Recall
      type: recall
      value: 0.9957
    - name: Out-of-Distribution Precision
      type: precision
      value: 0.9441
---


# DuckerTime-Normalize-Thai (WangchanBERTa Temporal Entity Slicer)

Fine-tuned `wangchanberta-base-att-spm-uncased` for token-level temporal boundary extraction (`B-TIME`, `I-TIME`, `O`) across colloquial Thai sentences, conversational chat slang, and compound date-time structures.

Paired Dataset: [DuckerMaster/Thai-Natural-DateTime-Dataset](https://huggingface.co/datasets/DuckerMaster/Thai-Natural-DateTime-Dataset)

Designed as the neural frontend for the End-to-End Hybrid Architecture:
1. **WangchanBERTa Frontend**: Extracts precise character and token spans from raw unstructured text.
2. **Deterministic Rule Engine Backend**: Parses the extracted temporal span into valid ISO-8601 points and ranges in sub-millisecond execution.

## Model Performance & Empirical Benchmark

![Empirical Benchmark Comparison](live_t4_benchmark_comparison.png)

Evaluated against disjoint stratified benchmarks and tested side-by-side with rule baselines and instruction-tuned LLMs on NVIDIA T4 hardware.

### Benchmark Summary (Batch Size = 1, Streaming Latency)

| System / Model Architecture | Parameter Size | Hardware Execution | OOD Accuracy / F1 | Mean Latency (ms) | Production SLA (<50ms) |
| :--- | :---: | :---: | :---: | :---: | :---: |
| **dateparser** (Heuristic Multilingual) | 0 | CPU | 6.0% | 12.4 ms | Pass |
| **PyThaiNLP** (Rule Parser) | 0 | CPU | 18.7% | 1.8 ms | Pass |
| **Qwen2.5-3B-Instruct** (4-bit NF4) | 3B | GPU (T4) | 3.3% | 383.3 ms | Fail (Over 7x threshold) |
| **Typhoon 30B (Cloud REST API)** | 30B | Cloud Server | 47.3% | 2,753.9 ms | Fail (Over 55x threshold) |
| **Our Hybrid System (WangchanBERTa + Rule)** | **106M** | **GPU (T4)** | **96.9%** | **10.2 ms** | **Pass (Optimal Frontier)** |

### Architectural Insights

- **Why Pure LLMs Fail on Strict Temporal Extraction**: Generative LLMs are prone to conversational framing (e.g. outputting conversational preambles or rephrasing targets) rather than returning strict token spans. This results in high parsing failure rates (3.3% exact match) and high latency (383ms+ per request).
- **Why Hybrid Architecture Wins**: Token classification via WangchanBERTa isolates target temporal spans with 99.57% Recall on out-of-distribution text. Passing this span to a deterministic rule engine guarantees valid ISO-8601 timestamps without hallucination.

### Accuracy vs. Latency Pareto Frontier

![Accuracy vs Latency Frontier](accuracy_vs_latency_frontier.png)

## Model Specifications and Hyperparameters

- **Base Architecture**: RoBERTa / CamemBERT architecture pre-trained on Thai Wikipedia, news, and social text (`airesearch/wangchanberta-base-att-spm-uncased`).
- **Target Entities**:
  - `O`: Outside temporal entity.
  - `B-TIME`: Beginning of temporal expression.
  - `I-TIME`: Continuation of temporal expression.
- **Training Epochs**: 4
- **Batch Size**: 16 (per device)
- **Optimizer**: AdamW (Learning Rate: 3e-5, Weight Decay: 0.01)
- **Warmup Steps**: 50
- **FP16 Mixed Precision**: Enabled
- **Inference Robustness**: Multi-token stitching with confidence thresholding (0.35) to handle spaced particles and chat modifiers.

## Intended Use and Pipeline Example

```python

import torch

from transformers import AutoTokenizer, AutoModelForTokenClassification



model_name = "DuckerMaster/DuckerTime-Normalize-Thai"

tokenizer = AutoTokenizer.from_pretrained(model_name)

model = AutoModelForTokenClassification.from_pretrained(model_name)



text = "ขอเลื่อนเป็นวันพุธหน้าช่วงบ่ายแก่ๆ สักสี่โมงเย็นได้ไหมคะ"

inputs = tokenizer(text, return_tensors="pt")



with torch.no_grad():

    logits = model(**inputs).logits

    preds = torch.argmax(logits, dim=2)[0].tolist()



tokens = tokenizer.convert_ids_to_tokens(inputs["input_ids"][0])

extracted_tokens = [tok for tok, pred in zip(tokens, preds) if pred != 0]

print("Extracted Temporal Tokens:", extracted_tokens)

```

## Limitations and Negative Sample Handling

- The model is fine-tuned to recognize temporal expressions in Thai. It actively suppresses non-temporal numeric entities (monetary sums, telephone sequences, tracking numbers) due to negative sampling in training data.
- For non-Thai text, fallback to multilingual parsers is recommended.
- Pair with `thai-temporal-normalizer` core package for full ISO-8601 normalization.

## Citation

If you use this model in your research or production systems, please cite:

```bibtex

@software{duckertime_thai_2026,

  author = {DuckerMaster},

  title = {DuckerTime-Normalize-Thai: Fine-Tuned WangchanBERTa for Colloquial Thai Temporal NLU},

  year = {2026},

  publisher = {HuggingFace},

  howpublished = {\url{https://huggingface.co/DuckerMaster/DuckerTime-Normalize-Thai}}

}

```

## References

- **WangchanBERTa**: Lowphansirikul, L., et al. (2021). WangchanBERTa: Pretrained language models for Thai language. *arXiv preprint arXiv:2101.09635*.
- **ISO-TimeML**: Pustejovsky, J., et al. (2010). ISO-TimeML: An International Standard for Semantic Annotation. *ISO/TC 37/SC 4*.
- **SUTime**: Chang, A. X., & Manning, C. D. (2012). SUTime: A library for recognizing and normalizing time expressions. In *LREC 2012*.
- **HeidelTime**: Strötgen, J., & Gertz, M. (2010). HeidelTime: High quality rule-based extraction and normalization of temporal expressions. In *SemEval 2010*.