pythainlp.lm.wangchanberta
Note
pythainlp.wangchanberta has moved to pythainlp.lm.wangchanberta.
Importing from pythainlp.wangchanberta still works but emits a
DeprecationWarning and will be removed in 6.0.
The pythainlp.lm.wangchanberta module is built upon the WangchanBERTa base model, specifically the wangchanberta-base-att-spm-uncased model, as detailed in the paper by Lowphansirikul et al. [1].
This base model is utilized for various natural language processing tasks in the Thai language, including named entity recognition, part-of-speech tagging, and subword tokenization.
If you intend to fine-tune the model or explore its capabilities further, please refer to the thai2transformers repository.
Speed Benchmark
Function |
Named Entity Recognition |
Part of Speech |
|---|---|---|
PyThaiNLP basic function |
89.7 ms |
312 ms |
pythainlp.wangchanberta (CPU) |
9.64 s |
9.65 s |
pythainlp.wangchanberta (GPU) |
8.02 s |
8 s |
For a comprehensive performance benchmark, the following notebooks are available:
Modules
- class pythainlp.lm.wangchanberta.NamedEntityRecognition(model: str = 'pythainlp/thainer-corpus-v2-base-model', revision: str | None = None)[source]
Recognize Thai named entities with a WangchanBERTa model.
The NamedEntityRecognition class is a fundamental component for identifying named entities in Thai text. It allows you to extract entities such as names, locations, and organizations from text data.
- __init__(model: str = 'pythainlp/thainer-corpus-v2-base-model', revision: str | None = None) None[source]
Initialize a named entity recognizer.
Use a model pretrained with WangchanBERTa.
- tokenizer: PreTrainedTokenizerBase
- model: PreTrainedModel
- class pythainlp.lm.wangchanberta.ThaiNameTagger(dataset_name: str = 'thainer', grouped_entities: bool = True)[source]
Tag named entities with the WangchanBERTa pipeline.
The ThaiNameTagger class is designed for tagging Thai names within text. This is essential for tasks such as entity recognition, information extraction, and text classification.
- __init__(dataset_name: str = 'thainer', grouped_entities: bool = True) None[source]
Initialize a named entity tagger in IOB format.
Use WangchanBERTa from the VISTEC-depa AI Research Institute of Thailand.
- classify_tokens: TokenClassificationPipeline