meanna / ThaiLMCUT

MIT License
15 stars 5 forks source link

ThaiLMCut - Word Tokenizer for Thai Language based on Transfer Learning and bidirectional-LSTM

About

Update

Requirements

Install LMCut as package

Download the weight file from:

Tokenizer models

Move the weight file to this directory:

lmcut/weight/

Create a package wheel using:

python setup.py bdist_wheel

Install the package using:

pip install dist/lmcut*

How to use LMCut

Tokenize a given Thai text

from lmcut import tokenize
text = "โรงแรมดี สวยงามน่าอยู่มากๆ"
result = tokenize(text)
print(result)

Result is a list of tokens:

['โรง', 'แรม', 'ดี', 'สวยงาม', 'น่า', 'อยู่', 'มาก', 'ๆ']

Train a language model

Prepare dataset for training

To resume the training of a language model, run

python train/LanguageModel.py \
--load_from [model name to resume] \
--dataset [dataset name] \
--epoch 3 \
--learning_rate 0.0001 \
--over_write 1

Pretrained language model

Train a new tokenizer

To train a new tokenizer, you could run:

python train/Tokenizer.py \
--dataset default \
--epoch 3 \
--lstm_num_direction 2 \
--batchSize 30 \
--sequence_length 80 \
--char_embedding_size 100 \
--hidden_dim 60 \
--layer_num 2 \
--optim adam \
--learning_rate 0.0001

To load a pre-trained language model(the embedding layer and recurrent layer) to the tokenizer and train, you could run

python train/Tokenizer.py \
--load_from [language model name] \
--dataset default \
--epoch 2 \
--learning_rate 0.0001 \
--over_write 0

To resume the training of a tokenizer, you could run

python train/Tokenizer.py \
--load_from [tokenizer name] \
--dataset default \
--epoch 2 \
--learning_rate 0.0001 \
--over_write 1

Credits

Acknowledgements

The project is funded by TrustYou. The author would like to sincerely thank TrustYou and other contributors.

Contributors

License

All original code in this project is licensed under the MIT License. See the included LICENSE file.