json of software for brain.js

<!DOCTYPE html>

<html>
<head runat="server">
    <meta charset="utf-8" />
    <title>Neural Network - Brain.js - Web Method Test</title>
    <style>
        div {
            padding: 12px;
            background-color: aliceblue;
        }

        .txt {
            width: 400px;
        }

        .info {
            font-size: 16px;
        }

        .btn {
            margin: 12px;
            height: 24px;
            width: 50px;
            padding: 6px;
        }

        .entry {
            padding: 30px;
            background: lightblue;
            color: black;
            font-size: 36px;
        }

        .example {
            padding: 100px;
            background: darkred;
            color: white;
            font-size: 36px;
        }

        .header {
            padding 22px;
            background: plum;
            font-size: 48px;
            color: black;
        }
    </style>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="//unpkg.com/brain.js"></script>
</head>
<body>
    <form id="form1" runat="server">
        <div class="header">
            Brain.JS Example
        </div>
        <div class="entry">
            <span class="info">How many Iterations to train (poor but fast: 100, good but slow: 4000)?</span>
            <input type="text" id="txtIterations" value="1000" />
            <br />
            <input type="button" value="Train the AI" onclick="javascript: TrainBrain();" />
        </div>
        <div>
            <span class="info">What is your computer issue?</span>
            <br />
            <input type="text" id="txtInput" class="txt" />
            <br />
            <span class="info">(will answer 'softare' or 'hardware') </span>
            <br />
            <br />
            <input type="button" value="Send Test" onclick="javascript: runRequest();" />
            <br />
        </div>
        <div id="example" class="example">Example Text</div>
    </form>
</body>
</html>

<script>
    const txtBrain = new brain.recurrent.LSTM();
    var example = document.querySelector("#example");

    document.addEventListener('DOMContentLoaded', function () {
        example.innerHTML = 'The Brain is Waiting to be Trained...';
        console.log('here');
    }, false);

    function TrainBrain() {
        example.innerHTML = "Training in progress... please wait"
        console.log('inside TrainBrain');
        var jsn = [];
        var TrainingData
        var TData = [];
        var txtIterations = document.getElementById("txtIterations").value

        setTimeout(function () {

            console.log('inside timeout');

            $.getJSON(['data.json'], function (jsn) {

                TrainingData = JSON.stringify(jsn);

                TData = JSON.parse(TrainingData);


                var TData2 = TData.map(item => ({
                    input: item.input,
                    output: item.output
                }))
                const iterations = txtIterations
                const config = {
                    iterations: iterations
                    , log: details => console.log(details)
                };
                txtBrain.train(TData2, config);
                example.innerHTML = 'Training is completed. Please ask your question.'
            });
        }, 2000);

        console.log('after timeout');
    }

    function runRequest() {
        var output = ''
        var txtInput = document.getElementById("txtInput").value

        console.log(txtInput);
        console.log('inside run request')

        output = txtBrain.run(txtInput.text);
        console.log('Category: ' + output);
        example.innerHTML = txtInput + '<br>... Category: ' + output;

    }

</script>

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source