Instructions to use Jayi2424/HumorGen-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use Jayi2424/HumorGen-7B with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("unsloth/qwen2.5-7b-instruct-unsloth-bnb-4bit") model = PeftModel.from_pretrained(base_model, "Jayi2424/HumorGen-7B") - Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,126 +1,118 @@
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
library_name: peft
|
| 5 |
language:
|
| 6 |
- en
|
| 7 |
-
|
| 8 |
tags:
|
| 9 |
- humor
|
| 10 |
-
-
|
| 11 |
-
-
|
| 12 |
-
-
|
| 13 |
-
- peft
|
| 14 |
-
- qwen2
|
| 15 |
-
- transformers
|
| 16 |
-
- unsloth
|
| 17 |
-
pipeline_tag: text-generation
|
| 18 |
---
|
| 19 |
|
| 20 |
# HumorGen-7B
|
| 21 |
|
| 22 |
-
**HumorGen-7B** is a
|
| 23 |
-
|
| 24 |
-
This model achieves a Bradley-Terry rating of **1083.9** on automated pairwise evaluation, outperforming Qwen-2.5-32B and GPT-OSS-120B on humor generation despite being 4–17× smaller.
|
| 25 |
|
| 26 |
-
|
| 27 |
-
> **Authors:** Edward Ajayi, Prasenjit Mitra (Carnegie Mellon University Africa)
|
| 28 |
-
|
| 29 |
-
---
|
| 30 |
-
|
| 31 |
-
## Model Details
|
| 32 |
-
|
| 33 |
-
| Property | Value |
|
| 34 |
-
|---|---|
|
| 35 |
-
| Base Model | Qwen/Qwen2.5-7B-Instruct |
|
| 36 |
-
| Fine-tuning Method | SFT (Supervised Fine-Tuning) |
|
| 37 |
-
| Adapter Type | LoRA (r=16, alpha=16) |
|
| 38 |
-
| Target Modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
|
| 39 |
-
| Training Framework | Unsloth + TRL |
|
| 40 |
-
| Training Data | SemEval 2026 MWAHAHA (1,200 news headline prompts) |
|
| 41 |
-
| BT Rating | 1083.9 (Win rate: 59.5%) |
|
| 42 |
-
|
| 43 |
-
---
|
| 44 |
-
|
| 45 |
-
## How to Use
|
| 46 |
-
|
| 47 |
-
This is a LoRA adapter. You need to load it on top of the base model using PEFT.
|
| 48 |
|
| 49 |
```python
|
| 50 |
-
|
| 51 |
-
|
|
|
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
torch_dtype="auto",
|
| 60 |
device_map="auto"
|
| 61 |
)
|
| 62 |
-
model = PeftModel.from_pretrained(model, adapter_model_id)
|
| 63 |
-
model = model.merge_and_unload() # optional: merge for faster inference
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
```
|
| 74 |
|
| 75 |
-
|
|
|
|
|
|
|
| 76 |
|
| 77 |
-
#
|
|
|
|
|
|
|
| 78 |
|
| 79 |
-
|
| 80 |
|
| 81 |
-
|
| 82 |
-
2. **Elo Ranking:** All candidates are ranked via pairwise LLM evaluation using Llama-3.3-70B-Instruct as judge, producing per-prompt Elo ratings.
|
| 83 |
-
3. **SFT Training:** The top-10 Elo-ranked candidates per prompt (12,000 total) are used to fine-tune the student model, promoting diversity of humor styles (wordplay, absurdity, sarcasm).
|
| 84 |
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
-
##
|
| 88 |
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
| Gemini-2.5-Pro | 1190.3 | 72.0% |
|
| 96 |
-
| **HumorGen-SFT-7B (this model)** | **1083.9** | **59.5%** |
|
| 97 |
-
| HumorGen-DPO-7B | 1079.9 | 59.0% |
|
| 98 |
-
| GPT-OSS-120B | 989.2 | 47.7% |
|
| 99 |
-
| Qwen-2.5-32B-Instruct | 964.3 | 44.5% |
|
| 100 |
-
| Base Qwen-7B | 607.1 | 10.8% |
|
| 101 |
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
-
|
| 109 |
-
- **The Explainer Trap:** Training on reasoning traces (CSD/Think variants) hurts performance — the model learns to explain jokes rather than deliver them.
|
| 110 |
-
- **Data > Scale:** A well-curated 7B student outperforms a 32B teacher and a 120B open-weight model.
|
| 111 |
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
## Citation
|
| 115 |
|
| 116 |
-
If you use this model, please cite
|
| 117 |
|
| 118 |
```bibtex
|
| 119 |
-
@
|
| 120 |
-
title
|
| 121 |
-
author
|
| 122 |
-
year
|
| 123 |
-
|
| 124 |
-
|
| 125 |
}
|
| 126 |
```
|
|
|
|
| 1 |
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: unsloth/qwen2.5-7b-instruct-unsloth-bnb-4bit
|
|
|
|
| 4 |
language:
|
| 5 |
- en
|
| 6 |
+
pipeline_tag: text-generation
|
| 7 |
tags:
|
| 8 |
- humor
|
| 9 |
+
- jokes
|
| 10 |
+
- comedy
|
| 11 |
+
- causal-lm
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
# HumorGen-7B
|
| 15 |
|
| 16 |
+
**HumorGen-7B** is a humor generation model based on [Qwen2.5-7B-Instruct](https://huggingface.co/unsloth/qwen2.5-7b-instruct-unsloth-bnb-4bit), fine-tuned to generate funny jokes from headlines or topics.
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
## Quick Start
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
```python
|
| 21 |
+
# Install required packages
|
| 22 |
+
!pip install -q "unsloth[colab-new]" bitsandbytes xformers trl peft transformers
|
| 23 |
+
!pip install -U bitsandbytes>=0.46.1
|
| 24 |
|
| 25 |
+
from peft import PeftModel
|
| 26 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 27 |
|
| 28 |
+
# Load base model with 4-bit quantization (memory-efficient)
|
| 29 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
| 30 |
+
"unsloth/qwen2.5-7b-instruct-unsloth-bnb-4bit",
|
|
|
|
| 31 |
device_map="auto"
|
| 32 |
)
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
# Load the HumorGen LoRA adapter
|
| 35 |
+
model = PeftModel.from_pretrained(base_model, "Jayi2424/HumorGen-7B")
|
| 36 |
|
| 37 |
+
# Load tokenizer
|
| 38 |
+
tokenizer = AutoTokenizer.from_pretrained("unsloth/qwen2.5-7b-instruct-unsloth-bnb-4bit")
|
| 39 |
|
| 40 |
+
# Create a prompt for joke generation
|
| 41 |
+
prompt = "Generate a joke using the words 'Nigeria' and 'Capstone':\n"
|
|
|
|
| 42 |
|
| 43 |
+
# Tokenize and generate
|
| 44 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 45 |
+
outputs = model.generate(**inputs, max_new_tokens=100, use_cache=True)
|
| 46 |
|
| 47 |
+
# Print the generated joke
|
| 48 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 49 |
+
```
|
| 50 |
|
| 51 |
+
## Usage Examples
|
| 52 |
|
| 53 |
+
### Basic Generation
|
|
|
|
|
|
|
| 54 |
|
| 55 |
+
```python
|
| 56 |
+
prompt = "Write a funny joke about: coffee"
|
| 57 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 58 |
+
outputs = model.generate(**inputs, max_new_tokens=150, temperature=0.8)
|
| 59 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 60 |
+
```
|
| 61 |
|
| 62 |
+
### With System Prompt (Chat Format)
|
| 63 |
|
| 64 |
+
```python
|
| 65 |
+
SYSTEM_PROMPT = (
|
| 66 |
+
"You are a joke generator. Given a headline or topic, generate a funny joke. "
|
| 67 |
+
"Output ONLY the joke text. No thinking tags, no reasoning, no explanation, no extra words."
|
| 68 |
+
)
|
| 69 |
|
| 70 |
+
messages = [
|
| 71 |
+
{"role": "system", "content": SYSTEM_PROMPT},
|
| 72 |
+
{"role": "user", "content": "Write a funny joke about: Monday meetings"},
|
| 73 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
+
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 76 |
+
inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 77 |
+
|
| 78 |
+
outputs = model.generate(
|
| 79 |
+
**inputs,
|
| 80 |
+
max_new_tokens=512,
|
| 81 |
+
temperature=0.7,
|
| 82 |
+
top_p=0.9,
|
| 83 |
+
do_sample=True,
|
| 84 |
+
pad_token_id=tokenizer.eos_token_id,
|
| 85 |
+
)
|
| 86 |
|
| 87 |
+
print(tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
## Model Details
|
| 91 |
|
| 92 |
+
- **Base Model:** [Qwen2.5-7B-Instruct](https://huggingface.co/unsloth/qwen2.5-7b-instruct-unsloth-bnb-4bit)
|
| 93 |
+
- **Architecture:** LoRA (Low-Rank Adaptation) adapter
|
| 94 |
+
- **License:** Apache-2.0
|
| 95 |
+
- **Language:** English
|
| 96 |
|
| 97 |
+
## Generation Parameters
|
|
|
|
|
|
|
| 98 |
|
| 99 |
+
| Parameter | Default | Description |
|
| 100 |
+
|-----------|---------|-------------|
|
| 101 |
+
| `max_new_tokens` | 100-512 | Maximum length of generated joke |
|
| 102 |
+
| `temperature` | 0.7-0.8 | Controls creativity (higher = more random) |
|
| 103 |
+
| `top_p` | 0.9 | Nucleus sampling threshold |
|
| 104 |
+
| `do_sample` | True | Enable sampling for diverse outputs |
|
| 105 |
|
| 106 |
## Citation
|
| 107 |
|
| 108 |
+
If you use this model in your research, please cite:
|
| 109 |
|
| 110 |
```bibtex
|
| 111 |
+
@misc{ajayi2025humorgen,
|
| 112 |
+
title = {HumorGen: Cognitive Synergy for Humor Generation in Large Language Models via Persona-Based Distillation},
|
| 113 |
+
author = {Ajayi, Edward and Mitra, Prasenjit},
|
| 114 |
+
year = {2025},
|
| 115 |
+
howpublished = {\url{https://edwardajayi.github.io/assets/papers/HumorGen_CSF.pdf}},
|
| 116 |
+
note = {Preprint}
|
| 117 |
}
|
| 118 |
```
|