src/demo/TextSeqDemo.java
public static void main(String [] args) {

        int numOfInputs = 5;

        NeuralNetwork neuralNetwork;
        try {
            String persistenceName = "<PATH>/TextSeqNN";
            HashMap<Integer, String> dictionaryIndexMapping = new HashMap<>();
            HashMap<Integer, HashMap<Integer, MMatrix>> data = getTextSeqData(numOfInputs, dictionaryIndexMapping);
            neuralNetwork = buildNeuralNetwork(data.get(0).get(0).get(0).getRows(), data.get(1).get(0).get(0).getRows());
//            neuralNetwork = Persistence.restoreNeuralNetwork(persistenceName);
            Persistence persistence = new Persistence(true, 100, neuralNetwork, persistenceName, true);
            neuralNetwork.setPersistence(persistence);
            neuralNetwork.verboseTraining(10);
            neuralNetwork.start();
            neuralNetwork.print();
            neuralNetwork.printExpressions();
            neuralNetwork.printGradients();
            neuralNetwork.setTrainingData(new BasicSampler(data.get(0), data.get(1),"randomOrder = false, randomStart = false, stepSize = 1, shuffleSamples = false, sampleSize = 100, numberOfIterations = 100"));
            while (neuralNetwork.getTotalIterations() < 100000) {
                neuralNetwork.train();
                System.out.println("Validating...");
                Matrix input = data.get(0).get(1).get(0);
                ArrayList<Matrix> encodedWords = input.getSubMatrices();
                int inputSize = encodedWords.get(0).size();
                for (int pos = 0; pos < 1000; pos++) {
                    Matrix nextEncodedWord = neuralNetwork.predict(input);
                    int wordIndex = nextEncodedWord.argmax()[0];
                    String currentWord = dictionaryIndexMapping.getOrDefault(wordIndex, "???");
                    System.out.print(currentWord + " ");
                    nextEncodedWord = ComputableMatrix.encodeToBitColumnVector(wordIndex, inputSize);
                    for (int index = 0; index < encodedWords.size() - 1; index++) {
                        encodedWords.set(index, encodedWords.get(index + 1));
                    }
                    encodedWords.set(encodedWords.size() - 1, nextEncodedWord);
                    input = new JMatrix(encodedWords, true);
                    encodedWords = input.getSubMatrices();
                }
                System.out.println();
            }

            neuralNetwork.stop();
        }
        catch (Exception exception) {
            exception.printStackTrace();
            System.exit(-1);
        }
    }
/**
     * Main function that reads data, executes learning process and replicates learnt text sequences.
     *
     * @param args input arguments (not used).
     */
Main function that reads data, executes learning process and replicates learnt text sequences.
@param args input arguments (not used).
Main function that reads data executes learning process and replicates learnt text sequences . @param args input arguments ( not used ) .
public static void main(String [] args) {
        int numOfInputs = 5;
        NeuralNetwork neuralNetwork;
        try {
            String persistenceName = "<PATH>/TextSeqNN";
            HashMap<Integer, String> dictionaryIndexMapping = new HashMap<>();
            HashMap<Integer, HashMap<Integer, MMatrix>> data = getTextSeqData(numOfInputs, dictionaryIndexMapping);
            neuralNetwork = buildNeuralNetwork(data.get(0).get(0).get(0).getRows(), data.get(1).get(0).get(0).getRows());
            Persistence persistence = new Persistence(true, 100, neuralNetwork, persistenceName, true);
            neuralNetwork.setPersistence(persistence);
            neuralNetwork.verboseTraining(10);
            neuralNetwork.start();
            neuralNetwork.print();
            neuralNetwork.printExpressions();
            neuralNetwork.printGradients();
            neuralNetwork.setTrainingData(new BasicSampler(data.get(0), data.get(1),"randomOrder = false, randomStart = false, stepSize = 1, shuffleSamples = false, sampleSize = 100, numberOfIterations = 100"));
            while (neuralNetwork.getTotalIterations() < 100000) {
                neuralNetwork.train();
                System.out.println("Validating...");
                Matrix input = data.get(0).get(1).get(0);
                ArrayList<Matrix> encodedWords = input.getSubMatrices();
                int inputSize = encodedWords.get(0).size();
                for (int pos = 0; pos < 1000; pos++) {
                    Matrix nextEncodedWord = neuralNetwork.predict(input);
                    int wordIndex = nextEncodedWord.argmax()[0];
                    String currentWord = dictionaryIndexMapping.getOrDefault(wordIndex, "???");
                    System.out.print(currentWord + " ");
                    nextEncodedWord = ComputableMatrix.encodeToBitColumnVector(wordIndex, inputSize);
                    for (int index = 0; index < encodedWords.size() - 1; index++) {
                        encodedWords.set(index, encodedWords.get(index + 1));
                    }
                    encodedWords.set(encodedWords.size() - 1, nextEncodedWord);
                    input = new JMatrix(encodedWords, true);
                    encodedWords = input.getSubMatrices();
                }
                System.out.println();
            }
            neuralNetwork.stop();
        }
        catch (Exception exception) {
            exception.printStackTrace();
            System.exit(-1);
        }
    }
public static void main ( String [ ] args ) { int numOfInputs = 5 ; NeuralNetwork neuralNetwork ; try { String persistenceName = "<PATH>/TextSeqNN" ; HashMap < Integer , String > dictionaryIndexMapping = new HashMap < > ( ) ; HashMap < Integer , HashMap < Integer , MMatrix > > data = getTextSeqData ( numOfInputs , dictionaryIndexMapping ) ; neuralNetwork = buildNeuralNetwork ( data . get ( 0 ) . get ( 0 ) . get ( 0 ) . getRows ( ) , data . get ( 1 ) . get ( 0 ) . get ( 0 ) . getRows ( ) ) ; Persistence persistence = new Persistence ( true , 100 , neuralNetwork , persistenceName , true ) ; neuralNetwork . setPersistence ( persistence ) ; neuralNetwork . verboseTraining ( 10 ) ; neuralNetwork . start ( ) ; neuralNetwork . print ( ) ; neuralNetwork . printExpressions ( ) ; neuralNetwork . printGradients ( ) ; neuralNetwork . setTrainingData ( new BasicSampler ( data . get ( 0 ) , data . get ( 1 ) , "randomOrder = false, randomStart = false, stepSize = 1, shuffleSamples = false, sampleSize = 100, numberOfIterations = 100" ) ) ; while ( neuralNetwork . getTotalIterations ( ) < 100000 ) { neuralNetwork . train ( ) ; System . out . println ( "Validating..." ) ; Matrix input = data . get ( 0 ) . get ( 1 ) . get ( 0 ) ; ArrayList < Matrix > encodedWords = input . getSubMatrices ( ) ; int inputSize = encodedWords . get ( 0 ) . size ( ) ; for ( int pos = 0 ; pos < 1000 ; pos ++ ) { Matrix nextEncodedWord = neuralNetwork . predict ( input ) ; int wordIndex = nextEncodedWord . argmax ( ) [ 0 ] ; String currentWord = dictionaryIndexMapping . getOrDefault ( wordIndex , "???" ) ; System . out . print ( currentWord + " " ) ; nextEncodedWord = ComputableMatrix . encodeToBitColumnVector ( wordIndex , inputSize ) ; for ( int index = 0 ; index < encodedWords . size ( ) - 1 ; index ++ ) { encodedWords . set ( index , encodedWords . get ( index + 1 ) ) ; } encodedWords . set ( encodedWords . size ( ) - 1 , nextEncodedWord ) ; input = new JMatrix ( encodedWords , true ) ; encodedWords = input . getSubMatrices ( ) ; } System . out . println ( ) ; } neuralNetwork . stop ( ) ; } catch ( Exception exception ) { exception . printStackTrace ( ) ; System . exit ( - 1 ) ; } }
Main function that reads data, executes learning process and replicates learnt text sequences.
Main function that reads data executes learning process and replicates learnt text sequences .
//            neuralNetwork = Persistence.restoreNeuralNetwork(persistenceName);