CoolFace
Modelpublic

somosnlp-hackathon-2022/poem-gen-spanish-t5-small

sourceHugging Facemitupdated 3y agoView on Hugging Face
5likes47downloads
Model Card

poem-gen-spanish-t5-small

This model is a fine-tuned version of flax-community/spanish-t5-small on the Spanish Poetry Dataset dataset.

The model was created during the First Spanish Hackathon organized by Somos NLP.

The team who participated was composed by:

It achieves the following results on the evaluation set:

  • โ€”Loss: 2.8707
  • โ€”Perplexity: 17.65

Model description

The model was trained to generate spanish poems attending to some parameters like style, sentiment, words to include and starting phrase.

Example:

poema:
  estilo: Pablo Neruda &&
  sentimiento: positivo &&
  palabras: cielo, luna, mar &&
  texto: Todos fueron a verle pasar

How to use

You can use this model directly with a pipeline for masked language modeling:

python
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
model_name = 'hackathon-pln-es/poem-gen-spanish-t5-small'
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)

author, sentiment, word, start_text = 'Pablo Neruda', 'positivo', 'cielo', 'Todos fueron a la plaza'
input_text = f"""poema: estilo: {author} && sentimiento: {sentiment} && palabras: {word} && texto: {start_text} """
inputs = tokenizer(input_text, return_tensors="pt")

outputs = model.generate(inputs["input_ids"],
                         do_sample = True,
                         max_length = 30,
                         repetition_penalty = 20.0,
                         top_k = 50,
                         top_p = 0.92)
detok_outputs = [tokenizer.decode(x, skip_special_tokens=True) for x in outputs]
res = detok_outputs[0]

Training and evaluation data

The original dataset has the columns author, content and title. For each poem we generate new examples:

  • โ€”content: line_i , generated: line_i+1
  • โ€”content: concatenate(line_i, line_i+1) , generated: line_i+2
  • โ€”content: concatenate(line_i, line_i+1, line_i+2) , generated: line_i+3

The resulting dataset has the columns author, content, title and generated.

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.

Training procedure

Training hyperparameters

The following hyperparameters were used during training:

  • โ€”learning_rate: 2e-05
  • โ€”trainbatchsize: 6
  • โ€”evalbatchsize: 6
  • โ€”seed: 42
  • โ€”optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
  • โ€”lrschedulertype: linear
  • โ€”num_epochs: 6

Training results

Training LossEpochStepValidation Loss
2.70820.73300002.8878
2.62511.46600002.8940
2.57962.19900002.8853
2.55562.931200002.8749
2.5273.661500002.8850
2.50244.391800002.8760
2.48875.122100002.8749
2.48085.852400002.8707

Framework versions

  • โ€”Transformers 4.17.0
  • โ€”Pytorch 1.10.0+cu111
  • โ€”Datasets 2.0.0
  • โ€”Tokenizers 0.11.6