julien-c HF staff commited on
Commit
f3dba62
1 Parent(s): 99ff5a6

Migrate model card from transformers-repo

Browse files

Read announcement at https://discuss.huggingface.co/t/announcement-all-model-cards-will-be-migrated-to-hf-co-model-repos/2755
Original file history: https://github.com/huggingface/transformers/commits/master/model_cards/bert-base-multilingual-cased-README.md

Files changed (1) hide show
  1. README.md +152 -0
README.md ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: multilingual
3
+ license: apache-2.0
4
+ datasets:
5
+ - wikipedia
6
+ ---
7
+
8
+ # BERT multilingual base model (cased)
9
+
10
+ Pretrained model on the top 104 languages with the largest Wikipedia using a masked language modeling (MLM) objective.
11
+ It was introduced in [this paper](https://arxiv.org/abs/1810.04805) and first released in
12
+ [this repository](https://github.com/google-research/bert). This model is case sensitive: it makes a difference
13
+ between english and English.
14
+
15
+ Disclaimer: The team releasing BERT did not write a model card for this model so this model card has been written by
16
+ the Hugging Face team.
17
+
18
+ ## Model description
19
+
20
+ BERT is a transformers model pretrained on a large corpus of multilingual data in a self-supervised fashion. This means
21
+ it was pretrained on the raw texts only, with no humans labelling them in any way (which is why it can use lots of
22
+ publicly available data) with an automatic process to generate inputs and labels from those texts. More precisely, it
23
+ was pretrained with two objectives:
24
+
25
+ - Masked language modeling (MLM): taking a sentence, the model randomly masks 15% of the words in the input then run
26
+ the entire masked sentence through the model and has to predict the masked words. This is different from traditional
27
+ recurrent neural networks (RNNs) that usually see the words one after the other, or from autoregressive models like
28
+ GPT which internally mask the future tokens. It allows the model to learn a bidirectional representation of the
29
+ sentence.
30
+ - Next sentence prediction (NSP): the models concatenates two masked sentences as inputs during pretraining. Sometimes
31
+ they correspond to sentences that were next to each other in the original text, sometimes not. The model then has to
32
+ predict if the two sentences were following each other or not.
33
+
34
+ This way, the model learns an inner representation of the languages in the training set that can then be used to
35
+ extract features useful for downstream tasks: if you have a dataset of labeled sentences for instance, you can train a
36
+ standard classifier using the features produced by the BERT model as inputs.
37
+
38
+ ## Intended uses & limitations
39
+
40
+ You can use the raw model for either masked language modeling or next sentence prediction, but it's mostly intended to
41
+ be fine-tuned on a downstream task. See the [model hub](https://huggingface.co/models?filter=bert) to look for
42
+ fine-tuned versions on a task that interests you.
43
+
44
+ Note that this model is primarily aimed at being fine-tuned on tasks that use the whole sentence (potentially masked)
45
+ to make decisions, such as sequence classification, token classification or question answering. For tasks such as text
46
+ generation you should look at model like GPT2.
47
+
48
+ ### How to use
49
+
50
+ You can use this model directly with a pipeline for masked language modeling:
51
+
52
+ ```python
53
+ >>> from transformers import pipeline
54
+ >>> unmasker = pipeline('fill-mask', model='bert-base-multilingual-cased')
55
+ >>> unmasker("Hello I'm a [MASK] model.")
56
+
57
+ [{'sequence': "[CLS] Hello I'm a model model. [SEP]",
58
+ 'score': 0.10182085633277893,
59
+ 'token': 13192,
60
+ 'token_str': 'model'},
61
+ {'sequence': "[CLS] Hello I'm a world model. [SEP]",
62
+ 'score': 0.052126359194517136,
63
+ 'token': 11356,
64
+ 'token_str': 'world'},
65
+ {'sequence': "[CLS] Hello I'm a data model. [SEP]",
66
+ 'score': 0.048930276185274124,
67
+ 'token': 11165,
68
+ 'token_str': 'data'},
69
+ {'sequence': "[CLS] Hello I'm a flight model. [SEP]",
70
+ 'score': 0.02036019042134285,
71
+ 'token': 23578,
72
+ 'token_str': 'flight'},
73
+ {'sequence': "[CLS] Hello I'm a business model. [SEP]",
74
+ 'score': 0.020079681649804115,
75
+ 'token': 14155,
76
+ 'token_str': 'business'}]
77
+ ```
78
+
79
+ Here is how to use this model to get the features of a given text in PyTorch:
80
+
81
+ ```python
82
+ from transformers import BertTokenizer, BertModel
83
+ tokenizer = BertTokenizer.from_pretrained('bert-base-multilingual-cased')
84
+ model = BertModel.from_pretrained("bert-base-multilingual-cased")
85
+ text = "Replace me by any text you'd like."
86
+ encoded_input = tokenizer(text, return_tensors='pt')
87
+ output = model(**encoded_input)
88
+ ```
89
+
90
+ and in TensorFlow:
91
+
92
+ ```python
93
+ from transformers import BertTokenizer, TFBertModel
94
+ tokenizer = BertTokenizer.from_pretrained('bert-base-multilingual-cased')
95
+ model = TFBertModel.from_pretrained("bert-base-multilingual-cased")
96
+ text = "Replace me by any text you'd like."
97
+ encoded_input = tokenizer(text, return_tensors='tf')
98
+ output = model(encoded_input)
99
+ ```
100
+
101
+ ## Training data
102
+
103
+ The BERT model was pretrained on the 104 languages with the largest Wikipedias. You can find the complete list
104
+ [here](https://github.com/google-research/bert/blob/master/multilingual.md#list-of-languages).
105
+
106
+ ## Training procedure
107
+
108
+ ### Preprocessing
109
+
110
+ The texts are lowercased and tokenized using WordPiece and a shared vocabulary size of 110,000. The languages with a
111
+ larger Wikipedia are under-sampled and the ones with lower resources are oversampled. For languages like Chinese,
112
+ Japanese Kanji and Korean Hanja that don't have space, a CJK Unicode block is added around every character.
113
+
114
+ The inputs of the model are then of the form:
115
+
116
+ ```
117
+ [CLS] Sentence A [SEP] Sentence B [SEP]
118
+ ```
119
+
120
+ With probability 0.5, sentence A and sentence B correspond to two consecutive sentences in the original corpus and in
121
+ the other cases, it's another random sentence in the corpus. Note that what is considered a sentence here is a
122
+ consecutive span of text usually longer than a single sentence. The only constrain is that the result with the two
123
+ "sentences" has a combined length of less than 512 tokens.
124
+
125
+ The details of the masking procedure for each sentence are the following:
126
+ - 15% of the tokens are masked.
127
+ - In 80% of the cases, the masked tokens are replaced by `[MASK]`.
128
+ - In 10% of the cases, the masked tokens are replaced by a random token (different) from the one they replace.
129
+ - In the 10% remaining cases, the masked tokens are left as is.
130
+
131
+
132
+ ### BibTeX entry and citation info
133
+
134
+ ```bibtex
135
+ @article{DBLP:journals/corr/abs-1810-04805,
136
+ author = {Jacob Devlin and
137
+ Ming{-}Wei Chang and
138
+ Kenton Lee and
139
+ Kristina Toutanova},
140
+ title = {{BERT:} Pre-training of Deep Bidirectional Transformers for Language
141
+ Understanding},
142
+ journal = {CoRR},
143
+ volume = {abs/1810.04805},
144
+ year = {2018},
145
+ url = {http://arxiv.org/abs/1810.04805},
146
+ archivePrefix = {arXiv},
147
+ eprint = {1810.04805},
148
+ timestamp = {Tue, 30 Oct 2018 20:39:56 +0100},
149
+ biburl = {https://dblp.org/rec/journals/corr/abs-1810-04805.bib},
150
+ bibsource = {dblp computer science bibliography, https://dblp.org}
151
+ }
152
+ ```