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
Update model card: add paper link, benchmark results, methodology, and Quick Start code
Browse files
README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
-
base_model:
|
| 4 |
language:
|
| 5 |
- en
|
| 6 |
pipeline_tag: text-generation
|
|
@@ -8,14 +8,32 @@ tags:
|
|
| 8 |
- humor
|
| 9 |
- jokes
|
| 10 |
- comedy
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
- causal-lm
|
| 12 |
---
|
| 13 |
|
| 14 |
# HumorGen-7B
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
```python
|
| 21 |
# Install required packages
|
|
@@ -37,29 +55,45 @@ model = PeftModel.from_pretrained(base_model, "Jayi2424/HumorGen-7B")
|
|
| 37 |
# Load tokenizer
|
| 38 |
tokenizer = AutoTokenizer.from_pretrained("unsloth/qwen2.5-7b-instruct-unsloth-bnb-4bit")
|
| 39 |
|
| 40 |
-
#
|
| 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 |
-
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
###
|
| 54 |
|
| 55 |
```python
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
```
|
| 61 |
|
| 62 |
-
### With System Prompt
|
| 63 |
|
| 64 |
```python
|
| 65 |
SYSTEM_PROMPT = (
|
|
@@ -83,27 +117,75 @@ outputs = model.generate(
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
-
|
| 93 |
-
-
|
| 94 |
-
-
|
| 95 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
-
##
|
| 98 |
|
| 99 |
-
|
|
| 100 |
-
|----------
|
| 101 |
-
|
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
+
base_model: Qwen/Qwen2.5-7B-Instruct
|
| 4 |
language:
|
| 5 |
- en
|
| 6 |
pipeline_tag: text-generation
|
|
|
|
| 8 |
- humor
|
| 9 |
- jokes
|
| 10 |
- comedy
|
| 11 |
+
- lora
|
| 12 |
+
- sft
|
| 13 |
+
- qwen2
|
| 14 |
+
- unsloth
|
| 15 |
+
- peft
|
| 16 |
- causal-lm
|
| 17 |
---
|
| 18 |
|
| 19 |
# HumorGen-7B
|
| 20 |
|
| 21 |
+
<p align="center">
|
| 22 |
+
<a href="https://edwardajayi.github.io/assets/papers/HumorGen_CSF.pdf">π Paper</a> β’
|
| 23 |
+
<a href="https://huggingface.co/Jayi2424/HumorGen-7B">π€ Model</a> β’
|
| 24 |
+
<a href="https://github.com/edwardajayi">π» GitHub</a>
|
| 25 |
+
</p>
|
| 26 |
|
| 27 |
+
**HumorGen-7B** is a 7B-parameter humor generation model fine-tuned from [Qwen/Qwen2.5-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct) using the **Cognitive Synergy Framework** introduced in our paper. It is a LoRA adapter trained with Supervised Fine-Tuning (SFT) on high-quality humor data curated via a Mixture-of-Thought (MoT) approach with six cognitive personas grounded in psychological humor theory.
|
| 28 |
+
|
| 29 |
+
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.
|
| 30 |
+
|
| 31 |
+
> **Paper:** [HumorGen: Cognitive Synergy for Humor Generation in Large Language Models via Persona-Based Distillation](https://edwardajayi.github.io/assets/papers/HumorGen_CSF.pdf)
|
| 32 |
+
> **Authors:** Edward Ajayi, Prasenjit Mitra β *Carnegie Mellon University Africa*
|
| 33 |
+
|
| 34 |
+
---
|
| 35 |
+
|
| 36 |
+
## π Quick Start (Colab / Jupyter)
|
| 37 |
|
| 38 |
```python
|
| 39 |
# Install required packages
|
|
|
|
| 55 |
# Load tokenizer
|
| 56 |
tokenizer = AutoTokenizer.from_pretrained("unsloth/qwen2.5-7b-instruct-unsloth-bnb-4bit")
|
| 57 |
|
| 58 |
+
# Generate a joke
|
| 59 |
prompt = "Generate a joke using the words 'Nigeria' and 'Capstone':\n"
|
|
|
|
|
|
|
| 60 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 61 |
outputs = model.generate(**inputs, max_new_tokens=100, use_cache=True)
|
|
|
|
|
|
|
| 62 |
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 63 |
```
|
| 64 |
|
| 65 |
+
---
|
| 66 |
+
|
| 67 |
+
## π Usage
|
| 68 |
|
| 69 |
+
### Standard Usage (Full Precision)
|
| 70 |
|
| 71 |
```python
|
| 72 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 73 |
+
from peft import PeftModel
|
| 74 |
+
|
| 75 |
+
base_model_id = "Qwen/Qwen2.5-7B-Instruct"
|
| 76 |
+
adapter_model_id = "Jayi2424/HumorGen-7B"
|
| 77 |
+
|
| 78 |
+
tokenizer = AutoTokenizer.from_pretrained(base_model_id)
|
| 79 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 80 |
+
base_model_id,
|
| 81 |
+
torch_dtype="auto",
|
| 82 |
+
device_map="auto"
|
| 83 |
+
)
|
| 84 |
+
model = PeftModel.from_pretrained(model, adapter_model_id)
|
| 85 |
+
model = model.merge_and_unload() # optional: merge for faster inference
|
| 86 |
+
|
| 87 |
+
headline = "Denzel Washington reveals he doesn't watch movies anymore"
|
| 88 |
+
messages = [{"role": "user", "content": f"Write a funny joke based on this news headline: {headline}"}]
|
| 89 |
+
|
| 90 |
+
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 91 |
+
inputs = tokenizer(text, return_tensors="pt").to(model.device)
|
| 92 |
+
outputs = model.generate(**inputs, max_new_tokens=256, temperature=0.8, do_sample=True)
|
| 93 |
+
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
|
| 94 |
```
|
| 95 |
|
| 96 |
+
### With System Prompt
|
| 97 |
|
| 98 |
```python
|
| 99 |
SYSTEM_PROMPT = (
|
|
|
|
| 117 |
do_sample=True,
|
| 118 |
pad_token_id=tokenizer.eos_token_id,
|
| 119 |
)
|
|
|
|
| 120 |
print(tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))
|
| 121 |
```
|
| 122 |
|
| 123 |
+
---
|
| 124 |
+
|
| 125 |
+
## π Benchmark Results
|
| 126 |
+
|
| 127 |
+
Evaluated on the **SemEval 2026 MWAHAHA** held-out test set (50 prompts, 43,048 pairwise comparisons judged by Llama-3.3-70B-Instruct):
|
| 128 |
|
| 129 |
+
| Model | BT Rating | Win % |
|
| 130 |
+
|-------|-----------|-------|
|
| 131 |
+
| GPT-5 | 1323.7 | 84.7% |
|
| 132 |
+
| Kimi-K2 | 1221.6 | 75.3% |
|
| 133 |
+
| Gemini-2.5-Pro | 1190.3 | 72.0% |
|
| 134 |
+
| **HumorGen-SFT-7B (this model)** | **1083.9** | **59.5%** |
|
| 135 |
+
| HumorGen-DPO-7B | 1079.9 | 59.0% |
|
| 136 |
+
| GPT-OSS-120B | 989.2 | 47.7% |
|
| 137 |
+
| Qwen-2.5-32B-Instruct | 964.3 | 44.5% |
|
| 138 |
+
| Base Qwen-7B | 607.1 | 10.8% |
|
| 139 |
+
|
| 140 |
+
> HumorGen-SFT-7B outperforms Qwen-2.5-32B and GPT-OSS-120B while being **4β17Γ smaller**.
|
| 141 |
+
|
| 142 |
+
---
|
| 143 |
|
| 144 |
+
## π§ Model Details
|
| 145 |
|
| 146 |
+
| Property | Value |
|
| 147 |
+
|----------|-------|
|
| 148 |
+
| Base Model | [Qwen/Qwen2.5-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct) |
|
| 149 |
+
| Fine-tuning Method | SFT (Supervised Fine-Tuning) |
|
| 150 |
+
| Adapter Type | LoRA (r=16, alpha=16) |
|
| 151 |
+
| Target Modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
|
| 152 |
+
| Training Framework | Unsloth + TRL |
|
| 153 |
+
| Training Data | SemEval 2026 MWAHAHA (1,200 news headline prompts) |
|
| 154 |
+
| BT Rating | 1083.9 (Win rate: 59.5%) |
|
| 155 |
+
| License | Apache-2.0 |
|
| 156 |
+
|
| 157 |
+
---
|
| 158 |
+
|
| 159 |
+
## βοΈ Generation Parameters
|
| 160 |
+
|
| 161 |
+
| Parameter | Recommended | Description |
|
| 162 |
+
|-----------|-------------|-------------|
|
| 163 |
+
| `max_new_tokens` | 100β512 | Maximum length of generated joke |
|
| 164 |
+
| `temperature` | 0.7β0.8 | Controls creativity (higher = more varied) |
|
| 165 |
| `top_p` | 0.9 | Nucleus sampling threshold |
|
| 166 |
+
| `do_sample` | `True` | Enable sampling for diverse outputs |
|
| 167 |
+
|
| 168 |
+
---
|
| 169 |
+
|
| 170 |
+
## π¬ Training Methodology
|
| 171 |
+
|
| 172 |
+
Data was synthesized using the **Cognitive Synergy Framework**:
|
| 173 |
+
|
| 174 |
+
1. **Mixture-of-Thought (MoT):** Six distinct cognitive personas β *The Absurdist, The Cynic, The Neurotic, The Observer, The Wordsmith, The Optimist* β each generate 4 joke candidates per prompt from a teacher ensemble of Kimi-K2 and Qwen-2.5-32B-Instruct, yielding ~28,800 candidates across 1,200 prompts.
|
| 175 |
+
2. **Elo Ranking:** All candidates are ranked via pairwise LLM evaluation using Llama-3.3-70B-Instruct as judge, producing per-prompt Elo ratings.
|
| 176 |
+
3. **SFT Training:** The top-10 Elo-ranked candidates per prompt (12,000 total) are used to fine-tune the student model, promoting diversity across humor styles (wordplay, absurdity, sarcasm).
|
| 177 |
+
|
| 178 |
+
---
|
| 179 |
+
|
| 180 |
+
## π‘ Key Findings
|
| 181 |
+
|
| 182 |
+
- **SFT is the strongest variant:** DPO and GRPO do not improve over the SFT baseline β cognitive data quality is the primary driver of humor generation performance.
|
| 183 |
+
- **The Explainer Trap:** Training on reasoning traces hurts performance; the model learns to explain jokes rather than deliver them.
|
| 184 |
+
- **Data > Scale:** A well-curated 7B student outperforms a 32B teacher and a 120B open-weight model.
|
| 185 |
+
|
| 186 |
+
---
|
| 187 |
|
| 188 |
+
## π Citation
|
| 189 |
|
| 190 |
If you use this model in your research, please cite:
|
| 191 |
|