Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read properties of undefined (reading 'rows') #889

Open
Aidan-The-Dev opened this issue Apr 17, 2023 · 1 comment
Open

Cannot read properties of undefined (reading 'rows') #889

Aidan-The-Dev opened this issue Apr 17, 2023 · 1 comment
Assignees
Labels

Comments

@Aidan-The-Dev
Copy link

Im trying to make a chat bot but I keep getting an error when I try and start it so it will learn

Code:

const fs = require('fs')
const readline = require('readline')
const brain = require('brain.js')
const net = new brain.recurrent.LSTM()

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
})

const array = []

fs.readFile('learned.json', (err, data) => {
  if(err) return console.log(err)

  if(data.toString() === '') {
    console.log('Network already trained.')
    train()
  } else {
    net.fromJSON(JSON.parse(data.toString()))
    boot()
  }
})

const train = () => {
  console.log('Training...')
  const d = new Date()
  fs.readFile('essay.txt', (err, data) => {
    array = data.toString().split('.')
    net.train(array, {
      iterations: 20000,
      log: true,
      errorThresh: 0.01
    })
    fs.writeFile('learned.JSON', JSON.stringify(net.toJSON()))
    console.log(`Training finished in ${(new Date() - d) / 1000} s`)
  })
}

const boot = () => {
  rl.question('Enter: ', (q) => {
    console.log(net.run(q))
    boot()
  })
}
@robertleeplummerjr
Copy link
Contributor

Could you provide a sample of the data from the learned.json file?

@robertleeplummerjr robertleeplummerjr self-assigned this Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants