AbdulElahGwaith's picture
Upload folder using huggingface_hub
a9bd396 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.
-->
<div style="float: right;">
<div class="flex flex-wrap space-x-1">
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white" >
<img alt= "TensorFlow" src= "https://img.shields.io/badge/TensorFlow-FF6F00?style=flat&logo=tensorflow&logoColor=white" >
<img alt= "Flax" src="https://img.shields.io/badge/Flax-29a79b.svg?styleโ€ฆNu+W0m6K/I9gGPd/dfx/EN/wN62AhsBWuAAAAAElFTkSuQmCC">
<img alt="SDPA" src= "https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white" >
</div>
</div>
# ALBERT[[albert]]
[ALBERT](https://huggingface.co/papers/1909.11942)๋Š” [BERT](./bert)์˜ ํ™•์žฅ์„ฑ๊ณผ ํ•™์Šต ์‹œ ๋ฉ”๋ชจ๋ฆฌ ํ•œ๊ณ„๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ์„ค๊ณ„๋œ ๋ชจ๋ธ์ž…๋‹ˆ๋‹ค. ์ด ๋ชจ๋ธ์€ ๋‘ ๊ฐ€์ง€ ํŒŒ๋ผ๋ฏธํ„ฐ ๊ฐ์†Œ ๊ธฐ๋ฒ•์„ ๋„์ž…ํ•ฉ๋‹ˆ๋‹ค. ์ฒซ ๋ฒˆ์งธ๋Š” ์ž„๋ฒ ๋”ฉ ํ–‰๋ ฌ ๋ถ„ํ•ด(factorized embedding parametrization)๋กœ, ํฐ ์–ดํœ˜ ์ž„๋ฒ ๋”ฉ ํ–‰๋ ฌ์„ ๋‘ ๊ฐœ์˜ ์ž‘์€ ํ–‰๋ ฌ๋กœ ๋ถ„ํ•ดํ•˜์—ฌ ํžˆ๋“  ์‚ฌ์ด์ฆˆ๋ฅผ ๋Š˜๋ ค๋„ ํŒŒ๋ผ๋ฏธํ„ฐ ์ˆ˜๊ฐ€ ํฌ๊ฒŒ ์ฆ๊ฐ€ํ•˜์ง€ ์•Š๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. ๋‘ ๋ฒˆ์งธ๋Š” ๊ณ„์ธต ๊ฐ„ ํŒŒ๋ผ๋ฏธํ„ฐ ๊ณต์œ (cross-layer parameter sharing)๋กœ, ์—ฌ๋Ÿฌ ๊ณ„์ธต์ด ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๊ณต์œ ํ•˜์—ฌ ํ•™์Šตํ•ด์•ผ ํ•  ํŒŒ๋ผ๋ฏธํ„ฐ ์ˆ˜๋ฅผ ์ค„์ž…๋‹ˆ๋‹ค.
ALBERT๋Š” BERT์—์„œ ๋ฐœ์ƒํ•˜๋Š” GPU/TPU ๋ฉ”๋ชจ๋ฆฌ ํ•œ๊ณ„, ๊ธด ํ•™์Šต ์‹œ๊ฐ„, ๊ฐ‘์ž‘์Šค๋Ÿฐ ์„ฑ๋Šฅ ์ €ํ•˜ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ๋งŒ๋“ค์–ด์กŒ์Šต๋‹ˆ๋‹ค. ALBERT๋Š” ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์ค„์ด๊ธฐ ์œ„ํ•ด ๋‘ ๊ฐ€์ง€ ๊ธฐ๋ฒ•์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ๋Ÿ‰์„ ์ค„์ด๊ณ  BERT์˜ ํ•™์Šต ์†๋„๋ฅผ ๋†’์ž…๋‹ˆ๋‹ค:
- **์ž„๋ฒ ๋”ฉ ํ–‰๋ ฌ ๋ถ„ํ•ด:** ํฐ ์–ดํœ˜ ์ž„๋ฒ ๋”ฉ ํ–‰๋ ฌ์„ ๋‘ ๊ฐœ์˜ ๋” ์ž‘์€ ํ–‰๋ ฌ๋กœ ๋ถ„ํ•ดํ•˜์—ฌ ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ๋Ÿ‰์„ ์ค„์ž…๋‹ˆ๋‹ค.
- **๊ณ„์ธต ๊ฐ„ ํŒŒ๋ผ๋ฏธํ„ฐ ๊ณต์œ :** ๊ฐ ํŠธ๋žœ์Šคํฌ๋จธ ๊ณ„์ธต๋งˆ๋‹ค ๋ณ„๋„์˜ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ํ•™์Šตํ•˜๋Š” ๋Œ€์‹ , ์—ฌ๋Ÿฌ ๊ณ„์ธต์ด ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๊ณต์œ ํ•˜์—ฌ ํ•™์Šตํ•ด์•ผ ํ•  ๊ฐ€์ค‘์น˜ ์ˆ˜๋ฅผ ๋”์šฑ ์ค„์ž…๋‹ˆ๋‹ค.
ALBERT๋Š” BERT์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ ˆ๋Œ€ ์œ„์น˜ ์ž„๋ฒ ๋”ฉ(absolute position embeddings)์„ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ, ์ž…๋ ฅ ํŒจ๋”ฉ์€ ์˜ค๋ฅธ์ชฝ์— ์ ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ž„๋ฒ ๋”ฉ ํฌ๊ธฐ๋Š” 128์ด๋ฉฐ, BERT์˜ 768๋ณด๋‹ค ์ž‘์Šต๋‹ˆ๋‹ค. ALBERT๋Š” ํ•œ ๋ฒˆ์— ์ตœ๋Œ€ 512๊ฐœ์˜ ํ† ํฐ์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๋ชจ๋“  ๊ณต์‹ ALBERT ์ฒดํฌํฌ์ธํŠธ๋Š” [ALBERT ์ปค๋ฎค๋‹ˆํ‹ฐ](https://huggingface.co/albert) ์กฐ์ง์—์„œ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
> [!TIP]
> ์˜ค๋ฅธ์ชฝ ์‚ฌ์ด๋“œ๋ฐ”์˜ ALBERT ๋ชจ๋ธ์„ ํด๋ฆญํ•˜์‹œ๋ฉด ๋‹ค์–‘ํ•œ ์–ธ์–ด ์ž‘์—…์— ALBERT๋ฅผ ์ ์šฉํ•˜๋Š” ์˜ˆ์‹œ๋ฅผ ๋” ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์•„๋ž˜ ์˜ˆ์‹œ๋Š” [`Pipeline`], [`AutoModel`] ๊ทธ๋ฆฌ๊ณ  ์ปค๋งจ๋“œ๋ผ์ธ์—์„œ `[MASK]` ํ† ํฐ์„ ์˜ˆ์ธกํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.
<hfoptions id="usage">
<hfoption id="Pipeline">
```py
import torch
from transformers import pipeline
pipeline = pipeline(
task="fill-mask",
model="albert-base-v2",
dtype=torch.float16,
device=0
)
pipeline("์‹๋ฌผ์€ ๊ด‘ํ•ฉ์„ฑ์ด๋ผ๊ณ  ์•Œ๋ ค์ง„ ๊ณผ์ •์„ ํ†ตํ•ด [MASK]๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.", top_k=5)
```
</hfoption>
<hfoption id="AutoModel">
```py
import torch
from transformers import AutoModelForMaskedLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("albert/albert-base-v2")
model = AutoModelForMaskedLM.from_pretrained(
"albert/albert-base-v2",
dtype=torch.float16,
attn_implementation="sdpa",
device_map="auto"
)
prompt = "์‹๋ฌผ์€ [MASK]์ด๋ผ๊ณ  ์•Œ๋ ค์ง„ ๊ณผ์ •์„ ํ†ตํ•ด ์—๋„ˆ์ง€๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค."
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model(**inputs)
mask_token_index = torch.where(inputs["input_ids"] == tokenizer.mask_token_id)[1]
predictions = outputs.logits[0, mask_token_index]
top_k = torch.topk(predictions, k=5).indices.tolist()
for token_id in top_k[0]:
print(f"์˜ˆ์ธก: {tokenizer.decode([token_id])}")
```
</hfoption>
<hfoption id="transformers CLI">
```bash
echo -e "Plants create [MASK] through a process known as photosynthesis." | transformers run --task fill-mask --model albert-base-v2 --device 0
```
</hfoption>
</hfoptions>
## ์ฐธ๊ณ  ์‚ฌํ•ญ[[notes]]
- BERT๋Š” ์ ˆ๋Œ€ ์œ„์น˜ ์ž„๋ฒ ๋”ฉ์„ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ, ์˜ค๋ฅธ์ชฝ์— ์ž…๋ ฅ์ด ํŒจ๋”ฉ๋ผ์•ผ ํ•ฉ๋‹ˆ๋‹ค.
- ์ž„๋ฒ ๋”ฉ ํฌ๊ธฐ `E`๋Š” ํžˆ๋“  ํฌ๊ธฐ `H`์™€ ๋‹ค๋ฆ…๋‹ˆ๋‹ค. ์ž„๋ฒ ๋”ฉ์€ ๋ฌธ๋งฅ์— ๋…๋ฆฝ์ (๊ฐ ํ† ํฐ๋งˆ๋‹ค ํ•˜๋‚˜์˜ ์ž„๋ฒ ๋”ฉ ๋ฒกํ„ฐ)์ด๊ณ , ์€๋‹‰ ์ƒํƒœ๋Š” ๋ฌธ๋งฅ์— ์˜์กด์ (ํ† ํฐ ์‹œํ€€์Šค๋งˆ๋‹ค ํ•˜๋‚˜์˜ ์€๋‹‰ ์ƒํƒœ)์ž…๋‹ˆ๋‹ค. ์ž„๋ฒ ๋”ฉ ํ–‰๋ ฌ์€ `V x E`(V: ์–ดํœ˜ ํฌ๊ธฐ)์ด๋ฏ€๋กœ, ์ผ๋ฐ˜์ ์œผ๋กœ `H >> E`๊ฐ€ ๋” ๋…ผ๋ฆฌ์ ์ž…๋‹ˆ๋‹ค. `E < H`์ผ ๋•Œ ๋ชจ๋ธ ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ๋” ์ ์–ด์ง‘๋‹ˆ๋‹ค.
## ์ฐธ๊ณ  ์ž๋ฃŒ[[resources]]
์•„๋ž˜ ์„น์…˜์˜ ์ž๋ฃŒ๋“ค์€ ๊ณต์‹ Hugging Face ๋ฐ ์ปค๋ฎค๋‹ˆํ‹ฐ(๐ŸŒŽ ํ‘œ์‹œ) ์ž๋ฃŒ๋กœ, AlBERT๋ฅผ ์‹œ์ž‘ํ•˜๋Š” ๋ฐ ๋„์›€์ด ๋ฉ๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์— ์ถ”๊ฐ€ํ•  ์ž๋ฃŒ๊ฐ€ ์žˆ๋‹ค๋ฉด Pull Request๋ฅผ ๋ณด๋‚ด์ฃผ์„ธ์š”! ๊ธฐ์กด ์ž๋ฃŒ์™€ ์ค‘๋ณต๋˜์ง€ ์•Š๊ณ  ์ƒˆ๋กœ์šด ๋‚ด์šฉ์„ ๋‹ด๊ณ  ์žˆ์œผ๋ฉด ์ข‹์Šต๋‹ˆ๋‹ค.
<PipelineTag pipeline="text-classification"/>
- [`AlbertForSequenceClassification`]์€ ์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](https://github.com/huggingface/transformers/tree/main/examples/pytorch/text-classification)์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
- [`TFAlbertForSequenceClassification`]์€ ์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](https://github.com/huggingface/transformers/tree/main/examples/tensorflow/text-classification)์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
- [`FlaxAlbertForSequenceClassification`]์€ ์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](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"/>
- [`AlbertForTokenClassification`]์€ ์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](https://github.com/huggingface/transformers/tree/main/examples/pytorch/token-classification)์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
- [`TFAlbertForTokenClassification`]์€ ์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](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)์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
- [`FlaxAlbertForTokenClassification`]์€ ์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](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"/>
- [`AlbertForMaskedLM`]์€ ์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](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)์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
- [`TFAlbertForMaskedLM`]์€ ์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](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)์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
- [`FlaxAlbertForMaskedLM`]์€ ์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](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"/>
- [`AlbertForQuestionAnswering`]์€ ์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](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)์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
- [`TFAlbertForQuestionAnswering`]์€ ์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](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)์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
- [`FlaxAlbertForQuestionAnswering`]์€ ์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](https://github.com/huggingface/transformers/tree/main/examples/flax/question-answering)์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
- [์งˆ์˜์‘๋‹ต](https://huggingface.co/course/chapter7/7?fw=pt) ๐Ÿค— Hugging Face ๊ฐ•์ขŒ์˜ ์ฑ•ํ„ฐ.
- [์งˆ์˜์‘๋‹ต ์ž‘์—… ๊ฐ€์ด๋“œ](../tasks/question_answering)์—์„œ ๋ชจ๋ธ ์‚ฌ์šฉ๋ฒ•์„ ํ™•์ธํ•˜์„ธ์š”.
**๋‹ค์ค‘ ์„ ํƒ(Multiple choice)**
- [`AlbertForMultipleChoice`]๋Š” ์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](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)์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
- [`TFAlbertForMultipleChoice`]๋Š” ์ด [์˜ˆ์ œ ์Šคํฌ๋ฆฝํŠธ](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)์—์„œ ๋ชจ๋ธ ์‚ฌ์šฉ๋ฒ•์„ ํ™•์ธํ•˜์„ธ์š”.
## AlbertConfig[[albertconfig]]
[[autodoc]] AlbertConfig
## AlbertTokenizer[[alberttokenizer]]
[[autodoc]] AlbertTokenizer
- get_special_tokens_mask
- save_vocabulary
## AlbertTokenizerFast[[alberttokenizerfast]]
[[autodoc]] AlbertTokenizerFast
## Albert ํŠนํ™” ์ถœ๋ ฅ[[albert-specific-outputs]]
[[autodoc]] models.albert.modeling_albert.AlbertForPreTrainingOutput
## AlbertModel[[albertmodel]]
[[autodoc]] AlbertModel
- forward
## AlbertForPreTraining[[albertforpretraining]]
[[autodoc]] AlbertForPreTraining
- forward
## AlbertForMaskedLM[[albertformaskedlm]]
[[autodoc]] AlbertForMaskedLM
- forward
## AlbertForSequenceClassification[[albertforsequenceclassification]]
[[autodoc]] AlbertForSequenceClassification
- forward
## AlbertForMultipleChoice[[albertformultiplechoice]]
[[autodoc]] AlbertForMultipleChoice
## AlbertForTokenClassification[[albertfortokenclassification]]
[[autodoc]] AlbertForTokenClassification
- forward
## AlbertForQuestionAnswering[[albertforquestionanswering]]
[[autodoc]] AlbertForQuestionAnswering
- forward