🚀 PhoBERT:越南語預訓練語言模型
PhoBERT 預訓練模型是目前最先進的越南語語言模型(Pho,即“越南河粉”,是越南的一種流行美食)。它具有以下特點:
- “基礎版”和“大型版”這兩個 PhoBERT 版本是首批為越南語預訓練的公開大規模單語言模型。PhoBERT 的預訓練方法基於 RoBERTa,該方法優化了 BERT 的預訓練過程,以獲得更強大的性能。
- PhoBERT 在詞性標註、依存句法分析、命名實體識別和自然語言推理這四個下游越南語自然語言處理任務中,超越了之前的單語言和多語言方法,取得了新的最優性能。
PhoBERT 的總體架構和實驗結果可在我們的論文中找到:
@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}
}
請在使用 PhoBERT 幫助產生已發表的研究結果或將其集成到其他軟件中時引用我們的論文。
🚀 快速開始
本部分將介紹如何使用 PhoBERT 進行越南語自然語言處理任務。
✨ 主要特性
- 首批為越南語預訓練的公開大規模單語言模型。
- 基於 RoBERTa 優化預訓練過程,性能更強大。
- 在多個下游越南語自然語言處理任務中取得新的最優性能。
📦 安裝指南
使用 transformers
庫安裝
- 使用 pip 安裝
transformers
:pip install transformers
,或從源代碼安裝 transformers
。
注意,我們已將 PhoBERT 的慢速分詞器合併到 transformers
的主分支中。如此拉取請求所述,合併 PhoBERT 快速分詞器的過程正在討論中。如果用戶想使用快速分詞器,可以按以下方式安裝 transformers
:
git clone --single-branch --branch fast_tokenizers_BARTpho_PhoBERT_BERTweet https://github.com/datquocnguyen/transformers.git
cd transformers
pip3 install -e .
- 使用 pip 安裝
tokenizers
:pip3 install tokenizers
使用 fairseq
庫安裝
請查看此處的詳細信息。
安裝 VnCoreNLP
進行分詞
pip install py_vncorenlp
💻 使用示例
使用 transformers
庫的基礎用法
import torch
from transformers import AutoModel, AutoTokenizer
phobert = AutoModel.from_pretrained("vinai/phobert-base-v2")
tokenizer = AutoTokenizer.from_pretrained("vinai/phobert-base-v2")
sentence = 'Chúng_tôi là những nghiên_cứu_viên .'
input_ids = torch.tensor([tokenizer.encode(sentence)])
with torch.no_grad():
features = phobert(input_ids)
使用 VnCoreNLP
進行分詞的示例
import py_vncorenlp
py_vncorenlp.download_model(save_dir='/absolute/path/to/vncorenlp')
rdrsegmenter = py_vncorenlp.VnCoreNLP(annotators=["wseg"], save_dir='/absolute/path/to/vncorenlp')
text = "Ô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."
output = rdrsegmenter.word_segment(text)
print(output)
📚 詳細文檔
預訓練模型
模型名稱 |
參數數量 |
架構 |
最大長度 |
預訓練數據 |
vinai/phobert-base |
1.35 億 |
基礎版 |
256 |
20GB 的維基百科和新聞文本 |
vinai/phobert-large |
3.7 億 |
大型版 |
256 |
20GB 的維基百科和新聞文本 |
vinai/phobert-base-v2 |
1.35 億 |
基礎版 |
256 |
20GB 的維基百科和新聞文本 + 120GB 的 OSCAR - 2301 文本 |
🔧 技術細節
- PhoBERT 基於 RoBERTa 優化預訓練過程,以獲得更強大的性能。
- 在預訓練數據處理方面,使用了 RDRSegmenter 進行詞性標註、依存句法分析、命名實體識別和自然語言推理等任務。
📄 許可證
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/>.
⚠️ 重要提示
如果輸入文本是未分詞的原始文本,則必須先使用分詞器對文本進行分詞,然後再將其輸入到 PhoBERT 中。由於 PhoBERT 在預訓練數據處理中使用了 RDRSegmenter 進行詞性標註、依存句法分析、命名實體識別和自然語言推理等任務,因此建議在基於 PhoBERT 的下游應用中,對原始輸入文本也使用相同的分詞器。
💡 使用建議
在使用 PhoBERT 進行下游任務時,建議使用預訓練模型 vinai/phobert-base-v2
,因為它使用了更多的預訓練數據,性能可能更好。