def getStopwords(self):
    return self.getOrDefault(self.stopwords)

def _transform(self, dataset):
    stopwords = self.getStopwords()

def f(s):
    tokens = nltk.tokenize.wordpunct_tokenize(s)
return [t for t in tokens if t.lower() not in stopwords]
t = ArrayType(StringType())
out_col = self.getOutputCol()
in_col = dataset[self.getInputCol()]
return dataset.withColumn(out_col, udf(f, t)(in_col))
Create a custom Transformer in PySpark ML