Stop Words Cleaner for English

Description

This model removes ‘stop words’ from text. Stop words are words so common that they can be removed without significantly altering the meaning of a text. Removing stop words is useful when one wants to deal with only the most semantically important words in a text, and ignore words that are rarely semantically relevant, such as articles and prepositions.

Open in Colab Download Copy S3 URI

How to use

...
stop_words = StopWordsCleaner.pretrained("stopwords_en", "en") \
.setInputCols(["token"]) \
.setOutputCol("cleanTokens")
nlp_pipeline = Pipeline(stages=[document_assembler, tokenizer, stop_words])
light_pipeline = LightPipeline(nlp_pipeline.fit(spark.createDataFrame([['']]).toDF("text")))
results = light_pipeline.fullAnnotate("Other than being the king of the north, John Snow is a an English physician and a leader in the development of anaesthesia and medical hygiene.")
...
val stopWords = StopWordsCleaner.pretrained("stopwords_en", "en")
.setInputCols(Array("token"))
.setOutputCol("cleanTokens")
val pipeline = new Pipeline().setStages(Array(document_assembler, tokenizer, stopWords))
val data = Seq("Other than being the king of the north, John Snow is a an English physician and a leader in the development of anaesthesia and medical hygiene.").toDF("text")
val result = pipeline.fit(data).transform(data)
import nlu

text = ["""Other than being the king of the north, John Snow is a an English physician and a leader in the development of anaesthesia and medical hygiene."""]
stopword_df = nlu.load('en.stopwords').predict(text)
stopword_df[["cleanTokens"]]

Results

[Row(annotatorType='token', begin=21, end=24, result='king', metadata={'sentence': '0'}),
Row(annotatorType='token', begin=33, end=37, result='north', metadata={'sentence': '0'}),
Row(annotatorType='token', begin=38, end=38, result=',', metadata={'sentence': '0'}),
Row(annotatorType='token', begin=40, end=43, result='John', metadata={'sentence': '0'}),
Row(annotatorType='token', begin=45, end=48, result='Snow', metadata={'sentence': '0'}),
...]

Model Information

Model Name: stopwords_en
Type: stopwords
Compatibility: Spark NLP 2.5.4+
Edition: Official
Input Labels: [token]
Output Labels: [cleanTokens]
Language: en
Case sensitive: false
License: Open Source

Data Source

The model is imported from https://github.com/WorldBrain/remove-stopwords