モデル概要
モデル特徴
モデル能力
使用事例
🚀 CAMeLBERT: アラビア語の自然言語処理タスク用の事前学習モデルコレクション
CAMeLBERTは、様々なサイズとバリエーションのアラビア語テキストで事前学習されたBERTモデルのコレクションです。現代標準アラビア語(MSA)、方言アラビア語(DA)、古典アラビア語(CA)用の事前学習言語モデルを公開しており、さらにこれら3つの混合データで事前学習されたモデルも提供しています。また、MSAバリエーションの縮小版(半分、4分の1、8分の1、16分の1)で事前学習された追加モデルも用意しています。詳細は論文 "The Interplay of Variant, Size, and Task Type in Arabic Pre-trained Language Models" で説明されています。
このモデルカードでは、CAMeLBERT-MSA-sixteenth (bert-base-arabic-camelbert-msa-sixteenth
)、つまり全MSAデータセットの16分の1で事前学習されたモデルについて説明します。
✨ 主な機能
モデルの多様性
異なるサイズとバリエーションのアラビア語テキストで事前学習された複数のBERTモデルを提供しています。
タスクへの適用性
マスク言語モデリングや次文予測に使用でき、NER、POSタグ付け、センチメント分析、方言識別、詩分類などのNLPタスクに微調整することもできます。
🚀 クイックスタート
このモデルは、マスク言語モデリングのパイプラインで直接使用できます。また、与えられたテキストの特徴を取得することもできます。以下にPythonとTensorFlowでの使用例を示します。
💻 使用例
基本的な使用法
マスク言語モデリングのパイプラインでの使用例:
>>> from transformers import pipeline
>>> unmasker = pipeline('fill-mask', model='CAMeL-Lab/bert-base-arabic-camelbert-msa-sixteenth')
>>> unmasker("الهدف من الحياة هو [MASK] .")
[{'sequence': '[CLS] الهدف من الحياة هو التغيير. [SEP]',
'score': 0.08320745080709457,
'token': 7946,
'token_str': 'التغيير'},
{'sequence': '[CLS] الهدف من الحياة هو التعلم. [SEP]',
'score': 0.04305094853043556,
'token': 12554,
'token_str': 'التعلم'},
{'sequence': '[CLS] الهدف من الحياة هو العمل. [SEP]',
'score': 0.0417640283703804,
'token': 2854,
'token_str': 'العمل'},
{'sequence': '[CLS] الهدف من الحياة هو الحياة. [SEP]',
'score': 0.041371218860149384,
'token': 3696,
'token_str': 'الحياة'},
{'sequence': '[CLS] الهدف من الحياة هو المعرفة. [SEP]',
'score': 0.039794355630874634,
'token': 7344,
'token_str': 'المعرفة'}]
注意: モデルをダウンロードするには、transformers>=3.5.0
が必要です。それ以外の場合は、手動でモデルをダウンロードすることができます。
高度な使用法
与えられたテキストの特徴を取得する例:
PyTorchでの使用
from transformers import AutoTokenizer, AutoModel
tokenizer = AutoTokenizer.from_pretrained('CAMeL-Lab/bert-base-arabic-camelbert-msa-sixteenth')
model = AutoModel.from_pretrained('CAMeL-Lab/bert-base-arabic-camelbert-msa-sixteenth')
text = "مرحبا يا عالم."
encoded_input = tokenizer(text, return_tensors='pt')
output = model(**encoded_input)
TensorFlowでの使用
from transformers import AutoTokenizer, TFAutoModel
tokenizer = AutoTokenizer.from_pretrained('CAMeL-Lab/bert-base-arabic-camelbert-msa-sixteenth')
model = TFAutoModel.from_pretrained('CAMeL-Lab/bert-base-arabic-camelbert-msa-sixteenth')
text = "مرحبا يا عالم."
encoded_input = tokenizer(text, return_tensors='tf')
output = model(encoded_input)
📚 ドキュメント
モデルの詳細
モデル | バリエーション | サイズ | 単語数 | |
---|---|---|---|---|
bert-base-arabic-camelbert-mix |
CA,DA,MSA | 167GB | 17.3B | |
bert-base-arabic-camelbert-ca |
CA | 6GB | 847M | |
bert-base-arabic-camelbert-da |
DA | 54GB | 5.8B | |
bert-base-arabic-camelbert-msa |
MSA | 107GB | 12.6B | |
bert-base-arabic-camelbert-msa-half |
MSA | 53GB | 6.3B | |
bert-base-arabic-camelbert-msa-quarter |
MSA | 27GB | 3.1B | |
bert-base-arabic-camelbert-msa-eighth |
MSA | 14GB | 1.6B | |
✔ | bert-base-arabic-camelbert-msa-sixteenth |
MSA | 6GB | 746M |
学習データ
- MSA(現代標準アラビア語)
- The Arabic Gigaword Fifth Edition
- Abu El-Khair Corpus
- OSIAN corpus
- Arabic Wikipedia
- アラビア語のOSCARコーパスのシャッフルされていないバージョン
学習手順
Googleが公開した元の実装を使用して事前学習を行いました。特に指定がない限り、元の英語のBERTモデルのハイパーパラメータを使用して事前学習を行いました。
前処理
- 各コーパスから生テキストを抽出した後、以下の前処理を適用します。
- 元のBERT実装が提供するユーティリティを使用して、無効な文字を削除し、空白を正規化します。
- アラビア文字が含まれない行を削除します。
- CAMeL Toolsを使用して、ダイアクリティックとカシダを削除します。
- 最後に、ヒューリスティックベースの文分割器を使用して、各行を文に分割します。
- HuggingFaceのトークナイザーを使用して、全データセット(167GBのテキスト)で語彙サイズ30,000のWordPieceトークナイザーを学習させます。
- 小文字化やアクセントの削除は行いません。
事前学習
- モデルは、単一のクラウドTPU (
v3-8
) で合計100万ステップ学習されました。 - 最初の90,000ステップはバッチサイズ1,024で学習され、残りはバッチサイズ256で学習されました。
- シーケンス長は、90%のステップで128トークンに制限され、残りの10%では512トークンに制限されました。
- ホールワードマスキングと重複係数10を使用します。
- 最大シーケンス長が128トークンのデータセットでは、シーケンスあたりの最大予測数を20に設定し、最大シーケンス長が512トークンのデータセットでは80に設定します。
- 乱数シードは12345、マスク言語モデルの確率は0.15、短いシーケンスの確率は0.1を使用します。
- 使用されるオプティマイザはAdamで、学習率は1e-4、\(\beta_{1} = 0.9\)、\(\beta_{2} = 0.999\)、重み減衰は0.01、学習率のウォームアップは10,000ステップ、その後は学習率の線形減衰を使用します。
評価結果
- 事前学習された言語モデルを、NER、POSタグ付け、センチメント分析、方言識別、詩分類の5つのNLPタスクで評価しました。
- 12のデータセットを使用してモデルを微調整し、評価しました。
- Hugging Faceのtransformersを使用して、CAMeLBERTモデルを微調整しました。
- transformers
v3.1.0
とPyTorchv1.5.1
を使用しました。 - 微調整は、最後の隠れ層に全結合線形層を追加することで行いました。
- すべてのタスクで\(F_{1}\)スコアを指標として使用します。
- 微調整に使用されるコードはこちらで入手できます。
結果
タスク | データセット | バリエーション | 混合 | CA | DA | MSA | MSA-1/2 | MSA-1/4 | MSA-1/8 | MSA-1/16 |
---|---|---|---|---|---|---|---|---|---|---|
NER | ANERcorp | MSA | 80.8% | 67.9% | 74.1% | 82.4% | 82.0% | 82.1% | 82.6% | 80.8% |
POS | PATB (MSA) | MSA | 98.1% | 97.8% | 97.7% | 98.3% | 98.2% | 98.3% | 98.2% | 98.2% |
ARZTB (EGY) | DA | 93.6% | 92.3% | 92.7% | 93.6% | 93.6% | 93.7% | 93.6% | 93.6% | |
Gumar (GLF) | DA | 97.3% | 97.7% | 97.9% | 97.9% | 97.9% | 97.9% | 97.9% | 97.9% | |
SA | ASTD | MSA | 76.3% | 69.4% | 74.6% | 76.9% | 76.0% | 76.8% | 76.7% | 75.3% |
ArSAS | MSA | 92.7% | 89.4% | 91.8% | 93.0% | 92.6% | 92.5% | 92.5% | 92.3% | |
SemEval | MSA | 69.0% | 58.5% | 68.4% | 72.1% | 70.7% | 72.8% | 71.6% | 71.2% | |
DID | MADAR-26 | DA | 62.9% | 61.9% | 61.8% | 62.6% | 62.0% | 62.8% | 62.0% | 62.2% |
MADAR-6 | DA | 92.5% | 91.5% | 92.2% | 91.9% | 91.8% | 92.2% | 92.1% | 92.0% | |
MADAR-Twitter-5 | MSA | 75.7% | 71.4% | 74.2% | 77.6% | 78.5% | 77.3% | 77.7% | 76.2% | |
NADI | DA | 24.7% | 17.3% | 20.1% | 24.9% | 24.6% | 24.6% | 24.9% | 23.8% | |
詩分類 | APCD | CA | 79.8% | 80.9% | 79.6% | 79.7% | 79.9% | 80.0% | 79.7% | 79.8% |
結果(平均)
バリエーション | 混合 | CA | DA | MSA | MSA-1/2 | MSA-1/4 | MSA-1/8 | MSA-1/16 | |
---|---|---|---|---|---|---|---|---|---|
バリエーションごとの平均[1] | MSA | 82.1% | 75.7% | 80.1% | 83.4% | 83.0% | 83.3% | 83.2% | 82.3% |
DA | 74.4% | 72.1% | 72.9% | 74.2% | 74.0% | 74.3% | 74.1% | 73.9% | |
CA | 79.8% | 80.9% | 79.6% | 79.7% | 79.9% | 80.0% | 79.7% | 79.8% | |
マクロ平均 | すべて | 78.7% | 74.7% | 77.1% | 79.2% | 79.0% | 79.2% | 79.1% | 78.6% |
[1]: バリエーションごとの平均は、同じ言語バリエーションのタスクグループの平均を指します。
謝辞
この研究は、GoogleのTensorFlow Research Cloud (TFRC) から提供されたクラウドTPUによって支援されました。
📄 ライセンス
このモデルはApache-2.0ライセンスの下で提供されています。
引用
@inproceedings{inoue-etal-2021-interplay,
title = "The Interplay of Variant, Size, and Task Type in {A}rabic Pre-trained Language Models",
author = "Inoue, Go and
Alhafni, Bashar and
Baimukan, Nurpeiis and
Bouamor, Houda and
Habash, Nizar",
booktitle = "Proceedings of the Sixth Arabic Natural Language Processing Workshop",
month = apr,
year = "2021",
address = "Kyiv, Ukraine (Online)",
publisher = "Association for Computational Linguistics",
abstract = "In this paper, we explore the effects of language variants, data sizes, and fine-tuning task types in Arabic pre-trained language models. To do so, we build three pre-trained language models across three variants of Arabic: Modern Standard Arabic (MSA), dialectal Arabic, and classical Arabic, in addition to a fourth language model which is pre-trained on a mix of the three. We also examine the importance of pre-training data size by building additional models that are pre-trained on a scaled-down set of the MSA variant. We compare our different models to each other, as well as to eight publicly available models by fine-tuning them on five NLP tasks spanning 12 datasets. Our results suggest that the variant proximity of pre-training data to fine-tuning data is more important than the pre-training data size. We exploit this insight in defining an optimized system selection model for the studied tasks.",
}



