Skip to content

Commit 30cdc4c

Browse files
Partially fix #188. Add missing api documentation to readme.
1 parent 01415ae commit 30cdc4c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
+ [Browser](#browser)
1919
- [Training](#training)
2020
+ [Data format](#data-format)
21+
+ [For training with NeuralNetwork](#For-training-with-NeuralNetwork)
2122
+ [Training Options](#training-options)
2223
+ [Async Training](#async-training)
2324
- [Methods](#methods)
@@ -104,6 +105,7 @@ Use `train()` to train the network with an array of training data. The network h
104105
at classifying new patterns.
105106

106107
### Data format
108+
#### For training with `NeuralNetwork`
107109
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:
108110

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

124126
var output = net.run({ r: 1, g: 0.4, b: 0 }); // { white: 0.81, black: 0.18 }
125127
```
128+
#### For training with `RNN`, `LSTM` and `GRU`
129+
Each training pattern can either:
130+
* Be an array of values
131+
* Be a string
132+
* Have an `input` and an `output`
133+
* Either of which can an array of values or a string
134+
135+
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
136+
137+
Example using direct strings:
138+
```javascript
139+
var net = new brain.NeuralNetwork();
140+
141+
net.train([
142+
'doe, a deer, a female deer',
143+
'ray, a drop of golden sun',
144+
'me, a name I call myself',
145+
]);
146+
147+
var output = net.run('doe'); // ', a deer, a female deer'
148+
```
149+
150+
Example using strings with inputs and outputs:
151+
```javascript
152+
var net = new brain.NeuralNetwork();
153+
154+
net.train([
155+
{ input: 'I feel great about the world!', output: 'happy' },
156+
{ input: 'The world is a terrible place!', output: 'sad' },
157+
]);
158+
159+
var output = net.run('I feel great about the world!'); // 'happy'
160+
```
126161

127162

128163
### Training Options

0 commit comments

Comments
 (0)