T5 for Informal to Formal Style Transfer

Description

This is a text-to-text model based on T5 fine-tuned to generate informal text from formal text input, for the task “transfer Casual to Formal:”. It is based on Prithiviraj Damodaran’s Styleformer.

Predicted Entities

Live Demo Open in Colab Download Copy S3 URI

How to use

import sparknlp
from sparknlp.base import *
from sparknlp.annotator import *

spark = sparknlp.start()

documentAssembler = DocumentAssembler() \
.setInputCol("text") \
.setOutputCol("documents")

t5 = T5Transformer.pretrained("t5_informal_to_formal_styletransfer") \
.setTask("transfer Casual to Formal:") \
.setInputCols(["documents"]) \
.setMaxOutputLength(200) \
.setOutputCol("transfers")

pipeline = Pipeline().setStages([documentAssembler, t5])
data = spark.createDataFrame([["Who gives a crap?"]]).toDF("text")
result = pipeline.fit(data).transform(data)
result.select("transfers.result").show(truncate=False)
import spark.implicits._
import com.johnsnowlabs.nlp.base.DocumentAssembler
import com.johnsnowlabs.nlp.annotators.seq2seq.T5Transformer
import org.apache.spark.ml.Pipeline

val documentAssembler = new DocumentAssembler()
.setInputCol("text")
.setOutputCol("documents")

val t5 = T5Transformer.pretrained("t5_informal_to_formal_styletransfer")
.setTask("transfer Casual to Formal:")
.setMaxOutputLength(200)
.setInputCols("documents")
.setOutputCol("transfer")

val pipeline = new Pipeline().setStages(Array(documentAssembler, t5))

val data = Seq("Who gives a crap?").toDF("text")
val result = pipeline.fit(data).transform(data)

result.select("transfer.result").show(false)
import nlu
nlu.load("en.t5.informal_to_formal_styletransfer").predict("""transfer Casual to Formal:""")

Results

+------------+
|result      |
+------------+
|[Who cares?]|
+------------+

Model Information

Model Name: t5_informal_to_formal_styletransfer
Compatibility: Spark NLP 4.0.0+
License: Open Source
Edition: Official
Input Labels: [documents]
Output Labels: [t5]
Language: en
Size: 924.0 MB

References

The original model is from the transformers library:

https://huggingface.co/prithivida/informal_to_formal_styletransfer