Text Generation
Transformers
Safetensors
Spanish
gemma
clickbait
noticia
spanish
summary
summarization
conversational
text-generation-inference
Instructions to use Iker/ClickbaitFighter-2B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Iker/ClickbaitFighter-2B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Iker/ClickbaitFighter-2B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Iker/ClickbaitFighter-2B") model = AutoModelForCausalLM.from_pretrained("Iker/ClickbaitFighter-2B", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Iker/ClickbaitFighter-2B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Iker/ClickbaitFighter-2B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Iker/ClickbaitFighter-2B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Iker/ClickbaitFighter-2B
- SGLang
How to use Iker/ClickbaitFighter-2B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Iker/ClickbaitFighter-2B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Iker/ClickbaitFighter-2B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Iker/ClickbaitFighter-2B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Iker/ClickbaitFighter-2B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Iker/ClickbaitFighter-2B with Docker Model Runner:
docker model run hf.co/Iker/ClickbaitFighter-2B
| license: cc-by-nc-sa-4.0 | |
| datasets: | |
| - Iker/NoticIA | |
| language: | |
| - es | |
| metrics: | |
| - rouge | |
| library_name: transformers | |
| pipeline_tag: text-generation | |
| base_model: google/gemma-2b-it | |
| tags: | |
| - clickbait | |
| - noticia | |
| - spanish | |
| - summary | |
| - summarization | |
| widget: | |
| - example_title: Summary | |
| messages: | |
| - role: user | |
| content: "Ahora eres una Inteligencia Artificial experta en desmontar titulares | |
| sensacionalistas o clickbait. Tu tarea consiste en analizar noticias | |
| con titulares sensacionalistas y generar un resumen de una sola frase | |
| que revele la verdad detrás del titular.\\nEste es el titular de la | |
| noticia: Le compra un abrigo a su abuela de 97 años y la reacción de | |
| esta es una fantasía\\nEl titular plantea una pregunta o proporciona | |
| información incompleta. Debes buscar en el cuerpo de la noticia una | |
| frase que responda lo que se sugiere en el título. Siempre que puedas | |
| cita el texto original, especialmente si se trata de una frase que | |
| alguien ha dicho. Si citas una frase que alguien ha dicho, usa | |
| comillas para indicar que es una cita. Usa siempre las mínimas | |
| palabras posibles. No es necesario que la respuesta sea una oración | |
| completa. Puede ser sólo el foco de la pregunta. Recuerda responder | |
| siempre en Español.\\nEste es el cuerpo de la noticia:\\nLa usuaria de | |
| X @Kokreta1 ha relatado la conversación que ha tenido con su abuela de | |
| 97 años cuando le ha dado el abrigo que le ha comprado para su | |
| cumpleaños.\\nTeniendo en cuenta la avanzada edad de la señora, la | |
| tuitera le ha regalado una prenda acorde a sus años, algo con lo que | |
| su yaya no ha estado de acuerdo.\\nEl abrigo es de vieja, ha opinado | |
| la mujer cuando lo ha visto. Os juro que soy muy fan. Mañana vamos las | |
| dos (a por otro). Eso sí, la voy a llevar al Bershka, ha asegurado | |
| entre risas la joven.\\nSegún la propia cadena de ropa, la cual | |
| pertenece a Inditex, su público se caracteriza por ser jóvenes | |
| atrevidos, conocedores de las últimas tendencias e interesados en la | |
| música, las redes sociales y las nuevas tecnologías, por lo que la | |
| gente mayor no suele llevar este estilo.\\nLa inusual personalidad de | |
| la señora ha encantado a los usuarios de la red. Es por eso que el | |
| relato ha acumulado más de 1.000 me gusta y cerca de 100 retuits, | |
| además de una multitud de comentarios.\\n" | |
| <table> | |
| <tr> | |
| <td style="width:100%"><img src="https://github.com/ikergarcia1996/NoticIA/blob/main/assets/head.png?raw=true" align="right" width="100%"> </td> | |
| </tr> | |
| </table> | |
| A model finetuned with the [NoticIA Dataset](https://huggingface.co/datasets/Iker/NoticIA). This model can generate summaries of clickbait headlines | |
| If you are looking for a larger model, with better performance, check out [ClickbaitFighter-10B](https://huggingface.co/Iker/ClickbaitFighter-10B). | |
| - 📖 Paper: [NoticIA: A Clickbait Article Summarization Dataset in Spanish](https://arxiv.org/abs/2404.07611) | |
| - 📓 NoticIA Dataset: [https://huggingface.co/datasets/Iker/NoticIA](https://huggingface.co/datasets/Iker/NoticIA) | |
| - 💻 Baseline Code: [https://github.com/ikergarcia1996/NoticIA](https://github.com/ikergarcia1996/NoticIA) | |
| - 🤖 Pre Trained Models [https://huggingface.co/collections/Iker/noticia-and-clickbaitfighter-65fdb2f80c34d7c063d3e48e](https://huggingface.co/collections/Iker/noticia-and-clickbaitfighter-65fdb2f80c34d7c063d3e48e) | |
| - 🔌 Online Demo: [https://iker-clickbaitfighter.hf.space/](https://iker-clickbaitfighter.hf.space/) | |
| # Open Source Models | |
| <table border="1" cellspacing="0" cellpadding="5"> | |
| <thead> | |
| <tr> | |
| <th></th> | |
| <th><a href="https://huggingface.co/Iker/ClickbaitFighter-2B">Iker/ClickbaitFighter-2B</a></th> | |
| <th><a href="https://huggingface.co/Iker/ClickbaitFighter-7B">Iker/ClickbaitFighter-7B</a></th> | |
| <th><a href="https://huggingface.co/Iker/ClickbaitFighter-10B">Iker/ClickbaitFighter-10B</a></th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| <tr> | |
| <td>Param. no.</td> | |
| <td>2B</td> | |
| <td>7B</td> | |
| <td>10M</td> | |
| </tr> | |
| <tr> | |
| <td>ROUGE</td> | |
| <td>36.26</td> | |
| <td>49.81</td> | |
| <td>52.01</td> | |
| </tr> | |
| <tr> | |
| </tbody> | |
| </table> | |
| # Evaluation Results | |
| <table> | |
| <tr> | |
| <td style="width:100%"><img src="https://github.com/ikergarcia1996/NoticIA/raw/main/results/Results.png" align="right" width="100%"> </td> | |
| </tr> | |
| </table> | |
| # Usage example: | |
| ## Summarize a web article | |
| ```python | |
| import torch # pip install torch | |
| from newspaper import Article #pip3 install newspaper3k | |
| from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig # pip install transformers | |
| article_url ="https://www.huffingtonpost.es/virales/le-compra-abrigo-abuela-97nos-reaccion-fantasia.html" | |
| article = Article(article_url) | |
| article.download() | |
| article.parse() | |
| headline=article.title | |
| body = article.text | |
| def prompt( | |
| headline: str, | |
| body: str, | |
| ) -> str: | |
| """ | |
| Generate the prompt for the model. | |
| Args: | |
| headline (`str`): | |
| The headline of the article. | |
| body (`str`): | |
| The body of the article. | |
| Returns: | |
| `str`: The formatted prompt. | |
| """ | |
| return ( | |
| f"Ahora eres una Inteligencia Artificial experta en desmontar titulares sensacionalistas o clickbait. " | |
| f"Tu tarea consiste en analizar noticias con titulares sensacionalistas y " | |
| f"generar un resumen de una sola frase que revele la verdad detrás del titular.\n" | |
| f"Este es el titular de la noticia: {headline}\n" | |
| f"El titular plantea una pregunta o proporciona información incompleta. " | |
| f"Debes buscar en el cuerpo de la noticia una frase que responda lo que se sugiere en el título. " | |
| f"Siempre que puedas cita el texto original, especialmente si se trata de una frase que alguien ha dicho. " | |
| f"Si citas una frase que alguien ha dicho, usa comillas para indicar que es una cita. " | |
| f"Usa siempre las mínimas palabras posibles. No es necesario que la respuesta sea una oración completa. " | |
| f"Puede ser sólo el foco de la pregunta. " | |
| f"Recuerda responder siempre en Español.\n" | |
| f"Este es el cuerpo de la noticia:\n" | |
| f"{body}\n" | |
| ) | |
| prompt = prompt(headline=headline, body=body) | |
| tokenizer = AutoTokenizer.from_pretrained("Iker/ClickbaitFighter-2B") | |
| model = AutoModelForCausalLM.from_pretrained( | |
| "Iker/ClickbaitFighter-2B", torch_dtype=torch.bfloat16, device_map="auto" | |
| ) | |
| formatted_prompt = tokenizer.apply_chat_template( | |
| [{"role": "user", "content": prompt}], | |
| tokenize=False, | |
| add_generation_prompt=True, | |
| ) | |
| model_inputs = tokenizer( | |
| [formatted_prompt], return_tensors="pt", add_special_tokens=False | |
| ) | |
| model_output = model.generate(**model_inputs.to(model.device), generation_config=GenerationConfig( | |
| max_new_tokens=32, | |
| min_new_tokens=1, | |
| do_sample=False, | |
| num_beams=1, | |
| use_cache=True | |
| )) | |
| summary = tokenizer.batch_decode(model_output,skip_special_tokens=True)[0] | |
| print(summary.strip().split("\n")[-1]) # Get only the summary, without the prompt. | |
| ``` | |
| ## Run inference in the NoticIA dataset | |
| ```python | |
| import torch # pip install torch | |
| from datasets import load_dataset # pip install datasets | |
| from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig # pip install transformers | |
| dataset = load_dataset("Iker/NoticIA") | |
| example = dataset["test"][0] | |
| headline = example["web_headline"] | |
| body = example["web_text"] | |
| def prompt( | |
| headline: str, | |
| body: str, | |
| ) -> str: | |
| """ | |
| Generate the prompt for the model. | |
| Args: | |
| headline (`str`): | |
| The headline of the article. | |
| body (`str`): | |
| The body of the article. | |
| Returns: | |
| `str`: The formatted prompt. | |
| """ | |
| return ( | |
| f"Ahora eres una Inteligencia Artificial experta en desmontar titulares sensacionalistas o clickbait. " | |
| f"Tu tarea consiste en analizar noticias con titulares sensacionalistas y " | |
| f"generar un resumen de una sola frase que revele la verdad detrás del titular.\n" | |
| f"Este es el titular de la noticia: {headline}\n" | |
| f"El titular plantea una pregunta o proporciona información incompleta. " | |
| f"Debes buscar en el cuerpo de la noticia una frase que responda lo que se sugiere en el título. " | |
| f"Siempre que puedas cita el texto original, especialmente si se trata de una frase que alguien ha dicho. " | |
| f"Si citas una frase que alguien ha dicho, usa comillas para indicar que es una cita. " | |
| f"Usa siempre las mínimas palabras posibles. No es necesario que la respuesta sea una oración completa. " | |
| f"Puede ser sólo el foco de la pregunta. " | |
| f"Recuerda responder siempre en Español.\n" | |
| f"Este es el cuerpo de la noticia:\n" | |
| f"{body}\n" | |
| ) | |
| prompt = prompt(headline=headline, body=body) | |
| tokenizer = AutoTokenizer.from_pretrained("Iker/ClickbaitFighter-2B") | |
| model = AutoModelForCausalLM.from_pretrained( | |
| "Iker/ClickbaitFighter-2B", torch_dtype=torch.bfloat16, device_map="auto" | |
| ) | |
| formatted_prompt = tokenizer.apply_chat_template( | |
| [{"role": "user", "content": prompt}], | |
| tokenize=False, | |
| add_generation_prompt=True, | |
| ) | |
| model_inputs = tokenizer( | |
| [formatted_prompt], return_tensors="pt", add_special_tokens=False | |
| ) | |
| model_output = model.generate(**model_inputs.to(model.device), generation_config=GenerationConfig( | |
| max_new_tokens=32, | |
| min_new_tokens=1, | |
| do_sample=False, | |
| num_beams=1, | |
| use_cache=True | |
| )) | |
| summary = tokenizer.batch_decode(model_output,skip_special_tokens=True)[0] | |
| print(summary.strip().split("\n")[-1]) # Get only the summary, without the prompt. | |
| ``` | |
| # Citation | |
| ```bittext | |
| @misc{noticia2024, | |
| title={NoticIA: A Clickbait Article Summarization Dataset in Spanish}, | |
| author={Iker García-Ferrero and Begoña Altuna}, | |
| year={2024}, | |
| eprint={2404.07611}, | |
| archivePrefix={arXiv}, | |
| primaryClass={cs.CL} | |
| } | |
| ``` |