Comments (11)
The dictionary is autogenerated during the training process but if you autogenerate it during the inference mode, there are issues on how javascript and python sort characters. They must be the same in both for the lstm to work.
This was my initial approach:
In python using hamlet.txt in train.py
:
chars = sorted(list(set(text)))
char_indices = dict((c,i) for i,c in enumerate(chars))
returns:
{' ': 0, '!': 1, '&': 2, "'": 3, ',': 4, '-': 5, '.': 6, '1': 7, '2': 8, ':': 9, ';': 10, '?': 11, '[': 12, ']': 13, 'a': 14, 'b': 15, 'c': 16, 'd': 17, 'e': 18, 'f': 19, 'g': 20, 'h': 21, 'i': 22, 'j': 23, 'k': 24, 'l': 25, 'm': 26, 'n': 27, 'o': 28, 'p': 29, 'q': 30, 'r': 31, 's': 32, 't': 33, 'u': 34, 'v': 35, 'w': 36, 'x': 37, 'y': 38, 'z': 39}
But the same in lstm.js
let chars = Array.from(new Set(Array.from(text))).sort();
let char_indices = chars.reduce((acc, cur, i) => {
acc[cur] = i;
return acc;
}, {});
returns:
{ '1': 8, '2': 9, '\n': 0, ' ': 1, '!': 2, '&': 3, '\'': 4, ',': 5, '-': 6, '.': 7, ':': 10, ';': 11, '?': 12, '[': 13, ']': 14, a: 15, b: 16, c: 17, d: 18, e: 19, f: 20, g: 21, h: 22, i: 23, j: 24, k: 25, l: 26, m: 27, n: 28, o: 29, p: 30, q: 31, r: 32, s: 33, t: 34, u: 35, v: 36, w: 37, x: 38, y: 39, z: 40 }
That's why I just copied the dictionary from train.py
into js. I'm not sure if there's a better approach to this.
from ml5-library.
Ah, I see, perhaps we could add something to either train.py
or json_checkpoints_var.py
that generates a JSON file with the character tables so that at least removes the manual copying and would be less prone to error?
from ml5-library.
I did a round of work on this in 1b8160d and 93e4fe8. I'm not getting good results, this is most likely due to the tiniest data set ever and training for only 50 epochs. But @cvalenzuela can you look over what I've done to training
and examples/lstm_1
and see if you notice anything awry?
from ml5-library.
I also added a README
with instructions on doing the training if you want to take a look.
https://github.com/ITPNYU/p5-deeplearn-js/blob/master/training/lstm/README.md
from ml5-library.
nice!
I'm looking at the example now
from ml5-library.
So I did some test and I think I got better results. Here's what I did:
I trained a new model with the itp.txt
data. In train.py
I updated the length of the dictionary, that always needs to match the source text:
NLABELS = len(chars)
and trained it on 1000 epochs since it's a really small source text.
In the lstm.js
the onehot
variable needs to have a shape that includes the dictionary:
const onehot = track(deeplearn.Array2D.zeros([1, 32]));
Here is what I'm getting from the lstm_1
example
I'll push the code now
from ml5-library.
awesome, that's great! Thank you! Can the onehot
variable pull its shape dynamically?
from ml5-library.
Oh, and feel free to add any of these details to the README
in train/
!
from ml5-library.
Maybe in the training process, train.py
could output just one file that has all the variables and objects that could later be imported into the sketch file?
We could also try other rnn implementations that use words instead of characters. Maybe using something like this, this or this. I'll post how this goes
from ml5-library.
I updated the README
in train/
to reflect this changes
from ml5-library.
This is great! I made a small change in the code (2dbaf98) to skip saving the model at step 0. Or maybe it's a good idea to leave this in since you get something immediately even if it's nonsense. In any case, I'm closing this issue for now! We can open new ones as to things come up re: LSTM training and generation examples!
from ml5-library.
Related Issues (20)
- Using safetensors or pkl models (like python)
- ml5.min.js.map not found if offline HOT 2
- DOMException: Failed to execute 'texImage2D' on 'WebGL2RenderingContext': Tainted canvases may not be loaded. HOT 1
- knnClassifier result after .save() and .load() - classIndex becomes undefined and label becomes number, labelToClassId disappears HOT 1
- memory leak in featureExtractor on addImage in WebGL backend HOT 3
- ML5 fails to load on Chrome incognito - localstorage error HOT 1
- PoseNet Bug using custom trained model in a reactjs environment HOT 6
- about use ml5 in vue HOT 1
- How should we handle input data with Nulls/Blanks? HOT 1
- Always outputting the same thing. Might be something wrong with my HTML not sure HOT 2
- add facemesh and handpose to preload
- Possible memory leak in BodyPix and WEBGL
- Various problems with the training-charRNN repo
- Problem with CORS HOT 1
- model topology missing handpose regression HOT 9
- ERR_CONNECTION_REFUSED
- New m15 Coder, couldn't find answer online, Error "Error in oneHot: depth must be >=2, but it is 1" HOT 1
- Memory leak in PoseNet's video processing pattern HOT 3
- "Feature Extractor Examples" from ml5.js website / TypeError: Failed to fetch HOT 9
- Need some information on using NeuralNetworkVis HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ml5-library.