<commit_before>var fs = require('fs');
var assert = require('assert');
var RNN = require('../../../lib/recurrent/rnn');
var Vocab = require('../../../lib/recurrent/vocab');
var vocab = new Vocab(['0','1','2','3','4','5','6','7','8','9','+','=', '-', '/', '*']);

function randomMath() {
  var left = Math.floor(Math.random() * 10);
  var right = Math.floor(Math.random() * 10);
  return left + '+' + right + '=' + (left + right);
}

describe('rnn', function() {
  describe('math', function() {
    it('can predict what a math problem is after being fed 1000 random math problems', function() {
      var rnn = new RNN({
        inputSize: vocab.characters.length + 1,
        outputSize: vocab.characters.length + 1,
        vocab: vocab
      });

      for (var i = 0; i < 1000; i++) {
        rnn.inputVocab(randomMath());
      }

      for (i = 0; i < 5; i++) {
        var prediction = rnn.predictVocab();
        assert(/[+]/.test(prediction));
        assert(/[=]/.test(prediction));
      }
    });
  });
});<commit_msg>test lstm<commit_after>var fs = require('fs');
var assert = require('assert');
var RNN = require('../../../lib/recurrent/rnn');
var LSTM = require('../../../lib/recurrent/lstm');
var Vocab = require('../../../lib/recurrent/vocab');
var vocab = new Vocab(['0','1','2','3','4','5','6','7','8','9','+','=', '-', '/', '*']);

function randomMath() {
  var left = Math.floor(Math.random() * 10);
  var right = Math.floor(Math.random() * 10);
  return left + '+' + right + '=' + (left + right);
}

describe('math', function() {
  describe('rnn', function() {
    it('can predict what a math problem is after being fed 1000 random math problems', function() {
      var rnn = new RNN({
        inputSize: vocab.characters.length + 1,
        outputSize: vocab.characters.length + 1,
        vocab: vocab
      });

      for (var i = 0; i < 1000; i++) {
        rnn.inputVocab(randomMath());
      }

      for (i = 0; i < 5; i++) {
        var prediction = rnn.predictVocab();
        assert(/[+]/.test(prediction));
        assert(/[=]/.test(prediction));
      }
    });
  });
  describe('lstm', function() {
    it('can predict what a math problem is after being fed 1000 random math problems', function() {
      var lstm = new LSTM({
        inputSize: vocab.characters.length + 1,
        outputSize: vocab.characters.length + 1,
        vocab: vocab
      });

      for (var i = 0; i < 1000; i++) {
        lstm.inputVocab(randomMath());
      }

      for (i = 0; i < 5; i++) {
        var prediction = lstm.predictVocab();
        assert(/[+]/.test(prediction));
        assert(/[=]/.test(prediction));
      }
    });
  });
});
{'fraction_non_alphanumeric': 0.22059376174370537, 'fraction_numerical': 0.025178504321683576, 'mean_word_length': 2.5588235294117645, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7030105', 'n_tokens_mistral': 950, 'n_tokens_neox': 894, 'n_words': 214}