가이드2026년 3월 28일
Hugging Face 완전 가이드: AI 개발자의 GitHub (2025)
## Hugging Face가 뭐하는 곳인가?
Hugging Face는 AI 모델과 데이터셋의 GitHub입니다. 2025년 현재 80만 개 이상의 모델, 15만 개 이상의 데이터셋이 공개되어 있습니다. Meta, Google, Mistral 같은 대기업도 자사 모델을 여기에 올립니다.
```mermaid
flowchart LR
HF[Hugging Face Hub] --> Models[모델 허브<br/>80만+ 모델]
HF --> Datasets[데이터셋<br/>15만+ 데이터셋]
HF --> Spaces[Spaces<br/>데모 앱 호스팅]
HF --> Inference[Inference API<br/>모델 즉시 사용]
Models --> Use1[로컬 실행]
Models --> Use2[파인튜닝]
Models --> Use3[API 호출]
```
---
## 핵심 라이브러리
### transformers:
모델의 모든 것
```bash
pip install transformers torch
```
```python
from transformers import pipeline
# 가장 간단한 사용법: pipeline
# 한국어 감성 분석
classifier = pipeline(
"text-classification",
model="snunlp/KR-FinBert-SC", # 한국어 금융 감성 분석 모델
device=0 # GPU 사용 (없으면 -1)
)
result = classifier("삼성전자 주가가 급등했다. 긍정적인 실적 발표 덕분이다.")
# [{'label': 'positive', 'score': 0.97}]
# 이미지 분류
image_classifier = pipeline("image-classification", model="google/vit-base-patch16-224")
# 번역
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
result = translator("안녕하세요, 저는 AI 개발자입니다.")
# [{'translation_text': 'Hello, I am an AI developer.'}]
```
### 텍스트 생성
```python
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_name = "Qwen/Qwen2.5-7B-Instruct"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.float16,
device_map="auto"
)
# 채팅 형식으로 생성
messages = [
{"role": "system", "content": "당신은 AI 전문가입니다."},
{"role": "user", "content": "RAG와 파인튜닝의 차이를 설명해줘"}
]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.7)
response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
print(response)
```
---
## datasets: 데이터셋 다루기
```python
from datasets import load_dataset
# 공개 데이터셋 로드
dataset = load_dataset("klue", "ynat") # KLUE 한국어 NLU 벤치마크
print(dataset)
# DatasetDict({
# train: Dataset({features: ['guid', 'title', 'label', 'url'], num_rows: 45678})
# validation: Dataset({...num_rows: 9107})
# })
# 데이터 확인
print(dataset["train"][0])
# {'guid': 'ynat-v1_train_00000', 'title': '인천공항 ...', 'label': 6}
# 필터링
short_texts = dataset["train"].filter(lambda x: len(x["title"]) < 20)
# 커스텀 데이터셋 업로드
from datasets import Dataset
my_data = {"text": ["문장1", "문장2"], "label": [0, 1]}
ds = Dataset.from_dict(my_data)
ds.push_to_hub("your-username/my-dataset")
```
---
## Inference API: 코드 없이 즉시 사용
Hugging Face의 Inference API로 모델을 API처럼 사용합니다:
```python
import requests
API_URL = "https://api-inference.huggingface.co/models/Qwen/Qwen2.5-7B-Instruct"
headers = {"Authorization": "Bearer hf_..."}
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
result = query({
"inputs": "한국의 AI 산업 동향을 요약해줘",
"parameters": {"max_new_tokens": 500}
})
```
**Serverless Inference 가격:**
- 무료 티어: 월 30,000 토큰
- Pro ($9/월): 월 2억 토큰
- 대부분의 모델 지원
---
## Spaces: AI 데모 즉시 배포
Spaces는 Gradio나 Streamlit 앱을 무료로 호스팅합니다:
```python
# app.py (Gradio)
import gradio as gr
from transformers import pipeline
pipe = pipeline("text-generation", model="gpt2")
def generate(prompt):
result = pipe(prompt, max_length=100)[0]["generated_text"]
return result
demo = gr.Interface(
fn=generate,
inputs=gr.Textbox(label="프롬프트"),
outputs=gr.Textbox(label="생성된 텍스트"),
title="GPT-2 텍스트 생성기"
)
demo.launch()
```
```yaml
# README.md 앞에 추가 (Space 메타데이터)
---
title: My AI Demo
emoji: 🤖
colorFrom: blue
colorTo: green
sdk: gradio
sdk_version: 4.0.0
app_file: app.py
---
```
`huggingface-cli` 또는 Git으로 push하면 자동 배포됩니다.
---
## 한국어 특화 모델 추천
| 태스크 | 모델 | 특징 |
|--------|------|------|
| 텍스트 생성 | `Qwen/Qwen2.5-7B-Instruct` | 한국어 가장 강함 |
| 임베딩 | `BAAI/bge-m3` | 다국어 SOTA |
| 감성 분석 | `snunlp/KR-FinBert-SC` | 금융 특화 |
| NLI | `monologg/koelectra-base-v3` | KoELECTRA |
| 번역 | `Helsinki-NLP/opus-mt-ko-en` | 경량 번역 |
| STT | `openai/whisper-large-v3` | 한국어 최강 |
---
## 모델 허브에서 모델 찾는 법
```python
from huggingface_hub import list_models
# 한국어 텍스트 분류 모델 검색
models = list_models(
filter="text-classification",
language="ko",
sort="downloads",
direction=-1,
limit=10
)
for model in models:
print(f"{model.id}: {model.downloads:,} downloads")
```
또는 [huggingface.co/models](https://huggingface.co/models)에서:
- Language: Korean
- Task: 원하는 태스크
- Sort by: Downloads (인기순)
---
## 결론Hugging Face는 AI 개발자의 필수 도구입니다:
1. **모델 발견**: 어떤 태스크든 이미 누군가 학습시킨 모델이 있음
2. **빠른 프로토타입**: `pipeline` 5줄로 시작, 필요하면 커스터마이징
3. **한국어 생태계**: KoELECTRA, KoBERT, BGE-M3 등 한국어 특화 모델들
4. **무료 인프라**: Spaces로 무료 GPU 데모, Inference API로 즉시 사용
시작점: `transformers` 설치 후 `pipeline("task", model="...")` 한 줄로 어떤 모델이든 즉시 실행해보세요.