Update README.md
Browse files
README.md
CHANGED
@@ -94,7 +94,7 @@ Hemos realizado una evaluación incluyendo los mejores modelos de lenguaje entre
|
|
94 |
El código para reproducir los resultados se encuentra en el siguiente enlace: [https://github.com/ikergarcia1996/NoticIA](https://github.com/ikergarcia1996/NoticIA)
|
95 |
|
96 |
<p align="center">
|
97 |
-
<img src="https://huggingface.co/
|
98 |
</p>
|
99 |
|
100 |
|
@@ -106,6 +106,138 @@ Al mismo tiempo, el modelo produce resúmenes más concisos y cortos.
|
|
106 |
Una demo para probar nuestro modelo está disponible en el siguiente enlace: [Coming Soon]()
|
107 |
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
# Usos del modelo
|
111 |
Este dataset ha sido entrenado para su uso en investigación científica. Si quieres hacer un uso comercial del modelo tendrás que tener
|
|
|
94 |
El código para reproducir los resultados se encuentra en el siguiente enlace: [https://github.com/ikergarcia1996/NoticIA](https://github.com/ikergarcia1996/NoticIA)
|
95 |
|
96 |
<p align="center">
|
97 |
+
<img src="https://huggingface.co/somosnlp/Resumen_Noticias_Clickbait/resolve/main/Results_finetune.png" style="width: 100%;">
|
98 |
</p>
|
99 |
|
100 |
|
|
|
106 |
Una demo para probar nuestro modelo está disponible en el siguiente enlace: [Coming Soon]()
|
107 |
|
108 |
|
109 |
+
# Realizar un resumen de un artículo clickbait en la Web
|
110 |
+
El siguiente código muestra un ejemplo de como usar el modelo para generar un resumen a partir de la URL de un artículo clickbait.
|
111 |
+
|
112 |
+
```python
|
113 |
+
import torch # pip install torch
|
114 |
+
from newspaper import Article #pip3 install newspaper3k
|
115 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig # pip install transformers
|
116 |
+
from transformers import BitsAndBytesConfig # pip install bitsandbytes
|
117 |
+
|
118 |
+
article_url ="https://www.huffingtonpost.es/virales/le-compra-abrigo-abuela-97nos-reaccion-fantasia.html"
|
119 |
+
article = Article(article_url)
|
120 |
+
article.download()
|
121 |
+
article.parse()
|
122 |
+
headline=article.title
|
123 |
+
body = article.text
|
124 |
+
|
125 |
+
def prompt(
|
126 |
+
headline: str,
|
127 |
+
body: str,
|
128 |
+
) -> str:
|
129 |
+
"""
|
130 |
+
Generate the prompt for the model.
|
131 |
+
|
132 |
+
Args:
|
133 |
+
headline (`str`):
|
134 |
+
The headline of the article.
|
135 |
+
body (`str`):
|
136 |
+
The body of the article.
|
137 |
+
Returns:
|
138 |
+
`str`: The formatted prompt.
|
139 |
+
"""
|
140 |
+
|
141 |
+
return (
|
142 |
+
f"Ahora eres una Inteligencia Artificial experta en desmontar titulares sensacionalistas o clickbait. "
|
143 |
+
f"Tu tarea consiste en analizar noticias con titulares sensacionalistas y "
|
144 |
+
f"generar un resumen de una sola frase que revele la verdad detrás del titular.\n"
|
145 |
+
f"Este es el titular de la noticia: {headline}\n"
|
146 |
+
f"El titular plantea una pregunta o proporciona información incompleta. "
|
147 |
+
f"Debes buscar en el cuerpo de la noticia una frase que responda lo que se sugiere en el título. "
|
148 |
+
f"Siempre que puedas cita el texto original, especialmente si se trata de una frase que alguien ha dicho. "
|
149 |
+
f"Si citas una frase que alguien ha dicho, usa comillas para indicar que es una cita. "
|
150 |
+
f"Usa siempre las mínimas palabras posibles. No es necesario que la respuesta sea una oración completa. "
|
151 |
+
f"Puede ser sólo el foco de la pregunta. "
|
152 |
+
f"Recuerda responder siempre en Español.\n"
|
153 |
+
f"Este es el cuerpo de la noticia:\n"
|
154 |
+
f"{body}\n"
|
155 |
+
)
|
156 |
+
|
157 |
+
prompt = prompt(headline=headline, body=body)
|
158 |
+
|
159 |
+
tokenizer = AutoTokenizer.from_pretrained("somosnlp/Resumen_Noticias_Clickbait")
|
160 |
+
|
161 |
+
|
162 |
+
quantization_config = BitsAndBytesConfig(
|
163 |
+
load_in_4bit=True,
|
164 |
+
bnb_4bit_compute_dtype=torch.bfloat16,
|
165 |
+
bnb_4bit_use_double_quant=True,
|
166 |
+
)
|
167 |
+
|
168 |
+
model = AutoModelForCausalLM.from_pretrained(
|
169 |
+
"somosnlp/Resumen_Noticias_Clickbait", torch_dtype=torch.bfloat16, device_map="auto",quantization_config=quantization_config,
|
170 |
+
)
|
171 |
+
|
172 |
+
formatted_prompt = tokenizer.apply_chat_template(
|
173 |
+
[{"role": "user", "content": prompt}],
|
174 |
+
tokenize=False,
|
175 |
+
add_generation_prompt=True,
|
176 |
+
)
|
177 |
+
|
178 |
+
model_inputs = tokenizer(
|
179 |
+
[formatted_prompt], return_tensors="pt", add_special_tokens=False
|
180 |
+
)
|
181 |
+
|
182 |
+
model_output = model.generate(**model_inputs.to(model.device), generation_config=GenerationConfig(
|
183 |
+
max_new_tokens=32,
|
184 |
+
min_new_tokens=1,
|
185 |
+
do_sample=False,
|
186 |
+
num_beams=1,
|
187 |
+
use_cache=True
|
188 |
+
))
|
189 |
+
|
190 |
+
summary = tokenizer.batch_decode(model_output,skip_special_tokens=True)[0]
|
191 |
+
|
192 |
+
print(summary.strip().split("\n")[-1]) # Get only the summary, without the prompt.
|
193 |
+
```
|
194 |
+
|
195 |
+
# Realizar inferencia en el dataset NoticIA
|
196 |
+
El siguiente código muestra un ejemplo de como realizar una inferencia sobre un ejemplo de nuestro dataset.
|
197 |
+
```python
|
198 |
+
import torch # pip install torch
|
199 |
+
from datasets import load_dataset # pip install datasets
|
200 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig # pip install transformers
|
201 |
+
from transformers import BitsAndBytesConfig # pip install bitsandbytes
|
202 |
+
|
203 |
+
|
204 |
+
dataset = load_dataset("somosnlp/Resumen_Noticias_Clickbait",split="test")
|
205 |
+
|
206 |
+
tokenizer = AutoTokenizer.from_pretrained("Iker/ClickbaitFighter-7B")
|
207 |
+
|
208 |
+
quantization_config = BitsAndBytesConfig(
|
209 |
+
load_in_4bit=True,
|
210 |
+
bnb_4bit_compute_dtype=torch.bfloat16,
|
211 |
+
bnb_4bit_use_double_quant=True,
|
212 |
+
)
|
213 |
+
|
214 |
+
model = AutoModelForCausalLM.from_pretrained(
|
215 |
+
"Iker/ClickbaitFighter-7B", torch_dtype=torch.bfloat16, device_map="auto", quantization_config=quantization_config,
|
216 |
+
)
|
217 |
+
|
218 |
+
formatted_prompt = tokenizer.apply_chat_template(
|
219 |
+
[{"role": "user", "content": dataset[0]["prompt"]}],
|
220 |
+
tokenize=False,
|
221 |
+
add_generation_prompt=True,
|
222 |
+
)
|
223 |
+
|
224 |
+
model_inputs = tokenizer(
|
225 |
+
[formatted_prompt], return_tensors="pt", add_special_tokens=False
|
226 |
+
)
|
227 |
+
|
228 |
+
model_output = model.generate(**model_inputs.to(model.device), generation_config=GenerationConfig(
|
229 |
+
max_new_tokens=32,
|
230 |
+
min_new_tokens=1,
|
231 |
+
do_sample=False,
|
232 |
+
num_beams=1,
|
233 |
+
use_cache=True
|
234 |
+
))
|
235 |
+
|
236 |
+
summary = tokenizer.batch_decode(model_output,skip_special_tokens=True)[0]
|
237 |
+
|
238 |
+
print(summary.strip().split("\n")[-1]) # Get only the summary, without the prompt.
|
239 |
+
```
|
240 |
+
|
241 |
|
242 |
# Usos del modelo
|
243 |
Este dataset ha sido entrenado para su uso en investigación científica. Si quieres hacer un uso comercial del modelo tendrás que tener
|