Fix typos and minor inconsistencies.

This commit is contained in:
rpinsler 2015-12-23 13:06:03 +01:00
parent 29e60ab372
commit 85e51a0f8f
17 changed files with 56 additions and 56 deletions

@ -122,7 +122,7 @@ conv_output = get_conv_output(input_data_dict)
### Isn't there a bug with Merge or Graph related to input concatenation?
Yes, there was a known bug with tensor concatenation in Thenao that was fixed early 2015.
Yes, there was a known bug with tensor concatenation in Theano that was fixed early 2015.
Please upgrade to the latest version of Theano:
```bash
@ -155,7 +155,7 @@ Find out more in the [callbacks documentation](callbacks.md).
### How is the validation split computed?
If you set the `validation_split` arugment in `model.fit` to e.g. 0.1, then the validation data used will be the *last 10%* of the data. If you set it to 0.25, it will be the last 25% of the data, etc.
If you set the `validation_split` argument in `model.fit` to e.g. 0.1, then the validation data used will be the *last 10%* of the data. If you set it to 0.25, it will be the last 25% of the data, etc.
---
@ -191,7 +191,7 @@ When using stateful RNNs, it is therefore assumed that:
To use statefulness in RNNs, you need to:
- explicitely specify the batch size you are using, by passing a `batch_input_shape` argument to the first layer in your model. It should be a tuple of integers, e.g. `(32, 10, 16)` for a 32-samples batch of sequences of 10 timesteps with 16 features per timestep.
- explicitly specify the batch size you are using, by passing a `batch_input_shape` argument to the first layer in your model. It should be a tuple of integers, e.g. `(32, 10, 16)` for a 32-samples batch of sequences of 10 timesteps with 16 features per timestep.
- set `stateful=True` in your RNN layer(s).
To reset the states accumulated:

@ -2,7 +2,7 @@
## You have just found Keras.
Keras is a minimalist, highly modular neural networks library, written in Python and capable of running either on top of either [TensorFlow](https://github.com/tensorflow/tensorflow) or [Theano](https://github.com/Theano/Theano). It was developed with a focus on enabling fast experimentation. Being able to go from idea to result with the least possible delay is key to doing good research.
Keras is a minimalist, highly modular neural networks library, written in Python and capable of running on top of either [TensorFlow](https://github.com/tensorflow/tensorflow) or [Theano](https://github.com/Theano/Theano). It was developed with a focus on enabling fast experimentation. Being able to go from idea to result with the least possible delay is key to doing good research.
Use Keras if you need a deep learning library that:
- allows for easy and fast prototyping (through total modularity, minimalism, and extensibility).
@ -26,7 +26,7 @@ Keras is compatible with: __Python 2.7-3.5__.
- __Easy extensibility.__ New modules are dead simple to add (as new classes and functions), and existing modules provide ample examples. To be able to easily create new modules allows for total expressiveness, making Keras suitable for advanced research.
- __Work with Python__. No separate models configuration files in a declarative format. Models are described in Python code, which is compact, easier to debug, and allows for ease of extensibility.
- __Work with Python__. No separate model configuration files in a declarative format. Models are described in Python code, which is compact, easier to debug, and allows for ease of extensibility.
------------------
@ -34,7 +34,7 @@ Keras is compatible with: __Python 2.7-3.5__.
## Getting started: 30 seconds to Keras
The core datastructure of Keras is a __model__, a way to organize layers. There are two types of models: [`Sequential`](/models/#sequential) and [`Graph`](/models/#graph).
The core data structure of Keras is a __model__, a way to organize layers. There are two types of models: [`Sequential`](/models/#sequential) and [`Graph`](/models/#graph).
Here's the `Sequential` model (a linear pile of layers):
@ -157,4 +157,4 @@ Keras was initially developed as part of the research effort of project ONEIROS
>_"Oneiroi are beyond our unravelling --who can be sure what tale they tell? Not all that men look for comes to pass. Two gates there are that give passage to fleeting Oneiroi; one is made of horn, one of ivory. The Oneiroi that pass through sawn ivory are deceitful, bearing a message that will not be fulfilled; those that come out through polished horn have truth behind them, to be accomplished for men who see them."_ Homer, Odyssey 19. 562 ff (Shewring translation).
------------------
------------------

@ -39,7 +39,7 @@ def hard_sigmoid(x):
def linear(x):
'''
The function returns the variable that is passed in, so all types work
The function returns the variable that is passed in, so all types work.
'''
return x

@ -11,7 +11,7 @@ theano.config.floatX = _FLOATX
def _on_gpu():
'''Returns whether the session is set to
'''Return whether the session is set to
run on GPU or not (i.e. on CPU).
'''
return theano.config.device[:3] == 'gpu'
@ -19,7 +19,7 @@ def _on_gpu():
if _on_gpu():
'''Import cuDNN only if running on GPU:
not having Cuda install should not
not having Cuda installed should not
prevent from running the present code.
'''
from theano.sandbox.cuda import dnn
@ -244,18 +244,18 @@ def permute_dimensions(x, pattern):
def repeat_elements(x, rep, axis):
'''Repeats the elements of a tensor along an axis, like np.repeat
'''Repeat the elements of a tensor along an axis, like np.repeat.
If x has shape (s1, s2, s3) and axis=1, the output
will have shape (s1, s2 * rep, s3)
will have shape (s1, s2 * rep, s3).
'''
return T.repeat(x, rep, axis=axis)
def repeat(x, n):
'''Repeat a 2D tensor:
'''Repeat a 2D tensor.
if x has shape (samples, dim) and n=2,
the output will have shape (samples, 2, dim)
If x has shape (samples, dim) and n=2,
the output will have shape (samples, 2, dim).
'''
tensors = [x] * n
stacked = T.stack(*tensors)
@ -377,7 +377,7 @@ def gradients(loss, variables):
def rnn(step_function, inputs, initial_states,
go_backwards=False, masking=True):
'''Iterates over the time dimension of a tensor.
'''Iterate over the time dimension of a tensor.
Parameters
----------

@ -256,7 +256,7 @@ class ModelCheckpoint(Callback):
if mode not in ['auto', 'min', 'max']:
warnings.warn('ModelCheckpoint mode %s is unknown, '
'fallback to auto mode' % (self.mode),
'fallback to auto mode.' % (self.mode),
RuntimeWarning)
mode = 'auto'
@ -311,7 +311,7 @@ class EarlyStopping(Callback):
mode: one of {auto, min, max}. In 'min' mode,
training will stop when the quantity
monitored has stopped decreasing; in 'max'
mode it will stopped when the quantity
mode it will stop when the quantity
monitored has stopped increasing.
'''
def __init__(self, monitor='val_loss', patience=0, verbose=0, mode='auto'):
@ -324,7 +324,7 @@ class EarlyStopping(Callback):
if mode not in ['auto', 'min', 'max']:
warnings.warn('EarlyStopping mode %s is unknown, '
'fallback to auto mode' % (self.mode), RuntimeWarning)
'fallback to auto mode.' % (self.mode), RuntimeWarning)
mode = 'auto'
if mode == 'min':
@ -364,7 +364,7 @@ class RemoteMonitor(Callback):
Requires the `requests` library.
# Arguments
root: root url to which the events will be send (at the end
root: root url to which the events will be sent (at the end
of every epoch). Events are sent to
`root + '/publish/epoch/end/'`. Calls are HTTP POST,
with a `data` argument which is a JSON-encoded dictionary
@ -453,7 +453,7 @@ class TensorBoard(Callback):
super(Callback, self).__init__()
if K._BACKEND != 'tensorflow':
raise Exception('TensorBoard callback only works '
'with the TensorFlow backend')
'with the TensorFlow backend.')
self.log_dir = log_dir
self.histogram_freq = histogram_freq

@ -69,7 +69,7 @@ def orthogonal(shape, scale=1.1):
def identity(shape, scale=1):
if len(shape) != 2 or shape[0] != shape[1]:
raise Exception('Identity matrix initialization can only be used '
'for 2D square matrices')
'for 2D square matrices.')
else:
return K.variable(scale * np.identity(shape[0]))

@ -104,7 +104,7 @@ class Sequential(Layer):
@property
def state_updates(self):
"""
Returns the `updates` from all layers in the sequence that are
Return the `updates` from all layers in the sequence that are
stateful. This is useful for separating _training_ updates and
_prediction_ updates for when we need to update a layers internal state
during a stateful prediction.
@ -232,7 +232,7 @@ class Graph(Layer):
@property
def state_updates(self):
"""
Returns the `updates` from all nodes in that graph for nodes that are
Return the `updates` from all nodes in that graph for nodes that are
stateful. This is useful for separating _training_ updates and
_prediction_ updates for when we need to update a layers internal state
during a stateful prediction.

@ -584,7 +584,7 @@ class AveragePooling2D(_Pooling2D):
class UpSampling1D(Layer):
'''Repeats each temporal step `length` times along the time axis.
'''Repeat each temporal step `length` times along the time axis.
# Input shape
3D tensor with shape: `(samples, steps, features)`.
@ -620,7 +620,7 @@ class UpSampling1D(Layer):
class UpSampling2D(Layer):
'''Repeats the rows and columns of the data
'''Repeat the rows and columns of the data
by size[0] and size[1] respectively.
# Input shape

@ -84,7 +84,7 @@ class Layer(object):
' but previous layer has output_shape ' +
str(layer.output_shape))
if layer.get_output_mask() is not None:
assert self.supports_masked_input(), 'Cannot connect non-masking layer to layer with masked output'
assert self.supports_masked_input(), 'Cannot connect non-masking layer to layer with masked output.'
self.previous = layer
self.build()
@ -530,7 +530,7 @@ class Merge(Layer):
for i in range(len(self.layers)):
X = self.layers[i].get_output(train)
if X.name is None:
raise ValueError('merge_mode="join" only works with named inputs')
raise ValueError('merge_mode="join" only works with named inputs.')
else:
inputs[X.name] = X
return inputs
@ -560,7 +560,7 @@ class Merge(Layer):
output = output.dimshuffle((0, 'x'))
return output
else:
raise Exception('Unknown merge mode')
raise Exception('Unknown merge mode.')
def get_input(self, train=False):
res = []
@ -748,7 +748,7 @@ class Flatten(Layer):
'''Flatten the input. Does not affect the batch size.
# Input shape
Arbitrary, although all dimensions in the input shaped must be fixed.
Arbitrary, although all dimensions in the input shape must be fixed.
Use the keyword argument `input_shape`
(tuple of integers, does not include the samples axis)
when using this layer as the first layer in a model.
@ -1363,7 +1363,7 @@ class LambdaMerge(Lambda):
def __init__(self, layers, function, output_shape=None):
if len(layers) < 2:
raise Exception('Please specify two or more input layers '
'(or containers) to merge')
'(or containers) to merge.')
self.layers = layers
self.params = []
self.regularizers = []
@ -1406,7 +1406,7 @@ class LambdaMerge(Lambda):
output_shape_func = types.FunctionType(output_shape_func, globals())
shape = output_shape_func(input_shapes)
if type(shape) not in {list, tuple}:
raise Exception('output_shape function must return a tuple')
raise Exception('output_shape function must return a tuple.')
return tuple(shape)
def get_params(self):
@ -1486,7 +1486,7 @@ class Siamese(Layer):
if merge_mode in {'cos', 'dot'}:
if len(inputs) > 2:
raise Exception(merge_mode + ' merge takes exactly 2 layers')
raise Exception(merge_mode + ' merge takes exactly 2 layers.')
self.layer = layer
self.trainable = layer.trainable
@ -1573,7 +1573,7 @@ class Siamese(Layer):
X = self.get_output_at(i, train)
if X.name is None:
raise ValueError('merge_mode="join" '
'only works with named inputs')
'only works with named inputs.')
o[X.name] = X
return o
@ -1691,10 +1691,10 @@ class Siamese(Layer):
class SiameseHead(Layer):
'''This layer should be added only on top of a Siamese layer
with merge_mode = None
with merge_mode = None.
Outputs the output of the Siamese layer at a given index,
specified by the head argument
specified by the head argument.
# Arguments
head: The index at which the output of the Siamese layer
@ -1729,7 +1729,7 @@ class SiameseHead(Layer):
def add_shared_layer(layer, inputs):
'''Use this function to add a shared layer across
multiple Sequential models without merging the outputs
multiple Sequential models without merging the outputs.
'''
input_layers = [l.layers[-1] for l in inputs]
s = Siamese(layer, input_layers, merge_mode=None)
@ -1741,7 +1741,7 @@ def add_shared_layer(layer, inputs):
class Highway(Layer):
'''Densely connected highway network,
a natural extension of LSTMs to feedforward networks
a natural extension of LSTMs to feedforward networks.
cite: http://arxiv.org/pdf/1505.00387v2.pdf

@ -8,10 +8,10 @@ from ..constraints import unitnorm
class Embedding(Layer):
'''Turn positive integers (indexes) into denses vectors of fixed size.
'''Turn positive integers (indexes) into dense vectors of fixed size.
eg. [[4], [20]] -> [[0.25, 0.1], [0.6, -0.2]]
This layer can only be used as the first layer in a model.
This layer can only be used as the first layer in a model.
# Input shape
2D tensor with shape: `(nb_samples, sequence_length)`.
@ -38,7 +38,7 @@ class Embedding(Layer):
This is useful for [recurrent layers](recurrent.md) which may take
variable length input. If this is `True` then all subsequent layers
in the model need to support masking or an exception will be raised.
input_length: Length of input sequences, when it is constantself.
input_length: Length of input sequences, when it is constant.
This argument is required if you are going to connect
`Flatten` then `Dense` layers upstream
(without it, the shape of the dense outputs cannot be computed).

@ -6,7 +6,7 @@ from .. import backend as K
class BatchNormalization(Layer):
'''Normalize the activations of the previous layer at each batch,
i.e. applies a transformation that maintains the mean activation
close to 0. and the activation standard deviation close to 1.
close to 0 and the activation standard deviation close to 1.
# Input shape
Arbitrary. Use the keyword argument `input_shape`

@ -30,7 +30,7 @@ class Recurrent(MaskedLayer):
return_sequences: Boolean. Whether to return the last output
in the output sequence, or the full sequence.
go_backwards: Boolean (default False).
If True, rocess the input sequence backwards.
If True, process the input sequence backwards.
stateful: Boolean (default False). If True, the last state
for each sample at index i in a batch will be used as initial
state for the sample of index i in the following batch.
@ -43,7 +43,7 @@ class Recurrent(MaskedLayer):
`Flatten` then `Dense` layers upstream
(without it, the shape of the dense outputs cannot be computed).
Note that if the recurrent layer is not the first layer
in your model, you would need to specify the input Length
in your model, you would need to specify the input length
at the level of the first layer
(e.g. via the `input_shape` argument)
@ -129,7 +129,7 @@ class Recurrent(MaskedLayer):
if K._BACKEND == 'tensorflow':
if not self.input_shape[1]:
raise Exception('When using TensorFlow, you should define ' +
'explicitely the number of timesteps of ' +
'explicitly the number of timesteps of ' +
'your sequences. Make sure the first layer ' +
'has a "batch_input_shape" argument ' +
'including the samples axis.')

@ -59,7 +59,7 @@ def slice_X(X, start=None, stop=None):
'''
if type(X) == list:
if hasattr(start, '__len__'):
# hdf5 dataset only support list object as indices
# hdf5 datasets only support list objects as indices
if hasattr(start, 'shape'):
start = start.tolist()
return [x[start] for x in X]
@ -84,7 +84,7 @@ def weighted_objective(fn):
# mask should have the same shape as score_array
score_array *= mask
# the loss per batch should be proportional
# to the number of unmasked sampled.
# to the number of unmasked samples.
score_array /= K.mean(mask)
# reduce score_array to 1D
@ -461,7 +461,7 @@ class Sequential(Model, containers.Sequential):
show_accuracy=False, class_weight=None, sample_weight=None):
'''Train the model for a fixed number of epochs.
Returns a history object. It `history` attribute is a record of
Returns a history object. Its `history` attribute is a record of
training loss values at successive epochs,
as well as validation loss values (if applicable).
@ -984,7 +984,7 @@ class Graph(Model, containers.Graph):
class_weight={}, sample_weight={}):
'''Train the model for a fixed number of epochs.
Returns a history object. It `history` attribute is a record of
Returns a history object. Its `history` attribute is a record of
training loss values at successive epochs,
as well as validation loss values (if applicable).

@ -35,7 +35,7 @@ def hinge(y_true, y_pred):
def categorical_crossentropy(y_true, y_pred):
'''Expects a binary class matrix instead of a vector of scalar classes
'''Expects a binary class matrix instead of a vector of scalar classes.
'''
return K.mean(K.categorical_crossentropy(y_pred, y_true), axis=-1)

@ -59,7 +59,7 @@ class Tokenizer(object):
By default, all punctuation is removed, turning the texts into
space-separated sequences of words
(words maybe include the `'` character). These sequences are then
splits into lists of tokens. They will then be indexed or vectorized.
split into lists of tokens. They will then be indexed or vectorized.
`0` is a reserved index that won't be assigned to any word.
'''
@ -167,12 +167,12 @@ class Tokenizer(object):
if self.word_index:
nb_words = len(self.word_index) + 1
else:
raise Exception("Specify a dimension (nb_words argument), or fit on some text data first")
raise Exception("Specify a dimension (nb_words argument), or fit on some text data first.")
else:
nb_words = self.nb_words
if mode == "tfidf" and not self.document_count:
raise Exception("Fit the Tokenizer on some data before using tfidf mode")
raise Exception("Fit the Tokenizer on some data before using tfidf mode.")
X = np.zeros((len(sequences), nb_words))
for i, seq in enumerate(sequences):

@ -7,7 +7,7 @@ from six.moves import zip
def to_categorical(y, nb_classes=None):
'''Convert class vector (integers from 0 to nb_classes)
to binary class matrix, for use with categorical_crossentropy
to binary class matrix, for use with categorical_crossentropy.
'''
y = np.asarray(y, dtype='int32')
if not nb_classes:

@ -143,8 +143,8 @@ class ModelToDot(object):
def to_graph(model, **kwargs):
"""
`recursive` controls wether we recursively explore container layers
`show_shape` controls wether the shape is shown in the graph
`recursive` controls whether we recursively explore container layers
`show_shape` controls whether the shape is shown in the graph
"""
return ModelToDot()(model, **kwargs)