Views
No views yet
@inproceedings{phobert,
title = {{PhoBERT: Pre-trained language models for Vietnamese}},
author = {Dat Quoc Nguyen and Anh Tuan Nguyen},
booktitle = {Findings of the Association for Computational Linguistics: EMNLP 2020},
year = {2020},
pages = {1037--1042}
}transformerstransformers with pip: pip install transformers, or install transformers from source. transformers branch. The process of merging a fast tokenizer for PhoBERT is in the discussion, as mentioned in this pull request. If users would like to utilize the fast tokenizer, the users might install transformers as follows:git clone --single-branch --branch fast_tokenizers_BARTpho_PhoBERT_BERTweet https://github.com/datquocnguyen/transformers.git
cd transformers
pip3 install -e .tokenizers with pip: pip3 install tokenizers| Model | #params | Arch. | Max length | Pre-training data |
|---|---|---|---|---|
vinai/phobert-base | 135M | base | 256 | 20GB of Wikipedia and News texts |
vinai/phobert-large | 370M | large | 256 | 20GB of Wikipedia and News texts |
vinai/phobert-base-v2 | 135M | base | 256 | 20GB of Wikipedia and News texts + 120GB of texts from OSCAR-2301 |
1import torch
2from transformers import AutoModel, AutoTokenizer
3
4phobert = AutoModel.from_pretrained("vinai/phobert-base-v2")
5tokenizer = AutoTokenizer.from_pretrained("vinai/phobert-base-v2")
6
7# INPUT TEXT MUST BE ALREADY WORD-SEGMENTED!
8sentence = 'Chúng_tôi là những nghiên_cứu_viên .'
9
10input_ids = torch.tensor([tokenizer.encode(sentence)])
11
12with torch.no_grad():
13 features = phobert(input_ids) # Models outputs are now tuples
14
15## With TensorFlow 2.0+:
16# from transformers import TFAutoModel
17# phobert = TFAutoModel.from_pretrained("vinai/phobert-base")fairseqraw, i.e. without word segmentation, a word segmenter must be applied to produce word-segmented texts before feeding to PhoBERT. As PhoBERT employed the RDRSegmenter from VnCoreNLP to pre-process the pre-training data (including Vietnamese tone normalization and word and sentence segmentation), it is recommended to also use the same word segmenter for PhoBERT-based downstream applications w.r.t. the input raw texts.pip install py_vncorenlp1import py_vncorenlp
2
3# Automatically download VnCoreNLP components from the original repository
4# and save them in some local machine folder
5py_vncorenlp.download_model(save_dir='/absolute/path/to/vncorenlp')
6
7# Load the word and sentence segmentation component
8rdrsegmenter = py_vncorenlp.VnCoreNLP(annotators=["wseg"], save_dir='/absolute/path/to/vncorenlp')
9
10text = "Ông Nguyễn Khắc Chúc đang làm việc tại Đại học Quốc gia Hà Nội. Bà Lan, vợ ông Chúc, cũng làm việc tại đây."
11
12output = rdrsegmenter.word_segment(text)
13
14print(output)
15# ['Ông Nguyễn_Khắc_Chúc đang làm_việc tại Đại_học Quốc_gia Hà_Nội .', 'Bà Lan , vợ ông Chúc , cũng làm_việc tại đây .']Copyright (c) 2023 VinAI Research
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.