BrainJS / brain.js

🤖 GPU accelerated Neural networks in JavaScript for Browsers and Node.js
https://brain.js.org
MIT License
14.34k stars 1.07k forks source link

[help wanted] How can I use brain.js to generate poetry? #371

Closed blismatic closed 4 years ago

blismatic commented 5 years ago

A GIF or MEME to give some spice of the internet

Can I use brain.js to generate poetry?

Hi, I'm a (somewhat) novice in javaScript, but for my high school final project, I wanted to try to make a program that could generate poetry. Is this possible to do with brain.js, and if so, what type of neural network would I need to look into to accomplish this? This is my first time using a js library, so all of this is a bit foreign to me, but I am very interested in how brain.js can be applied to something like language and poetry.

Any help is appreciated, thank you !

WowItsDoge commented 5 years ago

This question could not be answered generaly, I guess. There are multiple options to try to generate poetry with neuronal networks.

Maybe this example could provide some usefull idea how to start: https://github.com/BrainJS/brain.js/blob/master/examples/childrens-book.js

blismatic commented 5 years ago

@WowItsDoge

This question could not be answered generaly, I guess. There are multiple options to try to generate poetry with neuronal networks.

Maybe this example could provide some usefull idea how to start: https://github.com/BrainJS/brain.js/blob/master/examples/childrens-book.js

I've taken a look at that example, and it seems that the neural network only finds what line the given input is found in, and then repeats that line. This doesn't really seem like it "writing" a children's book to me, or am I misinterpreting how the neural net is working? Maybe with a larger amount of training data the outcome would be different?

WowItsDoge commented 5 years ago

Maybe you want to create something like this: https://hackernoon.com/automated-text-generator-using-markov-chain-de999a41e047

But I am not shure if this library already supports Markov Chains.

blismatic commented 5 years ago

@WowItsDoge I suppose that Markov Chain example is more of what I want to accomplish. How does the brain.js example involving a children's book differ from the Markov Chain in terms of the output they give?

CamK06 commented 5 years ago

A GIF or MEME to give some spice of the internet

Can I use brain.js to generate poetry?

Hi, I'm a (somewhat) novice in javaScript, but for my high school final project, I wanted to try to make a program that could generate poetry. Is this possible to do with brain.js, and if so, what type of neural network would I need to look into to accomplish this? This is my first time using a js library, so all of this is a bit foreign to me, but I am very interested in how brain.js can be applied to something like language and poetry.

Any help is appreciated, thank you !

Seems no one is willing to actually help you with just brain.js, here's a script I made to generate text from input text. The trainingData constant can be replaced with a const trainingData = require('trainingData.json') if you want to put the data in a json string array (which looks like ["text1", "text2", "text3])

Anyways, this script will replicate your data really well although you might want to increase the amount of iterations if you have a lot more data than in the example. Just to make viewing your training easier I made it so each iteration's train gets logged in console and in a log file (TrainingLog.txt)

Anyways, hope this helps :)

Edit: If you're interested here's an example of something it might output with that example data Below, a Shistling wind

I also forgot to mention you might want to modify the maxPredictionLength accordingly if you're getting results that are too long (or even too short, I don't know what kind of poetry you're feeding this thing)

mubaidr commented 4 years ago

Also this could be helpful: https://github.com/BrainJS/brain.js/issues/375