Skip to content

Commit

Permalink
Test init args in documentation (keras-team#12192)
Browse files Browse the repository at this point in the history
* Test init args in documentation

* Impact associated docstrings
  • Loading branch information
RaphaelMeudec authored and gabrieldemarmiesse committed Feb 2, 2019
1 parent e59570a commit a139716
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 13 deletions.
10 changes: 5 additions & 5 deletions keras/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,9 @@ class ModelCheckpoint(Callback):
save_best_only: if `save_best_only=True`,
the latest best model according to
the quantity monitored will not be overwritten.
save_weights_only: if True, then only the model's weights will be
saved (`model.save_weights(filepath)`), else the full model
is saved (`model.save(filepath)`).
mode: one of {auto, min, max}.
If `save_best_only=True`, the decision
to overwrite the current save file is made
Expand All @@ -656,9 +659,6 @@ class ModelCheckpoint(Callback):
this should be `max`, for `val_loss` this should
be `min`, etc. In `auto` mode, the direction is
automatically inferred from the name of the monitored quantity.
save_weights_only: if True, then only the model's weights will be
saved (`model.save_weights(filepath)`), else the full model
is saved (`model.save(filepath)`).
period: Interval (number of epochs) between checkpoints.
"""

Expand Down Expand Up @@ -967,13 +967,13 @@ class TensorBoard(Callback):
and weight histograms for the layers of the model. If set to 0,
histograms won't be computed. Validation data (or split) must be
specified for histogram visualizations.
batch_size: size of batch of inputs to feed to the network
for histograms computation.
write_graph: whether to visualize the graph in TensorBoard.
The log file can become quite large when
write_graph is set to True.
write_grads: whether to visualize gradient histograms in TensorBoard.
`histogram_freq` must be greater than 0.
batch_size: size of batch of inputs to feed to the network
for histograms computation.
write_images: whether to write model weights to visualize as
image in TensorBoard.
embeddings_freq: frequency (in epochs) at which selected embedding
Expand Down
1 change: 1 addition & 0 deletions keras/engine/sequential.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Sequential(Model):
# Arguments
layers: list of layers to add to the model.
name: Name given to the model
# Example
Expand Down
5 changes: 5 additions & 0 deletions keras/layers/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class Masking(Layer):
model.add(Masking(mask_value=0., input_shape=(timesteps, features)))
model.add(LSTM(32))
```
# Arguments
mask_value: Either None or mask value to skip
"""

def __init__(self, mask_value=0., **kwargs):
Expand Down Expand Up @@ -625,6 +628,8 @@ def hadamard_product_sum_output_shape(input_shapes):
`output_shape = (None, ) + output_shape`
If a function, it specifies the entire shape as a function of the
input shape: `output_shape = f(input_shape)`
mask: Either None (indicating no masking) or a Tensor indicating the
input mask for Embedding.
arguments: optional dictionary of keyword arguments to be passed
to the function.
Expand Down
10 changes: 5 additions & 5 deletions keras/layers/cudnn_recurrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,17 +335,17 @@ class CuDNNLSTM(_CuDNNRNN):
kernel_initializer: Initializer for the `kernel` weights matrix,
used for the linear transformation of the inputs.
(see [initializers](../initializers.md)).
unit_forget_bias: Boolean.
If True, add 1 to the bias of the forget gate at initialization.
Setting it to true will also force `bias_initializer="zeros"`.
This is recommended in [Jozefowicz et al. (2015)](
http://www.jmlr.org/proceedings/papers/v37/jozefowicz15.pdf).
recurrent_initializer: Initializer for the `recurrent_kernel`
weights matrix,
used for the linear transformation of the recurrent state.
(see [initializers](../initializers.md)).
bias_initializer: Initializer for the bias vector
(see [initializers](../initializers.md)).
unit_forget_bias: Boolean.
If True, add 1 to the bias of the forget gate at initialization.
Setting it to true will also force `bias_initializer="zeros"`.
This is recommended in [Jozefowicz et al. (2015)](
http://www.jmlr.org/proceedings/papers/v37/jozefowicz15.pdf).
kernel_regularizer: Regularizer function applied to
the `kernel` weights matrix
(see [regularizer](../regularizers.md)).
Expand Down
3 changes: 3 additions & 0 deletions keras/layers/embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class Embedding(Layer):
embeddings_regularizer: Regularizer function applied to
the `embeddings` matrix
(see [regularizer](../regularizers.md)).
activity_regularizer: Regularizer function applied to
the output of the layer (its "activation").
(see [regularizer](../regularizers.md)).
embeddings_constraint: Constraint function applied to
the `embeddings` matrix
(see [constraints](../constraints.md)).
Expand Down
1 change: 1 addition & 0 deletions keras/layers/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class LocallyConnected1D(Layer):
any `dilation_rate` value != 1.
padding: Currently only supports `"valid"` (case-insensitive).
`"same"` may be supported in the future.
data_format: String, one of `channels_first`, `channels_last`.
activation: Activation function to use
(see [activations](../activations.md)).
If you don't specify anything, no activation is applied
Expand Down
2 changes: 2 additions & 0 deletions keras/layers/noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class AlphaDropout(Layer):
rate: float, drop probability (as with `Dropout`).
The multiplicative noise will have
standard deviation `sqrt(rate / (1 - rate))`.
noise_shape: A 1-D `Tensor` of type `int32`, representing the
shape for randomly generated keep/drop flags.
seed: A Python integer to use as random seed.
# Input shape
Expand Down
1 change: 1 addition & 0 deletions keras/layers/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ class Bidirectional(Wrapper):
One of {'sum', 'mul', 'concat', 'ave', None}.
If None, the outputs will not be combined,
they will be returned as a list.
weights: Initial weights to load in the Bidirectional model
# Raises
ValueError: In case of invalid `merge_mode` argument.
Expand Down
10 changes: 8 additions & 2 deletions keras/optimizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,8 @@ class Adamax(Optimizer):
# Arguments
lr: float >= 0. Learning rate.
beta_1/beta_2: floats, 0 < beta < 1. Generally close to 1.
beta_1: floats, 0 < beta < 1. Generally close to 1.
beta_2: floats, 0 < beta < 1. Generally close to 1.
epsilon: float >= 0. Fuzz factor. If `None`, defaults to `K.epsilon()`.
decay: float >= 0. Learning rate decay over each update.
Expand Down Expand Up @@ -614,8 +615,10 @@ class Nadam(Optimizer):
# Arguments
lr: float >= 0. Learning rate.
beta_1/beta_2: floats, 0 < beta < 1. Generally close to 1.
beta_1: floats, 0 < beta < 1. Generally close to 1.
beta_2: floats, 0 < beta < 1. Generally close to 1.
epsilon: float >= 0. Fuzz factor. If `None`, defaults to `K.epsilon()`.
schedule_decay: floats, 0 < schedule_decay < 1.
# References
- [Nadam report](http://cs229.stanford.edu/proj2015/054_report.pdf)
Expand Down Expand Up @@ -694,6 +697,9 @@ def get_config(self):

class TFOptimizer(Optimizer):
"""Wrapper class for native TensorFlow optimizers.
# Arguments
optimizer: Selected optimizer
"""

def __init__(self, optimizer):
Expand Down
2 changes: 1 addition & 1 deletion keras/utils/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ class GeneratorEnqueuer(SequenceEnqueuer):
Used in `fit_generator`, `evaluate_generator`, `predict_generator`.
# Arguments
generator: a generator function which yields data
sequence: a sequence function which yields data
use_multiprocessing: use multiprocessing if True, otherwise threading
wait_time: time to sleep in-between calls to `put()`
random_seed: Initial seed for workers,
Expand Down
11 changes: 11 additions & 0 deletions tests/test_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,24 @@
MIN_CODE_SIZE = 10


def handle_class_init(name, member):
init_args = [
arg for arg in list(inspect.signature(member.__init__).parameters.keys())
if arg not in ['self', 'args', 'kwargs']
]
assert_args_presence(init_args, member.__doc__, member, name)


def handle_class(name, member):
if is_accepted(name, member):
return

if member.__doc__ is None and not member_too_small(member):
raise ValueError("{} class doesn't have any documentation".format(name),
member.__module__, inspect.getmodule(member).__file__)

handle_class_init(name, member)

for n, met in inspect.getmembers(member):
if inspect.ismethod(met):
handle_method(n, met)
Expand Down

0 comments on commit a139716

Please sign in to comment.