‹ Lecture 2 17 / 23

Static → Contextual Embeddings

river bank와 financial bank에서 bank의 Token ID가 같다면 Embedding lookup도 같은 row를 돌려준다. 이것이 Static representation의 출발점이다. 문제는 정보가 하나도 없다는 것이 아니라 여러 sense가 같은 row에 섞여 있다는 데 있다. 이번 문장에서 어떤 sense가 필요한지에 따라 representation이 달라져야 한다는 요구에서 Contextual hidden state로 이어진다.

  1. 동일 EE[token]
  2. position + Attention / MLP
  3. context-dependent hidden state

word2vec & GloVe

word2vec Skip-gram은 center word로 주변 words를 예측한다. the cat sat on the mat에서 sat 주변의 단어를 학습하는 식이며, 비슷한 문맥에 나타나는 words가 비슷한 vector를 갖도록 만든다. Negative sampling은 실제 neighbours와 random neighbours를 구분하게 한다.

GloVe는 개별 문장마다 예측하는 방식 대신 corpus 전체의 word–context co-occurrence counts를 사용한다. 교수님이 든 ice–solid, steam–gas 같은 관계를 window 안의 동시 출현으로 모으고, 매우 빈번한 값이 지나치게 지배하지 않도록 log 관점으로 vector를 맞춘다. 두 방법 모두 분포에서 의미 관계를 배우지만 결과는 word type마다 하나의 stored vector다.

king−man+woman≈queen\mathrm{king}-\mathrm{man}+\mathrm{woman}\approx\mathrm{queen}은 nearest-neighbour offset 패턴 예시이지 정확한 항등식이 아니다. Static은 type당 한 vector라는 뜻이며 parameter가 frozen이라는 뜻은 아니다.

Polysemy

river bank/financial bank, 배(belly/pear/boat)는 하나의 Static row에 여러 sense가 섞인다. 정보가 전혀 없다는 것이 아니라 occurrence별 sense를 선택할 문맥별 vector가 없다는 한계다. BERT/GPT도 출발점은 Static table이고 위 layer가 Contextual state를 만든다.

Contextual Representations

같은 EE[bank]를 가져와도 이후 Attention과 MLP가 다른 문맥을 반영하면 state가 달라진다. Table 자체가 매 문장마다 새 row를 만드는 것이 아니라, 같은 row에서 시작한 state가 layers를 통과하며 달라지는 것이다.

E[bank]⟶{h(bank∣river context)h(bank∣finance context)E[\mathrm{bank}] \longrightarrow \begin{cases} h(\mathrm{bank}\mid\mathrm{river\ context})\\ h(\mathrm{bank}\mid\mathrm{finance\ context}) \end{cases}

BERT에서는 해당 position이 양쪽 문맥을 볼 수 있고, causal GPT에서는 왼쪽 문맥만 볼 수 있다. 따라서 Contextual이라는 같은 이름 안에서도 어떤 context가 허용되는지를 확인해야 한다. 슬라이드의 layer-depth 경향은 upper layers에서 문맥별로 더 달라질 수 있음을 보이는 schematic이며 모든 모델의 curve가 같다는 뜻은 아니다.

Static vector 하나가 Contextual variance의 5% 미만을 설명한다는 결과는 Ethayarajh2019의 분석 setting에 한정된다.

Static Embeddings in Practice

Static Embedding은 lookup→mean pool만으로 text vector를 얻을 수 있어 edge/large dedup/latency-critical search에 유용하다. Model2Vec의 distillation, HF StaticEmbedding의 direct contrastive training 두 경로가 소개된다.

100–400×CPU throughput과≥85% benchmark score는 강의가 인용한 특정 설정의 수치다. Polysemy 한계는 남는다.

Contextual representation을 얻으려면 입력을 Transformer blocks 전체로 처리해야 한다. 반면 Static embedder는 lookup 뒤 mean pool만 하면 되므로 table read 중심의 비용으로 text vector를 얻는다. Model2Vec은 contextual encoder의 출력을 distill하여 Static vectors를 만들고, HF StaticEmbedding은 lookup과 pooling을 contrastive objective로 직접 학습한다. 둘 다 sentence-transformers에서 사용할 수 있는 경로로 소개되었다.

대규모 corpus의 near-duplicate 제거처럼 모든 문서를 GPU model로 처리하기 어려운 경우, 이 속도 차이는 실용적이다. 따라서 최신 architecture인지보다 task에 필요한 context 구분과 budget이 무엇인지가 선택 기준이다. 대신 bank의 polysemy를 occurrence별로 해결하지 못하는 한계는 그대로 남는다.

Static은 context-blind lookup이라는 뜻이며 frozen과 다르다.

Static · Contextual

학습에 문맥을 사용했는지와 occurrence별 vector를 만드는지는 다른 질문이다.

AspectStaticContextual
출력 단위Word/token type의 같은 row문맥별 occurrence hidden state
문맥 활용학습에 사용 가능; lookup은 context-blindAttention/MLP layers에서 문맥 반영
Polysemy여러 sense가 한 vector에 혼합문장별 sense를 반영 가능
실행 비용Lookup + pooling 가능Transformer 계산 필요

Check

Static Embedding이 문맥을 전혀 모른 채 학습된 것이라는 설명이 틀린 이유는?

Answer

word2vec도 주변 문맥으로 학습한다. Static은 학습 후 한 word type에 같은 vector를 반환한다는 뜻이며 Contextual은 occurrence마다 hidden state가 달라진다.

최신 Contextual 모델 대신 Static Embedding을 선택할 만한 조건은?

Answer

낮은 latency·CPU/edge 실행·대량 dedup 등에서 lookup/pooling 비용이 유리하고 품질 손실이 task에서 허용될 때다.

같은 token이 다른 문장에 나올 때 lookup vector와 최종 state는 각각 어떻게 달라지는가?

Answer

기본 lookup은 같은 E의 row를 읽으므로 같은 vector다. 그 뒤 contextual model은 주변 tokens를 읽어 state를 바꾸므로 최종 표현은 달라질 수 있다. Static Embedding과 contextual state를 구분한다.

Static · Contextual를 축별로 비교하고 그 차이가 필요한 이유를 설명하세요.

Answer

학습에 문맥을 사용했는지와 occurrence별 vector를 만드는지는 다른 질문이다.

출력 단위: Static=Word/token type의 같은 row / Contextual=문맥별 occurrence hidden state

문맥 활용: Static=학습에 사용 가능; lookup은 context-blind / Contextual=Attention/MLP layers에서 문맥 반영

Polysemy: Static=여러 sense가 한 vector에 혼합 / Contextual=문장별 sense를 반영 가능

실행 비용: Static=Lookup + pooling 가능 / Contextual=Transformer 계산 필요

Contents