Using DJL.AI For Deep Learning BERT Q&A in NiFi DataFlows
Published: 2020-09-20 16:13:49

---
title: Using DJL.AI For Deep Learning BERT Q&A in NiFi DataFlows
published: true
date: 2020-09-20 16:13:00 UTC
tags: 
canonical_url: 
---

 

# Using DJL.AI For Deep Learning BERT Q&A in NiFi DataFlows

[![](https://1.bp.blogspot.com/-7PbVZouBgCY/X2YWNYrjUtI/AAAAAAAAboc/bRv5yte9VMAoLzd4R8TweMOrQrU0V5iOQCLcBGAsYHQ/w699-h579/DeepLearningExampleFlowSentimentBERT.png)](https://1.bp.blogspot.com/-7PbVZouBgCY/X2YWNYrjUtI/AAAAAAAAboc/bRv5yte9VMAoLzd4R8TweMOrQrU0V5iOQCLcBGAsYHQ/s1294/DeepLearningExampleFlowSentimentBERT.png)

  

#### Introduction:

I will be talking about this processor at Apache Con @ Home 2020 in my "Apache Deep Learning 301" talk with Dr. Ian Brooks.

Sometimes you want your Deep Learning Easy and in Java, so let's do that with DJL in a custom Apache NiFi processor running in CDP Data Hubs.   This one does BERT QA.

To use the processor feed in a paragraph to analyze via the **paragraph**  parameter in the NiFi processor.   Also feed in a question, like **Why?**  or something very specific like asking the date or an event.

[![](https://1.bp.blogspot.com/-_PpZFPz8M-E/X2d_aB20cXI/AAAAAAAAbpE/v1swG4iYY_A0bve7LZ1KWTPtdnQbpfsyQCLcBGAsYHQ/w595-h346/qawhy.png)](https://1.bp.blogspot.com/-_PpZFPz8M-E/X2d_aB20cXI/AAAAAAAAbpE/v1swG4iYY_A0bve7LZ1KWTPtdnQbpfsyQCLcBGAsYHQ/s575/qawhy.png)

### The pretrained model is BERT QA model using PyTorch. the NiFi Processor Source:

[https://github.com/tspannhw/nifi-djlqa-processor](https://github.com/tspannhw/nifi-djlqa-processor)

### Grab the Recent Release NAR to install to your NiFi lib directories:

[https://github.com/tspannhw/nifi-djlqa-processor/releases/tag/1.2](https://github.com/tspannhw/nifi-djlqa-processor/releases/tag/1.2)

### Example Run

[![](https://1.bp.blogspot.com/-fa7phpyNqME/X2d_aBq9gmI/AAAAAAAAbpI/kn-rmYL8y7gcKRLaDPYMMsGVIQRq1QKGQCLcBGAsYHQ/w576-h171/qaprediction.png)](https://1.bp.blogspot.com/-fa7phpyNqME/X2d_aBq9gmI/AAAAAAAAbpI/kn-rmYL8y7gcKRLaDPYMMsGVIQRq1QKGQCLcBGAsYHQ/s225/qaprediction.png)
  

  

  

  

#### **Demo Data Source**

https://newsapi.org/v2/everything?q=cloudera&apiKey=REGISTERFORAKEY

  

  

  

#### **Reference:**

- [Deep Learning Sentiment Analysis with DJL.ai](https://docs.djl.ai/examples/docs/sentiment_analysis.html)
- [https://github.com/awslabs/djl/blob/master/mxnet/mxnet-engine/README.md](https://github.com/awslabs/djl/blob/master/mxnet/mxnet-engine/README.md)
- [https://github.com/aws-samples/djl-demo/tree/master/flink/sentiment-analysis](https://github.com/aws-samples/djl-demo/tree/master/flink/sentiment-analysis)
- [https://github.com/awslabs/djl/releases](https://github.com/awslabs/djl/releases)
- [https://www.datainmotion.dev/2020/09/using-djlai-for-deep-learning-based.html](https://dev.to/tspannhw/using-djl-ai-for-deep-learning-based-sentiment-analysis-in-nifi-dataflow-3c3a)
- [http://docs.djl.ai/jupyter/BERTQA.html](http://docs.djl.ai/jupyter/BERTQA.html)

  

  

### Deep Learning Note:   

BERT QA Model

### Tip

Make sure you have 1-2 GB of RAM extra for your NiFi instance for running each DJL processor.   If you have a lot of text, run more nodes and/or RAM.   Make sure you have at least 8 cores per Deep Learning process.   I prefer JDK 11 for this.

**See Also:**    [https://www.datainmotion.dev/2019/12/easy-deep-learning-in-apache-nifi-with.html](https://dev.to/tspannhw/easy-deep-learning-in-apache-nifi-with-djl-2d79)