Javaika
Javaika Technologies:

Lightweight platform for web developers.

Skip the bloat, build on clean infrastructure.

Modular decentralised web frameworks.

JT - "Just Works"

User Guide - Web Neural

5. Basic Neural Inference

This exercise will demonstrate how to perform basic inference over the neural network from the previous exercise. The model is retrieved from IndexedDB and inference is performed 'client side' over the model. The same input values are used compared to the original training examples, and you should observe an approximation of the target values used during training. The JSON result is returned in the console of Browser Developer Tools (DevTools).


                
               <!DOCTYPE html> <!-- Copyright (c) 2026 by Javaika Technologies -->

               <html lang = "en-AU"> <!-- Set the primary language to en-AU -->
    
                  <head>

                     <title>Basic Inference</title> <!-- Set the page title -->
                     
                     <meta name = "robots" content = "noindex, follow">
  
                  </head>


                  <body>
                  
                     <!-- Add the UI elements to the page -->
    
      
                     <div>
                
                        <input id = "input-1" size = "35" type = "text" placeholder = "Identifier (ID)">
                
                     </div>
                      
                    
                     <div style = "margin-top: 20px;">
                
                        <button id = "button-1">Infer</button>
                
                     </div>
                     

                     <!-- Include the framework script tag -->
    
                     <script type = "module" src = "https://www.javaika.com/frame/web-neural@main/api.js"></script>
                     
                     <script type = "module" src = "https://www.javaika.com/frame/web-persist@main/api.js"></script>
    
    
                     <!-- Run the demo as an ES Module -->

                     <script type = "module">
      
                        const input1 = document.getElementById('input-1');
      
                        const button1 = document.getElementById('button-1');
                     
                  
                        // Initialize a shorter prefix for referencing.
              
                        const jwn = window.javaika.webNeural;
                   
                        const jwp = window.javaika.webPersist;
                   
            
                        // Initialize the developer token endpoint.
            
                        jwn.init({
            
                           tokenEndpoint: "https://www.javaika.com/pscript/jwt-access.php"
            
                        });
            
            
                        // Authenticate before using the framework.
            
                        jwn.requestToken({
              
                           framework: "web_neural" // Specify the framework for token issuance.
              
                        });
                        
                        
                        // Listener for button click event.
         
                        button1.addEventListener('click', () => {
                        
                           let inferRequestBuilder = new jwn.InferRequestBuilder();
                      
                           let inferRequest = buildInferRequest(inferRequestBuilder);
                        
                        
                           jwn.submitInferenceJob(inferRequest);
                    
                        });
                     
                     
                        // Build the infer request.
                     
                        function buildInferRequest(inferRequestBuilder)
                        {
                           let inferRequest = inferRequestBuilder
                      
                              .addRoot(root => root.setType("infer")
                           
                              .setLayerValues(false).setJobId(input1.value))
                        
                              .setInputs([[1, 2], [3, 4], [5, 6], [7, 8]])
                           
                           .finalize(); // Finalize the inference reuest.
                        
                        
                           return inferRequest;
                        }
                     
                     
                        // Authenticate callback handler.
                     
                        function onAuthenticate(event)
                        {
                           jwn.refreshToken(); // Refresh the authentication token.
              
                           console.log('[Web Neural] Authentication received callback:', event);
                        }
                     
                     
                        // Initialized callback handler.
                     
                        function onInitialized(event)
                        {
                           console.log('[Web Neural] Framework initialized callback:', event);
                        }
                     
                     
                        // Inference requested callback handler.
                     
                        function onInferenceRequested(event)
                        {
                           const key = event.detail.key; 
                        
                           const options = {'storeName': 'web-neural'};
                    
                    
                           jwp.fetchJsonRecord(key, options);
                           
                           console.log('[Web Neural] Inference requested callback:', event);
                        }
                     
                     
                        // Json record fetched callback handler.
                     
                        function onJsonRecordFetched(event)
                        {
                           const model = event.detail.json; // Model.
                    
                           jwn.runInferenceJob(model);
                           
                           
                           console.log('[Web Neural] Json record fetched callback:', event);
                        }
                        
                        
                        // Infer model response callback handler.
                     
                        function onInferModelResponse(event)
                        {
                           console.log('[Web Neural] Infer model response callback:', event);
                        }
                     
                     
                        // Callback event after authenticate.
                     
                        document.addEventListener
                        (
                           'javaika.webNeural.authenticate', onAuthenticate
                        );
                     
                     
                        // Callback event after initialized.
            
                        document.addEventListener
                        (
                           'javaika.webNeural.initialized', onInitialized
                        );
                     
                     
                        // Callback event after inference requested.
                   
                        document.addEventListener
                        (
                           'javaika.webNeural.inferenceRequested', onInferenceRequested
                        );
                     
                     
                        // Callback event after json record fetched.
                    
                        document.addEventListener
                        (
                           'javaika.webPersist.jsonRecordFetched', onJsonRecordFetched
                        );
                        
                        
                        // Callback event after infer model response.
                    
                        document.addEventListener
                        (
                           'javaika.webNeural.serverMessage.inferModelResponse', onInferModelResponse
                        );
    
                     </script>

                  </body>
  
               </html>

            
View Demo   Download Demo