T5 for Formal to Informal Style Transfer

Description

This is a text-to-text model based on T5 fine-tuned to generate informal text from a formal text input, for the task “transfer Formal to Casual:”. 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_formal_to_informal_styletransfer") \
.setTask("transfer Formal to Casual:") \
.setInputCols(["documents"]) \
.setMaxOutputLength(200) \
.setOutputCol("transfers")
pipeline = Pipeline().setStages([documentAssembler, t5])
data = spark.createDataFrame([["Please leave the room now."]]).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_formal_to_informal_styletransfer")
.setTask("transfer Formal to Casual:")
.setMaxOutputLength(200)
.setInputCols("documents")
.setOutputCol("transfers")
val pipeline = new Pipeline().setStages(Array(documentAssembler, t5))
val data = Seq("Please leave the room now.")
.toDF("text")
val result = pipeline.fit(data).transform(data)
result.select("transfers.result").show(false)
import nlu
nlu.load("en.t5.formal_to_informal_styletransfer").predict("""transfer Formal to Casual:""")

Results

+---------------------+
|result               |
+---------------------+
|[leave the room now.]|
+---------------------+

Model Information

Model Name: t5_formal_to_informal_styletransfer
Compatibility: Spark NLP 3.4.0+
License: Open Source
Edition: Official
Input Labels: [documents]
Output Labels: [transfers]
Language: en
Size: 923.9 MB

Data Source

The original model is from the transformers library:

https://huggingface.co/prithivida/formal_to_informal_styletransfer