Path: blob/master/Generative NLP Models using Python/6 Hugging face libraries.ipynb
3074 views
Hugging Face Transformers for NLP Tasks
What is Hugging Face?
Hugging Face provides:
transformers
: State-of-the-art pre-trained models for NLP (and beyond).datasets
: Ready-to-use NLP datasets.tokenizers
: Fast and customizable tokenization.
Installation
pip install transformers pip install torch # or tensorflow, depending on backend
Common NLP Tasks with Hugging Face
Task | Description | Model Example |
---|---|---|
Text Classification | Classify text into categories | BERT, DistilBERT |
Named Entity Recognition (NER) | Identify entities in text | BERT, RoBERTa |
Question Answering | Extract answer from a given context | BERT, ALBERT |
Summarization | Summarize long text into key points | BART, T5 |
Translation | Translate text between languages | MarianMT, mBART |
Text Generation | Autocomplete or continue text generation | GPT-2, GPT-3, LLaMA |
Sentiment Analysis | Detect sentiment (positive/negative/etc.) | DistilBERT, BERT |
The pipeline() function is the simplest way to use Hugging Face models
Under the Hood: Model & Tokenizer Loading
You can manually load the model/tokenizer if you want finer control:
Advantages of Hugging Face Pipelines
Quick setup
Pre-trained models ready for use
Handles tokenization, model inference, and decoding internally
Easy to switch models by changing model name
Where to Find Models
Browse thousands of models at https://huggingface.co/models
Summary
Hugging Face makes using SOTA NLP models easy with pipeline().
Supports a wide variety of tasks: classification, NER, QA, summarization, etc.
You can dig deeper by using tokenizers and model classes directly.
Easily switch between models with AutoModel and AutoTokenizer.