콘텐츠로 이동

ALBERT[[albert]]

PyTorch TensorFlow Flax SDPA

ALBERTBERT의 확장성과 학습 시 메모리 한계를 해결하기 위해 설계된 모델입니다. 이 모델은 두 가지 파라미터 감소 기법을 도입합니다. 첫 번째는 임베딩 행렬 분해(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 커뮤니티 조직에서 확인하실 수 있습니다.

아래 예시는 Pipeline, AutoModel 그리고 커맨드라인에서 [MASK] 토큰을 예측하는 방법을 보여줍니다.

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)
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])}")
Terminal window
echo -e "Plants create [MASK] through a process known as photosynthesis." | transformers run --task fill-mask --model albert-base-v2 --device 0
  • BERT는 절대 위치 임베딩을 사용하므로, 오른쪽에 입력이 패딩돼야 합니다.
  • 임베딩 크기 E는 히든 크기 H와 다릅니다. 임베딩은 문맥에 독립적(각 토큰마다 하나의 임베딩 벡터)이고, 은닉 상태는 문맥에 의존적(토큰 시퀀스마다 하나의 은닉 상태)입니다. 임베딩 행렬은 V x E(V: 어휘 크기)이므로, 일반적으로 H >> E가 더 논리적입니다. E < H일 때 모델 파라미터가 더 적어집니다.

아래 섹션의 자료들은 공식 Hugging Face 및 커뮤니티(🌎 표시) 자료로, AlBERT를 시작하는 데 도움이 됩니다. 여기에 추가할 자료가 있다면 Pull Request를 보내주세요! 기존 자료와 중복되지 않고 새로운 내용을 담고 있으면 좋습니다.

다중 선택(Multiple choice)

[[autodoc]] AlbertConfig

[[autodoc]] AlbertTokenizer - get_special_tokens_mask - save_vocabulary

AlbertTokenizerFast[[alberttokenizerfast]]

섹션 제목: “AlbertTokenizerFast[[alberttokenizerfast]]”

[[autodoc]] AlbertTokenizerFast

Albert 특화 출력[[albert-specific-outputs]]

섹션 제목: “Albert 특화 출력[[albert-specific-outputs]]”

[[autodoc]] models.albert.modeling_albert.AlbertForPreTrainingOutput

[[autodoc]] AlbertModel - forward

AlbertForPreTraining[[albertforpretraining]]

섹션 제목: “AlbertForPreTraining[[albertforpretraining]]”

[[autodoc]] AlbertForPreTraining - forward

[[autodoc]] AlbertForMaskedLM - forward

AlbertForSequenceClassification[[albertforsequenceclassification]]

섹션 제목: “AlbertForSequenceClassification[[albertforsequenceclassification]]”

[[autodoc]] AlbertForSequenceClassification - forward

AlbertForMultipleChoice[[albertformultiplechoice]]

섹션 제목: “AlbertForMultipleChoice[[albertformultiplechoice]]”

[[autodoc]] AlbertForMultipleChoice

AlbertForTokenClassification[[albertfortokenclassification]]

섹션 제목: “AlbertForTokenClassification[[albertfortokenclassification]]”

[[autodoc]] AlbertForTokenClassification - forward

AlbertForQuestionAnswering[[albertforquestionanswering]]

섹션 제목: “AlbertForQuestionAnswering[[albertforquestionanswering]]”

[[autodoc]] AlbertForQuestionAnswering - forward