Generate textual narratives in Power BI using RosaeNLG

Ludan Stoecklé
4 min readApr 7, 2020

--

RosaeNLG is an open-source Natural Language Generation (NLG) library written in JavaScript. Using RosaeNLG, you can add narratives to your Power BI dashboards in English, French, German or Italian. Texts are rendered locally in the dashboard, without any API call.

This article explains why NLG is useful for Power BI dashboards, and how to build narratives in Power BI using RosaeNLG.

Photo by Carlos Muza on Unsplash

Why use NLG in dashboards

Natural Language Generation (NLG) can be used to analyse data dynamically in a dashboard, and summarize that data in a textual narrative.

Power BI dashboards are composed of nice graphics: bars, pie charts, maps etc. While graphics are nice and useful, some users do not have the expertise to understand the figures. Moreover, graphics show the data but do not convey a clear interpretation of that data.
Studies show that Data-to-Text Generation Improves Decision-Making Under Uncertainty.
At last, some users can just appreciate narratives as a addition to graphics.

Why RosaeNLG for Power BI and what are the alternatives

Some commercial NLG companies provide a Power BI plug-in: Narratives for Power BI by Narrative Science, and Natural Language Insights by Arria NLG.

While providing similar NLG features, using RosaeNLG for Power BI narratives has 2 major advantages:

  • RosaeNLG is completely open-source (MIT) and free to use
  • The text rendering is made locally, directly in Power BI (Desktop or online version), without any API call

As no data is sent to an API over the Internet, RosaeNLG is a very secure alternative.

How to create a Power BI plug-in using RosaeNLG

It takes 2 major steps:

  • Create the NLG templates: define how to produce the texts. This takes most of the time in a real-life project.
  • Package the NLG templates in a Power BI plug-in: it essentially consists of defining the parameters of your plug-in so that it can be plugged in a dashboard.

If the data needs to be analysed prior to text generation, it is convenient to do it in JavaScript, either in the NLG templates or in the Power BI plug-in.

Running the demo

On Windows, use the Edge browser to develop.

Follow the standard Power BI tutorial:

  • Setting up the developer environment: follow as described in the tutorial
  • Creating a custom visual: instead of using the CircleCard project, checkout Power BI RosaeNLG Demo Git repo, then run npm install and pbiviz start
  • Adding visual elements: follow as described in the tutorial

Obtain this result:

NLG plug-in just installed

This Power BI plug-in takes 2 parameters: sales total qty and sales total amount. Let’s map them (drag and drop):

NLG plug-in properly plugged

This simply means that both the Power BI plug-in and the RosaeNLG renderer are well plugged together, but this is not text generation yet.

Create the NLG template

For this demo, we will use the RosaeNLG browser IDE. For more complex projects, it is better to use VSCode to author, version and compile your RosaeNLG templates.

This basic template contains 2 synonymic alternatives which essentially output the parameters in text:

Use the Package compiled JavaScript — with export button to get the template compiled as a JavaScript function. Put the file in the powerbidemo folder and name it compiledTemplateSales.js (do not keep fruits.js).

Just refresh the dashboard and navigate in the data:

Plug-in with real NLG text

The text is still very basic, but there is not limit on the quality and complexity of the texts that you can generate!

Inside the Power BI plug-in — how it works

In externalJS section of pbiviz.json, there is a reference to the already tinified version of the RosaeNLG renderer. Change the reference to change the language and the version. Version must be aligned with the RosaeNLG version in package.json.

In visual.ts, import both the RosaeNLG lib (../node_modules/rosaenlg/dist/rollup/rosaenlg_tiny_en_US_1.14.0.js) and the compiled template (../compiledTemplateSales.js).

The capabilities.json file define the input parameters of your plug-in and your template. Complete that file to add parameters. Use visual.ts to make some mapping:

const data = {
salesQty: dataView.categorical.values[0].values[0],
salesAmount: dataView.categorical.values[1].values[0],
};

As an exercise you may add the sales date to the parameters and output it in the texts.

As any Power BI plug-in, it can be packaged and be run both in Desktop and Cloud versions of Power BI.

Wrap up

In this article, we have described why NLG can be useful for dashboards, and how to start developing a Power BI NLG plug-in based on RosaeNLG.

More

--

--

Ludan Stoecklé
Ludan Stoecklé

No responses yet