Spark NLP Overview
Spark NLP: A Unified Open-Source NLP Library
Overview and Background
Spark NLP is an Apache 2.0 licensed open-source natural language processing library supporting Python, Java, and Scala. It is completely free for personal and commercial use. The library has been in active development for over three years with nearly 80 releases, making it production-stable and widely deployed. Every Spark NLP pipeline is also an Apache Spark ML pipeline, enabling native scaling from a single machine to a cluster (on-premises, Databricks, cloud). Spark NLP is the most widely used NLP library among enterprise practitioners according to O’Reilly surveys (2019, 2020) and the most recent NLP Industry Survey (September 2020).
The library covers the entire NLP pipeline within a single framework, avoiding unnecessary data copying or movement between tools. Features range from basic text processing (sentence splitting, tokenization, stemming, lemmatization, part-of-speech tagging, dependency parsing) to advanced deep-learning algorithms (spell checking, named entity recognition, sentiment analysis, emotion analysis, document classification). It also includes built-in word embeddings, chunk embeddings, and sentence embeddings (e.g., BERT, BioBERT, ClinicalBERT) with automatic loading, caching, and distribution to the cluster.
Design Goals
Spark NLP was built from the ground up for large enterprise production use cases. Three core design goals:
State-of-the-art accuracy — the best peer-reviewed academic results on standard benchmarks.
State-of-the-art performance — optimized code, memory use, GPU and Intel chip support, lighter transformer models.
State-of-the-art scalability — native distribution across multiple machines (10, 50, 500+ nodes) giving tangible speedups.
State-of-the-Art Accuracy
Accuracy is the primary concern. Spark NLP aims to deliver the best results on academically accepted benchmarks, peer-reviewed, and production-ready.
Named Entity Recognition (NER)
The highest F1 score on CoNLL-2003 for named entity recognition in a production system was achieved by Spark NLP. The implementation uses bi-directional LSTM with character-level CNN + CRF and powerful word embeddings for transfer learning. Using BERT Large (case-sensitive) on CoNLL-2003, Spark NLP obtained:
93.3 F1 on the test set
95.9 F1 on the dev set
A direct comparison with another well-known open-source NLP library showed that Spark NLP, with default parameters, achieves higher accuracy across all embedding sizes—from small GloVe embeddings to large BERT models—while the competitor requires extra steps and still lags behind.
Key takeaway: Spark NLP provides high NER accuracy out of the box, with no additional tuning.
Word Embeddings and Transfer Learning
Most open-source libraries ship with very few pre-trained word embeddings. For example, spaCy v2 only provides vectors for three pipelines and four transformer models. In contrast, Spark NLP comes with over 50 pre-trained word embedding models out of the box, including state-of-the-art transformers like BERT, ALBERT, ELECTRA, XLNet, ELMo, and domain-specific models such as BioBERT, ClinicalBERT, and CovidBERT. Users can choose any embedding to train custom NER or text classification models.
Multi-class and Multi-label Text Classification
Spark NLP is one of the few libraries to offer built-in multi-class and multi-label classification.
Multi-class classification — one label per document (e.g., emotion detection, cyberbullying detection, fake news, spam).
Multi-label classification — multiple labels per document (e.g., toxic comment detection, movie genres).
Classifiers can use over 90 pre-trained word and sentence embeddings (including BERT and Universal Sentence Encoder), with dimensions from 100 to 1024, and support up to 100 classes without sacrificing accuracy. Models are implemented in TensorFlow using GRU followed by convolutional neural networks.
Language Detection / Identification
Spark NLP provides language detection models trained using TensorFlow Keras on 8 million Wikipedia pages. The models require no pre-processing or word embeddings, making the final model size only 3–5 MB. Accuracies achieved:
97% for 32 languages
99% for 22 languages
Spell Checking
Almost no major NLP library includes a spell-checking feature. Spark NLP’s spell checker was designed to handle bad inputs from OCR and can leverage sentence and document context. It preserves custom patterns and allows users to incorporate their own patterns. The contextual spell checker has outperformed nearly every publicly available benchmark.
Performance and Speed
Performance optimization is a continuous process. In early 2020, the training speed of NER was improved by over 60% and final F1 by 4% when moving to TensorFlow 1.15 and adding Windows, macOS, and Linux support.
BERT Embedding Optimizations
Transformers are inherently slow due to many encoder layers. In the latest release, Spark NLP:
Reduced memory usage by 30%
Improved inference performance by over 70% by implementing dynamic shapes in BERT embeddings.
Smaller BERT Models
Twenty-four new smaller models were added: TinyBERT, MiniBERT, SmallBERT, and MediumBERT.
Comparison of BERT-Base vs. BERT-Tiny:
BERT-Base: 12 layers (encoders), 768 dimensions.
BERT-Tiny: 2 layers, 128 dimensions → 24 times smaller and 28 times faster than BERT-Base. The smaller model is downloaded and loaded into TensorFlow almost seamlessly, reducing startup time.
GPU and Intel Optimizations
Using a GPU in Spark NLP is as simple as setting one parameter. Any TensorFlow-backed task can be 40–50% faster in both training and prediction.
On the newest Intel Cascade Lake processors (AWS), performance is close to GPU. When using a custom TensorFlow compiled with Intel MKL, training (e.g., French NER) was 19% faster than GPU and 46% cheaper than the GPU instance.
Scalability
Spark NLP is the only natively distributed open-source NLP library. It leverages Apache Spark’s execution planning, caching, serialization, and data shuffling. Scaling is not linear—it depends on the task and cluster configuration—but substantial gains are achieved with zero code change.
Benchmark: Pipeline (Tokenization + NER) on Amazon Reviews
Dataset: 50 million sentences, 255 million tokens.
Single node: 32 GB memory, 32 cores.
Cluster: 10 workers (each 32 GB memory, 16 cores) on Databricks AWS.
Task | Single Node (words/sec) | 10 Nodes (words/sec) |
|---|---|---|
Tokenization | 340,000 | 7,000,000 |
NER (deep learning) | 38,000 | 136,000 |
Tokenization scaled far more than linearly (7M vs 340k), while NER scaled about 3.6×. Tuning could improve the NER scaling further.
Benchmark: BERT Embeddings Distribution
Same dataset, max sequence length 128.
Single node BERT-Base: 19,000 words/sec
10 nodes BERT-Base: 76,000 words/sec
Single node BERT-Tiny: 170,000 words/sec
10 nodes BERT-Tiny: ~500,000 words/sec
These numbers demonstrate that smaller models combined with distribution can deliver very high throughput for complex transformer embeddings.
Ease of Use
Spark NLP provides three levels of pre-built functionality, all accessible in Python, Scala, or Java with identical APIs.
Pre-trained Pipelines
One line of code to load a pipeline and transform text.
Over 90 pre-trained pipelines supporting up to 13 languages.
Work both online and offline.
Caveat: Not flexible—the pipeline includes fixed tasks. If you don’t need part-of-speech, you still pay the computation cost; if you need a task the pipeline lacks, you cannot add it.
Pre-trained Models
Over 250 pre-trained models supporting 46 languages.
Work online and offline, and are flexible — users construct custom pipelines, selecting only the needed tasks (e.g., NER without POS).
Pre-trained models may have dependencies: a NER model trained on a specific BERT embedding (e.g., 128 dimensions) cannot be used with a different BERT embedding.
Training Custom Models
Spark NLP offers training classes for easy custom model development.
Part-of-Speech (POS) Tagging: Use the PerceptronApproach (averaged perceptron algorithm). Fast, language-agnostic, supports all languages. Convert a dataset (e.g., from Universal Dependencies) into the compatible format and train in 5–6 iterations for high accuracy.
Named Entity Recognition (NER): Use the NER DL annotator with training classes. Accepts the CoNLL 2003 format. Users choose from over 50 pre-trained word embeddings, set hyperparameters, and train on CPU or GPU. Built-in validation split and extended metrics are provided. Example: Training on Google Colab with a 2-layer BERT (768 dimensions) on the full CoNLL 2003 dataset took 16 minutes on a free GPU, achieving 91% micro F1 on the dev set and 90% CoNLL eval F1 (evaluating entity pairs, not just individual tokens).
Multi-class Classifier: Supports up to 100 classes, uses over 90 word/sentence embeddings, works on CPU and GPU, and provides extended evaluation metrics.
Summary and Conclusion
Spark NLP is a unified, production-grade NLP library that covers the entire pipeline from basic text processing to state-of-the-art deep learning. It delivers:
State-of-the-art accuracy: highest F1 on benchmarks like CoNLL-2003, with many pre-trained models and embeddings.
High performance: GPU support, Intel MKL optimizations, and lighter transformer variants (TinyBERT) that dramatically speed up inference.
Native scalability: the only NLP library that scales to clusters without code changes, with significant speedups on tokenization, NER, and BERT embeddings.
Ease of use: three levels of pre-built assets (pipelines, models, custom training) with identical Python/Scala/Java APIs.
With over 330 pre-trained models and pipelines supporting 46 languages, and a release cycle of one release every two weeks, Spark NLP remains at the forefront of the rapidly evolving NLP field. The library is backed by an active community on Slack and GitHub, and is used extensively in healthcare, life sciences, finance, and insurance—industries with high compliance requirements.

Ask anything
We've read this whole study set, so questions about it get the best answers.