Instructions to use nithin521/Meme_Caption_Generator with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use nithin521/Meme_Caption_Generator with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="nithin521/Meme_Caption_Generator")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("nithin521/Meme_Caption_Generator") model = AutoModelForCausalLM.from_pretrained("nithin521/Meme_Caption_Generator", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use nithin521/Meme_Caption_Generator with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "nithin521/Meme_Caption_Generator" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nithin521/Meme_Caption_Generator", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/nithin521/Meme_Caption_Generator
- SGLang
How to use nithin521/Meme_Caption_Generator with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "nithin521/Meme_Caption_Generator" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nithin521/Meme_Caption_Generator", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "nithin521/Meme_Caption_Generator" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nithin521/Meme_Caption_Generator", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use nithin521/Meme_Caption_Generator with Docker Model Runner:
docker model run hf.co/nithin521/Meme_Caption_Generator
- π Meme Caption Generator
- π Model Overview
- β¨ Features
- π§ Model Architecture
- π Training
- βοΈ Generation Parameters
- π» Usage
- ποΈ Generation Controls
- π Interactive Demo
- π― Intended Use
- β οΈ Limitations
- π Safety & Responsible Use
- π Technologies Used
- ποΈ Project Pipeline
- π Future Improvements
- π¨βπ» Project
- π Model Overview
π Meme Caption Generator
A fine-tuned GPT-2 language model designed to generate short, humorous, and social-media-style meme captions from user-provided prompts.
The model learns common meme caption patterns such as:
When ...Me when ...POV: ...How it feels when ...That one friend who ...
It can generate multiple caption variations for a single prompt.
π Model Overview
| Property | Details |
|---|---|
| Base Model | GPT-2 |
| Task | Meme Caption Generation |
| Language | English |
| Framework | PyTorch |
| Library | π€ Transformers |
| Model Type | Autoregressive Language Model |
| Output | Short Meme Captions |
| Fine-Tuning | Supervised Fine-Tuning |
| Format | Safetensors |
β¨ Features
- Generate meme captions from a text prompt
- Generate multiple caption variations
- Supports prompt-based and random caption generation
- Adjustable text-generation parameters
- Designed for short, humorous, social-media-style text
Example:
Prompt
When you finally get your salary
Possible generations
When you finally get your salary and your bills were waiting for you.
Me checking my bank account after getting paid.
POV: You finally get paid but somehow you're still broke.
π§ Model Architecture
This model is based on GPT-2, an autoregressive Transformer language model.
During fine-tuning, the model was trained to learn the distribution and writing style of meme captions.
Each training example follows a structure similar to:
<|capbos|> meme caption <|capeos|>
where:
<|capbos|>marks the beginning of a caption<|capeos|>marks the end of a caption<|cappad|>is used as the padding token
This allows the model to learn where meme captions begin and end.
π Training
The model was fine-tuned on a custom meme-caption dataset containing short English meme captions collected and processed for this project.
The dataset was cleaned and prepared before fine-tuning to improve training quality.
The preprocessing pipeline included:
- Caption extraction
- Text cleaning
- Duplicate removal
- Dataset preparation
- Tokenization
- Train/validation split
- GPT-2 fine-tuning
The training process used:
- PyTorch
- Hugging Face Transformers
- AdamW optimization
- Learning-rate scheduling
- Gradient accumulation
- Validation monitoring
- Early stopping
βοΈ Generation Parameters
The model can be used with sampling-based generation.
Recommended starting configuration:
max_new_tokens = 25
temperature = 0.75
top_k = 40
top_p = 0.90
repetition_penalty = 1.1
no_repeat_ngram_size = 3
do_sample = True
For more creative outputs, temperature and sampling parameters can be increased.
For more predictable outputs, temperature can be decreased.
π» Usage
Using Transformers
from transformers import AutoTokenizer, AutoModelForCausalLM
model_id = "nithin521/Meme_Caption_Generator"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id)
tokenizer.pad_token = tokenizer.eos_token
prompt = "When you finally get your salary"
text = "<|capbos|> " + prompt
inputs = tokenizer(
text,
return_tensors="pt"
)
outputs = model.generate(
**inputs,
max_new_tokens=25,
temperature=0.75,
top_k=40,
top_p=0.90,
do_sample=True,
repetition_penalty=1.1,
no_repeat_ngram_size=3,
num_return_sequences=5,
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.pad_token_id
)
for output in outputs:
caption = tokenizer.decode(
output,
skip_special_tokens=False
)
caption = caption.split("<|capeos|>")[0]
caption = caption.replace("<|capbos|>", "").strip()
print(caption)
ποΈ Generation Controls
The model works particularly well when generation parameters are adjusted according to the desired output.
| Parameter | Effect |
|---|---|
temperature |
Controls randomness |
top_k |
Limits token selection to the top K candidates |
top_p |
Controls nucleus sampling |
max_new_tokens |
Controls maximum caption length |
repetition_penalty |
Reduces repetitive text |
no_repeat_ngram_size |
Prevents repeated phrases |
Recommended values:
Temperature: 0.75
Top-K: 40
Top-P: 0.90
Max New Tokens: 25
π Interactive Demo
The model is deployed as an interactive Gradio application on Hugging Face Spaces.
Demo:
https://huggingface.co/spaces/nithin521/Meme-caption-generation
The application allows users to:
- Enter a meme prompt
- Generate multiple captions
- Adjust generation parameters
- Experiment with different levels of randomness
π― Intended Use
This model is intended for:
- Meme caption generation
- Social-media content experimentation
- NLP demonstrations
- Generative AI projects
- Educational purposes
- Exploring fine-tuned language models
β οΈ Limitations
The model may occasionally generate:
- Grammatically incorrect sentences
- Repetitive captions
- Incomplete captions
- Semantically unrelated text
- Offensive or inappropriate language
- Memorized patterns from the training dataset
- Captions that require human editing
Generated captions should therefore be reviewed before being used publicly.
The model is designed for creative generation rather than factual or reliable text generation.
π Safety & Responsible Use
The model generates text based on patterns learned from its training data and does not have an independent understanding of the generated content.
Users should review generated content before publishing it.
The model should not be used to generate targeted harassment, hateful content, misinformation, or other harmful material.
π Technologies Used
- Python
- PyTorch
- Hugging Face Transformers
- Hugging Face Hub
- GPT-2
- Gradio
- Safetensors
ποΈ Project Pipeline
The complete project includes a data-processing and caption-generation pipeline:
Meme Images
β
Text Detection
β
YOLO-based Caption Region Detection
β
Caption Cropping
β
OCR / Text Extraction
β
Dataset Cleaning
β
Duplicate Removal
β
GPT-2 Fine-tuning
β
Meme Caption Generation
β
Gradio Web Application
The YOLO-based text detector was developed to identify meme text regions and improve the quality of captions extracted from meme images during dataset preparation.
π Future Improvements
Potential improvements include:
- Increasing the size and diversity of the training dataset
- Improving dataset quality and caption filtering
- Adding automated generation-quality ranking
- Removing noisy or incomplete generations
- Fine-tuning larger language models
- Improving semantic control over generated captions
- Adding multilingual meme caption generation
- Improving safety filtering
- Adding image-to-caption generation
π¨βπ» Project
This model was developed as part of an end-to-end AI Meme Caption Generator project combining computer vision, natural language processing, and generative AI.
Author
Nithin Kumar
Hugging Face: https://huggingface.co/nithin521
- Downloads last month
- 44