Quick Start

 

Load & Predict 1 liner

The johnsnowlabs library provides 2 simple methods with which most visual NLP tasks can be solved while achieving state-of-the-art results.
The load and predict method.
When building a load&predict based model you will follow these steps:

  1. Pick a visual model/pipeline/component you want to create from the Namespace
  2. Call the model = ocr.load('visual_component') method which will return an auto-completed pipeline
  3. Call model.predict('path/to/image.png') with a path to a file or an array of paths

These 3 steps can be boiled down to just 1 line

from johnsnowlabs import nlp
nlp.load('img2text').predict('path/to/haiku.png')

jsl.load() defines 6 visual components types usable in 1-liners

1-liner Transformer Class
nlp.load('img2text').predict('path/to/cat.png') ImageToText
nlp.load('pdf2text').predict('path/to/taxes.pdf') PdfToText
nlp.load('doc2text').predict('path/to/my_homework.docx') DocToText
nlp.load('pdf2table').predict('path/to/data_tables.pdf') PdfToTextTable
nlp.load('ppt2table').predict('path/to/great_presentation_with_tabular_data.pptx') PptToTextTable
nlp.load('doc2table').predict('path/to/tabular_income_data.docx') DocToTextTable

Custom Pipelines

You can create Visual Annotator & PretrainedPipeline based pipelines using all the classes attached to the visual module which gives you the highest degree of freedom

from johnsnowlabs import nlp,visual
spark = nlp.start(visual=True)
# Load a PDF File and convert it into Spark DF format
doc_example = visual.pkg_resources.resource_filename('sparkocr', 'resources/ocr/docs/doc2.docx')
doc_example_df = spark.read.format("binaryFile").load(doc_example).cache()

# Run the visual DocToText Annotator inside a pipe, recognize text and show the result
pipe = nlp.PipelineModel(stages=[visual.DocToText().setInputCol("content").setOutputCol("text")])
result = pipe.transform(doc_example_df)

print(result.take(1)[0].text)

output: ocrresult.png

Last updated