Even Superheroes Need to Rest: Working on Trained Neural Networks in Weka

Post navigation

Applying neural networks could be divided into two phases as learning and forecasting. Learning phase has high cost whereas forecasting phase produces results very quickly. Epoch value (aka training time), network structure and historical data size specify the cost of learning phase. Normally, the larger epoch produces the better results. However, increment of epoch value will cause to be taken longer time. That’s why, picking up very large epoch value would not be applicable for online transaction if learning is implemented instantly.

Even superheroes need to rest

However, we can apply learning and forecasting steps asynchronously. We would perform neural network learning as batch application (e.g. periodic day-end or month-end calculation). Thus, epoch would be picked up as very large value. Besides, weights of neural networks will be calculated on low system load (most probably late night hours). In this way, no matter how long neural networks learning lasts. Thus, we can even make forecasts for online transactions in milliseconds. You might imagine this approach like that human nervous system updates its own weights while sleeping.

In previous post, we’ve mentioned java implementation of building neural networks with weka for xor example. Also, project code is shared on GitHub. Now, we will modify that code a little to apply this approach. Thus, we can make predictions faster.

When network is trained, we would store its binary content as illustrated below. We can either save it as a file or store it on a database as BLOB type. I prefer to save it as a file on a operation system in order to explain the subject in simple way.

For instance, learning process of xor problem lasts 22.70 seconds for 10M epoch value. This means that if this process is located behind an online transaction, you have to wait until training finished. In this example, network structure is too basic (2 nodes in input layer and 1 hidden layer consisting of 3 nodes). Moreover, historical data consists of 4 instances. Calculation time would increase dramatically (even in hours) for different problems which requires complex network structures, larger training sets or large epoch values.

First Time Network Training

Network content actually includes network structure (nodes and layers) and final weights. Stored network content provides us to use final weights without making any calculation. We would perform the following code block to restore network.

Thus, same results would be produced in 80 milliseconds. Almost 280 times faster than the previous example!

Working on Trained Network

In this post, predicting with neural network is thought to consist of two phases as learning and forecasting. We tried to show the advantages of working on trained network. Moreover, We’ve metioned how this approach makes calculations faster. Finally, this approach is added into the shared project on GitHub. You might change the dataset and monitor the changes on time.