maxpe commited on
Commit
28bafc5
·
verified ·
1 Parent(s): d2e5a01

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +351 -0
README.md ADDED
@@ -0,0 +1,351 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Model Card: GPT-OSS-20B Spanish Climate Change (Civility-Conditioned)
2
+
3
+ ## Model Description
4
+
5
+ This is a fine-tuned version of [gpt-oss-20b](https://huggingface.co/OpenSourceAI/gpt-oss-20b) trained on Spanish Facebook discussions about climate change with **civility conditioning**. The model learns to generate realistic Spanish social media posts while allowing users to control the civility level at inference time.
6
+
7
+ - **Model Type**: Autoregressive Language Model (Causal LM)
8
+ - **Base Model**: gpt-oss-20b (20 billion parameters)
9
+ - **Language**: Spanish
10
+ - **Training Objective**: Masked posting prediction with civility conditioning
11
+ - **License**: [Same as base model]
12
+ - **Model Size**: 20B parameters
13
+
14
+ ## Key Features
15
+
16
+ ### 1. Civility Control
17
+ The model can generate both civil and incivil content, controlled by a simple parameter:
18
+ - `[CIVILITY: civil]` → Generates respectful, constructive discourse
19
+ - `[CIVILITY: incivil]` → Generates content with rudeness, hate speech, or threats
20
+
21
+ ### 2. Realistic Spanish Social Media Generation
22
+ Trained on authentic Facebook discussions about climate change in Spanish, capturing:
23
+ - Natural conversation patterns
24
+ - Topic-appropriate vocabulary
25
+ - Social media communication styles
26
+ - Diverse perspectives and argumentation patterns
27
+
28
+ ### 3. Context-Aware Continuation
29
+ Uses masked posting prediction to generate responses that:
30
+ - Fit naturally within ongoing discussions
31
+ - Maintain topical coherence
32
+ - Respond appropriately to previous comments
33
+ - Match the conversational depth and complexity
34
+
35
+ ## Training Data
36
+
37
+ ### Source
38
+ - **Platform**: Facebook public posts
39
+ - **Topic**: Climate change discussions (Spanish language)
40
+ - **Format**: Conversation sequences with incivility annotations
41
+
42
+ ### Dataset Statistics
43
+ - **Total Training Examples**: 5,875
44
+ - **Validation Examples**: 653
45
+ - **Civil Examples**: ~65% of dataset
46
+ - **Incivil Examples**: ~35% of dataset
47
+
48
+ ### Incivility Annotations
49
+ Each post was labeled across multiple dimensions:
50
+ - **Impoliteness (imp)**: Rudeness, disrespect
51
+ - **Hate Speech/Stereotyping (hsst)**: Discriminatory language
52
+ - **Threats (threat)**: Threats to democratic freedoms
53
+ - **Negativity (neg)**: General negativity
54
+ - **Attack (att)**: Personal attacks
55
+ - **Sarcasm/Cynicism (sarcyn)**: Sarcastic or cynical tone
56
+
57
+ A post is classified as **incivil** if it has `imp ≥ 1` OR `hsst ≥ 1` OR `threat ≥ 1`.
58
+
59
+ ## Training Procedure
60
+
61
+ ### Hyperparameters
62
+ - **Epochs**: 3
63
+ - **Batch Size**: 2 per device
64
+ - **Gradient Accumulation Steps**: 8 (effective batch size: 16)
65
+ - **Learning Rate**: 2e-5
66
+ - **Warmup Steps**: 100
67
+ - **Weight Decay**: 0.01
68
+ - **Max Gradient Norm**: 1.0
69
+ - **Precision**: bfloat16
70
+ - **Max Sequence Length**: 2048 tokens
71
+ - **Optimizer**: AdamW
72
+
73
+ ### Training Features
74
+ - Gradient checkpointing for memory efficiency
75
+ - Dynamic padding via custom data collator
76
+ - Loss computed only on the final response (not context or instruction)
77
+ - Balanced exposure to civil and incivil examples
78
+ - Reasoning level variation (low/medium/high) for diversity
79
+
80
+ ### Infrastructure
81
+ - Trained on high-performance GPU cluster
82
+ - Model distributed across GPUs using `device_map="auto"`
83
+ - TensorBoard logging enabled
84
+
85
+ ## Usage
86
+
87
+ ### Basic Example
88
+
89
+ ```python
90
+ import torch
91
+ from transformers import AutoTokenizer, AutoModelForCausalLM
92
+
93
+ # Load model
94
+ model_path = "maxpe/gpt-oss-spanish-climate-conditioned"
95
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
96
+ model = AutoModelForCausalLM.from_pretrained(
97
+ model_path,
98
+ torch_dtype=torch.bfloat16,
99
+ device_map="auto"
100
+ )
101
+
102
+ # Format prompt with civility control
103
+ def format_prompt(context: str, civility_type: str = "civil") -> str:
104
+ if civility_type == "civil":
105
+ civility_instruction = "Esta publicación debe ser civil y respetuosa, sin elementos de descortesía, discurso de odio o amenazas."
106
+ else:
107
+ civility_instruction = "Esta publicación debe contener elementos de incivilidad (descortesía, discurso de odio, o amenazas)."
108
+
109
+ instruction = f"""[CIVILITY: {civility_type}]
110
+
111
+ Necesitas escribir una respuesta de Facebook que continúe esta discusión sobre cambio climático. {civility_instruction}
112
+
113
+ Aquí está el hilo de conversación:
114
+
115
+ {context}"""
116
+
117
+ system_message = """<|start|>system<|message|>Eres un asistente de IA que participa en discusiones de Facebook sobre cambio climático en español. Tu tarea es generar publicaciones y comentarios que reflejen el tono y estilo de las conversaciones reales. Puedes generar contenido civil o incivil según se especifique en el parámetro [CIVILITY].
118
+
119
+ Reasoning: medium
120
+
121
+ # Valid channels: analysis, final<|end|>"""
122
+
123
+ user_message = f"""<|start|>user<|message|>{instruction}<|end|>"""
124
+ assistant_start = """<|start|>assistant<|message|><|start|>final<|message|>"""
125
+
126
+ return f"{system_message}\n\n{user_message}\n\n{assistant_start}"
127
+
128
+ # Generate civil response
129
+ context = """**[Publicación Original]**
130
+ El gobierno debe prohibir los vehículos diésel inmediatamente.
131
+
132
+ **[Respuesta 1]**
133
+ Estoy de acuerdo, la calidad del aire es terrible."""
134
+
135
+ prompt = format_prompt(context, civility_type="civil")
136
+ inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=1536)
137
+ inputs = {k: v.to(model.device) for k, v in inputs.items()}
138
+
139
+ outputs = model.generate(
140
+ **inputs,
141
+ max_new_tokens=256,
142
+ temperature=0.8,
143
+ top_p=0.92,
144
+ top_k=50,
145
+ repetition_penalty=1.2,
146
+ do_sample=True,
147
+ pad_token_id=tokenizer.pad_token_id,
148
+ )
149
+
150
+ response = tokenizer.decode(outputs[0], skip_special_tokens=False)
151
+ # Extract text between <|start|>final<|message|> and <|end|>
152
+ ```
153
+
154
+ ### Quick Testing
155
+
156
+ Use the included test script:
157
+ ```bash
158
+ # Run pre-built test scenarios
159
+ python test_spanish_conditioned_model.py
160
+
161
+ # Interactive mode
162
+ python test_spanish_conditioned_model.py --interactive
163
+
164
+ # Adjust generation parameters
165
+ python test_spanish_conditioned_model.py --temperature 0.9 --max_new_tokens 250
166
+ ```
167
+
168
+ ## Generation Parameters
169
+
170
+ Recommended settings based on testing:
171
+ - **max_new_tokens**: 256 (for typical social media posts)
172
+ - **temperature**: 0.8 (balance between creativity and coherence)
173
+ - **top_p**: 0.92 (nucleus sampling)
174
+ - **top_k**: 50 (top-k sampling)
175
+ - **repetition_penalty**: 1.2 (avoid repetitive text)
176
+ - **do_sample**: True (enable sampling for diversity)
177
+
178
+ ## Model Capabilities
179
+
180
+ ### What the Model Does Well
181
+
182
+ ✅ Generate natural-sounding Spanish social media posts about climate change
183
+
184
+ ✅ Control civility level via simple parameter switch
185
+
186
+ ✅ Continue conversations with contextual awareness
187
+
188
+ ✅ Maintain topical coherence in climate discussions
189
+
190
+ ✅ Produce varied responses across different conversation contexts
191
+
192
+ ✅ Reflect authentic social media communication patterns
193
+
194
+ ### Limitations
195
+
196
+ ⚠️ Trained only on Facebook data (may not generalize perfectly to Twitter, Reddit, etc.)
197
+
198
+ ⚠️ Climate change domain-specific (not general-purpose Spanish generation)
199
+
200
+ ⚠️ Incivil content reflects training data patterns (may not cover all forms of toxicity)
201
+
202
+ ⚠️ No explicit fact-checking or accuracy verification
203
+
204
+ ⚠️ May occasionally generate biased or controversial viewpoints from training data
205
+
206
+ ## Intended Use Cases
207
+
208
+ ### Research Applications (Recommended)
209
+ - **Discourse Analysis**: Study patterns of civil vs incivil climate discourse
210
+ - **Content Moderation**: Generate training data for toxicity detection systems
211
+ - **Counter-Speech Research**: Create civil responses to incivil content
212
+ - **Polarization Studies**: Analyze dynamics of climate change discussions
213
+ - **Data Augmentation**: Expand datasets with realistic synthetic examples
214
+ - **Educational Tools**: Demonstrate effects of incivility in online discussions
215
+
216
+ ### Out-of-Scope Uses
217
+
218
+ ❌ Deploying to generate actual social media content at scale
219
+
220
+ ❌ Creating content intended to harass, mislead, or manipulate
221
+
222
+ ❌ Generating incivil content for malicious purposes
223
+
224
+ ❌ Using as a factual information source about climate science
225
+
226
+ ## Ethical Considerations
227
+
228
+ ### Incivil Content Generation
229
+ This model can generate incivil content including rudeness, hate speech, and threats. This capability is designed **exclusively for research purposes**:
230
+ - Understanding and mitigating online toxicity
231
+ - Training content moderation systems
232
+ - Studying polarization and discourse patterns
233
+ - Developing counter-speech interventions
234
+
235
+ **Users must ensure responsible use** and not deploy this model to create harmful content in real online environments.
236
+
237
+ ### Bias and Fairness
238
+ - The model reflects biases present in Spanish Facebook climate discussions
239
+ - Training data may contain controversial or fringe perspectives
240
+ - Generated content should not be treated as factual or representative of consensus views
241
+ - Researchers should be aware of potential demographic, political, and ideological biases
242
+
243
+ ### Privacy
244
+ - Trained on public Facebook posts
245
+ - No personally identifiable information (PII) should be present in outputs
246
+ - Users should verify generated content doesn't inadvertently reproduce private information
247
+
248
+ ## Evaluation
249
+
250
+ ### Training Metrics
251
+ - **Final Training Loss**: [See train_results.json]
252
+ - **Final Validation Loss**: [See eval_results.json]
253
+ - **Best Checkpoint**: Selected based on lowest validation loss
254
+
255
+ ### Qualitative Assessment
256
+ The model successfully:
257
+ - Generates fluent Spanish text
258
+ - Switches between civil and incivil tones based on the civility parameter
259
+ - Maintains relevance to climate change topics
260
+ - Produces contextually appropriate responses
261
+
262
+ ### Recommended Validation
263
+ Users should:
264
+ - Manually inspect generated outputs for quality and appropriateness
265
+ - Validate factual claims if using for educational purposes
266
+ - Check for unintended biases or problematic content
267
+ - Test across diverse conversation contexts
268
+
269
+ ## Technical Specifications
270
+
271
+ ### Model Architecture
272
+ - **Base**: gpt-oss-20b (20B parameter decoder-only transformer)
273
+ - **Format**: Harmony conversation format (OpenAI-style)
274
+ - **Channels**: analysis, final (model uses structured reasoning)
275
+ - **Vocabulary**: [From tokenizer - includes Spanish tokens]
276
+
277
+ ### Input Format
278
+ Uses structured prompt with:
279
+ 1. System message (defines model role and capabilities)
280
+ 2. User instruction (includes `[CIVILITY: civil|incivil]` parameter)
281
+ 3. Conversation context (previous posts in thread)
282
+ 4. Assistant prefix (triggers generation)
283
+
284
+ ### Output Format
285
+ Model generates:
286
+ 1. **Analysis channel** (optional): Internal reasoning about the task
287
+ 2. **Final channel**: The actual social media post response
288
+
289
+ **Recommendation**: Skip directly to final channel at inference using `<|start|>final<|message|>` prefix.
290
+
291
+ ### Special Tokens
292
+ - `<|start|>`, `<|end|>`: Conversation structure markers
293
+ - `<|message|>`: Message content delimiter
294
+ - Standard tokenizer special tokens (BOS, EOS, PAD)
295
+
296
+ ## Files and Artifacts
297
+
298
+ ### Model Files
299
+ - `model-*.safetensors`: Model weights (9 shards)
300
+ - `model.safetensors.index.json`: Weight shard index
301
+ - `config.json`: Model configuration
302
+ - `generation_config.json`: Default generation settings
303
+
304
+ ### Tokenizer Files
305
+ - `tokenizer.json`: Tokenizer vocabulary and rules
306
+ - `tokenizer_config.json`: Tokenizer configuration
307
+ - `special_tokens_map.json`: Special token mappings
308
+ - `chat_template.jinja`: Chat template (if applicable)
309
+
310
+ ### Training Files
311
+ - `training_args.bin`: Complete training arguments
312
+ - `train_results.json`: Final training metrics
313
+ - `eval_results.json`: Final evaluation metrics
314
+ - `all_results.json`: Combined results
315
+ - `checkpoint-*/`: Training checkpoints (600, 1000, 1104)
316
+ - `logs/`: TensorBoard training logs
317
+
318
+ ## Citation
319
+
320
+ If you use this model in your research, please cite:
321
+
322
+ ```bibtex
323
+ @misc{gpt-oss-spanish-climate-conditioned,
324
+ title={GPT-OSS-20B Spanish Climate Change Model with Civility Conditioning},
325
+ author={Max Pellert},
326
+ institution={Barcelona Supercomputing Center (BSC)},
327
+ year={2025},
328
+ note={Fine-tuned on Spanish Facebook climate discussions}
329
+ }
330
+ ```
331
+
332
+ ## Acknowledgments
333
+
334
+ - **Base Model**: gpt-oss-20b by OpenSourceAI
335
+ - **Framework**: Hugging Face Transformers
336
+ - **Data Source**: Spanish Facebook public climate change discussions
337
+ - **Annotation Framework**: Multi-dimensional incivility labeling scheme
338
+
339
+ ## Version History
340
+
341
+ - **v1.0** (2025-11): Initial release
342
+ - 5,875 training examples
343
+ - 3 epochs
344
+ - Civility-conditioned generation
345
+ - Checkpoint 1104 (best validation loss)
346
+
347
+ ## Additional Resources
348
+
349
+ - **Test Script**: `test_spanish_conditioned_model.py` - Run inference tests with various scenarios
350
+ - **Training Script**: `finetune_spanish_conditioned.py` - Complete training configuration
351
+ - **Dataset Creation**: `create_spanish_conditioned_more_sequences.py` - Dataset preparation pipeline (extracts 20 sequences per thread vs 3 in original version)