5.7 KiB
이 모델은 2020-07-28에 출시되었으며 2021-03-30에 Hugging Face Transformers에 추가되었습니다.
BigBirdbigbird
BigBird는 BERT의 512토큰과 달리 최대 4096토큰까지의 시퀀스 길이를 처리하도록 설계된 트랜스포머 모델입니다. 기존 트랜스포머들은 시퀀스 길이가 늘어날수록 어텐션 계산 비용이 급격히 증가하여 긴 입력 처리에 어려움을 겪습니다. BigBird는 희소 어텐션 메커니즘으로 이 문제를 해결하는데, 모든 토큰을 동시에 살펴보는 대신 로컬 어텐션, 랜덤 어텐션, 그리고 몇 개의 전역 토큰을 조합하여 전체 입력을 효율적으로 처리합니다. 이런 방식을 통해 계산 효율성을 유지하면서도 시퀀스 전체를 충분히 이해할 수 있게 됩니다. 따라서 BigBird는 질의응답, 요약, 유전체학 응용처럼 긴 문서를 다루는 작업에 특히 우수한 성능을 보입니다.
모든 원본 BigBird 체크포인트는 Google 조직에서 찾아볼 수 있습니다.
Tip
오른쪽 사이드바의 BigBird 모델들을 클릭하여 다양한 언어 작업에 BigBird를 적용하는 더 많은 예시를 확인해보세요.
아래 예시는 [Pipeline], [AutoModel], 그리고 명령줄에서 [MASK] 토큰을 예측하는 방법을 보여줍니다.
import torch
from transformers import pipeline
pipeline = pipeline(
task="fill-mask",
model="google/bigbird-roberta-base",
dtype=torch.float16,
device=0
)
pipeline("Plants create [MASK] through a process known as photosynthesis.")
import torch
from transformers import AutoModelForMaskedLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained(
"google/bigbird-roberta-base",
)
model = AutoModelForMaskedLM.from_pretrained(
"google/bigbird-roberta-base",
dtype=torch.float16,
device_map="auto",
)
inputs = tokenizer("Plants create [MASK] through a process known as photosynthesis.", return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model(**inputs)
predictions = outputs.logits
masked_index = torch.where(inputs['input_ids'] == tokenizer.mask_token_id)[1]
predicted_token_id = predictions[0, masked_index].argmax(dim=-1)
predicted_token = tokenizer.decode(predicted_token_id)
print(f"The predicted token is: {predicted_token}")
!echo -e "Plants create [MASK] through a process known as photosynthesis." | transformers-cli run --task fill-mask --model google/bigbird-roberta-base --device 0
참고사항notes
- BigBird는 절대 위치 임베딩을 사용하므로 입력을 오른쪽에 패딩해야 합니다.
- BigBird는
original_full과block_sparse어텐션을 지원합니다. 입력 시퀀스 길이가 1024 미만인 경우에는 희소 패턴의 이점이 크지 않으므로original_full사용을 권장합니다. - 현재 구현은 3블록 윈도우 크기와 2개의 전역 블록을 사용하며, ITC 구현만 지원하고
num_random_blocks=0은 지원하지 않습니다. - 시퀀스 길이는 블록 크기로 나누어떨어져야 합니다.
리소스resources
- BigBird 어텐션 메커니즘의 자세한 작동 원리는 BigBird 블로그 포스트를 참고하세요.
BigBirdConfigbigbirdconfig
autodoc BigBirdConfig
BigBirdTokenizerbigbirdtokenizer
autodoc BigBirdTokenizer - get_special_tokens_mask - save_vocabulary
BigBirdTokenizerFastbigbirdtokenizerfast
autodoc BigBirdTokenizerFast
BigBird 특정 출력bigbird-specific-outputs
autodoc models.big_bird.modeling_big_bird.BigBirdForPreTrainingOutput
BigBirdModelbigbirdmodel
autodoc BigBirdModel - forward
BigBirdForPreTrainingbigbirdforpretraining
autodoc BigBirdForPreTraining - forward
BigBirdForCausalLMbigbirdforcausallm
autodoc BigBirdForCausalLM - forward
BigBirdForMaskedLMbigbirdformaskedlm
autodoc BigBirdForMaskedLM - forward
BigBirdForSequenceClassificationbigbirdforsequenceclassification
autodoc BigBirdForSequenceClassification - forward
BigBirdForMultipleChoicebigbirdformultiplechoice
autodoc BigBirdForMultipleChoice - forward
BigBirdForTokenClassificationbigbirdfortokenclassification
autodoc BigBirdForTokenClassification - forward
BigBirdForQuestionAnsweringbigbirdforquestionanswering
autodoc BigBirdForQuestionAnswering - forward