트랜스포머 이해하기

Python으로 배우는 LLM 입문

Jasmin Ludolf

Senior Data Science Content Developer, DataCamp

트랜스포머란?

  • 딥러닝 아키텍처
  • 텍스트 처리, 이해 및 생성
  • 대부분의 LLM에 활용
  • 긴 텍스트 시퀀스를 병렬 처리

세 가지 트랜스포머 아키텍처 그림: 인코더 전용, 디코더 전용, 인코더-디코더

Python으로 배우는 LLM 입문

트랜스포머 아키텍처

세 가지 트랜스포머 아키텍처 그림: 인코더 전용, 디코더 전용, 인코더-디코더

  • Hugging Face 모델 카드에서 아키텍처 세부 정보 확인
Python으로 배우는 LLM 입문

인코더 전용

인코더 전용 아키텍처 그림

  • 입력 텍스트 이해
  • 순차적 출력 없음
  • 주요 태스크:
    • 텍스트 분류
    • 감성 분석
    • 추출형 질의응답 (추출 또는 레이블링)
  • BERT 모델
  • 예시: "distilbert-base-uncased-distilled-squad"
Python으로 배우는 LLM 입문

인코더 전용

인코더 전용 아키텍처 그림

llm = pipeline(model="bert-base-uncased")
print(llm.model)
BertForMaskedLM(
  (bert): ...
    )
    (encoder): BertEncoder(
      ...
print(llm.model.config)
BertConfig {
...
  "architectures": [
    "BertForMaskedLM"
...
Python으로 배우는 LLM 입문

인코더 전용

인코더 전용 아키텍처 그림

print(llm.model.config.is_decoder)
False
  • 또는: llm.model.config.is_encoder_decoder
Python으로 배우는 LLM 입문

디코더 전용

디코더 전용 아키텍처 그림

  • 출력에 초점
  • 주요 태스크:
    • 텍스트 생성
    • 생성형 질의응답 (문장 또는 문단)
  • GPT 모델
  • 예시: "gpt-5.4-mini"
Python으로 배우는 LLM 입문

디코더 전용

디코더 전용 아키텍처 그림

llm = pipeline(model="gpt2")
print(llm.model.config)
GPT2Config {
...
  "architectures": [
    "GPT2LMHeadModel"
  ],
...
  "task_specific_params": {
    "text-generation": {
...
print(llm.model.config.is_decoder)
False
Python으로 배우는 LLM 입문

인코더-디코더

인코더-디코더 아키텍처 그림

  • 입력과 출력을 모두 이해하고 처리
  • 주요 태스크:
    • 번역
    • 요약
  • T5, BART 모델
Python으로 배우는 LLM 입문

인코더-디코더

인코더-디코더 아키텍처 그림

llm = pipeline(model="Helsinki-NLP/opus-mt-es-en")
print(llm.model)
MarianMTModel(
...
    (encoder): MarianEncoder(
...
    (decoder): MarianDecoder(
...
Python으로 배우는 LLM 입문

인코더-디코더

인코더-디코더 아키텍처 그림

print(llm.model.config)
MarianConfig {
...
  "decoder_attention_heads": 8,
...
  "encoder_attention_heads": 8,
...
  "is_encoder_decoder": true,
...
print(llm.model.config.is_encoder_decoder)
True
Python으로 배우는 LLM 입문

연습해 봅시다!

Python으로 배우는 LLM 입문

Preparing Video For Download...