🤖 AI/ML

Hugging Face

Hugging Face

An ML model and dataset hub. Famous for the Transformers library.

📖 Detailed Explanation

Hugging Face is a platform for sharing ML models, datasets, and applications, and an AI company that develops open-source libraries. Founded in 2016, it is now called the "GitHub" of AI and hosts more than 500,000 models and more than 100,000 datasets.

Its flagship library, Transformers, lets you use major NLP models such as BERT, GPT, T5, and LLaMA through a unified API. A single from_pretrained() method downloads a pretrained model and makes it ready to use right away, greatly lowering the barrier to entry for ML development.

On the Hub platform, anyone can share models and datasets. You can document model information with a Model Card, host demo apps with Spaces, and serve models with the Inference API. The enterprise Pro plan provides private models and additional compute resources.

The Hugging Face ecosystem continues to expand. It includes libraries such as Diffusers (image generation), Datasets (dataset loading), Accelerate (distributed training), and PEFT (parameter-efficient fine-tuning), and AutoTrain also enables no-code model training.

💻 Code Example

from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM

# 1. 가장 간단한 사용법 - Pipeline
classifier = pipeline("sentiment-analysis")
result = classifier("Hugging Face is awesome!")
print(result)  # [{'label': 'POSITIVE', 'score': 0.9998}]

# 2. 텍스트 생성 예제
generator = pipeline("text-generation", model="gpt2")
output = generator("AI의 미래는", max_length=50, num_return_sequences=1)
print(output[0]['generated_text'])

# 3. 모델과 토크나이저 직접 로드
model_name = "meta-llama/Llama-2-7b-chat-hf"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype="auto",
    device_map="auto"  # 자동 GPU 할당
)

# 텍스트 생성
inputs = tokenizer("안녕하세요, ", return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=100)
print(tokenizer.decode(outputs[0]))

# 4. Hub에 모델 업로드
from huggingface_hub import login
login(token="hf_your_token")
model.push_to_hub("my-fine-tuned-model")

🗣️ Say It Like This in Practice

At an NLP project kickoff

"We don't need to build a sentiment analysis model from scratch. We can find a Korean sentiment analysis model on the Hugging Face Hub and fine-tune it. If we start with klue/bert-base, we can establish a baseline quickly."

In a technical interview

"The advantage of Hugging Face Transformers is its unified API. Whether it's BERT or GPT, you can load it with from_pretrained() and run inference and fine-tuning the same way, so adopting a new model is very fast."

In a model deployment discussion

"I think we should deploy the prototype to Hugging Face Spaces as a Gradio app. We can start with the free CPU tier, and if traffic grows, we can use a dedicated GPU instance through Inference Endpoints."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Common Mistakes & Cautions

1
Checking model licenses

Each model on the Hub has a different license. Before using one in a commercial service, be sure to check whether it is Apache 2.0, MIT, or a restrictive license.

2
Model size and memory

Large models (7B+) require tens of GB of VRAM. Before running one locally, check the model size and, if necessary, use a quantized (4-bit, 8-bit) version.

3
Variation in model quality

The Hub contains models of varying quality. Check the download count, like count, and Model Card documentation status, and choose a verified model.

🔗 Related Terms

📚 Learn More