question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't manage to have a string get analysed by brain.js

See original GitHub issue

A GIF or MEME to give some spice of the internet

What is wrong?

The training network doesn’t train, it returns NaN for the data that it should have analysed.

Where does it happen?

In the app.js run through node, after receiving data from the Twitter API

How do we replicate the issue?

  1. Use the dummy data below
const trainingData =[  
   {  
      input:'RT @ObamaFoundation: This week—50 years since Dr. Martin Luther King, Jr. was killed—@BarackObama and @RepJohnLewis sat down with a group o…',
      output:{  
         Barack:1
      }
   },
   {  
      input:'Incredible to have a Chicago team in the Final Four. I’ll take that over an intact bracket any day! Congratulations to everybody @LoyolaChicago - let’s keep it going!',
      output:{  
         Barack:1
      }
   },
   {  
      input:'In Singapore with young people who are advocating for education, empowering young women, and getting involved all over Southeast Asia with a profoundly optimistic commitment to building the world they want to see. ',
      output:{  
         Barack:1
      }
   },
   {  
      input:'Very thankful for President Xi of China’s kind words on tarrifs and automobile barriers...also, his enlightenment on intellectual property and technology transfers. We will make great progress together!',
      output:{  
         Donald:1
      }
   },
   {  
      input:'Last night, it was my great honor to host America’s senior defense and military leaders for dinner at the White House. America’s military is the GREATEST fighting force in the history of the world. They all have my pledge of unwavering commitment to our men and women in uniform! ',
      output:{  
         Donald:1
      }
   },
   {  
      input:'A TOTAL WITCH HUNT!!!',
      output:{  
         Donald:1
      }
   }
]
  1. Convert the input using encode
function encode(arg) {
return arg.split('').map(x => (x.charCodeAt(0) / 400));
}
  1. Run it through net.trainAsync()

How important is this (1-5)?

A 4, since I think this should be able to work, but it could be my bad too!

Expected behavior (i.e. solution)

The data should have been analysed, but somewhere inbetween something went wrong!

Other Comments

I’m think the encoding method might not be correct here.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
robertleeplummerjrcommented, Apr 12, 2018

The api is the same in whatever javascript you are on. I started experimenting with a lstm version, which I believe is the answer here, I’ll see what I can come up with as well.

1reaction
robertleeplummerjrcommented, Apr 10, 2018

Here is a better working prototype (the other one I forgot to click save on) https://jsfiddle.net/8Lvynxz5/38/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Brain js NaN when predicting is a combination of words is ...
Apparently, brain.js only understands numeric data. But it can be trained to represent each character as a neuron in the net.
Read more >
Build and train a neural network with nothing but ...
In this tutorial, we will explore one of them -- Brain.js -- and show how it's possible to build, train, and use a...
Read more >
Useful string methods - Learn web development | MDN
Now that we've looked at the very basics of strings, let's move up a gear and start thinking about what useful operations we...
Read more >
brain.js
brain.js is a GPU accelerated library for Neural Networks written in JavaScript. This is a continuation of the harthur/brain, ...
Read more >
Find if a string is interleaved of two other strings | DP-33
The simple solution doesn't work if the strings A and B have some common characters. For example, let the given string be A...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found