lsmpp's picture
Add files using upload-large-folder tool
4cef5ec verified
<!--Copyright 2020 The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
โš ๏ธ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
rendered properly in your Markdown viewer.
-->
# BERT[[BERT]]
<div class="flex flex-wrap space-x-1">
<a href="https://huggingface.co/models?filter=bert">
<img alt="Models" src="https://img.shields.io/badge/All_model_pages-bert-blueviolet">
</a>
<a href="https://huggingface.co/spaces/docs-demos/bert-base-uncased">
<img alt="Spaces" src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue">
</a>
</div>
## ๊ฐœ์š”[[Overview]]
BERT ๋ชจ๋ธ์€ Jacob Devlin. Ming-Wei Chang, Kenton Lee, Kristina Touranova๊ฐ€ ์ œ์•ˆํ•œ ๋…ผ๋ฌธ [BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding](https://huggingface.co/papers/1810.04805)์—์„œ ์†Œ๊ฐœ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. BERT๋Š” ์‚ฌ์ „ ํ•™์Šต๋œ ์–‘๋ฐฉํ–ฅ ํŠธ๋žœ์Šคํฌ๋จธ๋กœ, Toronto Book Corpus์™€ Wikipedia๋กœ ๊ตฌ์„ฑ๋œ ๋Œ€๊ทœ๋ชจ ์ฝ”ํผ์Šค์—์„œ ๋งˆ์Šคํ‚น๋œ ์–ธ์–ด ๋ชจ๋ธ๋ง๊ณผ ๋‹ค์Œ ๋ฌธ์žฅ ์˜ˆ์ธก(Next Sentence Prediction) ๋ชฉํ‘œ๋ฅผ ๊ฒฐํ•ฉํ•ด ํ•™์Šต๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
ํ•ด๋‹น ๋…ผ๋ฌธ์˜ ์ดˆ๋ก์ž…๋‹ˆ๋‹ค:
*์šฐ๋ฆฌ๋Š” BERT(Bidirectional Encoder Representations from Transformers)๋ผ๋Š” ์ƒˆ๋กœ์šด ์–ธ์–ด ํ‘œํ˜„ ๋ชจ๋ธ์„ ์†Œ๊ฐœํ•ฉ๋‹ˆ๋‹ค. ์ตœ๊ทผ์˜ ๋‹ค๋ฅธ ์–ธ์–ด ํ‘œํ˜„ ๋ชจ๋ธ๋“ค๊ณผ ๋‹ฌ๋ฆฌ, BERT๋Š” ๋ชจ๋“  ๊ณ„์ธต์—์„œ ์–‘๋ฐฉํ–ฅ์œผ๋กœ ์–‘์ชฝ ๋ฌธ๋งฅ์„ ์กฐ๊ฑด์œผ๋กœ ์‚ฌ์šฉํ•˜์—ฌ ๋น„์ง€๋„ ํ•™์Šต๋œ ํ…์ŠคํŠธ์—์„œ ๊นŠ์ด ์žˆ๋Š” ์–‘๋ฐฉํ–ฅ ํ‘œํ˜„์„ ์‚ฌ์ „ ํ•™์Šตํ•˜๋„๋ก ์„ค๊ณ„๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ ๊ฒฐ๊ณผ, ์‚ฌ์ „ ํ•™์Šต๋œ BERT ๋ชจ๋ธ์€ ์ถ”๊ฐ€์ ์ธ ์ถœ๋ ฅ ๊ณ„์ธต ํ•˜๋‚˜๋งŒ์œผ๋กœ ์งˆ๋ฌธ ์‘๋‹ต, ์–ธ์–ด ์ถ”๋ก ๊ณผ ๊ฐ™์€ ๋‹ค์–‘ํ•œ ์ž‘์—…์—์„œ ๋ฏธ์„ธ ์กฐ์ •๋  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ, ํŠน์ • ์ž‘์—…์„ ์œ„ํ•ด ์•„ํ‚คํ…์ฒ˜๋ฅผ ์ˆ˜์ •ํ•  ํ•„์š”๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.*
*BERT๋Š” ๊ฐœ๋…์ ์œผ๋กœ ๋‹จ์ˆœํ•˜๋ฉด์„œ๋„ ์‹ค์ฆ์ ์œผ๋กœ ๊ฐ•๋ ฅํ•œ ๋ชจ๋ธ์ž…๋‹ˆ๋‹ค. BERT๋Š” 11๊ฐœ์˜ ์ž์—ฐ์–ด ์ฒ˜๋ฆฌ ๊ณผ์ œ์—์„œ ์ƒˆ๋กœ์šด ์ตœ๊ณ  ์„ฑ๋Šฅ์„ ๋‹ฌ์„ฑํ–ˆ์œผ๋ฉฐ, GLUE ์ ์ˆ˜๋ฅผ 80.5% (7.7% ํฌ์ธํŠธ ์ ˆ๋Œ€ ๊ฐœ์„ )๋กœ, MultiNLI ์ •ํ™•๋„๋ฅผ 86.7% (4.6% ํฌ์ธํŠธ ์ ˆ๋Œ€ ๊ฐœ์„ ), SQuAD v1.1 ์งˆ๋ฌธ ์‘๋‹ต ํ…Œ์ŠคํŠธ์—์„œ F1 ์ ์ˆ˜๋ฅผ 93.2 (1.5% ํฌ์ธํŠธ ์ ˆ๋Œ€ ๊ฐœ์„ )๋กœ, SQuAD v2.0์—์„œ F1 ์ ์ˆ˜๋ฅผ 83.1 (5.1% ํฌ์ธํŠธ ์ ˆ๋Œ€ ๊ฐœ์„ )๋กœ ํ–ฅ์ƒ์‹œ์ผฐ์Šต๋‹ˆ๋‹ค.*
์ด ๋ชจ๋ธ์€ [thomwolf](https://huggingface.co/thomwolf)๊ฐ€ ๊ธฐ์—ฌํ•˜์˜€์Šต๋‹ˆ๋‹ค. ์›๋ณธ ์ฝ”๋“œ๋Š” [์—ฌ๊ธฐ](https://github.com/google-research/bert)์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
## ์‚ฌ์šฉ ํŒ[[Usage tips]]
- BERT๋Š” ์ ˆ๋Œ€ ์œ„์น˜ ์ž„๋ฒ ๋”ฉ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ชจ๋ธ์ด๋ฏ€๋กœ ์ž…๋ ฅ์„ ์™ผ์ชฝ์ด ์•„๋‹ˆ๋ผ ์˜ค๋ฅธ์ชฝ์—์„œ ํŒจ๋”ฉํ•˜๋Š” ๊ฒƒ์ด ์ผ๋ฐ˜์ ์œผ๋กœ ๊ถŒ์žฅ๋ฉ๋‹ˆ๋‹ค.
- BERT๋Š” ๋งˆ์Šคํ‚น๋œ ์–ธ์–ด ๋ชจ๋ธ(MLM)๊ณผ Next Sentence Prediction(NSP) ๋ชฉํ‘œ๋กœ ํ•™์Šต๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ด๋Š” ๋งˆ์Šคํ‚น๋œ ํ† ํฐ ์˜ˆ์ธก๊ณผ ์ „๋ฐ˜์ ์ธ ์ž์—ฐ์–ด ์ดํ•ด(NLU)์— ๋›ฐ์–ด๋‚˜์ง€๋งŒ, ํ…์ŠคํŠธ ์ƒ์„ฑ์—๋Š” ์ตœ์ ํ™”๋˜์–ด์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
- BERT์˜ ์‚ฌ์ „ ํ•™์Šต ๊ณผ์ •์—์„œ๋Š” ์ž…๋ ฅ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฌด์ž‘์œ„๋กœ ๋งˆ์Šคํ‚นํ•˜์—ฌ ์ผ๋ถ€ ํ† ํฐ์„ ๋งˆ์Šคํ‚นํ•ฉ๋‹ˆ๋‹ค. ์ „์ฒด ํ† ํฐ ์ค‘ ์•ฝ 15%๊ฐ€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ ๋งˆ์Šคํ‚น๋ฉ๋‹ˆ๋‹ค:
* 80% ํ™•๋ฅ ๋กœ ๋งˆ์Šคํฌ ํ† ํฐ์œผ๋กœ ๋Œ€์ฒด
* 10% ํ™•๋ฅ ๋กœ ์ž„์˜์˜ ๋‹ค๋ฅธ ํ† ํฐ์œผ๋กœ ๋Œ€์ฒด
* 10% ํ™•๋ฅ ๋กœ ์›๋ž˜ ํ† ํฐ ๊ทธ๋Œ€๋กœ ์œ ์ง€
- ๋ชจ๋ธ์˜ ์ฃผ์š” ๋ชฉํ‘œ๋Š” ์›๋ณธ ๋ฌธ์žฅ์„ ์˜ˆ์ธกํ•˜๋Š” ๊ฒƒ์ด์ง€๋งŒ, ๋‘ ๋ฒˆ์งธ ๋ชฉํ‘œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค: ์ž…๋ ฅ์œผ๋กœ ๋ฌธ์žฅ A์™€ B (์‚ฌ์ด์—๋Š” ๊ตฌ๋ถ„ ํ† ํฐ์ด ์žˆ์Œ)๊ฐ€ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. ์ด ๋ฌธ์žฅ ์Œ์ด ์—ฐ์†๋  ํ™•๋ฅ ์€ 50%์ด๋ฉฐ, ๋‚˜๋จธ์ง€ 50%๋Š” ์„œ๋กœ ๋ฌด๊ด€ํ•œ ๋ฌธ์žฅ๋“ค์ž…๋‹ˆ๋‹ค. ๋ชจ๋ธ์€ ์ด ๋‘ ๋ฌธ์žฅ์ด ์•„๋‹Œ์ง€๋ฅผ ์˜ˆ์ธกํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
### Scaled Dot Product Attention(SDPA) ์‚ฌ์šฉํ•˜๊ธฐ [[Using Scaled Dot Product Attention (SDPA)]]
Pytorch๋Š” `torch.nn.functional`์˜ ์ผ๋ถ€๋กœ Scaled Dot Product Attention(SDPA) ์—ฐ์‚ฐ์ž๋ฅผ ๊ธฐ๋ณธ์ ์œผ๋กœ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์ด ํ•จ์ˆ˜๋Š” ์ž…๋ ฅ๊ณผ ํ•˜๋“œ์›จ์–ด์— ๋”ฐ๋ผ ์—ฌ๋Ÿฌ ๊ตฌํ˜„ ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ [๊ณต์‹ ๋ฌธ์„œ](https://pytorch.org/docs/stable/generated/torch.nn.functional.scaled_dot_product_attention.html)๋‚˜ [GPU Inference](https://huggingface.co/docs/transformers/main/en/perf_infer_gpu_one#pytorch-scaled-dot-product-attention)์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
`torch>=2.1.1`์—์„œ๋Š” ๊ตฌํ˜„์ด ๊ฐ€๋Šฅํ•œ ๊ฒฝ์šฐ SDPA๊ฐ€ ๊ธฐ๋ณธ์ ์œผ๋กœ ์‚ฌ์šฉ๋˜์ง€๋งŒ, `from_pretrained()`ํ•จ์ˆ˜์—์„œ `attn_implementation="sdpa"`๋ฅผ ์„ค์ •ํ•˜์—ฌ SDPA๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋„๋ก ์ง€์ •ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
```
from transformers import BertModel
model = BertModel.from_pretrained("bert-base-uncased", torch_dtype=torch.float16, attn_implementation="sdpa")
...
```
์ตœ์  ์„ฑ๋Šฅ ํ–ฅ์ƒ์„ ์œ„ํ•ด ๋ชจ๋ธ์„ ๋ฐ˜์ •๋ฐ€๋„(์˜ˆ: `torch.float16` ๋˜๋Š” `torch.bfloat16`)๋กœ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๊ฒƒ์„ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค.
๋กœ์ปฌ ๋ฒค์น˜๋งˆํฌ (A100-80GB, CPUx12, RAM 96.6GB, PyTorch 2.2.0, OS Ubuntu 22.04)์—์„œ `float16`์„ ์‚ฌ์šฉํ•ด ํ•™์Šต ๋ฐ ์ถ”๋ก ์„ ์ˆ˜ํ–‰ํ•œ ๊ฒฐ๊ณผ, ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์†๋„ ํ–ฅ์ƒ์ด ๊ด€์ฐฐ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
#### ํ•™์Šต [[Training]]
|batch_size|seq_len|Time per batch (eager - s)|Time per batch (sdpa - s)|Speedup (%)|Eager peak mem (MB)|sdpa peak mem (MB)|Mem saving (%)|
|----------|-------|--------------------------|-------------------------|-----------|-------------------|------------------|--------------|
|4 |256 |0.023 |0.017 |35.472 |939.213 |764.834 |22.800 |
|4 |512 |0.023 |0.018 |23.687 |1970.447 |1227.162 |60.569 |
|8 |256 |0.023 |0.018 |23.491 |1594.295 |1226.114 |30.028 |
|8 |512 |0.035 |0.025 |43.058 |3629.401 |2134.262 |70.054 |
|16 |256 |0.030 |0.024 |25.583 |2874.426 |2134.262 |34.680 |
|16 |512 |0.064 |0.044 |46.223 |6964.659 |3961.013 |75.830 |
#### ์ถ”๋ก  [[Inference]]
|batch_size|seq_len|Per token latency eager (ms)|Per token latency SDPA (ms)|Speedup (%)|Mem eager (MB)|Mem BT (MB)|Mem saved (%)|
|----------|-------|----------------------------|---------------------------|-----------|--------------|-----------|-------------|
|1 |128 |5.736 |4.987 |15.022 |282.661 |282.924 |-0.093 |
|1 |256 |5.689 |4.945 |15.055 |298.686 |298.948 |-0.088 |
|2 |128 |6.154 |4.982 |23.521 |314.523 |314.785 |-0.083 |
|2 |256 |6.201 |4.949 |25.303 |347.546 |347.033 |0.148 |
|4 |128 |6.049 |4.987 |21.305 |378.895 |379.301 |-0.107 |
|4 |256 |6.285 |5.364 |17.166 |443.209 |444.382 |-0.264 |
## ์ž๋ฃŒ[[Resources]]
BERT๋ฅผ ์‹œ์ž‘ํ•˜๋Š” ๋ฐ ๋„์›€์ด ๋˜๋Š” Hugging Face์™€ community ์ž๋ฃŒ ๋ชฉ๋ก(๐ŸŒŽ๋กœ ํ‘œ์‹œ๋จ) ์ž…๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์— ํฌํ•จ๋  ์ž๋ฃŒ๋ฅผ ์ œ์ถœํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด PR(Pull Request)๋ฅผ ์—ด์–ด์ฃผ์„ธ์š”. ๋ฆฌ๋ทฐ ํ•ด๋“œ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค! ์ž๋ฃŒ๋Š” ๊ธฐ์กด ์ž๋ฃŒ๋ฅผ ๋ณต์ œํ•˜๋Š” ๋Œ€์‹  ์ƒˆ๋กœ์šด ๋‚ด์šฉ์„ ๋‹ด๊ณ  ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
<PipelineTag pipeline="text-classification"/>
- [BERT ํ…์ŠคํŠธ ๋ถ„๋ฅ˜ (๋‹ค๋ฅธ ์–ธ์–ด๋กœ)](https://www.philschmid.de/bert-text-classification-in-a-different-language)์— ๋Œ€ํ•œ ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŠธ.
- [๋‹ค์ค‘ ๋ ˆ์ด๋ธ” ํ…์ŠคํŠธ ๋ถ„๋ฅ˜๋ฅผ ์œ„ํ•œ BERT (๋ฐ ๊ด€๋ จ ๋ชจ๋ธ) ๋ฏธ์„ธ ์กฐ์ •](https://colab.research.google.com/github/NielsRogge/Transformers-Tutorials/blob/master/BERT/Fine_tuning_BERT_(and_friends)_for_multi_label_text_classification.ipynb)์— ๋Œ€ํ•œ ๋…ธํŠธ๋ถ.
- [PyTorch๋ฅผ ์ด์šฉํ•ด BERT๋ฅผ ๋‹ค์ค‘ ๋ ˆ์ด๋ธ” ๋ถ„๋ฅ˜๋ฅผ ์œ„ํ•ด ๋ฏธ์„ธ ์กฐ์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•](htt๊ธฐps://colab.research.google.com/github/abhimishra91/transformers-tutorials/blob/master/transformers_multi_label_classification.ipynb)์— ๋Œ€ํ•œ ๋…ธํŠธ๋ถ. ๐ŸŒŽ
- [BERT๋กœ EncoderDecoder ๋ชจ๋ธ์„ warm-startํ•˜์—ฌ ์š”์•ฝํ•˜๊ธฐ](https://colab.research.google.com/github/patrickvonplaten/notebooks/blob/master/BERT2BERT_for_CNN_Dailymail.ipynb)์— ๋Œ€ํ•œ ๋…ธํŠธ๋ถ.
- [`BertForSequenceClassification`]์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](https://github.com/huggingface/transformers/tree/main/examples/pytorch/text-classification)์™€ [๋…ธํŠธ๋ถ](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/text_classification.ipynb)์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
- [`TFBertForSequenceClassification`]์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](https://github.com/huggingface/transformers/tree/main/examples/tensorflow/text-classification)์™€ [๋…ธํŠธ๋ถ](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/text_classification-tf.ipynb)์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
- [`FlaxBertForSequenceClassification`]์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](https://github.com/huggingface/transformers/tree/main/examples/flax/text-classification)์™€ [๋…ธํŠธ๋ถ](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/text_classification_flax.ipynb)์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
- [ํ…์ŠคํŠธ ๋ถ„๋ฅ˜ ์ž‘์—… ๊ฐ€์ด๋“œ](../tasks/sequence_classification)
<PipelineTag pipeline="token-classification"/>
- [Keras์™€ ํ•จ๊ป˜ Hugging Face Transformers๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋น„์˜๋ฆฌ BERT๋ฅผ ๊ฐœ์ฒด๋ช… ์ธ์‹(NER)์šฉ์œผ๋กœ ๋ฏธ์„ธ ์กฐ์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•](https://www.philschmid.de/huggingface-transformers-keras-tf)์— ๋Œ€ํ•œ ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŠธ.
- [BERT๋ฅผ ๊ฐœ์ฒด๋ช… ์ธ์‹์„ ์œ„ํ•ด ๋ฏธ์„ธ ์กฐ์ •ํ•˜๊ธฐ](https://colab.research.google.com/github/NielsRogge/Transformers-Tutorials/blob/master/BERT/Custom_Named_Entity_Recognition_with_BERT_only_first_wordpiece.ipynb)์— ๋Œ€ํ•œ ๋…ธํŠธ๋ถ. ๊ฐ ๋‹จ์–ด์˜ ์ฒซ ๋ฒˆ์งธ wordpiece์—๋งŒ ๋ ˆ์ด๋ธ”์„ ์ง€์ •ํ•˜์—ฌ ํ•™์Šตํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค. ๋ชจ๋“  wordpiece์— ๋ ˆ์ด๋ธ”์„ ์ „ํŒŒํ•˜๋Š” ๋ฐฉ๋ฒ•์€ [์ด ๋ฒ„์ „](https://github.com/NielsRogge/Transformers-Tutorials/blob/master/BERT/Custom_Named_Entity_Recognition_with_BERT.ipynb)์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
- [`BertForTokenClassification`]์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](https://github.com/huggingface/transformers/tree/main/examples/pytorch/token-classification)์™€ [๋…ธํŠธ๋ถ](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/token_classification.ipynb)์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
- [`TFBertForTokenClassification`]์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](https://github.com/huggingface/transformers/tree/main/examples/tensorflow/token-classification)์™€ [๋…ธํŠธ๋ถ](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/token_classification-tf.ipynb)์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
- [`FlaxBertForTokenClassification`]์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](https://github.com/huggingface/transformers/tree/main/examples/flax/token-classification)์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
- ๐Ÿค— Hugging Face ์ฝ”์Šค์˜ [ํ† ํฐ ๋ถ„๋ฅ˜ ์ฑ•ํ„ฐ](https://huggingface.co/course/chapter7/2?fw=pt).
- [ํ† ํฐ ๋ถ„๋ฅ˜ ์ž‘์—… ๊ฐ€์ด๋“œ](../tasks/token_classification)
<PipelineTag pipeline="fill-mask"/>
- [`BertForMaskedLM`]์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](https://github.com/huggingface/transformers/tree/main/examples/pytorch/language-modeling#robertabertdistilbert-and-masked-language-modeling)์™€ [๋…ธํŠธ๋ถ](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/language_modeling.ipynb)์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
- [`TFBertForMaskedLM`]์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](https://github.com/huggingface/transformers/tree/main/examples/tensorflow/language-modeling#run_mlmpy) ์™€ [๋…ธํŠธ๋ถ](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/language_modeling-tf.ipynb)์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
- [`FlaxBertForMaskedLM`]์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](https://github.com/huggingface/transformers/tree/main/examples/flax/language-modeling#masked-language-modeling)์™€ [๋…ธํŠธ๋ถ](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/masked_language_modeling_flax.ipynb)์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
- ๐Ÿค— Hugging Face ์ฝ”์Šค์˜ [๋งˆ์Šคํ‚น๋œ ์–ธ์–ด ๋ชจ๋ธ๋ง ์ฑ•ํ„ฐ](https://huggingface.co/course/chapter7/3?fw=pt).
- [๋งˆ์Šคํ‚น๋œ ์–ธ์–ด ๋ชจ๋ธ๋ง ์ž‘์—… ๊ฐ€์ด๋“œ](../tasks/masked_language_modeling)
<PipelineTag pipeline="question-answering"/>
- [`BertForQuestionAnswering`]์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](https://github.com/huggingface/transformers/tree/main/examples/pytorch/question-answering)์™€ [๋…ธํŠธ๋ถ](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/question_answering.ipynb)์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
- [`TFBertForQuestionAnswering`]์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](https://github.com/huggingface/transformers/tree/main/examples/tensorflow/question-answering) ์™€ [๋…ธํŠธ๋ถ](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/question_answering-tf.ipynb)์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
- [`FlaxBertForQuestionAnswering`]์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](https://github.com/huggingface/transformers/tree/main/examples/flax/question-answering)์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
- ๐Ÿค— Hugging Face ์ฝ”์Šค์˜ [์งˆ๋ฌธ ๋‹ต๋ณ€ ์ฑ•ํ„ฐ](https://huggingface.co/course/chapter7/7?fw=pt).
- [์งˆ๋ฌธ ๋‹ต๋ณ€ ์ž‘์—… ๊ฐ€์ด๋“œ](../tasks/question_answering)
**๋‹ค์ค‘ ์„ ํƒ**
- [`BertForMultipleChoice`]์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](https://github.com/huggingface/transformers/tree/main/examples/pytorch/multiple-choice)์™€ [๋…ธํŠธ๋ถ](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/multiple_choice.ipynb)์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
- [`TFBertForMultipleChoice`]์ด [์—์ œ ์Šคํฌ๋ฆฝํŠธ](https://github.com/huggingface/transformers/tree/main/examples/tensorflow/multiple-choice)์™€ [๋…ธํŠธ๋ถ](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/multiple_choice-tf.ipynb)์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
- [๋‹ค์ค‘ ์„ ํƒ ์ž‘์—… ๊ฐ€์ด๋“œ](../tasks/multiple_choice)
โšก๏ธ **์ถ”๋ก **
- [Hugging Face Transformers์™€ AWS Inferentia๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ BERT ์ถ”๋ก ์„ ๊ฐ€์†ํ™”ํ•˜๋Š” ๋ฐฉ๋ฒ•](https://huggingface.co/blog/bert-inferentia-sagemaker)์— ๋Œ€ํ•œ ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŠธ.
- [GPU์—์„œ DeepSpeed-Inference๋กœ BERT ์ถ”๋ก ์„ ๊ฐ€์†ํ™”ํ•˜๋Š” ๋ฐฉ๋ฒ•](https://www.philschmid.de/bert-deepspeed-inference)์— ๋Œ€ํ•œ ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŠธ.
โš™๏ธ **์‚ฌ์ „ ํ•™์Šต**
- [Hugging Face Optimum์œผ๋กœ Transformers๋ฅผ ONMX๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๋ฐฉ๋ฒ•](https://www.philschmid.de/pre-training-bert-habana)์— ๋Œ€ํ•œ ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŠธ.
๐Ÿš€ **๋ฐฐํฌ**
- [Hugging Face Optimum์œผ๋กœ Transformers๋ฅผ ONMX๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๋ฐฉ๋ฒ•](https://www.philschmid.de/convert-transformers-to-onnx)์— ๋Œ€ํ•œ ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŠธ.
- [AWS์—์„œ Hugging Face Transformers๋ฅผ ์œ„ํ•œ Habana Gaudi ๋”ฅ๋Ÿฌ๋‹ ํ™˜๊ฒฝ ์„ค์ • ๋ฐฉ๋ฒ•](https://www.philschmid.de/getting-started-habana-gaudi#conclusion)์— ๋Œ€ํ•œ ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŠธ.
- [Hugging Face Transformers, Amazon SageMaker ๋ฐ Terraform ๋ชจ๋“ˆ์„ ์ด์šฉํ•œ BERT ์ž๋™ ํ™•์žฅ](https://www.philschmid.de/terraform-huggingface-amazon-sagemaker-advanced)์— ๋Œ€ํ•œ ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŠธ.
- [Hugging Face, AWS Lambda, Docker๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์„œ๋ฒ„๋ฆฌ์Šค BERT ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•](https://www.philschmid.de/serverless-bert-with-huggingface-aws-lambda-docker)์— ๋Œ€ํ•œ ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŠธ.
- [Amazon SageMaker์™€ Training Compiler๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Hugging Face Transformers์—์„œ BERT ๋ฏธ์„ธ ์กฐ์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•](https://www.philschmid.de/huggingface-amazon-sagemaker-training-compiler)์— ๋Œ€ํ•œ ๋ธ”๋กœ๊ทธ.
- [Amazon SageMaker๋ฅผ ์‚ฌ์šฉํ•œ Transformers์™€ BERT์˜ ์ž‘์—…๋ณ„ ์ง€์‹ ์ฆ๋ฅ˜](https://www.philschmid.de/knowledge-distillation-bert-transformers)์— ๋Œ€ํ•œ ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŠธ.
## BertConfig
[[autodoc]] BertConfig
- all
## BertTokenizer
[[autodoc]] BertTokenizer
- build_inputs_with_special_tokens
- get_special_tokens_mask
- create_token_type_ids_from_sequences
- save_vocabulary
<frameworkcontent>
<pt>
## BertTokenizerFast
[[autodoc]] BertTokenizerFast
</pt>
<tf>
## TFBertTokenizer
[[autodoc]] TFBertTokenizer
</tf>
</frameworkcontent>
## Bert specific outputs
[[autodoc]] models.bert.modeling_bert.BertForPreTrainingOutput
[[autodoc]] models.bert.modeling_tf_bert.TFBertForPreTrainingOutput
[[autodoc]] models.bert.modeling_flax_bert.FlaxBertForPreTrainingOutput
<frameworkcontent>
<pt>
## BertModel
[[autodoc]] BertModel
- forward
## BertForPreTraining
[[autodoc]] BertForPreTraining
- forward
## BertLMHeadModel
[[autodoc]] BertLMHeadModel
- forward
## BertForMaskedLM
[[autodoc]] BertForMaskedLM
- forward
## BertForNextSentencePrediction
[[autodoc]] BertForNextSentencePrediction
- forward
## BertForSequenceClassification
[[autodoc]] BertForSequenceClassification
- forward
## BertForMultipleChoice
[[autodoc]] BertForMultipleChoice
- forward
## BertForTokenClassification
[[autodoc]] BertForTokenClassification
- forward
## BertForQuestionAnswering
[[autodoc]] BertForQuestionAnswering
- forward
</pt>
<tf>
## TFBertModel
[[autodoc]] TFBertModel
- call
## TFBertForPreTraining
[[autodoc]] TFBertForPreTraining
- call
## TFBertModelLMHeadModel
[[autodoc]] TFBertLMHeadModel
- call
## TFBertForMaskedLM
[[autodoc]] TFBertForMaskedLM
- call
## TFBertForNextSentencePrediction
[[autodoc]] TFBertForNextSentencePrediction
- call
## TFBertForSequenceClassification
[[autodoc]] TFBertForSequenceClassification
- call
## TFBertForMultipleChoice
[[autodoc]] TFBertForMultipleChoice
- call
## TFBertForTokenClassification
[[autodoc]] TFBertForTokenClassification
- call
## TFBertForQuestionAnswering
[[autodoc]] TFBertForQuestionAnswering
- call
</tf>
<jax>
## FlaxBertModel
[[autodoc]] FlaxBertModel
- __call__
## FlaxBertForPreTraining
[[autodoc]] FlaxBertForPreTraining
- __call__
## FlaxBertForCausalLM
[[autodoc]] FlaxBertForCausalLM
- __call__
## FlaxBertForMaskedLM
[[autodoc]] FlaxBertForMaskedLM
- __call__
## FlaxBertForNextSentencePrediction
[[autodoc]] FlaxBertForNextSentencePrediction
- __call__
## FlaxBertForSequenceClassification
[[autodoc]] FlaxBertForSequenceClassification
- __call__
## FlaxBertForMultipleChoice
[[autodoc]] FlaxBertForMultipleChoice
- __call__
## FlaxBertForTokenClassification
[[autodoc]] FlaxBertForTokenClassification
- __call__
## FlaxBertForQuestionAnswering
[[autodoc]] FlaxBertForQuestionAnswering
- __call__
</jax>
</frameworkcontent>