spark-nlp 4.2.6__py2.py3-none-any.whl → 6.2.1__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. com/johnsnowlabs/ml/__init__.py +0 -0
  2. com/johnsnowlabs/ml/ai/__init__.py +10 -0
  3. spark_nlp-6.2.1.dist-info/METADATA +362 -0
  4. spark_nlp-6.2.1.dist-info/RECORD +292 -0
  5. {spark_nlp-4.2.6.dist-info → spark_nlp-6.2.1.dist-info}/WHEEL +1 -1
  6. sparknlp/__init__.py +81 -28
  7. sparknlp/annotation.py +3 -2
  8. sparknlp/annotator/__init__.py +6 -0
  9. sparknlp/annotator/audio/__init__.py +2 -0
  10. sparknlp/annotator/audio/hubert_for_ctc.py +188 -0
  11. sparknlp/annotator/audio/wav2vec2_for_ctc.py +14 -14
  12. sparknlp/annotator/audio/whisper_for_ctc.py +251 -0
  13. sparknlp/{base → annotator}/chunk2_doc.py +4 -7
  14. sparknlp/annotator/chunker.py +1 -2
  15. sparknlp/annotator/classifier_dl/__init__.py +17 -0
  16. sparknlp/annotator/classifier_dl/albert_for_multiple_choice.py +161 -0
  17. sparknlp/annotator/classifier_dl/albert_for_question_answering.py +3 -15
  18. sparknlp/annotator/classifier_dl/albert_for_sequence_classification.py +4 -18
  19. sparknlp/annotator/classifier_dl/albert_for_token_classification.py +3 -17
  20. sparknlp/annotator/classifier_dl/albert_for_zero_shot_classification.py +211 -0
  21. sparknlp/annotator/classifier_dl/bart_for_zero_shot_classification.py +225 -0
  22. sparknlp/annotator/classifier_dl/bert_for_multiple_choice.py +161 -0
  23. sparknlp/annotator/classifier_dl/bert_for_question_answering.py +6 -20
  24. sparknlp/annotator/classifier_dl/bert_for_sequence_classification.py +3 -17
  25. sparknlp/annotator/classifier_dl/bert_for_token_classification.py +3 -17
  26. sparknlp/annotator/classifier_dl/bert_for_zero_shot_classification.py +212 -0
  27. sparknlp/annotator/classifier_dl/camembert_for_question_answering.py +168 -0
  28. sparknlp/annotator/classifier_dl/camembert_for_sequence_classification.py +5 -19
  29. sparknlp/annotator/classifier_dl/camembert_for_token_classification.py +5 -19
  30. sparknlp/annotator/classifier_dl/camembert_for_zero_shot_classification.py +202 -0
  31. sparknlp/annotator/classifier_dl/classifier_dl.py +4 -4
  32. sparknlp/annotator/classifier_dl/deberta_for_question_answering.py +3 -17
  33. sparknlp/annotator/classifier_dl/deberta_for_sequence_classification.py +4 -19
  34. sparknlp/annotator/classifier_dl/deberta_for_token_classification.py +5 -21
  35. sparknlp/annotator/classifier_dl/deberta_for_zero_shot_classification.py +193 -0
  36. sparknlp/annotator/classifier_dl/distil_bert_for_question_answering.py +3 -17
  37. sparknlp/annotator/classifier_dl/distil_bert_for_sequence_classification.py +4 -18
  38. sparknlp/annotator/classifier_dl/distil_bert_for_token_classification.py +3 -17
  39. sparknlp/annotator/classifier_dl/distil_bert_for_zero_shot_classification.py +211 -0
  40. sparknlp/annotator/classifier_dl/distilbert_for_multiple_choice.py +161 -0
  41. sparknlp/annotator/classifier_dl/longformer_for_question_answering.py +3 -17
  42. sparknlp/annotator/classifier_dl/longformer_for_sequence_classification.py +4 -18
  43. sparknlp/annotator/classifier_dl/longformer_for_token_classification.py +3 -17
  44. sparknlp/annotator/classifier_dl/mpnet_for_question_answering.py +148 -0
  45. sparknlp/annotator/classifier_dl/mpnet_for_sequence_classification.py +188 -0
  46. sparknlp/annotator/classifier_dl/mpnet_for_token_classification.py +173 -0
  47. sparknlp/annotator/classifier_dl/multi_classifier_dl.py +3 -3
  48. sparknlp/annotator/classifier_dl/roberta_for_multiple_choice.py +161 -0
  49. sparknlp/annotator/classifier_dl/roberta_for_question_answering.py +3 -17
  50. sparknlp/annotator/classifier_dl/roberta_for_sequence_classification.py +4 -18
  51. sparknlp/annotator/classifier_dl/roberta_for_token_classification.py +1 -1
  52. sparknlp/annotator/classifier_dl/roberta_for_zero_shot_classification.py +225 -0
  53. sparknlp/annotator/classifier_dl/sentiment_dl.py +4 -4
  54. sparknlp/annotator/classifier_dl/tapas_for_question_answering.py +2 -2
  55. sparknlp/annotator/classifier_dl/xlm_roberta_for_multiple_choice.py +149 -0
  56. sparknlp/annotator/classifier_dl/xlm_roberta_for_question_answering.py +3 -17
  57. sparknlp/annotator/classifier_dl/xlm_roberta_for_sequence_classification.py +4 -18
  58. sparknlp/annotator/classifier_dl/xlm_roberta_for_token_classification.py +6 -20
  59. sparknlp/annotator/classifier_dl/xlm_roberta_for_zero_shot_classification.py +225 -0
  60. sparknlp/annotator/classifier_dl/xlnet_for_sequence_classification.py +4 -18
  61. sparknlp/annotator/classifier_dl/xlnet_for_token_classification.py +3 -17
  62. sparknlp/annotator/cleaners/__init__.py +15 -0
  63. sparknlp/annotator/cleaners/cleaner.py +202 -0
  64. sparknlp/annotator/cleaners/extractor.py +191 -0
  65. sparknlp/annotator/coref/spanbert_coref.py +4 -18
  66. sparknlp/annotator/cv/__init__.py +15 -0
  67. sparknlp/annotator/cv/blip_for_question_answering.py +172 -0
  68. sparknlp/annotator/cv/clip_for_zero_shot_classification.py +193 -0
  69. sparknlp/annotator/cv/convnext_for_image_classification.py +269 -0
  70. sparknlp/annotator/cv/florence2_transformer.py +180 -0
  71. sparknlp/annotator/cv/gemma3_for_multimodal.py +346 -0
  72. sparknlp/annotator/cv/internvl_for_multimodal.py +280 -0
  73. sparknlp/annotator/cv/janus_for_multimodal.py +351 -0
  74. sparknlp/annotator/cv/llava_for_multimodal.py +328 -0
  75. sparknlp/annotator/cv/mllama_for_multimodal.py +340 -0
  76. sparknlp/annotator/cv/paligemma_for_multimodal.py +308 -0
  77. sparknlp/annotator/cv/phi3_vision_for_multimodal.py +328 -0
  78. sparknlp/annotator/cv/qwen2vl_transformer.py +332 -0
  79. sparknlp/annotator/cv/smolvlm_transformer.py +426 -0
  80. sparknlp/annotator/cv/swin_for_image_classification.py +242 -0
  81. sparknlp/annotator/cv/vision_encoder_decoder_for_image_captioning.py +240 -0
  82. sparknlp/annotator/cv/vit_for_image_classification.py +36 -4
  83. sparknlp/annotator/dataframe_optimizer.py +216 -0
  84. sparknlp/annotator/date2_chunk.py +88 -0
  85. sparknlp/annotator/dependency/dependency_parser.py +2 -3
  86. sparknlp/annotator/dependency/typed_dependency_parser.py +3 -4
  87. sparknlp/annotator/document_character_text_splitter.py +228 -0
  88. sparknlp/annotator/document_normalizer.py +37 -1
  89. sparknlp/annotator/document_token_splitter.py +175 -0
  90. sparknlp/annotator/document_token_splitter_test.py +85 -0
  91. sparknlp/annotator/embeddings/__init__.py +11 -0
  92. sparknlp/annotator/embeddings/albert_embeddings.py +4 -18
  93. sparknlp/annotator/embeddings/auto_gguf_embeddings.py +539 -0
  94. sparknlp/annotator/embeddings/bert_embeddings.py +9 -22
  95. sparknlp/annotator/embeddings/bert_sentence_embeddings.py +12 -24
  96. sparknlp/annotator/embeddings/bge_embeddings.py +199 -0
  97. sparknlp/annotator/embeddings/camembert_embeddings.py +4 -20
  98. sparknlp/annotator/embeddings/chunk_embeddings.py +1 -2
  99. sparknlp/annotator/embeddings/deberta_embeddings.py +2 -16
  100. sparknlp/annotator/embeddings/distil_bert_embeddings.py +5 -19
  101. sparknlp/annotator/embeddings/doc2vec.py +7 -1
  102. sparknlp/annotator/embeddings/e5_embeddings.py +195 -0
  103. sparknlp/annotator/embeddings/e5v_embeddings.py +138 -0
  104. sparknlp/annotator/embeddings/elmo_embeddings.py +2 -2
  105. sparknlp/annotator/embeddings/instructor_embeddings.py +204 -0
  106. sparknlp/annotator/embeddings/longformer_embeddings.py +3 -17
  107. sparknlp/annotator/embeddings/minilm_embeddings.py +189 -0
  108. sparknlp/annotator/embeddings/mpnet_embeddings.py +192 -0
  109. sparknlp/annotator/embeddings/mxbai_embeddings.py +184 -0
  110. sparknlp/annotator/embeddings/nomic_embeddings.py +181 -0
  111. sparknlp/annotator/embeddings/roberta_embeddings.py +9 -21
  112. sparknlp/annotator/embeddings/roberta_sentence_embeddings.py +7 -21
  113. sparknlp/annotator/embeddings/sentence_embeddings.py +2 -3
  114. sparknlp/annotator/embeddings/snowflake_embeddings.py +202 -0
  115. sparknlp/annotator/embeddings/uae_embeddings.py +211 -0
  116. sparknlp/annotator/embeddings/universal_sentence_encoder.py +3 -3
  117. sparknlp/annotator/embeddings/word2vec.py +7 -1
  118. sparknlp/annotator/embeddings/word_embeddings.py +4 -5
  119. sparknlp/annotator/embeddings/xlm_roberta_embeddings.py +9 -21
  120. sparknlp/annotator/embeddings/xlm_roberta_sentence_embeddings.py +7 -21
  121. sparknlp/annotator/embeddings/xlnet_embeddings.py +4 -18
  122. sparknlp/annotator/er/entity_ruler.py +37 -23
  123. sparknlp/annotator/keyword_extraction/yake_keyword_extraction.py +2 -3
  124. sparknlp/annotator/ld_dl/language_detector_dl.py +2 -2
  125. sparknlp/annotator/lemmatizer.py +3 -4
  126. sparknlp/annotator/matcher/date_matcher.py +35 -3
  127. sparknlp/annotator/matcher/multi_date_matcher.py +1 -2
  128. sparknlp/annotator/matcher/regex_matcher.py +3 -3
  129. sparknlp/annotator/matcher/text_matcher.py +2 -3
  130. sparknlp/annotator/n_gram_generator.py +1 -2
  131. sparknlp/annotator/ner/__init__.py +3 -1
  132. sparknlp/annotator/ner/ner_converter.py +18 -0
  133. sparknlp/annotator/ner/ner_crf.py +4 -5
  134. sparknlp/annotator/ner/ner_dl.py +10 -5
  135. sparknlp/annotator/ner/ner_dl_graph_checker.py +293 -0
  136. sparknlp/annotator/ner/ner_overwriter.py +2 -2
  137. sparknlp/annotator/ner/zero_shot_ner_model.py +173 -0
  138. sparknlp/annotator/normalizer.py +2 -2
  139. sparknlp/annotator/openai/__init__.py +16 -0
  140. sparknlp/annotator/openai/openai_completion.py +349 -0
  141. sparknlp/annotator/openai/openai_embeddings.py +106 -0
  142. sparknlp/annotator/pos/perceptron.py +6 -7
  143. sparknlp/annotator/sentence/sentence_detector.py +2 -2
  144. sparknlp/annotator/sentence/sentence_detector_dl.py +3 -3
  145. sparknlp/annotator/sentiment/sentiment_detector.py +4 -5
  146. sparknlp/annotator/sentiment/vivekn_sentiment.py +4 -5
  147. sparknlp/annotator/seq2seq/__init__.py +17 -0
  148. sparknlp/annotator/seq2seq/auto_gguf_model.py +304 -0
  149. sparknlp/annotator/seq2seq/auto_gguf_reranker.py +334 -0
  150. sparknlp/annotator/seq2seq/auto_gguf_vision_model.py +336 -0
  151. sparknlp/annotator/seq2seq/bart_transformer.py +420 -0
  152. sparknlp/annotator/seq2seq/cohere_transformer.py +357 -0
  153. sparknlp/annotator/seq2seq/cpm_transformer.py +321 -0
  154. sparknlp/annotator/seq2seq/gpt2_transformer.py +1 -1
  155. sparknlp/annotator/seq2seq/llama2_transformer.py +343 -0
  156. sparknlp/annotator/seq2seq/llama3_transformer.py +381 -0
  157. sparknlp/annotator/seq2seq/m2m100_transformer.py +392 -0
  158. sparknlp/annotator/seq2seq/marian_transformer.py +124 -3
  159. sparknlp/annotator/seq2seq/mistral_transformer.py +348 -0
  160. sparknlp/annotator/seq2seq/nllb_transformer.py +420 -0
  161. sparknlp/annotator/seq2seq/olmo_transformer.py +326 -0
  162. sparknlp/annotator/seq2seq/phi2_transformer.py +326 -0
  163. sparknlp/annotator/seq2seq/phi3_transformer.py +330 -0
  164. sparknlp/annotator/seq2seq/phi4_transformer.py +387 -0
  165. sparknlp/annotator/seq2seq/qwen_transformer.py +340 -0
  166. sparknlp/annotator/seq2seq/starcoder_transformer.py +335 -0
  167. sparknlp/annotator/seq2seq/t5_transformer.py +54 -4
  168. sparknlp/annotator/similarity/__init__.py +0 -0
  169. sparknlp/annotator/similarity/document_similarity_ranker.py +379 -0
  170. sparknlp/annotator/spell_check/context_spell_checker.py +116 -17
  171. sparknlp/annotator/spell_check/norvig_sweeting.py +3 -6
  172. sparknlp/annotator/spell_check/symmetric_delete.py +1 -1
  173. sparknlp/annotator/stemmer.py +2 -3
  174. sparknlp/annotator/stop_words_cleaner.py +3 -4
  175. sparknlp/annotator/tf_ner_dl_graph_builder.py +1 -1
  176. sparknlp/annotator/token/__init__.py +0 -1
  177. sparknlp/annotator/token/recursive_tokenizer.py +2 -3
  178. sparknlp/annotator/token/tokenizer.py +2 -3
  179. sparknlp/annotator/ws/word_segmenter.py +35 -10
  180. sparknlp/base/__init__.py +2 -3
  181. sparknlp/base/doc2_chunk.py +0 -3
  182. sparknlp/base/document_assembler.py +5 -5
  183. sparknlp/base/embeddings_finisher.py +14 -2
  184. sparknlp/base/finisher.py +15 -4
  185. sparknlp/base/gguf_ranking_finisher.py +234 -0
  186. sparknlp/base/image_assembler.py +69 -0
  187. sparknlp/base/light_pipeline.py +53 -21
  188. sparknlp/base/multi_document_assembler.py +9 -13
  189. sparknlp/base/prompt_assembler.py +207 -0
  190. sparknlp/base/token_assembler.py +1 -2
  191. sparknlp/common/__init__.py +2 -0
  192. sparknlp/common/annotator_type.py +1 -0
  193. sparknlp/common/completion_post_processing.py +37 -0
  194. sparknlp/common/match_strategy.py +33 -0
  195. sparknlp/common/properties.py +914 -9
  196. sparknlp/internal/__init__.py +841 -116
  197. sparknlp/internal/annotator_java_ml.py +1 -1
  198. sparknlp/internal/annotator_transformer.py +3 -0
  199. sparknlp/logging/comet.py +2 -2
  200. sparknlp/partition/__init__.py +16 -0
  201. sparknlp/partition/partition.py +244 -0
  202. sparknlp/partition/partition_properties.py +902 -0
  203. sparknlp/partition/partition_transformer.py +200 -0
  204. sparknlp/pretrained/pretrained_pipeline.py +1 -1
  205. sparknlp/pretrained/resource_downloader.py +126 -2
  206. sparknlp/reader/__init__.py +15 -0
  207. sparknlp/reader/enums.py +19 -0
  208. sparknlp/reader/pdf_to_text.py +190 -0
  209. sparknlp/reader/reader2doc.py +124 -0
  210. sparknlp/reader/reader2image.py +136 -0
  211. sparknlp/reader/reader2table.py +44 -0
  212. sparknlp/reader/reader_assembler.py +159 -0
  213. sparknlp/reader/sparknlp_reader.py +461 -0
  214. sparknlp/training/__init__.py +1 -0
  215. sparknlp/training/conll.py +8 -2
  216. sparknlp/training/spacy_to_annotation.py +57 -0
  217. sparknlp/util.py +26 -0
  218. spark_nlp-4.2.6.dist-info/METADATA +0 -1256
  219. spark_nlp-4.2.6.dist-info/RECORD +0 -196
  220. {spark_nlp-4.2.6.dist-info → spark_nlp-6.2.1.dist-info}/top_level.txt +0 -0
  221. /sparknlp/annotator/{token/token2_chunk.py → token2_chunk.py} +0 -0
@@ -1,1256 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: spark-nlp
3
- Version: 4.2.6
4
- Summary: 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.
5
- Home-page: https://github.com/JohnSnowLabs/spark-nlp
6
- Author: John Snow Labs
7
- Keywords: NLP spark vision speech deep learning transformer tensorflow BERT GPT-2 Wav2Vec2 ViT
8
- Classifier: Development Status :: 5 - Production/Stable
9
- Classifier: Intended Audience :: Developers
10
- Classifier: Intended Audience :: Information Technology
11
- Classifier: Intended Audience :: Science/Research
12
- Classifier: License :: OSI Approved :: Apache Software License
13
- Classifier: Operating System :: OS Independent
14
- Classifier: Operating System :: POSIX :: Linux
15
- Classifier: Operating System :: MacOS :: MacOS X
16
- Classifier: Operating System :: Microsoft :: Windows
17
- Classifier: Programming Language :: Python :: 3
18
- Classifier: Programming Language :: Python :: 3.6
19
- Classifier: Programming Language :: Python :: 3.7
20
- Classifier: Programming Language :: Python :: 3.8
21
- Classifier: Programming Language :: Python :: 3.9
22
- Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
- Classifier: Topic :: Scientific/Engineering :: Information Analysis
24
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
25
- Classifier: Topic :: Software Development :: Internationalization
26
- Classifier: Topic :: Software Development :: Localization
27
- Classifier: Topic :: Software Development :: Build Tools
28
- Classifier: Topic :: Text Processing :: Linguistic
29
- Classifier: Topic :: Scientific/Engineering
30
- Classifier: Typing :: Typed
31
- Description-Content-Type: text/markdown
32
-
33
- # Spark NLP: State-of-the-Art Natural Language Processing
34
- <p align="center">
35
- <a href="https://github.com/JohnSnowLabs/spark-nlp/actions" alt="build">
36
- <img src="https://github.com/JohnSnowLabs/spark-nlp/workflows/build/badge.svg" /></a>
37
- <a href="https://github.com/JohnSnowLabs/spark-nlp/releases" alt="Current Release Version">
38
- <img src="https://img.shields.io/github/v/release/JohnSnowLabs/spark-nlp.svg?style=flat-square&logo=github" /></a>
39
- <a href="https://search.maven.org/artifact/com.johnsnowlabs.nlp/spark-nlp_2.12" alt="Maven Central">
40
- <img src="https://maven-badges.herokuapp.com/maven-central/com.johnsnowlabs.nlp/spark-nlp_2.12/badge.svg" /></a>
41
- <a href="https://badge.fury.io/py/spark-nlp" alt="PyPI version">
42
- <img src="https://badge.fury.io/py/spark-nlp.svg" /></a>
43
- <a href="https://anaconda.org/JohnSnowLabs/spark-nlp" alt="Anaconda-Cloud">
44
- <img src="https://anaconda.org/johnsnowlabs/spark-nlp/badges/version.svg" /></a>
45
- <a href="https://github.com/JohnSnowLabs/spark-nlp/blob/master/LICENSE" alt="License">
46
- <img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg" /></a>
47
- <a href="https://pypi.org/project/spark-nlp/" alt="PyPi downloads">
48
- <img src="https://static.pepy.tech/personalized-badge/spark-nlp?period=total&units=international_system&left_color=grey&right_color=orange&left_text=pip%20downloads" /></a>
49
- </p>
50
-
51
- 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.
52
- Spark NLP comes with **11000+** pretrained **pipelines** and **models** in more than **200+** languages.
53
- It also offers tasks such as **Tokenization**, **Word Segmentation**, **Part-of-Speech Tagging**, Word and Sentence **Embeddings**, **Named Entity Recognition**, **Dependency Parsing**, **Spell Checking**, **Text Classification**, **Sentiment Analysis**, **Token Classification**, **Machine Translation** (+180 languages), **Summarization**, **Question Answering**, **Table Question Answering**, **Text Generation**, **Image Classification**, **Automatic Speech Recognition**, and many more [NLP tasks](#features).
54
-
55
- **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**, **Google T5**, **MarianMT**, **GPT2**, and **Vision Transformers (ViT)** not only to **Python** and **R**, but also to **JVM** ecosystem (**Java**, **Scala**, and **Kotlin**) at **scale** by extending **Apache Spark** natively.
56
-
57
- ## Project's website
58
-
59
- Take a look at our official Spark NLP page: [http://nlp.johnsnowlabs.com/](http://nlp.johnsnowlabs.com/) for user documentation and examples
60
-
61
- ## Community support
62
-
63
- - [Slack](https://www.johnsnowlabs.com/slack-redirect/) For live discussion with the Spark NLP community and the team
64
- - [GitHub](https://github.com/JohnSnowLabs/spark-nlp) Bug reports, feature requests, and contributions
65
- - [Discussions](https://github.com/JohnSnowLabs/spark-nlp/discussions) Engage with other community members, share ideas, and show off how you use Spark NLP!
66
- - [Medium](https://medium.com/spark-nlp) Spark NLP articles
67
- - [YouTube](https://www.youtube.com/channel/UCmFOjlpYEhxf_wJUDuz6xxQ/videos) Spark NLP video tutorials
68
-
69
- ## Table of contents
70
-
71
- - [Features](#features)
72
- - [Requirements](#requirements)
73
- - [Quick Start](#quick-start)
74
- - [Apache Spark Support](#apache-spark-support)
75
- - [Scala & Python Support](#scala-and-python-support)
76
- - [Databricks Support](#databricks-support)
77
- - [EMR Support](#emr-support)
78
- - [Using Spark NLP](#usage)
79
- - [Packages Cheatsheet](#packages-cheatsheet)
80
- - [Spark Packages](#spark-packages)
81
- - [Scala](#scala)
82
- - [Maven](#maven)
83
- - [SBT](#sbt)
84
- - [Python](#python)
85
- - [Pip/Conda](#pipconda)
86
- - [Compiled JARs](#compiled-jars)
87
- - [Apache Zeppelin](#apache-zeppelin)
88
- - [Jupyter Notebook](#jupyter-notebook-python)
89
- - [Google Colab Notebook](#google-colab-notebook)
90
- - [Kaggle Kernel](#kaggle-kernel)
91
- - [Databricks Cluster](#databricks-cluster)
92
- - [EMR Cluster](#emr-cluster)
93
- - [GCP Dataproc](#gcp-dataproc)
94
- - [Spark NLP Configuration](#spark-nlp-configuration)
95
- - [Pipelines & Models](#pipelines-and-models)
96
- - [Pipelines](#pipelines)
97
- - [Models](#models)
98
- - [Offline](#offline)
99
- - [Examples](#examples)
100
- - [FAQ](#faq)
101
- - [Citation](#citation)
102
- - [Contributing](#contributing)
103
-
104
- ## Features
105
-
106
- - Tokenization
107
- - Trainable Word Segmentation
108
- - Stop Words Removal
109
- - Token Normalizer
110
- - Document Normalizer
111
- - Stemmer
112
- - Lemmatizer
113
- - NGrams
114
- - Regex Matching
115
- - Text Matching
116
- - Chunking
117
- - Date Matcher
118
- - Sentence Detector
119
- - Deep Sentence Detector (Deep learning)
120
- - Dependency parsing (Labeled/unlabeled)
121
- - SpanBertCorefModel (Coreference Resolution)
122
- - Part-of-speech tagging
123
- - Sentiment Detection (ML models)
124
- - Spell Checker (ML and DL models)
125
- - Word Embeddings (GloVe and Word2Vec)
126
- - Doc2Vec (based on Word2Vec)
127
- - BERT Embeddings (TF Hub & HuggingFace models)
128
- - DistilBERT Embeddings (HuggingFace models)
129
- - CamemBERT Embeddings (HuggingFace models)
130
- - RoBERTa Embeddings (HuggingFace models)
131
- - DeBERTa Embeddings (HuggingFace v2 & v3 models)
132
- - XLM-RoBERTa Embeddings (HuggingFace models)
133
- - Longformer Embeddings (HuggingFace models)
134
- - ALBERT Embeddings (TF Hub & HuggingFace models)
135
- - XLNet Embeddings
136
- - ELMO Embeddings (TF Hub models)
137
- - Universal Sentence Encoder (TF Hub models)
138
- - BERT Sentence Embeddings (TF Hub & HuggingFace models)
139
- - RoBerta Sentence Embeddings (HuggingFace models)
140
- - XLM-RoBerta Sentence Embeddings (HuggingFace models)
141
- - Sentence Embeddings
142
- - Chunk Embeddings
143
- - Unsupervised keywords extraction
144
- - Language Detection & Identification (up to 375 languages)
145
- - Multi-class Sentiment analysis (Deep learning)
146
- - Multi-label Sentiment analysis (Deep learning)
147
- - Multi-class Text Classification (Deep learning)
148
- - BERT for Token & Sequence Classification
149
- - DistilBERT for Token & Sequence Classification
150
- - CamemBERT for Token & Sequence Classification
151
- - ALBERT for Token & Sequence Classification
152
- - RoBERTa for Token & Sequence Classification
153
- - DeBERTa for Token & Sequence Classification
154
- - XLM-RoBERTa for Token & Sequence Classification
155
- - XLNet for Token & Sequence Classification
156
- - Longformer for Token & Sequence Classification
157
- - BERT for Token & Sequence Classification
158
- - DistilBERT for Question Answering
159
- - ALBERT for Question Answering
160
- - RoBERTa for Question Answering
161
- - DeBERTa for Question Answering
162
- - XLM-RoBERTa for Question Answering
163
- - Longformer for Question Answering
164
- - Table Question Answering (TAPAS)
165
- - Neural Machine Translation (MarianMT)
166
- - Text-To-Text Transfer Transformer (Google T5)
167
- - Generative Pre-trained Transformer 2 (OpenAI GPT2)
168
- - Vision Transformer (ViT)
169
- - Automatic Speech Recognition (Wav2Vec2)
170
- - Named entity recognition (Deep learning)
171
- - Easy TensorFlow integration
172
- - GPU Support
173
- - Full integration with Spark ML functions
174
- - +6150+ pre-trained models in +200 languages!
175
- - +1840 pre-trained pipelines in +200 languages!
176
- - Multi-lingual NER models: Arabic, Bengali, Chinese, Danish, Dutch, English, Finnish, French, German, Hebrew, Italian, Japanese, Korean, Norwegian, Persian, Polish, Portuguese, Russian, Spanish, Swedish, Urdu, and more.
177
-
178
- ## Requirements
179
-
180
- To use Spark NLP you need the following requirements:
181
-
182
- - Java 8 and 11
183
- - Apache Spark 3.3.x, 3.2.x, 3.1.x, 3.0.x
184
-
185
- **GPU (optional):**
186
-
187
- Spark NLP 4.2.6 is built with TensorFlow 2.7.1 and the following NVIDIA® software are only required for GPU support:
188
-
189
- - NVIDIA® GPU drivers version 450.80.02 or higher
190
- - CUDA® Toolkit 11.2
191
- - cuDNN SDK 8.1.0
192
-
193
- ## Quick Start
194
-
195
- This is a quick example of how to use Spark NLP pre-trained pipeline in Python and PySpark:
196
-
197
- ```sh
198
- $ java -version
199
- # should be Java 8 or 11 (Oracle or OpenJDK)
200
- $ conda create -n sparknlp python=3.7 -y
201
- $ conda activate sparknlp
202
- # spark-nlp by default is based on pyspark 3.x
203
- $ pip install spark-nlp==4.2.6 pyspark==3.2.3
204
- ```
205
-
206
- In Python console or Jupyter `Python3` kernel:
207
-
208
- ```python
209
- # Import Spark NLP
210
- from sparknlp.base import *
211
- from sparknlp.annotator import *
212
- from sparknlp.pretrained import PretrainedPipeline
213
- import sparknlp
214
-
215
- # Start SparkSession with Spark NLP
216
- # start() functions has 3 parameters: gpu, m1, and memory
217
- # sparknlp.start(gpu=True) will start the session with GPU support
218
- # sparknlp.start(m1=True) will start the session with macOS M1 support
219
- # sparknlp.start(memory="16G") to change the default driver memory in SparkSession
220
- spark = sparknlp.start()
221
-
222
- # Download a pre-trained pipeline
223
- pipeline = PretrainedPipeline('explain_document_dl', lang='en')
224
-
225
- # Your testing dataset
226
- text = """
227
- The Mona Lisa is a 16th century oil painting created by Leonardo.
228
- It's held at the Louvre in Paris.
229
- """
230
-
231
- # Annotate your testing dataset
232
- result = pipeline.annotate(text)
233
-
234
- # What's in the pipeline
235
- list(result.keys())
236
- Output: ['entities', 'stem', 'checked', 'lemma', 'document',
237
- 'pos', 'token', 'ner', 'embeddings', 'sentence']
238
-
239
- # Check the results
240
- result['entities']
241
- Output: ['Mona Lisa', 'Leonardo', 'Louvre', 'Paris']
242
- ```
243
-
244
- For more examples, you can visit our dedicated [repository](https://github.com/JohnSnowLabs/spark-nlp-workshop) to showcase all Spark NLP use cases!
245
-
246
- ## Apache Spark Support
247
-
248
- Spark NLP *4.2.6* has been built on top of Apache Spark 3.2 while fully supports Apache Spark 3.0.x, 3.1.x, 3.2.x, and 3.3.x:
249
-
250
- | Spark NLP | Apache Spark 2.3.x | Apache Spark 2.4.x | Apache Spark 3.0.x | Apache Spark 3.1.x | Apache Spark 3.2.x | Apache Spark 3.3.x |
251
- |-----------|--------------------|--------------------|--------------------|--------------------|--------------------|--------------------|
252
- | 4.2.x | NO | NO | YES | YES | YES | YES |
253
- | 4.1.x | NO | NO | YES | YES | YES | YES |
254
- | 4.0.x | NO | NO | YES | YES | YES | YES |
255
- | 3.4.x | YES | YES | YES | YES | Partially | N/A |
256
- | 3.3.x | YES | YES | YES | YES | NO | NO |
257
- | 3.2.x | YES | YES | YES | YES | NO | NO |
258
- | 3.1.x | YES | YES | YES | YES | NO | NO |
259
- | 3.0.x | YES | YES | YES | YES | NO | NO |
260
- | 2.7.x | YES | YES | NO | NO | NO | NO |
261
-
262
- NOTE: Starting 4.0.0 release, the default `spark-nlp` and `spark-nlp-gpu` packages are based on Scala 2.12.15 and Apache Spark 3.2 by default.
263
-
264
- Find out more about `Spark NLP` versions from our [release notes](https://github.com/JohnSnowLabs/spark-nlp/releases).
265
-
266
- ## Scala and Python Support
267
-
268
- | Spark NLP | Python 3.6 | Python 3.7 | Python 3.8 | Python 3.9 | Scala 2.11 | Scala 2.12 |
269
- |-----------|------------|------------|------------|------------|------------|------------|
270
- | 4.2.x | YES | YES | YES | YES | NO | YES |
271
- | 4.1.x | YES | YES | YES | YES | NO | YES |
272
- | 4.0.x | YES | YES | YES | YES | NO | YES |
273
- | 3.4.x | YES | YES | YES | YES | YES | YES |
274
- | 3.3.x | YES | YES | YES | NO | YES | YES |
275
- | 3.2.x | YES | YES | YES | NO | YES | YES |
276
- | 3.1.x | YES | YES | YES | NO | YES | YES |
277
- | 3.0.x | YES | YES | YES | NO | YES | YES |
278
- | 2.7.x | YES | YES | NO | NO | YES | NO |
279
-
280
- ## Databricks Support
281
-
282
- Spark NLP 4.2.6 has been tested and is compatible with the following runtimes:
283
-
284
- **CPU:**
285
-
286
- - 7.3
287
- - 7.3 ML
288
- - 9.1
289
- - 9.1 ML
290
- - 10.1
291
- - 10.1 ML
292
- - 10.2
293
- - 10.2 ML
294
- - 10.3
295
- - 10.3 ML
296
- - 10.4
297
- - 10.4 ML
298
- - 10.5
299
- - 10.5 ML
300
- - 11.0
301
- - 11.0 ML
302
- - 11.1
303
- - 11.1 ML
304
- - 11.2
305
- - 11.2 ML
306
- - 11.3
307
- - 11.3 ML
308
-
309
- **GPU:**
310
-
311
- - 9.1 ML & GPU
312
- - 10.1 ML & GPU
313
- - 10.2 ML & GPU
314
- - 10.3 ML & GPU
315
- - 10.4 ML & GPU
316
- - 10.5 ML & GPU
317
- - 11.0 ML & GPU
318
- - 11.1 ML & GPU
319
- - 11.2 ML & GPU
320
- - 11.3 ML & GPU
321
-
322
- NOTE: Spark NLP 4.0.x is based on TensorFlow 2.7.x which is compatible with CUDA11 and cuDNN 8.0.2. The only Databricks runtimes supporting CUDA 11 are 9.x and above as listed under GPU.
323
-
324
- ## EMR Support
325
-
326
- Spark NLP 4.2.6 has been tested and is compatible with the following EMR releases:
327
-
328
- - emr-6.2.0
329
- - emr-6.3.0
330
- - emr-6.3.1
331
- - emr-6.4.0
332
- - emr-6.5.0
333
- - emr-6.6.0
334
- - emr-6.7.0
335
-
336
- Full list of [Amazon EMR 6.x releases](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/emr-release-6x.html)
337
-
338
- NOTE: The EMR 6.1.0 and 6.1.1 are not supported.
339
-
340
- ## Usage
341
-
342
- ## Packages Cheatsheet
343
-
344
- This is a cheatsheet for corresponding Spark NLP Maven package to Apache Spark / PySpark major version:
345
-
346
- | Apache Spark | Spark NLP on CPU | Spark NLP on GPU | Spark NLP on AArch64 (linux) | Spark NLP on M1 |
347
- |------------------|--------------------|----------------------------|--------------------------------|---------------------------|
348
- | 3.0/3.1/3.2/3.3 | `spark-nlp` | `spark-nlp-gpu` | `spark-nlp-aarch64` | `spark-nlp-m1` |
349
- | Start Function | `sparknlp.start()` | `sparknlp.start(gpu=True)` | `sparknlp.start(aarch64=True)` | `sparknlp.start(m1=True)` |
350
-
351
- NOTE: `M1` 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.
352
-
353
- ## Spark Packages
354
-
355
- ### Command line (requires internet connection)
356
-
357
- Spark NLP supports all major releases of Apache Spark 3.0.x, Apache Spark 3.1.x, Apache Spark 3.2.x, and Apache Spark 3.3.x.
358
-
359
- #### Apache Spark 3.x (3.0.x, 3.1.x, 3.2.x, and 3.3.x - Scala 2.12)
360
-
361
- ```sh
362
- # CPU
363
-
364
- spark-shell --packages com.johnsnowlabs.nlp:spark-nlp_2.12:4.2.6
365
-
366
- pyspark --packages com.johnsnowlabs.nlp:spark-nlp_2.12:4.2.6
367
-
368
- spark-submit --packages com.johnsnowlabs.nlp:spark-nlp_2.12:4.2.6
369
- ```
370
-
371
- The `spark-nlp` has been published to the [Maven Repository](https://mvnrepository.com/artifact/com.johnsnowlabs.nlp/spark-nlp).
372
-
373
- ```sh
374
- # GPU
375
-
376
- spark-shell --packages com.johnsnowlabs.nlp:spark-nlp-gpu_2.12:4.2.6
377
-
378
- pyspark --packages com.johnsnowlabs.nlp:spark-nlp-gpu_2.12:4.2.6
379
-
380
- spark-submit --packages com.johnsnowlabs.nlp:spark-nlp-gpu_2.12:4.2.6
381
-
382
- ```
383
-
384
- The `spark-nlp-gpu` has been published to the [Maven Repository](https://mvnrepository.com/artifact/com.johnsnowlabs.nlp/spark-nlp-gpu).
385
-
386
- ```sh
387
- # AArch64
388
-
389
- spark-shell --packages com.johnsnowlabs.nlp:spark-nlp-aarch64_2.12:4.2.6
390
-
391
- pyspark --packages com.johnsnowlabs.nlp:spark-nlp-aarch64_2.12:4.2.6
392
-
393
- spark-submit --packages com.johnsnowlabs.nlp:spark-nlp-aarch64_2.12:4.2.6
394
-
395
- ```
396
-
397
- The `spark-nlp-aarch64` has been published to the [Maven Repository](https://mvnrepository.com/artifact/com.johnsnowlabs.nlp/spark-nlp-aarch64).
398
-
399
- ```sh
400
- # M1
401
-
402
- spark-shell --packages com.johnsnowlabs.nlp:spark-nlp-m1_2.12:4.2.6
403
-
404
- pyspark --packages com.johnsnowlabs.nlp:spark-nlp-m1_2.12:4.2.6
405
-
406
- spark-submit --packages com.johnsnowlabs.nlp:spark-nlp-m1_2.12:4.2.6
407
-
408
- ```
409
-
410
- The `spark-nlp-m1` has been published to the [Maven Repository](https://mvnrepository.com/artifact/com.johnsnowlabs.nlp/spark-nlp-m1).
411
-
412
- **NOTE**: In case you are using large pretrained models like UniversalSentenceEncoder, you need to have the following set in your SparkSession:
413
-
414
- ```sh
415
- spark-shell \
416
- --driver-memory 16g \
417
- --conf spark.kryoserializer.buffer.max=2000M \
418
- --packages com.johnsnowlabs.nlp:spark-nlp_2.12:4.2.6
419
- ```
420
-
421
- ## Scala
422
-
423
- Spark NLP supports Scala 2.12.15 if you are using Apache Spark 3.0.x, 3.1.x, 3.2.x, and 3.3.x versions. Our packages are deployed to Maven central. To add any of our packages as a dependency in your application you can follow these coordinates:
424
-
425
- ### Maven
426
-
427
- **spark-nlp** on Apache Spark 3.0.x, 3.1.x, 3.2.x, and 3.3.x:
428
-
429
- ```xml
430
- <!-- https://mvnrepository.com/artifact/com.johnsnowlabs.nlp/spark-nlp -->
431
- <dependency>
432
- <groupId>com.johnsnowlabs.nlp</groupId>
433
- <artifactId>spark-nlp_2.12</artifactId>
434
- <version>4.2.6</version>
435
- </dependency>
436
- ```
437
-
438
- **spark-nlp-gpu:**
439
-
440
- ```xml
441
- <!-- https://mvnrepository.com/artifact/com.johnsnowlabs.nlp/spark-nlp-gpu -->
442
- <dependency>
443
- <groupId>com.johnsnowlabs.nlp</groupId>
444
- <artifactId>spark-nlp-gpu_2.12</artifactId>
445
- <version>4.2.6</version>
446
- </dependency>
447
- ```
448
-
449
- **spark-nlp-aarch64:**
450
-
451
- ```xml
452
- <!-- https://mvnrepository.com/artifact/com.johnsnowlabs.nlp/spark-nlp-aarch64 -->
453
- <dependency>
454
- <groupId>com.johnsnowlabs.nlp</groupId>
455
- <artifactId>spark-nlp-aarch64_2.12</artifactId>
456
- <version>4.2.6</version>
457
- </dependency>
458
- ```
459
-
460
- **spark-nlp-m1:**
461
-
462
- ```xml
463
- <!-- https://mvnrepository.com/artifact/com.johnsnowlabs.nlp/spark-nlp-m1 -->
464
- <dependency>
465
- <groupId>com.johnsnowlabs.nlp</groupId>
466
- <artifactId>spark-nlp-m1_2.12</artifactId>
467
- <version>4.2.6</version>
468
- </dependency>
469
- ```
470
-
471
- ### SBT
472
-
473
- **spark-nlp** on Apache Spark 3.0.x, 3.1.x, 3.2.x, and 3.3.x:
474
-
475
- ```sbtshell
476
- // https://mvnrepository.com/artifact/com.johnsnowlabs.nlp/spark-nlp
477
- libraryDependencies += "com.johnsnowlabs.nlp" %% "spark-nlp" % "4.2.6"
478
- ```
479
-
480
- **spark-nlp-gpu:**
481
-
482
- ```sbtshell
483
- // https://mvnrepository.com/artifact/com.johnsnowlabs.nlp/spark-nlp-gpu
484
- libraryDependencies += "com.johnsnowlabs.nlp" %% "spark-nlp-gpu" % "4.2.6"
485
- ```
486
-
487
- **spark-nlp-aarch64:**
488
-
489
- ```sbtshell
490
- // https://mvnrepository.com/artifact/com.johnsnowlabs.nlp/spark-nlp-aarch64
491
- libraryDependencies += "com.johnsnowlabs.nlp" %% "spark-nlp-aarch64" % "4.2.6"
492
- ```
493
-
494
- **spark-nlp-m1:**
495
-
496
- ```sbtshell
497
- // https://mvnrepository.com/artifact/com.johnsnowlabs.nlp/spark-nlp-m1
498
- libraryDependencies += "com.johnsnowlabs.nlp" %% "spark-nlp-m1" % "4.2.6"
499
- ```
500
-
501
- Maven Central: [https://mvnrepository.com/artifact/com.johnsnowlabs.nlp](https://mvnrepository.com/artifact/com.johnsnowlabs.nlp)
502
-
503
- 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 SBT Starter](https://github.com/maziyarpanahi/spark-nlp-starter)
504
-
505
- ## Python
506
-
507
- Spark NLP supports Python 3.6.x and above depending on your major PySpark version.
508
-
509
- ### Python without explicit Pyspark installation
510
-
511
- ### Pip/Conda
512
-
513
- If you installed pyspark through pip/conda, you can install `spark-nlp` through the same channel.
514
-
515
- Pip:
516
-
517
- ```bash
518
- pip install spark-nlp==4.2.6
519
- ```
520
-
521
- Conda:
522
-
523
- ```bash
524
- conda install -c johnsnowlabs spark-nlp
525
- ```
526
-
527
- PyPI [spark-nlp package](https://pypi.org/project/spark-nlp/) / Anaconda [spark-nlp package](https://anaconda.org/JohnSnowLabs/spark-nlp)
528
-
529
- Then you'll have to create a SparkSession either from Spark NLP:
530
-
531
- ```python
532
- import sparknlp
533
-
534
- spark = sparknlp.start()
535
- ```
536
-
537
- or manually:
538
-
539
- ```python
540
- spark = SparkSession.builder \
541
- .appName("Spark NLP")\
542
- .master("local[*]")\
543
- .config("spark.driver.memory","16G")\
544
- .config("spark.driver.maxResultSize", "0") \
545
- .config("spark.kryoserializer.buffer.max", "2000M")\
546
- .config("spark.jars.packages", "com.johnsnowlabs.nlp:spark-nlp_2.12:4.2.6")\
547
- .getOrCreate()
548
- ```
549
-
550
- If using local jars, you can use `spark.jars` instead for comma-delimited jar files. For cluster setups, of course, you'll have to put the jars in a reachable location for all driver and executor nodes.
551
-
552
- **Quick example:**
553
-
554
- ```python
555
- import sparknlp
556
- from sparknlp.pretrained import PretrainedPipeline
557
-
558
- #create or get Spark Session
559
-
560
- spark = sparknlp.start()
561
-
562
- sparknlp.version()
563
- spark.version
564
-
565
- #download, load and annotate a text by pre-trained pipeline
566
-
567
- pipeline = PretrainedPipeline('recognize_entities_dl', 'en')
568
- result = pipeline.annotate('The Mona Lisa is a 16th century oil painting created by Leonardo')
569
- ```
570
-
571
- ## Compiled JARs
572
-
573
- ### Build from source
574
-
575
- #### spark-nlp
576
-
577
- - FAT-JAR for CPU on Apache Spark 3.0.x, 3.1.x, 3.2.x, and 3.3.x
578
-
579
- ```bash
580
- sbt assembly
581
- ```
582
-
583
- - FAT-JAR for GPU on Apache Spark 3.0.x, 3.1.x, 3.2.x, and 3.3.x
584
-
585
- ```bash
586
- sbt -Dis_gpu=true assembly
587
- ```
588
-
589
- - FAT-JAR for M! on Apache Spark 3.0.x, 3.1.x, 3.2.x, and 3.3.x
590
-
591
- ```bash
592
- sbt -Dis_m1=true assembly
593
- ```
594
-
595
- ### Using the jar manually
596
-
597
- If for some reason you need to use the JAR, you can either download the Fat JARs provided here or download it from [Maven Central](https://mvnrepository.com/artifact/com.johnsnowlabs.nlp).
598
-
599
- To add JARs to spark programs use the `--jars` option:
600
-
601
- ```sh
602
- spark-shell --jars spark-nlp.jar
603
- ```
604
-
605
- The preferred way to use the library when running spark programs is using the `--packages` option as specified in the `spark-packages` section.
606
-
607
- ## Apache Zeppelin
608
-
609
- Use either one of the following options
610
-
611
- - Add the following Maven Coordinates to the interpreter's library list
612
-
613
- ```bash
614
- com.johnsnowlabs.nlp:spark-nlp_2.12:4.2.6
615
- ```
616
-
617
- - Add a path to pre-built jar from [here](#compiled-jars) in the interpreter's library list making sure the jar is available to driver path
618
-
619
- ### Python in Zeppelin
620
-
621
- Apart from the previous step, install the python module through pip
622
-
623
- ```bash
624
- pip install spark-nlp==4.2.6
625
- ```
626
-
627
- Or you can install `spark-nlp` from inside Zeppelin by using Conda:
628
-
629
- ```bash
630
- python.conda install -c johnsnowlabs spark-nlp
631
- ```
632
-
633
- Configure Zeppelin properly, use cells with %spark.pyspark or any interpreter name you chose.
634
-
635
- Finally, in Zeppelin interpreter settings, make sure you set properly zeppelin.python to the python you want to use and install the pip library with (e.g. `python3`).
636
-
637
- An alternative option would be to set `SPARK_SUBMIT_OPTIONS` (zeppelin-env.sh) and make sure `--packages` is there as shown earlier since it includes both scala and python side installation.
638
-
639
- ## Jupyter Notebook (Python)
640
-
641
- **Recommended:**
642
-
643
- The easiest way to get this done on Linux and macOS is to simply install `spark-nlp` and `pyspark` PyPI packages and launch the Jupyter from the same Python environment:
644
-
645
- ```sh
646
- $ conda create -n sparknlp python=3.8 -y
647
- $ conda activate sparknlp
648
- # spark-nlp by default is based on pyspark 3.x
649
- $ pip install spark-nlp==4.2.6 pyspark==3.2.3 jupyter
650
- $ jupyter notebook
651
- ```
652
-
653
- Then you can use `python3` kernel to run your code with creating SparkSession via `spark = sparknlp.start()`.
654
-
655
- **Optional:**
656
-
657
- If you are in different operating systems and require to make Jupyter Notebook run by using pyspark, you can follow these steps:
658
-
659
- ```bash
660
- export SPARK_HOME=/path/to/your/spark/folder
661
- export PYSPARK_PYTHON=python3
662
- export PYSPARK_DRIVER_PYTHON=jupyter
663
- export PYSPARK_DRIVER_PYTHON_OPTS=notebook
664
-
665
- pyspark --packages com.johnsnowlabs.nlp:spark-nlp_2.12:4.2.6
666
- ```
667
-
668
- Alternatively, you can mix in using `--jars` option for pyspark + `pip install spark-nlp`
669
-
670
- If not using pyspark at all, you'll have to run the instructions pointed [here](#python-without-explicit-Pyspark-installation)
671
-
672
- ## Google Colab Notebook
673
-
674
- Google Colab is perhaps the easiest way to get started with spark-nlp. It requires no installation or setup other than having a Google account.
675
-
676
- Run the following code in Google Colab notebook and start using spark-nlp right away.
677
-
678
- ```sh
679
- # This is only to setup PySpark and Spark NLP on Colab
680
- !wget https://setup.johnsnowlabs.com/colab.sh -O - | bash
681
- ```
682
-
683
- This script comes with the two options to define `pyspark` and `spark-nlp` versions via options:
684
-
685
- ```sh
686
- # -p is for pyspark
687
- # -s is for spark-nlp
688
- # -g will enable upgrading libcudnn8 to 8.1.0 on Google Colab for GPU usage
689
- # by default they are set to the latest
690
- !wget https://setup.johnsnowlabs.com/colab.sh -O - | bash /dev/stdin -p 3.2.3 -s 4.2.6
691
- ```
692
-
693
- [Spark NLP quick start on Google Colab](https://colab.research.google.com/github/JohnSnowLabs/spark-nlp-workshop/blob/master/jupyter/quick_start_google_colab.ipynb) is a live demo on Google Colab that performs named entity recognitions and sentiment analysis by using Spark NLP pretrained pipelines.
694
-
695
- ## Kaggle Kernel
696
-
697
- Run the following code in Kaggle Kernel and start using spark-nlp right away.
698
-
699
- ```sh
700
- # Let's setup Kaggle for Spark NLP and PySpark
701
- !wget https://setup.johnsnowlabs.com/kaggle.sh -O - | bash
702
- ```
703
-
704
- This script comes with the two options to define `pyspark` and `spark-nlp` versions via options:
705
-
706
- ```sh
707
- # -p is for pyspark
708
- # -s is for spark-nlp
709
- # -g will enable upgrading libcudnn8 to 8.1.0 on Kaggle for GPU usage
710
- # by default they are set to the latest
711
- !wget https://setup.johnsnowlabs.com/colab.sh -O - | bash /dev/stdin -p 3.2.3 -s 4.2.6
712
- ```
713
-
714
- [Spark NLP quick start on Kaggle Kernel](https://www.kaggle.com/mozzie/spark-nlp-named-entity-recognition) is a live demo on Kaggle Kernel that performs named entity recognitions by using Spark NLP pretrained pipeline.
715
-
716
- ## Databricks Cluster
717
-
718
- 1. Create a cluster if you don't have one already
719
-
720
- 2. On a new cluster or existing one you need to add the following to the `Advanced Options -> Spark` tab:
721
-
722
- ```bash
723
- spark.kryoserializer.buffer.max 2000M
724
- spark.serializer org.apache.spark.serializer.KryoSerializer
725
- ```
726
-
727
- 3. In `Libraries` tab inside your cluster you need to follow these steps:
728
-
729
- 3.1. Install New -> PyPI -> `spark-nlp==4.2.6` -> Install
730
-
731
- 3.2. Install New -> Maven -> Coordinates -> `com.johnsnowlabs.nlp:spark-nlp_2.12:4.2.6` -> Install
732
-
733
- 4. Now you can attach your notebook to the cluster and use Spark NLP!
734
-
735
- NOTE: Databricks' runtimes support different Apache Spark major releases. Please make sure you choose the correct Spark NLP Maven package name (Maven Coordinate) for your runtime from our [Packages Cheatsheet](https://github.com/JohnSnowLabs/spark-nlp#packages-cheatsheet)
736
-
737
- ## EMR Cluster
738
-
739
- To launch EMR clusters with Apache Spark/PySpark and Spark NLP correctly you need to have bootstrap and software configuration.
740
-
741
- A sample of your bootstrap script
742
-
743
- ```.sh
744
- #!/bin/bash
745
- set -x -e
746
-
747
- echo -e 'export PYSPARK_PYTHON=/usr/bin/python3
748
- export HADOOP_CONF_DIR=/etc/hadoop/conf
749
- export SPARK_JARS_DIR=/usr/lib/spark/jars
750
- export SPARK_HOME=/usr/lib/spark' >> $HOME/.bashrc && source $HOME/.bashrc
751
-
752
- sudo python3 -m pip install awscli boto spark-nlp
753
-
754
- set +x
755
- exit 0
756
-
757
- ```
758
-
759
- A sample of your software configuration in JSON on S3 (must be public access):
760
-
761
- ```.json
762
- [{
763
- "Classification": "spark-env",
764
- "Configurations": [{
765
- "Classification": "export",
766
- "Properties": {
767
- "PYSPARK_PYTHON": "/usr/bin/python3"
768
- }
769
- }]
770
- },
771
- {
772
- "Classification": "spark-defaults",
773
- "Properties": {
774
- "spark.yarn.stagingDir": "hdfs:///tmp",
775
- "spark.yarn.preserve.staging.files": "true",
776
- "spark.kryoserializer.buffer.max": "2000M",
777
- "spark.serializer": "org.apache.spark.serializer.KryoSerializer",
778
- "spark.driver.maxResultSize": "0",
779
- "spark.jars.packages": "com.johnsnowlabs.nlp:spark-nlp_2.12:4.2.6"
780
- }
781
- }]
782
- ```
783
-
784
- A sample of AWS CLI to launch EMR cluster:
785
-
786
- ```.sh
787
- aws emr create-cluster \
788
- --name "Spark NLP 4.2.6" \
789
- --release-label emr-6.2.0 \
790
- --applications Name=Hadoop Name=Spark Name=Hive \
791
- --instance-type m4.4xlarge \
792
- --instance-count 3 \
793
- --use-default-roles \
794
- --log-uri "s3://<S3_BUCKET>/" \
795
- --bootstrap-actions Path=s3://<S3_BUCKET>/emr-bootstrap.sh,Name=custome \
796
- --configurations "https://<public_access>/sparknlp-config.json" \
797
- --ec2-attributes KeyName=<your_ssh_key>,EmrManagedMasterSecurityGroup=<security_group_with_ssh>,EmrManagedSlaveSecurityGroup=<security_group_with_ssh> \
798
- --profile <aws_profile_credentials>
799
- ```
800
-
801
- ## GCP Dataproc
802
-
803
- 1. Create a cluster if you don't have one already as follows.
804
-
805
- At gcloud shell:
806
-
807
- ```bash
808
- gcloud services enable dataproc.googleapis.com \
809
- compute.googleapis.com \
810
- storage-component.googleapis.com \
811
- bigquery.googleapis.com \
812
- bigquerystorage.googleapis.com
813
- ```
814
-
815
- ```bash
816
- REGION=<region>
817
- ```
818
-
819
- ```bash
820
- BUCKET_NAME=<bucket_name>
821
- gsutil mb -c standard -l ${REGION} gs://${BUCKET_NAME}
822
- ```
823
-
824
- ```bash
825
- REGION=<region>
826
- ZONE=<zone>
827
- CLUSTER_NAME=<cluster_name>
828
- BUCKET_NAME=<bucket_name>
829
- ```
830
-
831
- You can set image-version, master-machine-type, worker-machine-type,
832
- master-boot-disk-size, worker-boot-disk-size, num-workers as your needs.
833
- If you use the previous image-version from 2.0, you should also add ANACONDA to optional-components.
834
- And, you should enable gateway.
835
- Don't forget to set the maven coordinates for the jar in properties.
836
-
837
- ```bash
838
- gcloud dataproc clusters create ${CLUSTER_NAME} \
839
- --region=${REGION} \
840
- --zone=${ZONE} \
841
- --image-version=2.0 \
842
- --master-machine-type=n1-standard-4 \
843
- --worker-machine-type=n1-standard-2 \
844
- --master-boot-disk-size=128GB \
845
- --worker-boot-disk-size=128GB \
846
- --num-workers=2 \
847
- --bucket=${BUCKET_NAME} \
848
- --optional-components=JUPYTER \
849
- --enable-component-gateway \
850
- --metadata 'PIP_PACKAGES=spark-nlp spark-nlp-display google-cloud-bigquery google-cloud-storage' \
851
- --initialization-actions gs://goog-dataproc-initialization-actions-${REGION}/python/pip-install.sh \
852
- --properties spark:spark.serializer=org.apache.spark.serializer.KryoSerializer,spark:spark.driver.maxResultSize=0,spark:spark.kryoserializer.buffer.max=2000M,spark:spark.jars.packages=com.johnsnowlabs.nlp:spark-nlp_2.12:4.2.6
853
- ```
854
-
855
- 2. On an existing one, you need to install spark-nlp and spark-nlp-display packages from PyPI.
856
-
857
- 3. Now, you can attach your notebook to the cluster and use the Spark NLP!
858
-
859
- ## Spark NLP Configuration
860
-
861
- You can change the following Spark NLP configurations via Spark Configuration:
862
-
863
- | Property Name | Default | Meaning |
864
- |--------------------------------------------------------|----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
865
- | `spark.jsl.settings.pretrained.cache_folder` | `~/cache_pretrained` | The location to download and extract pretrained `Models` and `Pipelines`. By default, it will be in User's Home directory under `cache_pretrained` directory |
866
- | `spark.jsl.settings.storage.cluster_tmp_dir` | `hadoop.tmp.dir` | The location to use on a cluster for temporarily files such as unpacking indexes for WordEmbeddings. By default, this locations is the location of `hadoop.tmp.dir` set via Hadoop configuration for Apache Spark. NOTE: `S3` is not supported and it must be local, HDFS, or DBFS |
867
- | `spark.jsl.settings.annotator.log_folder` | `~/annotator_logs` | The location to save logs from annotators during training such as `NerDLApproach`, `ClassifierDLApproach`, `SentimentDLApproach`, `MultiClassifierDLApproach`, etc. By default, it will be in User's Home directory under `annotator_logs` directory |
868
- | `spark.jsl.settings.aws.credentials.access_key_id` | `None` | Your AWS access key to use your S3 bucket to store log files of training models or access tensorflow graphs used in `NerDLApproach` |
869
- | `spark.jsl.settings.aws.credentials.secret_access_key` | `None` | Your AWS secret access key to use your S3 bucket to store log files of training models or access tensorflow graphs used in `NerDLApproach` |
870
- | `spark.jsl.settings.aws.credentials.session_token` | `None` | Your AWS MFA session token to use your S3 bucket to store log files of training models or access tensorflow graphs used in `NerDLApproach` |
871
- | `spark.jsl.settings.aws.s3_bucket` | `None` | Your AWS S3 bucket to store log files of training models or access tensorflow graphs used in `NerDLApproach` |
872
- | `spark.jsl.settings.aws.region` | `None` | Your AWS region to use your S3 bucket to store log files of training models or access tensorflow graphs used in `NerDLApproach` |
873
-
874
- ### How to set Spark NLP Configuration
875
-
876
- **SparkSession:**
877
-
878
- You can use `.config()` during SparkSession creation to set Spark NLP configurations.
879
-
880
- ```python
881
- from pyspark.sql import SparkSession
882
-
883
- spark = SparkSession.builder \
884
- .master("local[*]") \
885
- .config("spark.driver.memory", "16G") \
886
- .config("spark.driver.maxResultSize", "0") \
887
- .config("spark.serializer", "org.apache.spark.serializer.KryoSerializer") \
888
- .config("spark.kryoserializer.buffer.max", "2000m") \
889
- .config("spark.jsl.settings.pretrained.cache_folder", "sample_data/pretrained") \
890
- .config("spark.jsl.settings.storage.cluster_tmp_dir", "sample_data/storage") \
891
- .config("spark.jars.packages", "com.johnsnowlabs.nlp:spark-nlp_2.12:4.2.6") \
892
- .getOrCreate()
893
- ```
894
-
895
- **spark-shell:**
896
-
897
- ```sh
898
- spark-shell \
899
- --driver-memory 16g \
900
- --conf spark.driver.maxResultSize=0 \
901
- --conf spark.serializer=org.apache.spark.serializer.KryoSerializer
902
- --conf spark.kryoserializer.buffer.max=2000M \
903
- --conf spark.jsl.settings.pretrained.cache_folder="sample_data/pretrained" \
904
- --conf spark.jsl.settings.storage.cluster_tmp_dir="sample_data/storage" \
905
- --packages com.johnsnowlabs.nlp:spark-nlp_2.12:4.2.6
906
- ```
907
-
908
- **pyspark:**
909
-
910
- ```sh
911
- pyspark \
912
- --driver-memory 16g \
913
- --conf spark.driver.maxResultSize=0 \
914
- --conf spark.serializer=org.apache.spark.serializer.KryoSerializer
915
- --conf spark.kryoserializer.buffer.max=2000M \
916
- --conf spark.jsl.settings.pretrained.cache_folder="sample_data/pretrained" \
917
- --conf spark.jsl.settings.storage.cluster_tmp_dir="sample_data/storage" \
918
- --packages com.johnsnowlabs.nlp:spark-nlp_2.12:4.2.6
919
- ```
920
-
921
- **Databricks:**
922
-
923
- On a new cluster or existing one you need to add the following to the `Advanced Options -> Spark` tab:
924
-
925
- ```bash
926
- spark.kryoserializer.buffer.max 2000M
927
- spark.serializer org.apache.spark.serializer.KryoSerializer
928
- spark.jsl.settings.pretrained.cache_folder dbfs:/PATH_TO_CACHE
929
- spark.jsl.settings.storage.cluster_tmp_dir dbfs:/PATH_TO_STORAGE
930
- spark.jsl.settings.annotator.log_folder dbfs:/PATH_TO_LOGS
931
- ```
932
-
933
- NOTE: If this is an existing cluster, after adding new configs or changing existing properties you need to restart it.
934
-
935
- ### S3 Integration
936
-
937
- In Spark NLP we can define S3 locations to:
938
-
939
- - Export log files of training models
940
- - Store tensorflow graphs used in `NerDLApproach`
941
-
942
- **Logging:**
943
-
944
- To configure S3 path for logging while training models. We need to set up AWS credentials as well as an S3 path
945
-
946
- ```bash
947
- spark.conf.set("spark.jsl.settings.annotator.log_folder", "s3://my/s3/path/logs")
948
- spark.conf.set("spark.jsl.settings.aws.credentials.access_key_id", "MY_KEY_ID")
949
- spark.conf.set("spark.jsl.settings.aws.credentials.secret_access_key", "MY_SECRET_ACCESS_KEY")
950
- spark.conf.set("spark.jsl.settings.aws.s3_bucket", "my.bucket")
951
- spark.conf.set("spark.jsl.settings.aws.region", "my-region")
952
- ```
953
-
954
- Now you can check the log on your S3 path defined in *spark.jsl.settings.annotator.log_folder* property.
955
- Make sure to use the prefix *s3://*, otherwise it will use the default configuration.
956
-
957
- **Tensorflow Graphs:**
958
-
959
- To reference S3 location for downloading graphs. We need to set up AWS credentials
960
-
961
- ```bash
962
- spark.conf.set("spark.jsl.settings.aws.credentials.access_key_id", "MY_KEY_ID")
963
- spark.conf.set("spark.jsl.settings.aws.credentials.secret_access_key", "MY_SECRET_ACCESS_KEY")
964
- spark.conf.set("spark.jsl.settings.aws.region", "my-region")
965
- ```
966
-
967
- **MFA Configuration:**
968
-
969
- In case your AWS account is configured with MFA. You will need first to get temporal credentials and add session token to the configuration as shown in the examples below
970
- For logging:
971
-
972
- ```bash
973
- spark.conf.set("spark.jsl.settings.aws.credentials.session_token", "MY_TOKEN")
974
- ```
975
-
976
- An example of a bash script that gets temporal AWS credentials can be found [here](https://github.com/JohnSnowLabs/spark-nlp/blob/master/scripts/aws_tmp_credentials.sh)
977
- This script requires three arguments:
978
-
979
- ```bash
980
- ./aws_tmp_credentials.sh iam_user duration serial_number
981
- ```
982
-
983
- ## Pipelines and Models
984
-
985
- ### Pipelines
986
-
987
- **Quick example:**
988
-
989
- ```scala
990
- import com.johnsnowlabs.nlp.pretrained.PretrainedPipeline
991
- import com.johnsnowlabs.nlp.SparkNLP
992
-
993
- SparkNLP.version()
994
-
995
- val testData = spark.createDataFrame(Seq(
996
- (1, "Google has announced the release of a beta version of the popular TensorFlow machine learning library"),
997
- (2, "Donald John Trump (born June 14, 1946) is the 45th and current president of the United States")
998
- )).toDF("id", "text")
999
-
1000
- val pipeline = PretrainedPipeline("explain_document_dl", lang="en")
1001
-
1002
- val annotation = pipeline.transform(testData)
1003
-
1004
- annotation.show()
1005
- /*
1006
- import com.johnsnowlabs.nlp.pretrained.PretrainedPipeline
1007
- import com.johnsnowlabs.nlp.SparkNLP
1008
- 2.5.0
1009
- testData: org.apache.spark.sql.DataFrame = [id: int, text: string]
1010
- pipeline: com.johnsnowlabs.nlp.pretrained.PretrainedPipeline = PretrainedPipeline(explain_document_dl,en,public/models)
1011
- annotation: org.apache.spark.sql.DataFrame = [id: int, text: string ... 10 more fields]
1012
- +---+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+
1013
- | id| text| document| token| sentence| checked| lemma| stem| pos| embeddings| ner| entities|
1014
- +---+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+
1015
- | 1|Google has announ...|[[document, 0, 10...|[[token, 0, 5, Go...|[[document, 0, 10...|[[token, 0, 5, Go...|[[token, 0, 5, Go...|[[token, 0, 5, go...|[[pos, 0, 5, NNP,...|[[word_embeddings...|[[named_entity, 0...|[[chunk, 0, 5, Go...|
1016
- | 2|The Paris metro w...|[[document, 0, 11...|[[token, 0, 2, Th...|[[document, 0, 11...|[[token, 0, 2, Th...|[[token, 0, 2, Th...|[[token, 0, 2, th...|[[pos, 0, 2, DT, ...|[[word_embeddings...|[[named_entity, 0...|[[chunk, 4, 8, Pa...|
1017
- +---+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+
1018
- */
1019
-
1020
- annotation.select("entities.result").show(false)
1021
-
1022
- /*
1023
- +----------------------------------+
1024
- |result |
1025
- +----------------------------------+
1026
- |[Google, TensorFlow] |
1027
- |[Donald John Trump, United States]|
1028
- +----------------------------------+
1029
- */
1030
- ```
1031
-
1032
- #### Showing Available Pipelines
1033
-
1034
- There are functions in Spark NLP that will list all the available Pipelines
1035
- of a particular language for you:
1036
-
1037
- ```scala
1038
- import com.johnsnowlabs.nlp.pretrained.ResourceDownloader
1039
-
1040
- ResourceDownloader.showPublicPipelines(lang="en")
1041
- /*
1042
- +--------------------------------------------+------+---------+
1043
- | Pipeline | lang | version |
1044
- +--------------------------------------------+------+---------+
1045
- | dependency_parse | en | 2.0.2 |
1046
- | analyze_sentiment_ml | en | 2.0.2 |
1047
- | check_spelling | en | 2.1.0 |
1048
- | match_datetime | en | 2.1.0 |
1049
- ...
1050
- | explain_document_ml | en | 3.1.3 |
1051
- +--------------------------------------------+------+---------+
1052
- */
1053
- ```
1054
-
1055
- Or if we want to check for a particular version:
1056
-
1057
- ```scala
1058
- import com.johnsnowlabs.nlp.pretrained.ResourceDownloader
1059
-
1060
- ResourceDownloader.showPublicPipelines(lang="en", version="3.1.0")
1061
- /*
1062
- +---------------------------------------+------+---------+
1063
- | Pipeline | lang | version |
1064
- +---------------------------------------+------+---------+
1065
- | dependency_parse | en | 2.0.2 |
1066
- ...
1067
- | clean_slang | en | 3.0.0 |
1068
- | clean_pattern | en | 3.0.0 |
1069
- | check_spelling | en | 3.0.0 |
1070
- | dependency_parse | en | 3.0.0 |
1071
- +---------------------------------------+------+---------+
1072
- */
1073
- ```
1074
-
1075
- #### Please check out our Models Hub for the full list of [pre-trained pipelines](https://nlp.johnsnowlabs.com/models) with examples, demos, benchmarks, and more
1076
-
1077
- ### Models
1078
-
1079
- **Some selected languages:** `Afrikaans, Arabic, Armenian, Basque, Bengali, Breton, Bulgarian, Catalan, Czech, Dutch, English, Esperanto, Finnish, French, Galician, German, Greek, Hausa, Hebrew, Hindi, Hungarian, Indonesian, Irish, Italian, Japanese, Latin, Latvian, Marathi, Norwegian, Persian, Polish, Portuguese, Romanian, Russian, Slovak, Slovenian, Somali, Southern Sotho, Spanish, Swahili, Swedish, Tswana, Turkish, Ukrainian, Zulu`
1080
-
1081
- **Quick online example:**
1082
-
1083
- ```python
1084
- # load NER model trained by deep learning approach and GloVe word embeddings
1085
- ner_dl = NerDLModel.pretrained('ner_dl')
1086
- # load NER model trained by deep learning approach and BERT word embeddings
1087
- ner_bert = NerDLModel.pretrained('ner_dl_bert')
1088
- ```
1089
-
1090
- ```scala
1091
- // load French POS tagger model trained by Universal Dependencies
1092
- val french_pos = PerceptronModel.pretrained("pos_ud_gsd", lang="fr")
1093
- // load Italian LemmatizerModel
1094
- val italian_lemma = LemmatizerModel.pretrained("lemma_dxc", lang="it")
1095
- ````
1096
-
1097
- **Quick offline example:**
1098
-
1099
- - Loading `PerceptronModel` annotator model inside Spark NLP Pipeline
1100
-
1101
- ```scala
1102
- val french_pos = PerceptronModel.load("/tmp/pos_ud_gsd_fr_2.0.2_2.4_1556531457346/")
1103
- .setInputCols("document", "token")
1104
- .setOutputCol("pos")
1105
- ```
1106
-
1107
- #### Showing Available Models
1108
-
1109
- There are functions in Spark NLP that will list all the available Models
1110
- of a particular Annotator and language for you:
1111
-
1112
- ```scala
1113
- import com.johnsnowlabs.nlp.pretrained.ResourceDownloader
1114
-
1115
- ResourceDownloader.showPublicModels(annotator="NerDLModel", lang="en")
1116
- /*
1117
- +---------------------------------------------+------+---------+
1118
- | Model | lang | version |
1119
- +---------------------------------------------+------+---------+
1120
- | onto_100 | en | 2.1.0 |
1121
- | onto_300 | en | 2.1.0 |
1122
- | ner_dl_bert | en | 2.2.0 |
1123
- | onto_100 | en | 2.4.0 |
1124
- | ner_conll_elmo | en | 3.2.2 |
1125
- +---------------------------------------------+------+---------+
1126
- */
1127
- ```
1128
-
1129
- Or if we want to check for a particular version:
1130
-
1131
- ```scala
1132
- import com.johnsnowlabs.nlp.pretrained.ResourceDownloader
1133
-
1134
- ResourceDownloader.showPublicModels(annotator="NerDLModel", lang="en", version="3.1.0")
1135
- /*
1136
- +----------------------------+------+---------+
1137
- | Model | lang | version |
1138
- +----------------------------+------+---------+
1139
- | onto_100 | en | 2.1.0 |
1140
- | ner_aspect_based_sentiment | en | 2.6.2 |
1141
- | ner_weibo_glove_840B_300d | en | 2.6.2 |
1142
- | nerdl_atis_840b_300d | en | 2.7.1 |
1143
- | nerdl_snips_100d | en | 2.7.3 |
1144
- +----------------------------+------+---------+
1145
- */
1146
- ```
1147
-
1148
- And to see a list of available annotators, you can use:
1149
-
1150
- ```scala
1151
- import com.johnsnowlabs.nlp.pretrained.ResourceDownloader
1152
-
1153
- ResourceDownloader.showAvailableAnnotators()
1154
- /*
1155
- AlbertEmbeddings
1156
- AlbertForTokenClassification
1157
- AssertionDLModel
1158
- ...
1159
- XlmRoBertaSentenceEmbeddings
1160
- XlnetEmbeddings
1161
- */
1162
- ```
1163
-
1164
- #### Please check out our Models Hub for the full list of [pre-trained models](https://nlp.johnsnowlabs.com/models) with examples, demo, benchmark, and more
1165
-
1166
- ## Offline
1167
-
1168
- Spark NLP library and all the pre-trained models/pipelines can be used entirely offline with no access to the Internet. If you are behind a proxy or a firewall with no access to the Maven repository (to download packages) or/and no access to S3 (to automatically download models and pipelines), you can simply follow the instructions to have Spark NLP without any limitations offline:
1169
-
1170
- - Instead of using the Maven package, you need to load our Fat JAR
1171
- - Instead of using PretrainedPipeline for pretrained pipelines or the `.pretrained()` function to download pretrained models, you will need to manually download your pipeline/model from [Models Hub](https://nlp.johnsnowlabs.com/models), extract it, and load it.
1172
-
1173
- Example of `SparkSession` with Fat JAR to have Spark NLP offline:
1174
-
1175
- ```python
1176
- spark = SparkSession.builder \
1177
- .appName("Spark NLP")\
1178
- .master("local[*]")\
1179
- .config("spark.driver.memory","16G")\
1180
- .config("spark.driver.maxResultSize", "0") \
1181
- .config("spark.kryoserializer.buffer.max", "2000M")\
1182
- .config("spark.jars", "/tmp/spark-nlp-assembly-4.2.6.jar")\
1183
- .getOrCreate()
1184
- ```
1185
-
1186
- - You can download provided Fat JARs from each [release notes](https://github.com/JohnSnowLabs/spark-nlp/releases), please pay attention to pick the one that suits your environment depending on the device (CPU/GPU) and Apache Spark version (3.0.x, 3.1.x, 3.2.x, and 3.3.x)
1187
- - If you are local, you can load the Fat JAR from your local FileSystem, however, if you are in a cluster setup you need to put the Fat JAR on a distributed FileSystem such as HDFS, DBFS, S3, etc. (i.e., `hdfs:///tmp/spark-nlp-assembly-4.2.6.jar`)
1188
-
1189
- Example of using pretrained Models and Pipelines in offline:
1190
-
1191
- ```python
1192
- # instead of using pretrained() for online:
1193
- # french_pos = PerceptronModel.pretrained("pos_ud_gsd", lang="fr")
1194
- # you download this model, extract it, and use .load
1195
- french_pos = PerceptronModel.load("/tmp/pos_ud_gsd_fr_2.0.2_2.4_1556531457346/")\
1196
- .setInputCols("document", "token")\
1197
- .setOutputCol("pos")
1198
-
1199
- # example for pipelines
1200
- # instead of using PretrainedPipeline
1201
- # pipeline = PretrainedPipeline('explain_document_dl', lang='en')
1202
- # you download this pipeline, extract it, and use PipelineModel
1203
- PipelineModel.load("/tmp/explain_document_dl_en_2.0.2_2.4_1556530585689/")
1204
- ```
1205
-
1206
- - Since you are downloading and loading models/pipelines manually, this means Spark NLP is not downloading the most recent and compatible models/pipelines for you. Choosing the right model/pipeline is on you
1207
- - If you are local, you can load the model/pipeline from your local FileSystem, however, if you are in a cluster setup you need to put the model/pipeline on a distributed FileSystem such as HDFS, DBFS, S3, etc. (i.e., `hdfs:///tmp/explain_document_dl_en_2.0.2_2.4_1556530585689/`)
1208
-
1209
- ## Examples
1210
-
1211
- Need more **examples**? Check out our dedicated [Spark NLP Showcase](https://github.com/JohnSnowLabs/spark-nlp-workshop) repository to showcase all Spark NLP use cases!
1212
-
1213
- Also, don't forget to check [Spark NLP in Action](https://nlp.johnsnowlabs.com/demo) built by Streamlit.
1214
-
1215
- ### All examples: [spark-nlp-workshop](https://github.com/JohnSnowLabs/spark-nlp-workshop)
1216
-
1217
- ## FAQ
1218
-
1219
- [Check our Articles and Videos page here](https://nlp.johnsnowlabs.com/learn)
1220
-
1221
- ## Citation
1222
-
1223
- We have published a [paper](https://www.sciencedirect.com/science/article/pii/S2665963821000063) that you can cite for the Spark NLP library:
1224
-
1225
- ```bibtex
1226
- @article{KOCAMAN2021100058,
1227
- title = {Spark NLP: Natural language understanding at scale},
1228
- journal = {Software Impacts},
1229
- pages = {100058},
1230
- year = {2021},
1231
- issn = {2665-9638},
1232
- doi = {https://doi.org/10.1016/j.simpa.2021.100058},
1233
- url = {https://www.sciencedirect.com/science/article/pii/S2665963.2.300063},
1234
- author = {Veysel Kocaman and David Talby},
1235
- keywords = {Spark, Natural language processing, Deep learning, Tensorflow, Cluster},
1236
- 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.}
1237
- }
1238
- }
1239
- ```
1240
-
1241
- ## Contributing
1242
-
1243
- We appreciate any sort of contributions:
1244
-
1245
- - ideas
1246
- - feedback
1247
- - documentation
1248
- - bug reports
1249
- - NLP training and testing corpora
1250
- - Development and testing
1251
-
1252
- Clone the repo and submit your pull-requests! Or directly create issues in this repo.
1253
-
1254
- ## John Snow Labs
1255
-
1256
- [http://johnsnowlabs.com](http://johnsnowlabs.com)