Jayi2424 commited on
Commit
5ce4522
·
verified ·
1 Parent(s): eca15ed

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +79 -87
README.md CHANGED
@@ -1,126 +1,118 @@
1
  ---
2
- base_model: Qwen/Qwen2.5-7B-Instruct
3
- base_model_relation: finetune
4
- library_name: peft
5
  language:
6
  - en
7
- license: apache-2.0
8
  tags:
9
  - humor
10
- - text-generation
11
- - lora
12
- - sft
13
- - peft
14
- - qwen2
15
- - transformers
16
- - unsloth
17
- pipeline_tag: text-generation
18
  ---
19
 
20
  # HumorGen-7B
21
 
22
- **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.
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
- > **Paper:** [HumorGen: Cognitive Synergy for Humor Generation in Large Language Models via Persona-Based Distillation](https://edwardajayi.github.io/assets/papers/HumorGen_CSF.pdf)
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
- from transformers import AutoModelForCausalLM, AutoTokenizer
51
- from peft import PeftModel
 
52
 
53
- base_model_id = "Qwen/Qwen2.5-7B-Instruct"
54
- adapter_model_id = "Jayi2424/HumorGen-7B"
55
 
56
- tokenizer = AutoTokenizer.from_pretrained(base_model_id)
57
- model = AutoModelForCausalLM.from_pretrained(
58
- base_model_id,
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
- headline = "Denzel Washington reveals he doesn't watch movies anymore"
66
- messages = [{"role": "user", "content": f"Write a funny joke based on this news headline: {headline}"}]
67
 
68
- text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
69
- inputs = tokenizer(text, return_tensors="pt").to(model.device)
70
 
71
- outputs = model.generate(**inputs, max_new_tokens=256, temperature=0.8, do_sample=True)
72
- print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
73
- ```
74
 
75
- ---
 
 
76
 
77
- ## Training Data & Methodology
 
 
78
 
79
- Data was synthesized using the **Cognitive Synergy Framework**:
80
 
81
- 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.
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
- ## Benchmark Results
88
 
89
- Evaluated on the SemEval 2026 MWAHAHA held-out test set (50 prompts, 43,048 pairwise comparisons judged by Llama-3.3-70B-Instruct):
 
 
 
 
90
 
91
- | Model | BT Rating | Win % |
92
- |---|---|---|
93
- | GPT-5 | 1323.7 | 84.7% |
94
- | Kimi-K2 | 1221.6 | 75.3% |
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
- HumorGen-SFT-7B outperforms Qwen-2.5-32B and GPT-OSS-120B while being a 7B model.
 
 
 
 
 
 
 
 
 
 
103
 
104
- ---
 
 
 
105
 
106
- ## Key Findings
 
 
 
107
 
108
- - **SFT is the strongest variant:** DPO and O-GRPO do not improve over the SFT baseline, confirming that cognitive data quality is the primary driver of humor generation performance.
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 our paper:
117
 
118
  ```bibtex
119
- @article{ajayi2025humorgen,
120
- title = {HumorGen: Cognitive Synergy for Humor Generation in Large Language Models via Persona-Based Distillation},
121
- author = {Ajayi, Edward and Mitra, Prasenjit},
122
- year = {2025},
123
- institution = {Carnegie Mellon University Africa},
124
- url = {https://edwardajayi.github.io/assets/papers/HumorGen_CSF.pdf}
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
  ```