Giter Site home page Giter Site logo

ktp-forked-repos / spark-nlp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from johnsnowlabs/spark-nlp

0.0 1.0 0.0 146.78 MB

Natural Language Understanding Library for Apache Spark.

License: Apache License 2.0

Dockerfile 0.03% Scala 62.92% Python 25.59% Java 11.46%

spark-nlp's Introduction

Spark-NLP

Build Status

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.

Project's website

Take a look at our official spark-nlp page: http://nlp.johnsnowlabs.com/ for user documentation and examples

Slack community channel

Questions? Feedback? Request access sending an email to [email protected]

Table of contents

Usage

Apache Spark Support

Spark-NLP 2.0.1 has been built on top of Apache Spark 2.4.0

Note that Spark is not retrocompatible with Spark 2.3.x, so models and environments might not work.

If you are still stuck on Spark 2.3.x feel free to use this assembly jar instead. Support is limited. For OCR module, this is for spark 2.3.x.

Spark NLP Spark 2.0.1 / Spark 2.3.x Spark 2.4
2.x.x NO YES
1.8.x Partially YES
1.7.3 YES N/A
1.6.3 YES N/A
1.5.0 YES N/A

Find out more about Spark-NLP versions from our release notes.

Spark Packages

Command line (requires internet connection)

This library has been uploaded to the spark-packages repository.

Benefit of spark-packages is that makes it available for both Scala-Java and Python

To use the most recent version just add the --packages JohnSnowLabs:spark-nlp:2.0.1 to you spark command

spark-shell --packages JohnSnowLabs:spark-nlp:2.0.1
pyspark --packages JohnSnowLabs:spark-nlp:2.0.1
spark-submit --packages JohnSnowLabs:spark-nlp:2.0.1

This can also be used to create a SparkSession manually by using the spark.jars.packages option in both Python and Scala

Compiled JARs

Build from source

Spark NLP

  • FAT-JAR for CPU
sbt assembly
  • FAT-JAR for GPU
sbt -Dis_gpu=true assembly
  • Packaging the project
sbt package

Spark-NLP-OCR

Requires native Tesseract 4.x+ for image based OCR. Does not require Spark-NLP to work but highly suggested

  • FAT-JAR
sbt ocr/assembly
  • Packaging the project
sbt ocr/package

Using the jar manually

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.

To add JARs to spark programs use the --jars option:

spark-shell --jars spark-nlp.jar

The preferred way to use the library when running spark programs is using the --packages option as specified in the spark-packages section.

Scala

Our package is deployed to maven central. In order to add this package as a dependency in your application:

Maven

<!-- https://mvnrepository.com/artifact/com.johnsnowlabs.nlp/spark-nlp -->
<dependency>
    <groupId>com.johnsnowlabs.nlp</groupId>
    <artifactId>spark-nlp_2.11</artifactId>
    <version>2.0.1</version>
</dependency>

and

<!-- https://mvnrepository.com/artifact/com.johnsnowlabs.nlp/spark-nlp-ocr -->
<dependency>
    <groupId>com.johnsnowlabs.nlp</groupId>
    <artifactId>spark-nlp-ocr_2.11</artifactId>
    <version>2.0.1</version>
</dependency>

SBT

// https://mvnrepository.com/artifact/com.johnsnowlabs.nlp/spark-nlp
libraryDependencies += "com.johnsnowlabs.nlp" %% "spark-nlp" % "2.0.1"

and

// https://mvnrepository.com/artifact/com.johnsnowlabs.nlp/spark-nlp-ocr
libraryDependencies += "com.johnsnowlabs.nlp" %% "spark-nlp-ocr" % "2.0.1"

Maven Central: https://mvnrepository.com/artifact/com.johnsnowlabs.nlp

Python

Python without explicit Pyspark installation

Pip

If you installed pyspark through pip, you can install spark-nlp through pip as well.

pip install spark-nlp==2.0.1

PyPI spark-nlp package

Conda

If you are using Anaconda/Conda for managing Python packages, you can install spark-nlp as follow:

conda install -c johnsnowlabs spark-nlp

Anaconda spark-nlp package

Then you'll have to create a SparkSession manually, for example:

spark = SparkSession.builder \
    .appName("ner")\
    .master("local[4]")\
    .config("spark.driver.memory","4G")\
    .config("spark.driver.maxResultSize", "2G") \
    .config("spark.jars.packages", "JohnSnowLabs:spark-nlp:2.0.1")\
    .config("spark.kryoserializer.buffer.max", "500m")\
    .getOrCreate()

If using local jars, you can use spark.jars instead for a 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

Apache Zeppelin

Use either one of the following options

  • Add the following Maven Coordinates to the interpreter's library list
com.johnsnowlabs.nlp:spark-nlp_2.11:2.0.1
  • Add path to pre-built jar from here in the interpreter's library list making sure the jar is available to driver path

Python in Zeppelin

Apart from previous step, install python module through pip

pip install spark-nlp==2.0.1

Or you can install spark-nlp from inside Zeppelin by using Conda:

%python.conda install -c johnsnowlabs spark-nlp

Configure Zeppelin properly, use cells with %spark.pyspark or any interpreter name you chose.

Finally, in Zeppelin interpreter settings, make sure you set properly zeppelin.python to the python you want to use and installed the pip library with (e.g. python3).

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.

Jupyter Notebook (Python)

Easiest way to get this done is by making Jupyter Notebook run using pyspark as follows:

export SPARK_HOME=/path/to/your/spark/folder
export PYSPARK_PYTHON=python3
export PYSPARK_DRIVER_PYTHON=jupyter
export PYSPARK_DRIVER_PYTHON_OPTS=notebook

pyspark --packages JohnSnowLabs:spark-nlp:2.0.1

Alternatively, you can mix in using --jars option for pyspark + pip install spark-nlp

If not using pyspark at all, you'll have to run the instructions pointed here

S3 Cluster

With no hadoop configuration

If your distributed storage is S3 and you don't have a standard hadoop configuration (i.e. fs.defaultFS) You need to specify where in the cluster distributed storage you want to store Spark-NLP's tmp files. First, decide where you want to put your application.conf file

import com.johnsnowlabs.uti.ConfigLoader
ConfigLoader.setConfigPath("/somewhere/to/put/application.conf")

And then we need to put in such application.conf the following content

sparknlp {
  settings {
    cluster_tmp_dir = "somewhere in s3n:// path to some folder"
  }
}

Models and Pipelines

Pipelines

Pipelines English Name
Explain Document ML Download explain_document_ml
Explain Document DL Download explain_document_dl
Entity Recognizer DL Download entity_recognizer_dl

Models

English

Model English
LemmatizerModel (Lemmatizer) Download
PerceptronModel (POS) Download
ViveknSentimentModel (Sentiment) Download
NerCRFModel (NER) Download
NerDLModel (NER) Download
SymmetricDeleteModel (Spell Checker) Download
ContextSpellCheckerModel (Spell Checker) Download
NorvigSweetingModel (Spell Checker) Download

Italian

Model Italian
LemmatizerModel (Lemmatizer) Download
SentimentDetector (Sentiment) Download

French

Model French
PerceptronModel (POS UD-GSD) Download

How to use Models and Pipelines

To use Spark NLP online pretrained pipelines, you can call PretrainedPipeline with pipeline's name and its language:

pipeline = PretrainedPipeline('explain_document_dl', lang='en')

To use Spark NLP online pretrained models:

ner = NerDLModel.pretrained()

If you have any trouble using online pipelines or models in your environment (maybe it's air-gapped), you can directly download them for offline use.

After downloading offline models/pipelines and extracting them, here is how you can use them iside your code (the path could be a shared storage like HDFS in a cluster):

  • Loading PerceptronModel annotator model inside Spark NLP Pipeline
val pos = PerceptronModel.load("/tmp/pos_ud-gsd_fr_2.0.0_2.4_1553029753307/")
      .setInputCols("document", "token")
      .setOutputCol("pos")
  • Loading Offline Pipeline
val advancedPipeline = PipelineModel.load("/tmp/explain_document_dl_en_2.0.0_2.4_1553227894237/")
// To use the loaded Pipeline for prediction
advancedPipeline.transform(predictionDF)

Examples

Need more examples? Check out our dedicated repository to showcase Spark NLP use cases! spark-nlp-workshop

FAQ

Check our Articles and FAQ page here

Troubleshooting

OCR

  • Q: I am getting a Java Core Dump when running OCR transformation

    • A: Add LC_ALL=C environment variable
  • Q: Getting org.apache.pdfbox.filter.MissingImageReaderException: Cannot read JPEG2000 image: Java Advanced Imaging (JAI) Image I/O Tools are not installed when running an OCR transformation

    • A: --packages com.github.jai-imageio:jai-imageio-jpeg2000:1.3.0. This library is non-free thus we can't include it as a Spark-NLP dependency by default

Acknowledgments

Special community aknowledgments

Thanks in general to the community who have been lately reporting important issues and pull request with bugfixes. Community has been key in the last releases with feedback in various Spark based environments.

Here a few specific mentions for recurring feedback and slack participation

  • @maziyarpanahi - For contributing with testing and valuable feedback
  • @easimadi - For contributing with documentation and valuable feedback

Contributing

We appreciate any sort of contributions:

  • ideas
  • feedback
  • documentation
  • bug reports
  • nlp training and testing corpora
  • development and testing

Clone the repo and submit your pull-requests! Or directly create issues in this repo.

Contact

[email protected]

John Snow Labs

http://johnsnowlabs.com

spark-nlp's People

Contributors

saif-ellafi avatar albertoandreottiatgmail avatar danilojsl avatar maziyarpanahi avatar aleksei-ai avatar showy avatar impr0grammer avatar anju-jsl avatar riyajohnsnow avatar tshimanga avatar lambdaofgod avatar easimadi avatar apiltamang avatar atomobianco avatar johnsnowlab avatar lgaud avatar nhan-jsl avatar dburbanotw avatar evgeniwk avatar sethah avatar

Watchers

Tadeusz Kurpiel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.