印尼语DistilBERT基础模型(无大小写)
模型描述
该模型是印尼语BERT基础模型的蒸馏版本。本模型为无大小写格式。
这是使用印尼语数据集预训练的若干语言模型之一。关于其在文本分类、文本生成等下游任务中的使用详情,请参阅基于Transformer的印尼语语言模型
使用范围与限制
使用方法
您可以直接使用该模型进行掩码语言建模:
>>> from transformers import pipeline
>>> unmasker = pipeline('fill-mask', model='cahya/distilbert-base-indonesian')
>>> unmasker("Ayahku sedang bekerja di sawah untuk [MASK] padi")
[
{
"sequence": "[CLS] ayahku sedang bekerja di sawah untuk menanam padi [SEP]",
"score": 0.6853187084197998,
"token": 12712,
"token_str": "menanam"
},
{
"sequence": "[CLS] ayahku sedang bekerja di sawah untuk bertani padi [SEP]",
"score": 0.03739545866847038,
"token": 15484,
"token_str": "bertani"
},
{
"sequence": "[CLS] ayahku sedang bekerja di sawah untuk memetik padi [SEP]",
"score": 0.02742469497025013,
"token": 30338,
"token_str": "memetik"
},
{
"sequence": "[CLS] ayahku sedang bekerja di sawah untuk penggilingan padi [SEP]",
"score": 0.02214187942445278,
"token": 28252,
"token_str": "penggilingan"
},
{
"sequence": "[CLS] ayahku sedang bekerja di sawah untuk tanam padi [SEP]",
"score": 0.0185895636677742,
"token": 11308,
"token_str": "tanam"
}
]
在PyTorch中获取文本特征的方法:
from transformers import DistilBertTokenizer, DistilBertModel
model_name='cahya/distilbert-base-indonesian'
tokenizer = DistilBertTokenizer.from_pretrained(model_name)
model = DistilBertModel.from_pretrained(model_name)
text = "Silakan diganti dengan text apa saja."
encoded_input = tokenizer(text, return_tensors='pt')
output = model(**encoded_input)
在Tensorflow中的使用方法:
from transformers import DistilBertTokenizer, TFDistilBertModel
model_name='cahya/distilbert-base-indonesian'
tokenizer = DistilBertTokenizer.from_pretrained(model_name)
model = TFDistilBertModel.from_pretrained(model_name)
text = "Silakan diganti dengan text apa saja."
encoded_input = tokenizer(text, return_tensors='tf')
output = model(encoded_input)
训练数据
该模型使用522MB的印尼语维基百科和1GB的印尼语报纸数据进行蒸馏训练。文本经过小写处理,并使用32,000词汇量的WordPiece进行分词。模型的输入格式为:
[CLS] 句子A [SEP] 句子B [SEP]