docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를 Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류. - 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로 자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거, 동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거. - 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming, Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business, Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로, 나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는 title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백). 원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지. - 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서. - 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는 지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지. - Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경. - 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
---
|
||||
id: wiki-2026-0508-sequence-to-sequence-models
|
||||
title: Sequence to Sequence Models
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [seq2seq, Encoder-Decoder, Sequence Modeling, Sequence-to-Sequence]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [architecture, nlp, transformer, encoder-decoder]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: PyTorch / Transformers
|
||||
---
|
||||
|
||||
# Sequence to Sequence Models
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 input sequence → output sequence — 매 길이 다른 변환"**. 매 Sutskever (2014) RNN encoder-decoder → Bahdanau (2015) attention → Vaswani (2017) Transformer 의 진화. 매 2026: 거의 모든 generative LLM (GPT, Claude, Gemini) 이 매 decoder-only seq2seq, 매 T5/BART 같은 encoder-decoder 는 specific task (번역, summarization fine-tune) 에 잔존.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Architecture family
|
||||
- **RNN encoder-decoder** (2014): 매 historical, vanishing gradient, no attention.
|
||||
- **Attention seq2seq** (2015): 매 alignment 학습 — 번역 quality 점프.
|
||||
- **Transformer encoder-decoder** (2017): 매 self-attention, parallelizable. T5, BART, mT5.
|
||||
- **Decoder-only** (2018+): GPT family. 매 LLM 의 dominant pattern.
|
||||
- **Encoder-only** (BERT): classification/embedding, generation 아님.
|
||||
|
||||
### 매 핵심 컴포넌트
|
||||
- Tokenizer (BPE, SentencePiece, tiktoken).
|
||||
- Embedding + positional encoding (RoPE, ALiBi 2026 표준).
|
||||
- Self-attention / cross-attention.
|
||||
- Teacher forcing for training, autoregressive decoding for inference.
|
||||
|
||||
### 매 Decoding 전략
|
||||
- Greedy / Beam search — 매 deterministic task.
|
||||
- Sampling (temperature, top-p, top-k, min-p) — 매 creative.
|
||||
- Speculative / Medusa — 매 inference 가속.
|
||||
- Constrained / structured (JSON schema) — 매 tool use.
|
||||
|
||||
### 매 응용
|
||||
1. Machine translation (NLLB, M2M-100).
|
||||
2. Summarization (BART, Pegasus).
|
||||
3. Code generation (Claude Code, Copilot).
|
||||
4. Speech (Whisper encoder + decoder).
|
||||
5. Image captioning, VQA (multimodal seq2seq).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Tiny Transformer encoder-decoder
|
||||
```python
|
||||
import torch.nn as nn
|
||||
class Seq2Seq(nn.Module):
|
||||
def __init__(self, vocab, d=256, nhead=4, nl=4):
|
||||
super().__init__()
|
||||
self.emb_s = nn.Embedding(vocab, d)
|
||||
self.emb_t = nn.Embedding(vocab, d)
|
||||
self.tx = nn.Transformer(d, nhead, nl, nl, batch_first=True)
|
||||
self.out = nn.Linear(d, vocab)
|
||||
def forward(self, src, tgt):
|
||||
return self.out(self.tx(self.emb_s(src), self.emb_t(tgt)))
|
||||
```
|
||||
|
||||
### HF Transformers (T5)
|
||||
```python
|
||||
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
||||
tok = T5Tokenizer.from_pretrained("t5-base")
|
||||
m = T5ForConditionalGeneration.from_pretrained("t5-base")
|
||||
inp = tok("translate English to German: Hello world", return_tensors="pt").input_ids
|
||||
print(tok.decode(m.generate(inp)[0], skip_special_tokens=True))
|
||||
```
|
||||
|
||||
### Decoder-only generation (Claude API)
|
||||
```python
|
||||
import anthropic
|
||||
c = anthropic.Anthropic()
|
||||
msg = c.messages.create(
|
||||
model="claude-opus-4-7",
|
||||
max_tokens=1024,
|
||||
messages=[{"role": "user", "content": "Summarize: ..."}],
|
||||
)
|
||||
print(msg.content[0].text)
|
||||
```
|
||||
|
||||
### Beam search decode
|
||||
```python
|
||||
out = model.generate(input_ids, num_beams=4, length_penalty=0.6,
|
||||
no_repeat_ngram_size=3, max_new_tokens=128)
|
||||
```
|
||||
|
||||
### Streaming
|
||||
```python
|
||||
with c.messages.stream(model="claude-opus-4-7", max_tokens=512,
|
||||
messages=msgs) as s:
|
||||
for text in s.text_stream:
|
||||
print(text, end="", flush=True)
|
||||
```
|
||||
|
||||
### KV cache reuse
|
||||
```python
|
||||
out = model(**inputs, use_cache=True, past_key_values=pkv)
|
||||
pkv = out.past_key_values # 매 next step 에 재사용
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| General LLM task | decoder-only (Claude, GPT) |
|
||||
| Specific translation/summarization fine-tune | T5/BART encoder-decoder |
|
||||
| Embedding / classification | encoder-only (BERT family) |
|
||||
| Speech-to-text | Whisper-style enc-dec |
|
||||
| Long sequences, low cost | Mamba / Hybrid seq2seq |
|
||||
|
||||
**기본값**: decoder-only LLM via API.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Deep Learning]] · [[NLP]]
|
||||
- 변형: [[Transformer]] · [[Selective State Space Models (Mamba)]] · [[Encoder-Decoder]]
|
||||
- 응용: [[Summarization]] · [[Code-Generation]]
|
||||
- Adjacent: [[Attention Mechanism]] · [[Tokenization]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: input → output 변환 task 정의 가능. 매 API call 로 충분.
|
||||
**언제 X**: pure classification — encoder + head 가 매 더 cheap.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Greedy for creative**: repetition. 매 sampling 사용.
|
||||
- **No cache**: O(L²) inference. 매 KV cache 필수.
|
||||
- **Train from scratch**: 매 거의 항상 잘못된 선택. Fine-tune 또는 prompt.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Sutskever 2014, Vaswani 2017, HF Transformers docs).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — full seq2seq family 2026 |
|
||||
Reference in New Issue
Block a user