English Part of Speech Tagger (from KoichiYasuoka)

Description

Pretrained Part of Speech model, adapted from Hugging Face and curated to provide scalability and production-readiness using Spark NLP. xlm-roberta-base-english-upos is a English model orginally trained by KoichiYasuoka.

Download Copy S3 URI

How to use

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

sentenceDetector = SentenceDetectorDLModel.pretrained("sentence_detector_dl", "xx")\
       .setInputCols(["document"])\
       .setOutputCol("sentence")

tokenizer = Tokenizer() \
    .setInputCols("sentence") \
    .setOutputCol("token")

tokenClassifier = XlmRoBertaForTokenClassification.pretrained("xlmroberta_pos_xlm_roberta_base_english_upos","en") \
    .setInputCols(["sentence", "token"]) \
    .setOutputCol("pos")

pipeline = Pipeline(stages=[documentAssembler, sentenceDetector, tokenizer, tokenClassifier])

data = spark.createDataFrame([["I love Spark NLP"]]).toDF("text")

result = pipeline.fit(data).transform(data)
val documentAssembler = new DocumentAssembler() 
          .setInputCol("text") 
          .setOutputCol("document")

val sentenceDetector = SentenceDetectorDLModel.pretrained("sentence_detector_dl", "xx")
       .setInputCols(Array("document"))
       .setOutputCol("sentence")

val tokenizer = new Tokenizer() 
    .setInputCols(Array("sentence"))
    .setOutputCol("token")

val tokenClassifier = XlmRoBertaForTokenClassification.pretrained("xlmroberta_pos_xlm_roberta_base_english_upos","en") 
    .setInputCols(Array("sentence", "token")) 
    .setOutputCol("pos")

val pipeline = new Pipeline().setStages(Array(documentAssembler,sentenceDetector, tokenizer, tokenClassifier))

val data = Seq("I love Spark NLP").toDF("text")

val result = pipeline.fit(data).transform(data)
import nlu
nlu.load("en.ner.pos.universal_dependencies.base").predict("""I love Spark NLP""")

Model Information

Model Name: xlmroberta_pos_xlm_roberta_base_english_upos
Compatibility: Spark NLP 3.4.2+
License: Open Source
Edition: Official
Input Labels: [document, token]
Output Labels: [ner]
Language: en
Size: 791.1 MB
Case sensitive: true
Max sentence length: 128

References

  • https://huggingface.co/KoichiYasuoka/xlm-roberta-base-english-upos
  • https://github.com/UniversalDependencies/UD_English-EWT
  • https://universaldependencies.org/u/pos/
  • https://github.com/KoichiYasuoka/esupar