Google's
BERT
is currently the state-of-the-art method of pre-training text representations which additionally provides multilingual models.
Unfortunately, Thai is the only one in 103 languages that is excluded due to difficulties in word segmentation.
BERT-th presents the Thai-only pre-trained model based on the BERT-Base structure. It is now available to download.
BERT-th also includes relevant codes and scripts along with the pre-trained model, all of which are the modified versions of those in the original BERT project.
Input data need to be segmented into separate sentences before further processing by BERT modules. Since Thai language has no explicit marker at the end of a sentence, it is quite problematic to pinpoint sentence boundaries. To the best of our knowledge, there is still no implementation of Thai sentence segmentation elsewhere. So, in this project, sentence segmentation is done by applying simple heuristics, considering spaces, sentence length and common conjunctions.
After preprocessing, the training corpus consists of approximately 2 million sentences and 40 million words (counting words after word segmentation by
PyThaiNLP
). The plain and segmented texts can be downloaded
here
.
Tokenization
BERT uses
WordPiece
as a tokenization mechanism. But it is Google internal, we cannot apply existing Thai word segmentation and then utilize WordPiece to learn the set of subword units. The best alternative is
SentencePiece
which implements
BPE
and needs no word segmentation.
In this project, we adopt a pre-trained Thai SentencePiece model from
BPEmb
. The model of 25000 vocabularies is chosen and the vocabulary file has to be augmented with BERT's special characters, including '[PAD]', '[CLS]', '[SEP]' and '[MASK]'. The model and vocabulary files can be downloaded
here
.
SentencePiece
and
bpe_helper.py
from BPEmb are both used to tokenize data.
ThaiTokenizer class
has been added to BERT's
tokenization.py
for tokenizing Thai texts.
Pre-training
The data can be prepared before pre-training by using this script.
We have trained the model for 1 million steps. On Tesla K80 GPU, it took around 20 days to complete. Though, we provide a snapshot at 0.8 million steps because it yields better results for downstream classification tasks.
Downstream Classification Tasks
XNLI
XNLI
is a dataset for evaluating a cross-lingual inferential classification task. The development and test sets contain 15 languages which data are thoroughly edited. The machine-translated versions of training data are also provided.
The Thai-only pre-trained BERT model can be applied to the XNLI task by using training data which are translated to Thai. Spaces between words in the training data need to be removed to make them consistent with inputs in the pre-training step. The processed files of XNLI related to Thai language can be downloaded
here
.
Afterwards, the XNLI task can be learned by using this script.
This table compares the Thai-only model with XNLI baselines and the Multilingual Cased model which is also trained by using translated data.
XNLI Baseline
BERT
Translate Train
Translate Test
Multilingual Model
Thai-only Model
62.8
64.4
66.1
68.9
Wongnai Review Dataset
Wongnai Review Dataset collects restaurant reviews and ratings from
Wongnai
website. The task is to classify a review into one of five ratings (1 to 5 stars). The dataset can be downloaded
here
and the following script can be run to use the Thai-only model for this task.
Without additional preprocessing and further fine-tuning, the Thai-only BERT model can achieve 0.56612 and 0.57057 for public and private test-set scores respectively.
Runs of monsoon-nlp bert-base-thai on huggingface.co
484
Total runs
34
24-hour runs
95
3-day runs
212
7-day runs
371
30-day runs
More Information About bert-base-thai huggingface.co Model
bert-base-thai huggingface.co
bert-base-thai huggingface.co is an AI model on huggingface.co that provides bert-base-thai's model effect (), which can be used instantly with this monsoon-nlp bert-base-thai model. huggingface.co supports a free trial of the bert-base-thai model, and also provides paid use of the bert-base-thai. Support call bert-base-thai model through api, including Node.js, Python, http.
bert-base-thai huggingface.co is an online trial and call api platform, which integrates bert-base-thai's modeling effects, including api services, and provides a free online trial of bert-base-thai, you can try bert-base-thai online for free by clicking the link below.
monsoon-nlp bert-base-thai online free url in huggingface.co:
bert-base-thai is an open source model from GitHub that offers a free installation service, and any user can find bert-base-thai on GitHub to install. At the same time, huggingface.co provides the effect of bert-base-thai install, users can directly use bert-base-thai installed effect in huggingface.co for debugging and trial. It also supports api for free installation.