📝

텍스트 AI 사전학습 모델 카탈로그 — 3줄 코드로 할 수 있는 12가지

감정 분석부터 코드 생성까지 — HuggingFace pipeline 한 줄이면 되는 모델 리스트와 난이도

전부 pip install transformers하고 3줄이면 된다.

공통 구조

from transformers import pipeline
pipe = pipeline("태스크", model="모델명")  # 모델 자동 다운로드
result = pipe("입력 텍스트")

이게 전부다. 전처리(토큰화)는 pipeline이 알아서 한다.


1. 감정 분석 — "이 문장이 긍정? 부정?" (난이도: ★☆☆☆☆)

가장 쉽다. AI 첫 체험 추천.

from transformers import pipeline

classifier = pipeline("sentiment-analysis")
print(classifier("I love this product!"))
# → [{'label': 'POSITIVE', 'score': 0.9998}]

print(classifier("This is terrible."))
# → [{'label': 'NEGATIVE', 'score': 0.9994}]

모델 크기 언어 비고
distilbert-base-uncased-finetuned-sst-2-english (기본) 260 MB 영어 가장 빠름
nlptown/bert-base-multilingual-uncased-sentiment 680 MB 다국어 1~5점
cardiffnlp/twitter-roberta-base-sentiment-latest 500 MB 영어 트위터 특화

2. 번역 — "이걸 일본어로" (난이도: ★☆☆☆☆)

translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-ja")
print(translator("The weather is nice today."))
# → [{'translation_text': '今日は天気がいいです。'}]

모델 크기 방향 비고
Helsinki-NLP/opus-mt-en-ja 300 MB 영→일 MarianMT 기반
Helsinki-NLP/opus-mt-en-ko 300 MB 영→한
Helsinki-NLP/opus-mt-ko-en 300 MB 한→영
facebook/nllb-200-distilled-600M 600 MB 200개 언어 어떤 언어 조합이든

Helsinki-NLP/opus-mt 시리즈는 언어쌍별로 존재한다. opus-mt-{소스}-{타겟} 형식.


3. 텍스트 요약 — "이 긴 글을 3줄로" (난이도: ★★☆☆☆)

summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
long_text = """여기에 긴 뉴스 기사를 넣으면..."""
print(summarizer(long_text, max_length=100, min_length=30))
# → [{'summary_text': '3줄 요약이 나온다'}]

모델 크기 특징
facebook/bart-large-cnn 1.6 GB 뉴스 요약 특화
sshleifer/distilbart-cnn-12-6 1.2 GB BART 경량화
google/pegasus-xsum 2.3 GB 극단적 요약 (1문장)

4. 질의응답 — "이 문서에서 답 찾기" (난이도: ★★☆☆☆)

qa = pipeline("question-answering")
result = qa(
    question="What is the capital of France?",
    context="France is a country in Europe. The capital of France is Paris."
)
print(result)
# → {'answer': 'Paris', 'score': 0.9987, 'start': 52, 'end': 57}

문서(context)에서 답을 추출한다. 생성이 아니라 추출이라서 환각이 없다.

모델 크기 언어
distilbert-base-cased-distilled-squad (기본) 260 MB 영어
deepset/roberta-base-squad2 500 MB 영어
timpal0l/mdeberta-v3-base-squad2 860 MB 다국어

5. 텍스트 생성 — "이어서 써줘" (난이도: ★★☆☆☆)

generator = pipeline("text-generation", model="gpt2")
result = generator("The future of AI is", max_length=50)
print(result[0]["generated_text"])
# → "The future of AI is likely to be shaped by..."

모델 크기 특징
gpt2 500 MB 가장 가벼움. 입문용
gpt2-medium 1.5 GB 좀 더 나은 품질
microsoft/phi-2 5.6 GB 소형이지만 고품질
meta-llama/Llama-2-7b-chat-hf 14 GB 대화형. GPU 필요
google/gemma-2b 5 GB 경량 고품질

GPT-2가 입문용으로 가장 좋다. 500MB로 CPU에서 돌아간다.


6. 빈칸 채우기 — "이 문장의 [MASK]는?" (난이도: ★☆☆☆☆)

unmasker = pipeline("fill-mask")
print(unmasker("The capital of France is [MASK]."))
# → [{'token_str': 'Paris', 'score': 0.95}, ...]

BERT 계열 모델의 핵심 동작. [MASK] 위치에 올 단어를 예측한다.

모델 크기
bert-base-uncased (기본) 440 MB
bert-base-multilingual-cased 680 MB
xlm-roberta-base 1.1 GB

7. 개체명 인식(NER) — "이름, 장소, 조직 찾기" (난이도: ★★☆☆☆)

ner = pipeline("ner", grouped_entities=True)
print(ner("Apple was founded by Steve Jobs in Cupertino."))
# → [{'entity_group': 'ORG', 'word': 'Apple', 'score': 0.99},
#    {'entity_group': 'PER', 'word': 'Steve Jobs', 'score': 0.99},
#    {'entity_group': 'LOC', 'word': 'Cupertino', 'score': 0.99}]

모델 크기 언어
dbmdz/bert-large-cased-finetuned-conll03-english (기본) 1.3 GB 영어
xlm-roberta-large-finetuned-conll03-english 2.2 GB 다국어

8. 텍스트 유사도 — "이 두 문장이 얼마나 비슷해?" (난이도: ★★☆☆☆)

from sentence_transformers import SentenceTransformer, util

model = SentenceTransformer("all-MiniLM-L6-v2")  # 80 MB
emb1 = model.encode("오늘 날씨가 좋다")
emb2 = model.encode("오늘 기온이 따뜻하다")
emb3 = model.encode("주식 시장이 하락했다")

print(f"유사: {util.cos_sim(emb1, emb2).item():.3f}")  # → 0.82
print(f"무관: {util.cos_sim(emb1, emb3).item():.3f}")  # → 0.11

pip install sentence-transformers 필요.

모델 크기 특징
all-MiniLM-L6-v2 80 MB 가장 가벼움. 입문용
all-mpnet-base-v2 420 MB 영어 최고 품질
paraphrase-multilingual-MiniLM-L12-v2 470 MB 다국어

9. 제로샷 분류 — "학습 없이 분류" (난이도: ★★★☆☆)

미리 정의된 카테고리 없이, 런타임에 카테고리를 지정하면 분류한다.

classifier = pipeline("zero-shot-classification")
result = classifier(
    "Apple just released a new iPhone with AI features",
    candidate_labels=["technology", "sports", "politics", "finance"]
)
print(f"{result['labels'][0]}: {result['scores'][0]:.2%}")
# → technology: 96.53%

모델 크기
facebook/bart-large-mnli (기본) 1.6 GB
MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli 730 MB

10. 코드 생성 — "함수 만들어줘" (난이도: ★★★☆☆)

generator = pipeline("text-generation", model="Salesforce/codegen-350M-mono")
result = generator("def fibonacci(n):", max_length=100)
print(result[0]["generated_text"])
# → def fibonacci(n):
#        if n <= 1:
#            return n
#        return fibonacci(n-1) + fibonacci(n-2)

모델 크기 언어
Salesforce/codegen-350M-mono 700 MB Python
bigcode/starcoder2-3b 6 GB 다중 언어
Qwen/Qwen2.5-Coder-1.5B 3 GB 다중 언어. 소형 고품질

11. 텍스트 → 구조화 데이터 (난이도: ★★★☆☆)

JSON 추출, 키워드 추출 등. 프롬프트 엔지니어링이 필요해서 난이도가 올라간다.

generator = pipeline("text-generation", model="gpt2")
prompt = """Extract the name and age from this text as JSON:
Text: "John is 25 years old and lives in Tokyo."
JSON:"""
result = generator(prompt, max_length=80)

작은 모델(GPT-2)로는 잘 안 된다. Phi-2나 Llama 급이 필요.


12. 대화 (챗봇) — "대화하기" (난이도: ★★★☆☆)

chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium")
from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium")
input_ids = tokenizer.encode("Hello, how are you?" + tokenizer.eos_token, return_tensors="pt")
output = chatbot.model.generate(input_ids, max_length=50, pad_token_id=tokenizer.eos_token_id)
print(tokenizer.decode(output[0], skip_special_tokens=True))
# → "Hello, how are you? I'm doing well, thanks!"

모델 크기 특징
microsoft/DialoGPT-medium 1.5 GB 간단한 대화
google/gemma-2b-it 5 GB instruction-tuned
meta-llama/Llama-2-7b-chat-hf 14 GB 고품질. GPU 필요

난이도 총정리

난이도 태스크 코드 양 GPU 필요 입문 추천
★☆☆☆☆ 감정 분석 3줄 불필요 최추천
★☆☆☆☆ 번역 3줄 불필요 추천
★☆☆☆☆ 빈칸 채우기 3줄 불필요 추천
★★☆☆☆ 요약 3줄 불필요 추천
★★☆☆☆ 질의응답 4줄 불필요 추천
★★☆☆☆ 텍스트 생성 3줄 불필요(GPT-2) 추천
★★☆☆☆ NER 3줄 불필요 추천
★★☆☆☆ 유사도 4줄 불필요 추천
★★★☆☆ 제로샷 분류 4줄 불필요 기초 후
★★★☆☆ 코드 생성 3줄 권장 기초 후
★★★☆☆ 구조화 추출 5줄+ 권장 기초 후
★★★☆☆ 대화 5줄+ 권장 기초 후

어디서부터 시작할까

1단계 (첫날): 감정 분석 3줄을 돌려본다. AI 추론이 뭔지 체감한다.

2단계 (1주차): 번역, 요약, 질의응답을 돌려본다. 태스크마다 input/output 형태가 다르다는 걸 느낀다.

3단계 (2주차): GPT-2로 텍스트 생성을 해본다. 자기회귀 생성(다음 토큰 예측)의 원리를 이해한다.

4단계 (1개월): 유사도 검색을 만들어본다. 임베딩의 개념을 이해한다.

5단계 (그 이후): 코드 생성, 제로샷 분류 등 프롬프트 엔지니어링이 필요한 태스크로 넘어간다.

전부 pip install transformers와 CPU만으로 가능하다. GPU는 큰 모델(7B+)을 쓸 때만 필요하다.

핵심 개념

1

감정 분석 (★☆☆☆☆) — pipeline(\"sentiment-analysis\") 한 줄이면 긍정/부정 판별

2

번역 (★☆☆☆☆) — Helsinki-NLP/opus-mt-{소스}-{타겟}으로 200+ 언어쌍

3

요약/QA/NER (★★☆☆☆) — BART, DistilBERT 등으로 텍스트 이해 태스크

4

텍스트 생성 (★★☆☆☆) — GPT-2(500MB)로 CPU에서 자기회귀 생성 체험

5

코드 생성/챗봇 (★★★☆☆) — CodeGen, DialoGPT로 프롬프트 엔지니어링 입문

사용 사례

AI 입문 — 감정 분석 3줄로 첫 AI 추론 체험 프로토타입 — 번역+요약+NER을 조합해 뉴스 분석 도구 제작 모델 선택 가이드 — 태스크별 추천 모델과 크기/품질 트레이드오프