airML integration with NSpM

Sahan Dilshan
3 min readAug 14, 2021

airML is now supporting NSpM (Neural SPARQL Machines) to load and maintain the trained model’s checkpoint. If you are not familiar with airML, I strongly recommend you to read this article before going any further.

NSPM is a Machine-Translation approach for question answering over knowledge graphs. NSpM has several datasets included so that a user can train/generate model checkpoints for several domains. You can read more in-detailed explanations about this with this link here. So in general, if you want to load a trained model into NSpM and generate the output (predict SPARQL query for a given sentence) using that model, you have to issue this command,

python interpreter.py --input data/art_30 --output data/art_30 --inputstr "yuncken freeman has architected in how many cities?"

When executing the above command, we get the SPARQL query for the “yuncken freeman has architected in how many cities?” text. Here to the--input argument, we have to pass the path to the model checkpoint. Then the NSpM model will check and load the relevant information from that directory. Then the generated output will be saved in a text file in the path given by the --output arguments. As you can clearly see, We should pass the text that we need to convert into a SPARQL query with the--inputstr argument.

Drawbacks of NSpM

This way of generating the output has some drawbacks. As you can see, we need to do the model (Checkpoint) management by ourselves. Let’s say we have several models stored locally in our computer in several directories. Then we have to remember each model path separately and provide the paths to each model separately. Also, there might be several model checkpoint versions. We also need to handle the versioning of model checkpoints too. Last but not least are online storage. Some model checkpoints are stored in cloud storage. To use those, we need to download them, then extracted those and put those in relevant directories. These are some major issues that we had to deal with when we were using the NSpM.

NSpM Old Implementation

airML integration with NSpM

NSpM has now been integrated with airML to solve all the above issues related to model management.

NSpM latest implementation with airML

With the features of airML, now we can forget about model management steps and directly use any model easily. As you can clearly see on the above image, airML can download and install any model stored anywhere (even local storage) and manage them locally on our computer. Actually, the airML is just a python wrapper for KBox. KBox is the one that does the heavy lifting here. You can read more about KBox from here. Once the airML installed the models locally, it will provide the local installation path of that model checkpoint to the NSpM to load the model and predict the output. It’s just simple as that. Now let’s see how we can use this cool new feature. It’s really simple. If you can remember, with the earlier implementation, we have to provide an argument called --input to provide the model path. With the latest implementation, you can use the --airml argument instead of the --input argument.

python interpreter.py --airml http://nspm.org/arts --output data/art_30 --inputstr "yuncken freeman has architected in how many cities?"

Now you might wonder what is that value passed with the --airML argument. It’s the name of the KN (Knowledge Name). Here you can see the details of the provided KN.

{"name": "http://nspm.org/art", "label":"DBpedia Art Dataset", "target": [[{"zip":[{"url":"https://drive.google.com/uc?export=download&id=1ZUejw1La1TcVowGH2S4XzUWNr-xhIlhY"}]}]], "format":"nspm", "version": {"name":"1.0", "tags":["latest"]}, "desc": "The pre-trained NSPM DBpedia Art Dataset.", "owner":"NSpM", "publisher":"KBox team", "license":["http://en.wikipedia.org/wiki/Wikipedia:Text_of_the_GNU_Free_Documentation_License", "http://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License"],"subsets": ["https://github.com/LiberAI/NSpM/blob/master/data/templates/Annotations_F30_art.csv"]}

name will be a unique identifier for the model checkpoint and the target will contain where the model is stored. When we provide the name into the --airml argument, the airML package will download and install that model with the details in the target. This is how basically the newest feature work underneath.

I hope you understood how to use the newest model management feature in the NSpM now. See you again with another article soon. 👋👋.

--

--