본문 바로가기
Digital pathology

HistoGPT

by 연금(Pension)술사 2025. 6. 15.

 

  • Nature communications
  • Published online: 2025, 5, 27

 

Preliminary


1. Receiver resampler: Cross modal의 efficient cross modal fusion을 위한 모듈.입

주로 아래와 같은 형태로 사용되는데, 입력을 이미지쪽에서 사용됨.

  1. 입력: Vision encoder에서의 feature map이 사용. (B, N, D). B:배치, N:패치수, D:차원. 이를 576을 24x24로 나눠도 꽤 숫자가 되기에, 이를 그냥 LM모델에 붙이기엔 너무 길다는 한계가 존재.
  2. Resampler token 초기화: 학습가능한 token을 만듬 (M, D). M은 하이퍼파라미터.
  3. Cross-attention: Resampler0=CrossAttention(Query=R, key,value=I). (입력: (M,D), (N, D), (N, D) -> 출력(M, D))
    1. R: trainable resampler token. $R \in \mathbb{R}^{M \times D}$
    2. I: vision feature map. $I \in \mathbb{R}^{N \times D}$
  4. Stacked Self-Attention + FeedForward Layers (L times): 여러 Transformer block을 통과시켜서 Resampler token을 더 많이 요약시킴.
for i in range(L):
    x = TransformerBlock(x)

 

요약하면 아래와 같음.

Image → Vision Encoder (e.g. frozen ViT)
      → Perceiver Resampler → Visual Tokens
Text → Frozen Language Model (e.g. Chinchilla)
      → Cross-Attend to Visual Tokens

 

 

Methods


  1. Preprocessing:
    1. image: 256x256 patchification + Resize(224) (# CLAM과 유사)
    2. text: pathology report을 GPT을 이용해서 6개정도 페러프레이징해서 보유
  2. Architecture:
    1. Visual encoder: CTransPath. 각 패치당 768-d vectors. (N, 768)
    2. Receiver Resampler: 고정수의 표현으로 변경. trainable vector (N, 768)->(640, 1536)
    3. Language model: BioGPT  (L, 1536)
    4. XATTN: Cross attention: 언어모델과 비전인코더를 있는 블록만 새로 학습.  (L, 1536), (640, 1536), (640, 1536) -> (L, 1536)
      1. Query: Language model (BioGPT) (L, 1536)
      2. Key: Receiver resampler로 부터온 벡터 (640, 1536)
      3. Value:  Receiver resampler로 부터온 벡터 (640, 1536)
    5. Linear + Softamx + word probablity
  3. Obejctive: PLIP(Pathology Language–Image Pretraining)의 Image-text contrastive learning 방식 (ITC)
  4. Generation: BioGPT가 생성. 재귀적생성.

 

위 과정을 재귀적으로 진행. [BOS] -> [BOS] + word1 -> [BOS] + word1 + word2... -> [BOS] + word1 + word2...[EOS]종

 

학습방법

  1. Image only pre-training: Resampler을 포함하여 MIL로 최종진단을 낼 수 있도록 사용. CrossEntropy로 목적함수
  2. joint tuning: 텍스트 생성에 대한 토큰 예측을 하기위해서 아래와 같이 구성
    1. Stage 1에서 학습한 이미지 인코더 및 리샘플러를 프리징 
    2. 입력토큰: [BOS] + 프롬프트("Final diagnosis":) 생성
    3. 모든 BioGPT내의 Transformer layer에 들어갈 때
      1. h = ffn(self_att(text_token)) 을 추림
      2. 이미지 인코더에서 얻은 요약정보을 (K,V)로 하여 h와 cross-attention
      3. 그 후에 vocabulary head을 이용해서 다음 단어에 대한 logit을 추
for layer in BioGPT_layers:
    h      = BioGPT_block(layer, txt_ids)            # (L,1536)
    z      = XATTN_layer(h, latents)                 # (L,1536)
    txt_ids = txt_ids + z                            # residual

loss = cross_entropy(next_token_logits, target_ids)  # CLM
반응형