Update README.md
Browse files
README.md
CHANGED
|
@@ -1,199 +1,267 @@
|
|
| 1 |
---
|
| 2 |
-
library_name: transformers
|
| 3 |
-
tags: []
|
| 4 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
## Model Details
|
| 13 |
-
|
| 14 |
-
### Model Description
|
| 15 |
-
|
| 16 |
-
<!-- Provide a longer summary of what this model is. -->
|
| 17 |
-
|
| 18 |
-
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
|
| 19 |
-
|
| 20 |
-
- **Developed by:** [More Information Needed]
|
| 21 |
-
- **Funded by [optional]:** [More Information Needed]
|
| 22 |
-
- **Shared by [optional]:** [More Information Needed]
|
| 23 |
-
- **Model type:** [More Information Needed]
|
| 24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
| 25 |
-
- **License:** [More Information Needed]
|
| 26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
| 27 |
-
|
| 28 |
-
### Model Sources [optional]
|
| 29 |
-
|
| 30 |
-
<!-- Provide the basic links for the model. -->
|
| 31 |
-
|
| 32 |
-
- **Repository:** [More Information Needed]
|
| 33 |
-
- **Paper [optional]:** [More Information Needed]
|
| 34 |
-
- **Demo [optional]:** [More Information Needed]
|
| 35 |
-
|
| 36 |
-
## Uses
|
| 37 |
-
|
| 38 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 39 |
-
|
| 40 |
-
### Direct Use
|
| 41 |
-
|
| 42 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
| 43 |
-
|
| 44 |
-
[More Information Needed]
|
| 45 |
-
|
| 46 |
-
### Downstream Use [optional]
|
| 47 |
-
|
| 48 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
| 49 |
-
|
| 50 |
-
[More Information Needed]
|
| 51 |
-
|
| 52 |
-
### Out-of-Scope Use
|
| 53 |
-
|
| 54 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
| 55 |
-
|
| 56 |
-
[More Information Needed]
|
| 57 |
-
|
| 58 |
-
## Bias, Risks, and Limitations
|
| 59 |
-
|
| 60 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
| 61 |
-
|
| 62 |
-
[More Information Needed]
|
| 63 |
-
|
| 64 |
-
### Recommendations
|
| 65 |
-
|
| 66 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
| 67 |
-
|
| 68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
| 69 |
-
|
| 70 |
-
## How to Get Started with the Model
|
| 71 |
-
|
| 72 |
-
Use the code below to get started with the model.
|
| 73 |
-
|
| 74 |
-
[More Information Needed]
|
| 75 |
-
|
| 76 |
-
## Training Details
|
| 77 |
-
|
| 78 |
-
### Training Data
|
| 79 |
-
|
| 80 |
-
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
| 81 |
-
|
| 82 |
-
[More Information Needed]
|
| 83 |
-
|
| 84 |
-
### Training Procedure
|
| 85 |
-
|
| 86 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
| 87 |
-
|
| 88 |
-
#### Preprocessing [optional]
|
| 89 |
-
|
| 90 |
-
[More Information Needed]
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
#### Training Hyperparameters
|
| 94 |
-
|
| 95 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
| 96 |
-
|
| 97 |
-
#### Speeds, Sizes, Times [optional]
|
| 98 |
-
|
| 99 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
| 100 |
-
|
| 101 |
-
[More Information Needed]
|
| 102 |
-
|
| 103 |
-
## Evaluation
|
| 104 |
-
|
| 105 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
| 106 |
-
|
| 107 |
-
### Testing Data, Factors & Metrics
|
| 108 |
-
|
| 109 |
-
#### Testing Data
|
| 110 |
-
|
| 111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
| 112 |
-
|
| 113 |
-
[More Information Needed]
|
| 114 |
-
|
| 115 |
-
#### Factors
|
| 116 |
-
|
| 117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
| 118 |
-
|
| 119 |
-
[More Information Needed]
|
| 120 |
-
|
| 121 |
-
#### Metrics
|
| 122 |
-
|
| 123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 124 |
-
|
| 125 |
-
[More Information Needed]
|
| 126 |
-
|
| 127 |
-
### Results
|
| 128 |
-
|
| 129 |
-
[More Information Needed]
|
| 130 |
-
|
| 131 |
-
#### Summary
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
## Model Examination [optional]
|
| 136 |
-
|
| 137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
| 138 |
-
|
| 139 |
-
[More Information Needed]
|
| 140 |
-
|
| 141 |
-
## Environmental Impact
|
| 142 |
-
|
| 143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
| 144 |
-
|
| 145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
| 146 |
-
|
| 147 |
-
- **Hardware Type:** [More Information Needed]
|
| 148 |
-
- **Hours used:** [More Information Needed]
|
| 149 |
-
- **Cloud Provider:** [More Information Needed]
|
| 150 |
-
- **Compute Region:** [More Information Needed]
|
| 151 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 152 |
-
|
| 153 |
-
## Technical Specifications [optional]
|
| 154 |
-
|
| 155 |
-
### Model Architecture and Objective
|
| 156 |
-
|
| 157 |
-
[More Information Needed]
|
| 158 |
-
|
| 159 |
-
### Compute Infrastructure
|
| 160 |
-
|
| 161 |
-
[More Information Needed]
|
| 162 |
-
|
| 163 |
-
#### Hardware
|
| 164 |
-
|
| 165 |
-
[More Information Needed]
|
| 166 |
-
|
| 167 |
-
#### Software
|
| 168 |
-
|
| 169 |
-
[More Information Needed]
|
| 170 |
-
|
| 171 |
-
## Citation [optional]
|
| 172 |
-
|
| 173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
| 174 |
-
|
| 175 |
-
**BibTeX:**
|
| 176 |
-
|
| 177 |
-
[More Information Needed]
|
| 178 |
-
|
| 179 |
-
**APA:**
|
| 180 |
-
|
| 181 |
-
[More Information Needed]
|
| 182 |
-
|
| 183 |
-
## Glossary [optional]
|
| 184 |
-
|
| 185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
| 186 |
-
|
| 187 |
-
[More Information Needed]
|
| 188 |
-
|
| 189 |
-
## More Information [optional]
|
| 190 |
-
|
| 191 |
-
[More Information Needed]
|
| 192 |
-
|
| 193 |
-
## Model Card Authors [optional]
|
| 194 |
-
|
| 195 |
-
[More Information Needed]
|
| 196 |
-
|
| 197 |
-
## Model Card Contact
|
| 198 |
|
| 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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
|
|
|
|
|
|
| 2 |
---
|
| 3 |
+
license: cc-by-nc-sa-4.0
|
| 4 |
+
datasets:
|
| 5 |
+
- Iker/NoticIA
|
| 6 |
+
language:
|
| 7 |
+
- es
|
| 8 |
+
metrics:
|
| 9 |
+
- rouge
|
| 10 |
+
library_name: transformers
|
| 11 |
+
pipeline_tag: text-generation
|
| 12 |
+
base_model: openchat/openchat-3.5-0106
|
| 13 |
+
tags:
|
| 14 |
+
- clickbait
|
| 15 |
+
- noticia
|
| 16 |
+
- spanish
|
| 17 |
+
- summary
|
| 18 |
+
- summarization
|
| 19 |
+
widget:
|
| 20 |
+
- example_title: Summary Example
|
| 21 |
+
messages:
|
| 22 |
+
- role: user
|
| 23 |
+
content: "Ahora eres una Inteligencia Artificial experta en desmontar titulares
|
| 24 |
+
sensacionalistas o clickbait. Tu tarea consiste en analizar noticias
|
| 25 |
+
con titulares sensacionalistas y generar un resumen de una sola frase
|
| 26 |
+
que revele la verdad detrás del titular.\\nEste es el titular de la
|
| 27 |
+
noticia: Le compra un abrigo a su abuela de 97 años y la reacción de
|
| 28 |
+
esta es una fantasía\\nEl titular plantea una pregunta o proporciona
|
| 29 |
+
información incompleta. Debes buscar en el cuerpo de la noticia una
|
| 30 |
+
frase que responda lo que se sugiere en el título. Siempre que puedas
|
| 31 |
+
cita el texto original, especialmente si se trata de una frase que
|
| 32 |
+
alguien ha dicho. Si citas una frase que alguien ha dicho, usa
|
| 33 |
+
comillas para indicar que es una cita. Usa siempre las mínimas
|
| 34 |
+
palabras posibles. No es necesario que la respuesta sea una oración
|
| 35 |
+
completa. Puede ser sólo el foco de la pregunta. Recuerda responder
|
| 36 |
+
siempre en Español.\\nEste es el cuerpo de la noticia:\\nLa usuaria de
|
| 37 |
+
X @Kokreta1 ha relatado la conversación que ha tenido con su abuela de
|
| 38 |
+
97 años cuando le ha dado el abrigo que le ha comprado para su
|
| 39 |
+
cumpleaños.\\nTeniendo en cuenta la avanzada edad de la señora, la
|
| 40 |
+
tuitera le ha regalado una prenda acorde a sus años, algo con lo que
|
| 41 |
+
su yaya no ha estado de acuerdo.\\nEl abrigo es de vieja, ha opinado
|
| 42 |
+
la mujer cuando lo ha visto. Os juro que soy muy fan. Mañana vamos las
|
| 43 |
+
dos (a por otro). Eso sí, la voy a llevar al Bershka, ha asegurado
|
| 44 |
+
entre risas la joven.\\nSegún la propia cadena de ropa, la cual
|
| 45 |
+
pertenece a Inditex, su público se caracteriza por ser jóvenes
|
| 46 |
+
atrevidos, conocedores de las últimas tendencias e interesados en la
|
| 47 |
+
música, las redes sociales y las nuevas tecnologías, por lo que la
|
| 48 |
+
gente mayor no suele llevar este estilo.\\nLa inusual personalidad de
|
| 49 |
+
la señora ha encantado a los usuarios de la red. Es por eso que el
|
| 50 |
+
relato ha acumulado más de 1.000 me gusta y cerca de 100 retuits,
|
| 51 |
+
además de una multitud de comentarios.\\n"
|
| 52 |
|
| 53 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
+
A model finetuned with the [NoticIA Dataset](https://huggingface.co/datasets/Iker/NoticIA). This model can generate summaries of clickbait headlines
|
| 62 |
+
|
| 63 |
+
- 📖 Paper: [Coming soon]()
|
| 64 |
+
- 📓 NoticIA Dataset: [https://huggingface.co/datasets/Iker/NoticIA](https://huggingface.co/datasets/Iker/NoticIA)
|
| 65 |
+
- 💻 Baseline Code: [https://github.com/ikergarcia1996/NoticIA](https://github.com/ikergarcia1996/NoticIA)
|
| 66 |
+
- 🤖 Pre Trained Models [https://huggingface.co/collections/Iker/noticia-and-clickbaitfighter-65fdb2f80c34d7c063d3e48e](https://huggingface.co/collections/Iker/noticia-and-clickbaitfighter-65fdb2f80c34d7c063d3e48e)
|
| 67 |
+
- 🔌 Online Demo: [https://iker-clickbaitfighter.hf.space/](https://iker-clickbaitfighter.hf.space/)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
# Open Source Models
|
| 71 |
+
<table border="1" cellspacing="0" cellpadding="5">
|
| 72 |
+
<thead>
|
| 73 |
+
<tr>
|
| 74 |
+
<th></th>
|
| 75 |
+
<th><a href="https://huggingface.co/Iker/ClickbaitFighter-2B">Iker/ClickbaitFighter-2B</a></th>
|
| 76 |
+
<th><a href="https://huggingface.co/Iker/ClickbaitFighter-7B">Iker/ClickbaitFighter-7B</a></th>
|
| 77 |
+
<th><a href="https://huggingface.co/Iker/ClickbaitFighter-10B">Iker/ClickbaitFighter-10B</a></th>
|
| 78 |
+
</tr>
|
| 79 |
+
</thead>
|
| 80 |
+
<tbody>
|
| 81 |
+
<tr>
|
| 82 |
+
<td>Param. no.</td>
|
| 83 |
+
<td>2B</td>
|
| 84 |
+
<td>7B</td>
|
| 85 |
+
<td>10M</td>
|
| 86 |
+
</tr>
|
| 87 |
+
<tr>
|
| 88 |
+
<td>ROUGE</td>
|
| 89 |
+
<td>36.26</td>
|
| 90 |
+
<td>49.81</td>
|
| 91 |
+
<td>52.01</td>
|
| 92 |
+
</tr>
|
| 93 |
+
<tr>
|
| 94 |
+
</tbody>
|
| 95 |
+
</table>
|
| 96 |
+
|
| 97 |
+
# Evaluation Results
|
| 98 |
+
<table>
|
| 99 |
+
<tr>
|
| 100 |
+
<td style="width:100%"><img src="https://github.com/ikergarcia1996/NoticIA/raw/main/results/Results.png" align="right" width="100%"> </td>
|
| 101 |
+
</tr>
|
| 102 |
+
</table>
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
# Usage example:
|
| 106 |
+
|
| 107 |
+
## Summarize a web article
|
| 108 |
+
```python
|
| 109 |
+
import torch # pip install torch
|
| 110 |
+
from newspaper import Article #pip3 install newspaper3k
|
| 111 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig # pip install transformers
|
| 112 |
+
|
| 113 |
+
article_url ="https://www.huffingtonpost.es/virales/le-compra-abrigo-abuela-97nos-reaccion-fantasia.html"
|
| 114 |
+
article = Article(article_url)
|
| 115 |
+
article.download()
|
| 116 |
+
article.parse()
|
| 117 |
+
headline=article.title
|
| 118 |
+
body = article.text
|
| 119 |
+
|
| 120 |
+
def prompt(
|
| 121 |
+
headline: str,
|
| 122 |
+
body: str,
|
| 123 |
+
) -> str:
|
| 124 |
+
"""
|
| 125 |
+
Generate the prompt for the model.
|
| 126 |
+
|
| 127 |
+
Args:
|
| 128 |
+
headline (`str`):
|
| 129 |
+
The headline of the article.
|
| 130 |
+
body (`str`):
|
| 131 |
+
The body of the article.
|
| 132 |
+
Returns:
|
| 133 |
+
`str`: The formatted prompt.
|
| 134 |
+
"""
|
| 135 |
+
|
| 136 |
+
return (
|
| 137 |
+
f"Ahora eres una Inteligencia Artificial experta en desmontar titulares sensacionalistas o clickbait. "
|
| 138 |
+
f"Tu tarea consiste en analizar noticias con titulares sensacionalistas y "
|
| 139 |
+
f"generar un resumen de una sola frase que revele la verdad detrás del titular.\n"
|
| 140 |
+
f"Este es el titular de la noticia: {headline}\n"
|
| 141 |
+
f"El titular plantea una pregunta o proporciona información incompleta. "
|
| 142 |
+
f"Debes buscar en el cuerpo de la noticia una frase que responda lo que se sugiere en el título. "
|
| 143 |
+
f"Siempre que puedas cita el texto original, especialmente si se trata de una frase que alguien ha dicho. "
|
| 144 |
+
f"Si citas una frase que alguien ha dicho, usa comillas para indicar que es una cita. "
|
| 145 |
+
f"Usa siempre las mínimas palabras posibles. No es necesario que la respuesta sea una oración completa. "
|
| 146 |
+
f"Puede ser sólo el foco de la pregunta. "
|
| 147 |
+
f"Recuerda responder siempre en Español.\n"
|
| 148 |
+
f"Este es el cuerpo de la noticia:\n"
|
| 149 |
+
f"{body}\n"
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
prompt = prompt(headline=headline, body=body)
|
| 153 |
+
|
| 154 |
+
tokenizer = AutoTokenizer.from_pretrained("Iker/ClickbaitFighter-7B")
|
| 155 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 156 |
+
"Iker/ClickbaitFighter-2B", torch_dtype=torch.bfloat16, device_map="auto"
|
| 157 |
+
)
|
| 158 |
+
|
| 159 |
+
formatted_prompt = tokenizer.apply_chat_template(
|
| 160 |
+
[{"role": "user", "content": prompt}],
|
| 161 |
+
tokenize=False,
|
| 162 |
+
add_generation_prompt=True,
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
model_inputs = tokenizer(
|
| 166 |
+
[formatted_prompt], return_tensors="pt", add_special_tokens=False
|
| 167 |
+
)
|
| 168 |
+
|
| 169 |
+
model_output = model.generate(**model_inputs.to(model.device), generation_config=GenerationConfig(
|
| 170 |
+
max_new_tokens=32,
|
| 171 |
+
min_new_tokens=1,
|
| 172 |
+
do_sample=False,
|
| 173 |
+
num_beams=1,
|
| 174 |
+
use_cache=True
|
| 175 |
+
))
|
| 176 |
+
|
| 177 |
+
summary = tokenizer.batch_decode(model_output,skip_special_tokens=True)[0]
|
| 178 |
+
|
| 179 |
+
print(summary.strip().split("\n")[-1]) # Get only the summary, without the prompt.
|
| 180 |
+
```
|
| 181 |
+
|
| 182 |
+
## Run inference in the NoticIA dataset
|
| 183 |
+
```python
|
| 184 |
+
import torch # pip install torch
|
| 185 |
+
from newspaper import Article #pip3 install newspaper3k
|
| 186 |
+
from datasets import load_dataset # pip install datasets
|
| 187 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig # pip install transformers
|
| 188 |
+
|
| 189 |
+
dataset = load_dataset("Iker/NoticIA")
|
| 190 |
+
example = dataset["test"][0]
|
| 191 |
+
headline = example["web_headline"]
|
| 192 |
+
body = example["web_text"]
|
| 193 |
+
|
| 194 |
+
def prompt(
|
| 195 |
+
headline: str,
|
| 196 |
+
body: str,
|
| 197 |
+
) -> str:
|
| 198 |
+
"""
|
| 199 |
+
Generate the prompt for the model.
|
| 200 |
+
|
| 201 |
+
Args:
|
| 202 |
+
headline (`str`):
|
| 203 |
+
The headline of the article.
|
| 204 |
+
body (`str`):
|
| 205 |
+
The body of the article.
|
| 206 |
+
Returns:
|
| 207 |
+
`str`: The formatted prompt.
|
| 208 |
+
"""
|
| 209 |
+
|
| 210 |
+
return (
|
| 211 |
+
f"Ahora eres una Inteligencia Artificial experta en desmontar titulares sensacionalistas o clickbait. "
|
| 212 |
+
f"Tu tarea consiste en analizar noticias con titulares sensacionalistas y "
|
| 213 |
+
f"generar un resumen de una sola frase que revele la verdad detrás del titular.\n"
|
| 214 |
+
f"Este es el titular de la noticia: {headline}\n"
|
| 215 |
+
f"El titular plantea una pregunta o proporciona información incompleta. "
|
| 216 |
+
f"Debes buscar en el cuerpo de la noticia una frase que responda lo que se sugiere en el título. "
|
| 217 |
+
f"Siempre que puedas cita el texto original, especialmente si se trata de una frase que alguien ha dicho. "
|
| 218 |
+
f"Si citas una frase que alguien ha dicho, usa comillas para indicar que es una cita. "
|
| 219 |
+
f"Usa siempre las mínimas palabras posibles. No es necesario que la respuesta sea una oración completa. "
|
| 220 |
+
f"Puede ser sólo el foco de la pregunta. "
|
| 221 |
+
f"Recuerda responder siempre en Español.\n"
|
| 222 |
+
f"Este es el cuerpo de la noticia:\n"
|
| 223 |
+
f"{body}\n"
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
prompt = prompt(headline=headline, body=body)
|
| 227 |
+
|
| 228 |
+
tokenizer = AutoTokenizer.from_pretrained("Iker/ClickbaitFighter-7B")
|
| 229 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 230 |
+
"Iker/ClickbaitFighter-2B", torch_dtype=torch.bfloat16, device_map="auto"
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
formatted_prompt = tokenizer.apply_chat_template(
|
| 234 |
+
[{"role": "user", "content": prompt}],
|
| 235 |
+
tokenize=False,
|
| 236 |
+
add_generation_prompt=True,
|
| 237 |
+
)
|
| 238 |
+
|
| 239 |
+
model_inputs = tokenizer(
|
| 240 |
+
[formatted_prompt], return_tensors="pt", add_special_tokens=False
|
| 241 |
+
)
|
| 242 |
+
|
| 243 |
+
model_output = model.generate(**model_inputs.to(model.device), generation_config=GenerationConfig(
|
| 244 |
+
max_new_tokens=32,
|
| 245 |
+
min_new_tokens=1,
|
| 246 |
+
do_sample=False,
|
| 247 |
+
num_beams=1,
|
| 248 |
+
use_cache=True
|
| 249 |
+
))
|
| 250 |
+
|
| 251 |
+
summary = tokenizer.batch_decode(model_output,skip_special_tokens=True)[0]
|
| 252 |
+
|
| 253 |
+
print(summary.strip().split("\n")[-1]) # Get only the summary, without the prompt.
|
| 254 |
+
```
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
# Citation
|
| 258 |
+
|
| 259 |
+
Paper coming soon, for now, you can use this citation:
|
| 260 |
+
```bittext
|
| 261 |
+
@misc{garcia-ferrero-etal-2024-noticia,
|
| 262 |
+
title = "NoticIA: A Clickbait Article Summarization Dataset in Spanish.",
|
| 263 |
+
author = "Garc{\'\i}a-Ferrero, Iker and Altuna, Bego{\~n}a",
|
| 264 |
+
year = "2024",
|
| 265 |
+
url = "https://github.com/ikergarcia1996/NoticIA"
|
| 266 |
+
}
|
| 267 |
+
```
|