Skip to content

Commit 1d643a3

Browse files
Merge pull request #194 from BrainJS/188-add-missing-api-documentation
Partially fix #188. Add missing api documentation to readme.
2 parents 6ceb8fa + e0bb309 commit 1d643a3

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

README.md

+36
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
+ [Browser](#browser)
2121
- [Training](#training)
2222
+ [Data format](#data-format)
23+
+ [For training with NeuralNetwork](#for-training-with-neuralnetwork)
24+
+ [For training with `RNN`, `LSTM` and `GRU`](#for-training-with-rnn-lstm-and-gpu)
2325
+ [Training Options](#training-options)
2426
+ [Async Training](#async-training)
2527
- [Methods](#methods)
@@ -106,6 +108,7 @@ Use `train()` to train the network with an array of training data. The network h
106108
at classifying new patterns.
107109

108110
### Data format
111+
#### For training with `NeuralNetwork`
109112
Each training pattern should have an `input` and an `output`, both of which can be either an array of numbers from `0` to `1` or a hash of numbers from `0` to `1`. For the [color contrast demo](https://brain.js.org/) it looks something like this:
110113

111114
```javascript
@@ -125,6 +128,39 @@ net.train([{input: { r: 0.03, g: 0.7 }, output: { black: 1 }},
125128

126129
var output = net.run({ r: 1, g: 0.4, b: 0 }); // { white: 0.81, black: 0.18 }
127130
```
131+
#### For training with `RNN`, `LSTM` and `GRU`
132+
Each training pattern can either:
133+
* Be an array of values
134+
* Be a string
135+
* Have an `input` and an `output`
136+
* Either of which can an array of values or a string
137+
138+
CAUTION: When using an array of values, you can use ANY value, however, the values are represented in the neural network by a single input. So the more _distinct values_ has _the larger your input layer_. If you have a hundreds, thousands, or millions of floating point values _THIS IS NOT THE RIGHT CLASS FOR THE JOB_. Also, when deviating from strings, this gets into beta
139+
140+
Example using direct strings:
141+
```javascript
142+
var net = new brain.recurrent.LSTM();
143+
144+
net.train([
145+
'doe, a deer, a female deer',
146+
'ray, a drop of golden sun',
147+
'me, a name I call myself',
148+
]);
149+
150+
var output = net.run('doe'); // ', a deer, a female deer'
151+
```
152+
153+
Example using strings with inputs and outputs:
154+
```javascript
155+
var net = new brain.recurrent.LSTM();
156+
157+
net.train([
158+
{ input: 'I feel great about the world!', output: 'happy' },
159+
{ input: 'The world is a terrible place!', output: 'sad' },
160+
]);
161+
162+
var output = net.run('I feel great about the world!'); // 'happy'
163+
```
128164

129165

130166
### Training Options

0 commit comments

Comments
 (0)