<commit_before>from __future__ import print_function
import numpy as np
import theano


def print_layer_shapes(model, input_shape):
    """
    Utility function that prints the shape of the output at each layer.

    Arguments:
        model: An instance of models.Model
        input_shape: The shape of the input you will provide to the model.
    """
    input_var = model.get_input(train=False)
    input_tmp = np.zeros(input_shape, dtype=np.float32)
    print("input shape : ", input_shape)
    for l in model.layers:
        shape_f = theano.function([input_var], l.get_output(train=False).shape)
        out_shape = shape_f(input_tmp)
        print('shape after', l.get_config()['name'], ":", out_shape)<commit_msg>Add check to print_layer_shapes to fail explicitely on model used connected to other models.<commit_after>from __future__ import print_function
import numpy as np
import theano


def print_layer_shapes(model, input_shape):
    """
    Utility function that prints the shape of the output at each layer.

    Arguments:
        model: An instance of models.Model
        input_shape: The shape of the input you will provide to the model.
    """
    # This is to handle the case where a model has been connected to a previous
    # layer (and therefore get_input would recurse into previous layer's
    # output).
    if hasattr(model.layers[0], 'previous'):
        # TODO: If the model is used as a part of another model, get_input will
        # return the input of the whole model and this won't work. So this is
        # not handled yet
        raise Exception("This function doesn't work on model used as subparts "
                        " for other models")

    input_var = model.get_input(train=False)
    input_tmp = np.zeros(input_shape, dtype=np.float32)
    print("input shape : ", input_shape)
    for l in model.layers:
        shape_f = theano.function([input_var], l.get_output(train=False).shape)
        out_shape = shape_f(input_tmp)
        print('shape after', l.get_config()['name'], ":", out_shape)
{'fraction_non_alphanumeric': 0.08455522971652003, 'fraction_numerical': 0.0024437927663734115, 'mean_word_length': 3.2032854209445585, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4120425', 'n_tokens_mistral': 592, 'n_tokens_neox': 577, 'n_words': 212}