spark-nlp: John Snow Labs Spark NLP is a natural language processing library built on top of Apache Spark ML. It provides simple, performant & accurate NLP annotations for machine learning pipelines, that scale easily in a distributed environment. · Pythie
John Snow Labs Spark NLP is a natural language processing library built on top of Apache Spark ML. It provides simple, performant & accurate NLP annotations for machine learning pipelines, that scale easily in a distributed environment.
Actively maintained.Last release 2 weeks ago, commits in 4 of the last 26 weeks. A safe choice.
Spark NLP: State-of-the-Art Natural Language Processing & LLMs Library
Spark NLP is a state-of-the-art Natural Language Processing library built on top of Apache Spark. It provides simple, performant & accurate NLP annotations for machine learning pipelines that scale easily in a distributed environment.
Spark NLP comes with 100000+ pretrained pipelines and models in more than 200+ languages.
It also offers tasks such as Tokenization, Word Segmentation, Part-of-Speech Tagging, Word and Sentence Embeddings, , , , , , , (+180 languages), , , , , , , , , and many more .
Spark NLP is the only open-source NLP library in production that offers state-of-the-art transformers such as BERT, CamemBERT, ALBERT, ELECTRA, XLNet, DistilBERT, RoBERTa, DeBERTa, XLM-RoBERTa, Longformer, ELMO, Universal Sentence Encoder, Llama-2, M2M100, BART, Instructor, E5, Google T5, MarianMT, OpenAI GPT2, Vision Transformers (ViT), OpenAI Whisper, Llama, Mistral, Phi, Qwen2, and many more not only to Python and R, but also to JVM ecosystem (Java, Scala, and Kotlin) at scale by extending Apache Spark natively.
Model Importing Support
Spark NLP provides easy support for importing models from various popular frameworks:
TensorFlow
ONNX
OpenVINO
Llama.cpp (GGUF)
This wide range of support allows you to seamlessly integrate models from different sources into your Spark NLP workflows, enhancing flexibility and compatibility with existing machine learning ecosystems.
Project's website
Take a look at our official Spark NLP page: https://sparknlp.org/ for user
documentation and examples
# Import Spark NLP
from sparknlp.base import *
from sparknlp.annotator import *
from sparknlp.pretrained import PretrainedPipeline
import sparknlp
# Start SparkSession with Spark NLP
# start() functions has 3 parameters: gpu, apple_silicon, and memory
# sparknlp.start(gpu=True) will start the session with GPU support
# sparknlp.start(apple_silicon=True) will start the session with macOS M1 & M2 support
# sparknlp.start(memory="16G") to change the default driver memory in SparkSession
spark = sparknlp.start()
# Download a pre-trained pipeline
pipeline = PretrainedPipeline('explain_document_dl', lang='en')
# Your testing dataset
text = """
The Mona Lisa is a 16th century oil painting created by Leonardo.
It's held at the Louvre in Paris.
"""
# Annotate your testing dataset
result = pipeline.annotate(text)
# What's in the pipeline
list(result.keys())
Output: ['entities', 'stem', 'checked', 'lemma', 'document',
'pos', 'token', 'ner', 'embeddings', 'sentence']
# Check the results
result['entities']
Output: ['Mona Lisa', 'Leonardo', 'Louvre', 'Paris']
For more examples, you can visit our dedicated examples to showcase all Spark NLP use cases!
Packages Cheatsheet
This is a cheatsheet for corresponding Spark NLP Maven package to Apache Spark / PySpark major version:
Apache Spark (Scala)
Spark NLP on CPU
Spark NLP on GPU
Spark NLP on AArch64 (linux)
Spark NLP on Apple Silicon
3.0/3.1/3.2/3.3/3.4/3.5 (2.12)
spark-nlp
spark-nlp-gpu
spark-nlp-aarch64
spark-nlp-silicon
4.0.0 (2.13)
spark-nlp-spark400
spark-nlp-gpu-spark400
spark-nlp-aarch64-spark400
spark-nlp-silicon-spark400
4.0.1/4.1.0/4.1.1/4.1.2 (2.13)
spark-nlp
spark-nlp-gpu
spark-nlp-aarch64
spark-nlp-silicon
Start Function
sparknlp.start()
sparknlp.start(gpu=True)
sparknlp.start(aarch64=True)
sparknlp.start(apple_silicon=True)
Append the Scala binary version to the artifact name for the Maven coordinate — for example
spark-nlp_2.12 on Apache Spark 3.x, spark-nlp-spark400_2.13 on Apache Spark 4.0.0, and
spark-nlp_2.13 on Apache Spark 4.0.1 and later validated Spark 4 versions. See the
install documentation for the full artifact table.
NOTE: M1/M2 and AArch64 are under experimental support. Access and support to these architectures are limited by the
community and we had to build most of the dependencies by ourselves to make them compatible. We support these two
architectures, however, they may not work in some environments.
Pipelines and Models
For a quick example of using pipelines and models take a look at our official documentation
Please check out our Models Hub for the full list of pre-trained models with examples, demo, benchmark, and more
Platform and Ecosystem Support
Apache Spark Support
Spark NLP 7.0.1 supports both Apache Spark 3.x (Scala 2.12) and the validated Apache Spark 4 versions
(Scala 2.13). Apache Spark 4.0.0 ships a separate artifact because of a binary-incompatible Param change,
so there are three artifact lanes:
Apache Spark runtime
Scala
Maven artifact
3.0.x - 3.5.x
2.12
spark-nlp_2.12
4.0.0
2.13
spark-nlp-spark400_2.13
4.0.1, 4.1.0, 4.1.1, 4.1.2
2.13
spark-nlp_2.13
Choose the artifact that matches your Spark distribution.
Find out more about Spark NLP versions from our release notes.
Scala and Python Support
Apache Spark 3.x (Scala 2.12)
Spark NLP
Python 3.6
Python 3.7
Python 3.8
Python 3.9
Python 3.10
Scala 2.11
Scala 2.12
7.0.x
NO
YES
YES
YES
YES
NO
YES
6.0.x
NO
YES
YES
YES
YES
NO
YES
5.5.x
NO
YES
YES
YES
YES
NO
YES
5.4.x
NO
YES
YES
YES
YES
NO
YES
5.3.x
NO
YES
YES
YES
YES
NO
YES
5.2.x
NO
YES
YES
YES
YES
NO
YES
5.1.x
NO
YES
YES
YES
YES
NO
YES
5.0.x
NO
YES
YES
YES
YES
NO
YES
Apache Spark 4.x (Scala 2.13)
Spark NLP
Python 3.9
Python 3.10
Python 3.11
Python 3.12
Scala 2.13
7.0.x
YES
YES
YES
YES
YES
Find out more about SparkNLP versions in our official documentation
Databricks Support
Spark NLP is compatible with the following runtimes:
CPU
GPU
14.1 / 14.1 ML
14.1 ML & GPU
14.2 / 14.2 ML
14.2 ML & GPU
14.3 / 14.3 ML
14.3 ML & GPU
15.0 / 15.0 ML
15.0 ML & GPU
15.1 / 15.1 ML
15.1 ML & GPU
15.2 / 15.2 ML
15.2 ML & GPU
15.3 / 15.3 ML
15.3 ML & GPU
15.4 / 15.4 ML
15.4 ML & GPU
16.4 / 16.4 ML
16.4 ML & GPU
We are compatible with older runtimes. For a full list check databricks support in our official documentation
EMR Support
Spark NLP is compatible with the following Amazon EMR 6.x and 7.x releases:
EMR Release
emr-6.13.0
emr-6.14.0
emr-6.15.0
emr-7.0.1
emr-7.1.0
emr-7.2.0
emr-7.3.0
emr-7.4.0
emr-7.5.0
emr-7.6.0
emr-7.7.0
emr-7.8.0
Spark NLP includes a Spark 4 / Scala 2.13 lane. The EMR Serverless setup is compatible with the following Amazon EMR 8 release:
EMR release
Spark
Scala
Java
Spark NLP artifact
emr-spark-8.0.0
4.0.2-amzn-0
2.13
17
spark-nlp_2.13
emr-spark-8.0.0 is a separate Spark-focused release label, not emr-8.0.0. Create a separate EMR Serverless application for this lane; an existing EMR 7.x application remains on Spark 3 / Scala 2.12.
We are compatible with older EMR releases. For a full list check EMR support in our official documentation
To install spark-nlp packages through command line follow these instructions from our official documentation
Scala
Spark NLP 7.0.1 supports Scala 2.12 with Apache Spark 3.0.x, 3.1.x, 3.2.x, 3.3.x, 3.4.x, and 3.5.x, and Scala 2.13
with Apache Spark 4.0.0 (spark-nlp-spark400_2.13) and Apache Spark 4.0.1, 4.1.0, 4.1.1, and 4.1.2
(spark-nlp_2.13). Our packages are
deployed to Maven central. To add any of our packages as a dependency in your application you can follow these instructions
from our official documentation.
If you are interested, there is a simple SBT project for Spark NLP to guide you on how to use it in your
projects Spark NLP Starter
Python
Spark NLP supports Python 3.7.x and above depending on your major PySpark version.
Check all available installations for Python in our official documentation
Compiled JARs
To compile the jars from source follow these instructions from our official documentation
Platform-Specific Instructions
For detailed instructions on how to use Spark NLP on supported platforms, please refer to our official documentation:
Spark NLP library and all the pre-trained models/pipelines can be used entirely offline with no access to the Internet.
Please check these instructions from our official documentation
to use Spark NLP offline.
Advanced Settings
You can change Spark NLP configurations via Spark properties configuration.
Please check these instructions from our official documentation.
We have published a paper that you can cite for
the Spark NLP library:
@article{KOCAMAN2021100058,
title = {Spark NLP: Natural language understanding at scale},
journal = {Software Impacts},
pages = {100058},
year = {2021},
issn = {2665-9638},
doi = {https://doi.org/10.1016/j.simpa.2021.100058},
url = {https://www.sciencedirect.com/science/article/pii/S2665963.2.300063},
author = {Veysel Kocaman and David Talby},
keywords = {Spark, Natural language processing, Deep learning, Tensorflow, Cluster},
abstract = {Spark NLP is a Natural Language Processing (NLP) library built on top of Apache Spark ML. It provides simple, performant & accurate NLP annotations for machine learning pipelines that can scale easily in a distributed environment. Spark NLP comes with 1100+ pretrained pipelines and models in more than 192+ languages. It supports nearly all the NLP tasks and modules that can be used seamlessly in a cluster. Downloaded more than 2.7 million times and experiencing 9x growth since January 2020, Spark NLP is used by 54% of healthcare organizations as the world’s most widely used NLP library in the enterprise.}
}
}
Community support
Slack For live discussion with the Spark NLP community and the team
GitHub Bug reports, feature requests, and contributions
Discussions Engage with other community members, share ideas,
and show off how you use Spark NLP!