Iker commited on
Commit
d2c5c92
1 Parent(s): 3f4232e

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +384 -0
README.md ADDED
@@ -0,0 +1,384 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - es
4
+ license: apache-2.0
5
+ library_name: transformers
6
+ tags:
7
+ - clickbait
8
+ - noticia
9
+ - spanish
10
+ - summary
11
+ - summarization
12
+ base_model: openchat/openchat-3.5-0106
13
+ datasets:
14
+ - somosnlp/NoticIA-it
15
+ metrics:
16
+ - rouge
17
+ pipeline_tag: text-generation
18
+ widget:
19
+ - example_title: Summary Example
20
+ messages:
21
+ - role: user
22
+ content: 'Ahora eres una Inteligencia Artificial experta en desmontar titulares
23
+ sensacionalistas o clickbait. Tu tarea consiste en analizar noticias con titulares
24
+ sensacionalistas y generar un resumen de una sola frase que revele la verdad
25
+ detrás del titular.\nEste es el titular de la noticia: Le compra un abrigo a
26
+ su abuela de 97 años y la reacción de esta es una fantasía\nEl titular plantea
27
+ una pregunta o proporciona información incompleta. Debes buscar en el cuerpo
28
+ de la noticia una frase que responda lo que se sugiere en el título. Siempre
29
+ que puedas cita el texto original, especialmente si se trata de una frase que
30
+ alguien ha dicho. Si citas una frase que alguien ha dicho, usa comillas para
31
+ indicar que es una cita. Usa siempre las mínimas palabras posibles. No es necesario
32
+ que la respuesta sea una oración completa. Puede ser sólo el foco de la pregunta.
33
+ Recuerda responder siempre en Español.\nEste es el cuerpo de la noticia:\nLa
34
+ usuaria de X @Kokreta1 ha relatado la conversación que ha tenido con su abuela
35
+ de 97 años cuando le ha dado el abrigo que le ha comprado para su cumpleaños.\nTeniendo
36
+ en cuenta la avanzada edad de la señora, la tuitera le ha regalado una prenda
37
+ acorde a sus años, algo con lo que su yaya no ha estado de acuerdo.\nEl abrigo
38
+ es de vieja, ha opinado la mujer cuando lo ha visto. Os juro que soy muy fan.
39
+ Mañana vamos las dos (a por otro). Eso sí, la voy a llevar al Bershka, ha asegurado
40
+ entre risas la joven.\nSegún la propia cadena de ropa, la cual pertenece a Inditex,
41
+ su público se caracteriza por ser jóvenes atrevidos, conocedores de las últimas
42
+ tendencias e interesados en la música, las redes sociales y las nuevas tecnologías,
43
+ por lo que la gente mayor no suele llevar este estilo.\nLa inusual personalidad
44
+ de la señora ha encantado a los usuarios de la red. Es por eso que el relato
45
+ ha acumulado más de 1.000 me gusta y cerca de 100 retuits, además de una multitud
46
+ de comentarios.\n'
47
+ ---
48
+
49
+ <p align="center">
50
+ <img src="https://huggingface.co/datasets/Iker/NoticIA/resolve/main/assets/logo.png" style="width: 50%;">
51
+ </p>
52
+ <h1 align="center">NoticIA-7B: A Model for Clickbait Article Summarization in Spanish.</h1>
53
+
54
+
55
+ - 📖 Dataset Card en Español: https://huggingface.co/somosnlp/NoticIA-7B/blob/main/README_es.md
56
+
57
+
58
+ ## Model Details
59
+
60
+ ### Model Description
61
+
62
+ We define a clickbait article as one that seeks to attract the reader's attention through curiosity. To do this, the headline poses a question or an incomplete, sensationalist, exaggerated, or misleading statement. The answer to the question generated by the headline usually does not appear until the end of the article, which is preceded by a large amount of irrelevant content. The goal is for the user to enter the website through the headline and then scroll to the end of the article, viewing as much advertising as possible. Clickbait articles tend to be of low quality and do not provide value to the reader beyond the initial curiosity. This phenomenon undermines public trust in news sources and negatively affects the advertising revenues of legitimate content creators, who could see their web traffic reduced.
63
+
64
+ We present a 7B parameter model, trained with the dataset [NoticIA](https://huggingface.co/datasets/somosnlp/NoticIA-it). This model is capable of generating concise and high-quality summaries of articles with clickbait headlines.
65
+
66
+ - **Developed by:** [Iker García-Ferrero](https://ikergarcia1996.github.io/Iker-Garcia-Ferrero/), [Begoña Altuna](https://www.linkedin.com/in/bego%C3%B1a-altuna-78014139)
67
+ - **Funded by:** SomosNLP, HuggingFace, [HiTZ Zentroa](https://www.hitz.eus/)
68
+ - **Model type:** Language model, instruction tuned
69
+ - **Language(s):** es-ES
70
+ - **License:** apache-2.0
71
+ - **Fine-tuned from model:** [openchat/openchat-3.5-0106](https://huggingface.co/openchat/openchat-3.5-0106)
72
+ - **Dataset used:** https://huggingface.co/datasets/somosnlp/NoticIA-it
73
+
74
+ ### Model Sources
75
+
76
+ - **💻 Repository:** https://github.com/ikergarcia1996/NoticIA
77
+ - **📖 Paper:** [NoticIA: A Clickbait Article Summarization Dataset in Spanish](https://arxiv.org/abs/2404.07611)
78
+ - **🤖 Dataset and Pre Trained Models** [https://huggingface.co/collections/Iker/noticia-and-clickbaitfighter-65fdb2f80c34d7c063d3e48e](https://huggingface.co/collections/Iker/noticia-and-clickbaitfighter-65fdb2f80c34d7c063d3e48e)
79
+ - **🔌 Demo:** https://huggingface.co/spaces/somosnlp/NoticIA-demo
80
+ - **▶️ Video presentation (Spanish):** https://youtu.be/xc60K_NzUgk?si=QMqk6OzQZfKP1EUS
81
+ - **🐱‍💻 Hackathon #Somos600M**: https://somosnlp.org/hackathon
82
+
83
+
84
+ ## Uses
85
+
86
+
87
+ This model is tailored for scientific research, particularly for evaluating the performance of task-specific models in contrast to using instruction-tuned models in zero-shot settings. It can also be used by individuals to summarize clickbait articles for personal use.
88
+
89
+ ### Direct Use
90
+
91
+ - 📖 Summarization of clickbait articles
92
+ - 📈 Evaluation of Language Models in Spanish.
93
+ - 📚 Develop new academic resources (ie. synthetic data generation)
94
+ - 🎓 Any other academic research purpose.
95
+
96
+
97
+ ### Out-of-Scope Use
98
+
99
+ We prohibit the use of this model for any action that may harm the legitimacy or economic viability of legitimate and professional media outlets.
100
+
101
+ ## Bias, Risks, and Limitations
102
+
103
+ The model has been primarily trained with Spanish news from Spain, and the annotators of the data are also from Spain. Therefore, we expect this model to be proficient with Spanish from Spain. However, we cannot assure that it will perform well with news from Latin America or news in other languages.
104
+
105
+
106
+ ## How to Get Started with the Model
107
+
108
+ ### Making a summary of a clickbait article on the Web
109
+
110
+ The following code shows an example of how to use the template to generate a summary from the URL of a clickbait article.
111
+
112
+
113
+ ```python
114
+ import torch # pip install torch
115
+ from newspaper import Article #pip3 install newspaper3k
116
+ from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig # pip install transformers
117
+ from transformers import BitsAndBytesConfig # pip install bitsandbytes
118
+
119
+ article_url ="https://www.huffingtonpost.es/virales/le-compra-abrigo-abuela-97nos-reaccion-fantasia.html"
120
+ article = Article(article_url)
121
+ article.download()
122
+ article.parse()
123
+ headline=article.title
124
+ body = article.text
125
+
126
+ def prompt(
127
+ headline: str,
128
+ body: str,
129
+ ) -> str:
130
+ """
131
+ Generate the prompt for the model.
132
+
133
+ Args:
134
+ headline (`str`):
135
+ The headline of the article.
136
+ body (`str`):
137
+ The body of the article.
138
+ Returns:
139
+ `str`: The formatted prompt.
140
+ """
141
+
142
+ return (
143
+ f"Ahora eres una Inteligencia Artificial experta en desmontar titulares sensacionalistas o clickbait. "
144
+ f"Tu tarea consiste en analizar noticias con titulares sensacionalistas y "
145
+ f"generar un resumen de una sola frase que revele la verdad detrás del titular.\n"
146
+ f"Este es el titular de la noticia: {headline}\n"
147
+ f"El titular plantea una pregunta o proporciona información incompleta. "
148
+ f"Debes buscar en el cuerpo de la noticia una frase que responda lo que se sugiere en el título. "
149
+ f"Siempre que puedas cita el texto original, especialmente si se trata de una frase que alguien ha dicho. "
150
+ f"Si citas una frase que alguien ha dicho, usa comillas para indicar que es una cita. "
151
+ f"Usa siempre las mínimas palabras posibles. No es necesario que la respuesta sea una oración completa. "
152
+ f"Puede ser sólo el foco de la pregunta. "
153
+ f"Recuerda responder siempre en Español.\n"
154
+ f"Este es el cuerpo de la noticia:\n"
155
+ f"{body}\n"
156
+ )
157
+
158
+ prompt = prompt(headline=headline, body=body)
159
+
160
+ tokenizer = AutoTokenizer.from_pretrained("somosnlp/NoticIA-7B")
161
+
162
+
163
+ quantization_config = BitsAndBytesConfig(
164
+ load_in_4bit=True,
165
+ bnb_4bit_compute_dtype=torch.bfloat16,
166
+ bnb_4bit_use_double_quant=True,
167
+ )
168
+
169
+ model = AutoModelForCausalLM.from_pretrained(
170
+ "somosnlp/NoticIA-7B", torch_dtype=torch.bfloat16, device_map="auto", quantization_config=quantization_config,
171
+ )
172
+
173
+ formatted_prompt = tokenizer.apply_chat_template(
174
+ [{"role": "user", "content": prompt}],
175
+ tokenize=False,
176
+ add_generation_prompt=True,
177
+ )
178
+
179
+ model_inputs = tokenizer(
180
+ [formatted_prompt], return_tensors="pt", add_special_tokens=False
181
+ )
182
+
183
+ model_output = model.generate(**model_inputs.to(model.device), generation_config=GenerationConfig(
184
+ max_new_tokens=64,
185
+ min_new_tokens=1,
186
+ do_sample=False,
187
+ num_beams=1,
188
+ use_cache=True
189
+ ))
190
+
191
+ summary = tokenizer.batch_decode(model_output,skip_special_tokens=True)[0]
192
+
193
+ print(summary.strip().split("\n")[-1]) # Get only the summary, without the prompt.
194
+ ```
195
+
196
+ # Performing inference on the NoticIA dataset
197
+ The following code shows an example of how to perform an inference on an example of our dataset.
198
+
199
+ ```python
200
+ import torch # pip install torch
201
+ from datasets import load_dataset # pip install datasets
202
+ from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig # pip install transformers
203
+ from transformers import BitsAndBytesConfig # pip install bitsandbytes
204
+
205
+
206
+ dataset = load_dataset("somosnlp/NoticIA-it",split="test")
207
+
208
+ tokenizer = AutoTokenizer.from_pretrained("somosnlp/NoticIA-7B")
209
+
210
+ quantization_config = BitsAndBytesConfig(
211
+ load_in_4bit=True,
212
+ bnb_4bit_compute_dtype=torch.bfloat16,
213
+ bnb_4bit_use_double_quant=True,
214
+ )
215
+
216
+ model = AutoModelForCausalLM.from_pretrained(
217
+ "somosnlp/NoticIA-7B", torch_dtype=torch.bfloat16, device_map="auto", quantization_config=quantization_config,
218
+ )
219
+
220
+ formatted_prompt = tokenizer.apply_chat_template(
221
+ [{"role": "user", "content": dataset[0]["pregunta"]}],
222
+ tokenize=False,
223
+ add_generation_prompt=True,
224
+ )
225
+
226
+ model_inputs = tokenizer(
227
+ [formatted_prompt], return_tensors="pt", add_special_tokens=False
228
+ )
229
+
230
+ model_output = model.generate(**model_inputs.to(model.device), generation_config=GenerationConfig(
231
+ max_new_tokens=64,
232
+ min_new_tokens=1,
233
+ do_sample=False,
234
+ num_beams=1,
235
+ use_cache=True
236
+ ))
237
+
238
+ summary = tokenizer.batch_decode(model_output,skip_special_tokens=True)[0]
239
+
240
+ print(summary.strip().split("\n")[-1]) # Get only the summary, without the prompt.
241
+ ```
242
+
243
+ ## Training Details
244
+
245
+ ### Training Data
246
+
247
+ We define a clickbait article as one that seeks to attract the reader's attention through curiosity. For this purpose, the headline poses a question or an incomplete, sensationalist, exaggerated, or misleading statement. The answer to the question raised in the headline usually does not appear until the end of the article, preceded by a large amount of irrelevant content. The goal is for the user to enter the website through the headline and then scroll to the end of the article, viewing as much advertising as possible. Clickbait articles tend to be of low quality and provide no value to the reader beyond the initial curiosity. This phenomenon undermines public trust in news sources and negatively affects the advertising revenue of legitimate content creators, who could see their web traffic reduced.
248
+
249
+ We train the model with [NoticIA](https://huggingface.co/datasets/somosnlp/NoticIA-it), a dataset consisting of 850 Spanish news articles with clickbait headlines, each paired with high-quality, single-sentence generative summaries written by humans. This task demands advanced skills in text comprehension and summarization, challenging the ability of models to infer and connect various pieces of information to satisfy the user's informational curiosity generated by the clickbait headline.
250
+
251
+
252
+ ### Training Procedure
253
+
254
+ To train the model, we have developed our own training and annotation library: [https://github.com/ikergarcia1996/NoticIA](https://github.com/ikergarcia1996/NoticIA). This library utilizes 🤗 Transformers, 🤗 PEFT, Bitsandbytes, and Deepspeed.
255
+
256
+ For the hackathon, we decided to train a model with 7 trillion parameters, since using 4-bit quantization, it is possible to run the model on domestic hardware. After analyzing the performance of a large number of LLMs, we chose [openchat-3.5-0106](https://huggingface.co/openchat/openchat-3.5-0106) due to its high performance without the need for pretraining. To minimally disturb the prior knowledge of the model that allows for this performance, we opted to use the *Low-Rank Adaptation* (LoRA) training technique.
257
+
258
+ The exact training configuration is available at []()
259
+
260
+
261
+ #### Training Hyperparameters
262
+
263
+
264
+ - **Training regime:** bfloat16
265
+ - **Training method:** LoRA + Deepspeed Zero3
266
+ - **Batch size:** 64
267
+ - **Sequence Length**: 8192
268
+ - **Epochs:** 3
269
+ - **Optimizer:**: AdamW
270
+ - **Software**: Huggingface, Peft, Pytorch, Deepspeed
271
+
272
+
273
+ ## Evaluation
274
+
275
+
276
+
277
+
278
+ ### Testing Data, Factors & Metrics
279
+
280
+ #### Testing Data
281
+
282
+ We use the Test split of the NoticIA dataset: https://huggingface.co/datasets/somosnlp/NoticIA-it
283
+
284
+ #### Prompts
285
+
286
+ The prompt used for training is the same as defined and explained at [https://huggingface.co/datasets/somosnlp/NoticIA-it](https://huggingface.co/datasets/somosnlp/NoticIA-it). The prompt is converted into the chat template specific to each model.
287
+
288
+ #### Metrics
289
+
290
+ As is customary in summarization tasks, we use the ROUGE scoring metric to automatically evaluate the summaries produced by the models. Our main metric is ROUGE-1, which considers whole words as basic units. To calculate the ROUGE score, we lowercase both summaries and remove punctuation marks. In addition to the ROUGE score, we also consider the average length of the summaries. For our task, we aim for the summaries to be concise, an aspect that the ROUGE score does not evaluate. Therefore, when evaluating models, we consider both the ROUGE-1 score and the average length of the summaries. Our goal is to find a model that achieves the highest possible ROUGE score with the shortest possible summary length, balancing quality and brevity.
291
+
292
+ ### Results
293
+
294
+ We have evaluated the best language models trained to follow current instructions, and we have also included the performance obtained by a human annotator. The code to reproduce the results is available at the following link: [https://github.com/ikergarcia1996/NoticIA](https://github.com/ikergarcia1996/NoticIA)
295
+
296
+ <p align="center">
297
+ <img src="https://huggingface.co/somosnlp/Resumen_Noticias_Clickbait/resolve/main/Results_finetune.png" style="width: 100%;">
298
+ </p>
299
+
300
+ After training, our model acquires the ability to perform summaries with a capacity close to that of humans, significantly surpassing any model in a zero-shot setting. At the same time, the model produces more concise and shorter summaries.
301
+
302
+
303
+ ## Environmental Impact
304
+
305
+
306
+ For the carbon footprint estimation, we estimated the values considering a 400W consumption per GPU with a 0.083 kg/kWh carbon intensity: https://app.electricitymaps.com/map
307
+
308
+ - **Hardware Type:** 4 X Nvidia A100 80Gb
309
+ - **Hours used:** 2 hours
310
+ - **Compute Region:** Donostia, Basque Country, Spain
311
+ - **Carbon Emitted:** 0.3984 kg Co2
312
+
313
+
314
+ ### Model Architecture and Objective
315
+
316
+ Decoder-only model. Pretrained for instruction. We employ the standard Next Token Prediction (NTP) loss for training our models. To prevent the loss associated with the article body tokens from overshadowing the loss of the summary output tokens, we compute the loss exclusively over the summary tokens.
317
+ ### Compute Infrastructure
318
+
319
+ We conducted all our experiments on a machine equipped with four NVIDIA A100 GPUs, each with 80GB of memory, interconnected via NVLink. The machine features two AMD EPYC 7513 32-Core Processors and 1TB (1024GB) of RAM.
320
+
321
+
322
+ #### Software
323
+
324
+ - Huggingface Transformers: https://github.com/huggingface/transformers
325
+ - PEFT: https://github.com/huggingface/peft
326
+ - Deepspeed: https://github.com/microsoft/DeepSpeed
327
+ - Pytorch: https://pytorch.org/
328
+
329
+ Our code is available at: [https://github.com/ikergarcia1996/NoticIA](https://github.com/ikergarcia1996/NoticIA)
330
+
331
+
332
+ ## License
333
+
334
+ We release our model under the Apache 2.0 license.
335
+
336
+ ## Citation
337
+
338
+ If you use this dataset, please cite our paper: [NoticIA: A Clickbait Article Summarization Dataset in Spanish](https://arxiv.org/abs/2404.07611)
339
+
340
+ **BibTeX:**
341
+
342
+ ```
343
+ @misc{garcíaferrero2024noticia,
344
+ title={NoticIA: A Clickbait Article Summarization Dataset in Spanish},
345
+ author={Iker García-Ferrero and Begoña Altuna},
346
+ year={2024},
347
+ eprint={2404.07611},
348
+ archivePrefix={arXiv},
349
+ primaryClass={cs.CL}
350
+ }
351
+ ```
352
+
353
+
354
+
355
+ ## More Information
356
+
357
+
358
+ This project was developed during the [Hackathon #Somos600M](https://somosnlp.org/hackathon) organized by SomosNLP. Demo endpoints were sponsored by HuggingFace.
359
+
360
+ **Team:**
361
+
362
+
363
+ - [Iker García-Ferrero](https://huggingface.co/Iker)
364
+ - [Begoña Altura](https://huggingface.co/baltuna)
365
+
366
+ **Contact**: {iker.garciaf,begona.altuna}@ehu.eus
367
+
368
+
369
+ This dataset was created by [Iker García-Ferrero](https://ikergarcia1996.github.io/Iker-Garcia-Ferrero/) and [Begoña Altuna](https://www.linkedin.com/in/bego%C3%B1a-altuna-78014139). We are researchers in NLP at the University of the Basque Country, within the [IXA](https://www.ixa.eus/) research group, and we are part of [HiTZ, the Basque Language Technology Center](https://www.hitz.eus/es).
370
+
371
+ <div style="display: flex; justify-content: space-around; width: 100%;">
372
+ <div style="width: 50%;" align="left">
373
+ <a href="http://ixa.si.ehu.es/">
374
+ <img src="https://raw.githubusercontent.com/ikergarcia1996/Iker-Garcia-Ferrero/master/icons/ixa.png" width="50" height="50" alt="Ixa NLP Group">
375
+ </a>
376
+ </div>
377
+ <div style="width: 50%;" align="right">
378
+ <a href="http://www.hitz.eus/">
379
+ <img src="https://raw.githubusercontent.com/ikergarcia1996/Iker-Garcia-Ferrero/master/icons/Hitz.png" width="300" height="50" alt="HiTZ Basque Center for Language Technologies">
380
+ </a>
381
+ </div>
382
+ </div>
383
+
384
+