Update README.md
Browse files
README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
---
|
2 |
license: mit
|
|
|
3 |
tags:
|
4 |
- generated_from_trainer
|
5 |
model-index:
|
@@ -38,13 +39,42 @@ poema:
|
|
38 |
texto: Todos fueron a verle pasar
|
39 |
```
|
40 |
|
41 |
-
|
42 |
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
## Training and evaluation data
|
46 |
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
## Training procedure
|
50 |
|
|
|
1 |
---
|
2 |
license: mit
|
3 |
+
language: es
|
4 |
tags:
|
5 |
- generated_from_trainer
|
6 |
model-index:
|
|
|
39 |
texto: Todos fueron a verle pasar
|
40 |
```
|
41 |
|
42 |
+
### How to use
|
43 |
|
44 |
+
You can use this model directly with a pipeline for masked language modeling:
|
45 |
+
|
46 |
+
```python
|
47 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
48 |
+
model_name = 'hackathon-pln-es/poem-gen-spanish-t5-small'
|
49 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
50 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
51 |
+
|
52 |
+
author, sentiment, word, start_text = 'Pablo Neruda', 'positivo', 'cielo', 'Todos fueron a la plaza'
|
53 |
+
input_text = f"""poema: estilo: {author} && sentimiento: {sentiment} && palabras: {word} && texto: {start_text} """
|
54 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
55 |
+
|
56 |
+
outputs = model.generate(inputs["input_ids"],
|
57 |
+
do_sample = True,
|
58 |
+
max_length = 30,
|
59 |
+
repetition_penalty = 20.0,
|
60 |
+
top_k = 50,
|
61 |
+
top_p = 0.92)
|
62 |
+
detok_outputs = [tokenizer.decode(x, skip_special_tokens=True) for x in outputs]
|
63 |
+
res = detok_outputs[0]
|
64 |
+
```
|
65 |
|
66 |
## Training and evaluation data
|
67 |
|
68 |
+
The original dataset has the columns `author`, `content` and `title`.
|
69 |
+
For each poem we generate new examples:
|
70 |
+
- content: *line_i* , generated: *line_i+1*
|
71 |
+
- content: *concatenate(line_i, line_i+1)* , generated: *line_i+2*
|
72 |
+
- content: *concatenate(line_i, line_i+1, line_i+2)* , generated: *line_i+3*
|
73 |
+
|
74 |
+
The resulting dataset has the columns `author`, `content`, `title` and `generated`.
|
75 |
+
|
76 |
+
For each example we compute the sentiment of the generated column and the nouns. In the case of sentiment, we used the model `mrm8488/electricidad-small-finetuned-restaurant-sentiment-analysis` and for nouns extraction we used spaCy.
|
77 |
+
|
78 |
|
79 |
## Training procedure
|
80 |
|