The following issues were found

keras/layers/embeddings.py
75 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Embedding layer."""

import tensorflow.compat.v2 as tf
# pylint: disable=g-classes-have-attributes

from keras import backend
from keras import constraints
from keras import initializers

            

Reported by Pylint.

Bad option value 'g-classes-have-attributes'
Error

Line: 18 Column: 1

              """Embedding layer."""

import tensorflow.compat.v2 as tf
# pylint: disable=g-classes-have-attributes

from keras import backend
from keras import constraints
from keras import initializers
from keras import regularizers

            

Reported by Pylint.

Unable to import 'tensorflow.python.util.tf_export'
Error

Line: 27 Column: 1

              from keras.engine import base_layer_utils
from keras.engine.base_layer import Layer
from keras.utils import tf_utils
from tensorflow.python.util.tf_export import keras_export


@keras_export('keras.layers.Embedding')
class Embedding(Layer):
  """Turns positive integers (indexes) into dense vectors of fixed size.

            

Reported by Pylint.

Attribute 'embeddings' defined outside __init__
Error

Line: 149 Column: 5

              
  @tf_utils.shape_type_conversion
  def build(self, input_shape=None):
    self.embeddings = self.add_weight(
        shape=(self.input_dim, self.output_dim),
        initializer=self.embeddings_initializer,
        name='embeddings',
        regularizer=self.embeddings_regularizer,
        constraint=self.embeddings_constraint,

            

Reported by Pylint.

Parameters differ from overridden 'call' method
Error

Line: 187 Column: 3

                          in_lens[i] = s2
      return (input_shape[0],) + tuple(in_lens) + (self.output_dim,)

  def call(self, inputs):
    dtype = backend.dtype(inputs)
    if dtype != 'int32' and dtype != 'int64':
      inputs = tf.cast(inputs, 'int32')
    out = tf.nn.embedding_lookup(self.embeddings, inputs)
    if self._dtype_policy.compute_dtype != self._dtype_policy.variable_dtype:

            

Reported by Pylint.

Too many instance attributes (11/7)
Error

Line: 31 Column: 1

              

@keras_export('keras.layers.Embedding')
class Embedding(Layer):
  """Turns positive integers (indexes) into dense vectors of fixed size.

  e.g. `[[4], [20]] -> [[0.25, 0.1], [0.6, -0.2]]`

  This layer can only be used as the first layer in a model.

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 32 Column: 1

              
@keras_export('keras.layers.Embedding')
class Embedding(Layer):
  """Turns positive integers (indexes) into dense vectors of fixed size.

  e.g. `[[4], [20]] -> [[0.25, 0.1], [0.6, -0.2]]`

  This layer can only be used as the first layer in a model.


            

Reported by Pylint.

Too many arguments (9/5)
Error

Line: 106 Column: 3

                (e.g. `x = embedding_layer(x)`), or used in a subclassed model.
  """

  def __init__(self,
               input_dim,
               output_dim,
               embeddings_initializer='uniform',
               embeddings_regularizer=None,
               activity_regularizer=None,

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 106 Column: 1

                (e.g. `x = embedding_layer(x)`), or used in a subclassed model.
  """

  def __init__(self,
               input_dim,
               output_dim,
               embeddings_initializer='uniform',
               embeddings_regularizer=None,
               activity_regularizer=None,

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 116 Column: 1

                             mask_zero=False,
               input_length=None,
               **kwargs):
    if 'input_shape' not in kwargs:
      if input_length:
        kwargs['input_shape'] = (input_length,)
      else:
        kwargs['input_shape'] = (None,)
    if input_dim <= 0 or output_dim <= 0:

            

Reported by Pylint.

keras/initializers/__init__.py
73 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Keras initializer serialization / deserialization."""

import tensorflow.compat.v2 as tf

import threading

from tensorflow.python import tf2
from keras.initializers import initializers_v1

            

Reported by Pylint.

Unable to import 'tensorflow.python'
Error

Line: 21 Column: 1

              
import threading

from tensorflow.python import tf2
from keras.initializers import initializers_v1
from keras.initializers import initializers_v2
from keras.utils import generic_utils
from keras.utils import tf_inspect as inspect
from tensorflow.python.ops import init_ops

            

Reported by Pylint.

Unable to import 'tensorflow.python.ops'
Error

Line: 26 Column: 1

              from keras.initializers import initializers_v2
from keras.utils import generic_utils
from keras.utils import tf_inspect as inspect
from tensorflow.python.ops import init_ops
from tensorflow.python.util.tf_export import keras_export


# LOCAL.ALL_OBJECTS is meant to be a global mutable. Hence we need to make it
# thread-local to avoid concurrent mutations.

            

Reported by Pylint.

Unable to import 'tensorflow.python.util.tf_export'
Error

Line: 27 Column: 1

              from keras.utils import generic_utils
from keras.utils import tf_inspect as inspect
from tensorflow.python.ops import init_ops
from tensorflow.python.util.tf_export import keras_export


# LOCAL.ALL_OBJECTS is meant to be a global mutable. Hence we need to make it
# thread-local to avoid concurrent mutations.
LOCAL = threading.local()

            

Reported by Pylint.

Using the global statement
Error

Line: 38 Column: 3

              def populate_deserializable_objects():
  """Populates dict ALL_OBJECTS with every built-in initializer.
  """
  global LOCAL
  if not hasattr(LOCAL, 'ALL_OBJECTS'):
    LOCAL.ALL_OBJECTS = {}
    LOCAL.GENERATED_WITH_V2 = None

  if LOCAL.ALL_OBJECTS and LOCAL.GENERATED_WITH_V2 == tf.__internal__.tf2.enabled():

            

Reported by Pylint.

standard import "import threading" should be placed before "import tensorflow.compat.v2 as tf"
Error

Line: 19 Column: 1

              
import tensorflow.compat.v2 as tf

import threading

from tensorflow.python import tf2
from keras.initializers import initializers_v1
from keras.initializers import initializers_v2
from keras.utils import generic_utils

            

Reported by Pylint.

Imports from package tensorflow are not grouped
Error

Line: 26 Column: 1

              from keras.initializers import initializers_v2
from keras.utils import generic_utils
from keras.utils import tf_inspect as inspect
from tensorflow.python.ops import init_ops
from tensorflow.python.util.tf_export import keras_export


# LOCAL.ALL_OBJECTS is meant to be a global mutable. Hence we need to make it
# thread-local to avoid concurrent mutations.

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 36 Column: 1

              

def populate_deserializable_objects():
  """Populates dict ALL_OBJECTS with every built-in initializer.
  """
  global LOCAL
  if not hasattr(LOCAL, 'ALL_OBJECTS'):
    LOCAL.ALL_OBJECTS = {}
    LOCAL.GENERATED_WITH_V2 = None

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 38 Column: 1

              def populate_deserializable_objects():
  """Populates dict ALL_OBJECTS with every built-in initializer.
  """
  global LOCAL
  if not hasattr(LOCAL, 'ALL_OBJECTS'):
    LOCAL.ALL_OBJECTS = {}
    LOCAL.GENERATED_WITH_V2 = None

  if LOCAL.ALL_OBJECTS and LOCAL.GENERATED_WITH_V2 == tf.__internal__.tf2.enabled():

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 39 Column: 1

                """Populates dict ALL_OBJECTS with every built-in initializer.
  """
  global LOCAL
  if not hasattr(LOCAL, 'ALL_OBJECTS'):
    LOCAL.ALL_OBJECTS = {}
    LOCAL.GENERATED_WITH_V2 = None

  if LOCAL.ALL_OBJECTS and LOCAL.GENERATED_WITH_V2 == tf.__internal__.tf2.enabled():
    # Objects dict is already generated for the proper TF version:

            

Reported by Pylint.

keras/layers/separable_convolutional_test.py
73 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Tests for separable convolutional layers."""

import tensorflow.compat.v2 as tf

from absl.testing import parameterized
import numpy as np

import keras

            

Reported by Pylint.

Unable to import 'absl.testing'
Error

Line: 19 Column: 1

              
import tensorflow.compat.v2 as tf

from absl.testing import parameterized
import numpy as np

import keras
from keras import keras_parameterized
from keras import testing_utils

            

Reported by Pylint.

TODO(b/62340061): Support channels_first on CPU.
Error

Line: 116 Column: 3

                    ('padding_same_dilation_2', {'padding': 'same', 'dilation_rate': 2}),
      ('strides', {'strides': 2}),
      # Only runs on GPU with CUDA, channels_first is not supported on CPU.
      # TODO(b/62340061): Support channels_first on CPU.
      ('data_format', {'data_format': 'channels_first'}),
      ('dilation_rate', {'dilation_rate': 2}),
      ('depth_multiplier', {'depth_multiplier': 2}),
  )
  def test_separable_conv2d(self, kwargs):

            

Reported by Pylint.

Missing class docstring
Error

Line: 28 Column: 1

              

@keras_parameterized.run_all_keras_modes
class SeparableConv1DTest(keras_parameterized.TestCase):

  def _run_test(self, kwargs):
    num_samples = 2
    stack_size = 3
    length = 7

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 30 Column: 1

              @keras_parameterized.run_all_keras_modes
class SeparableConv1DTest(keras_parameterized.TestCase):

  def _run_test(self, kwargs):
    num_samples = 2
    stack_size = 3
    length = 7

    with self.cached_session():

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 31 Column: 1

              class SeparableConv1DTest(keras_parameterized.TestCase):

  def _run_test(self, kwargs):
    num_samples = 2
    stack_size = 3
    length = 7

    with self.cached_session():
      testing_utils.layer_test(

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 32 Column: 1

              
  def _run_test(self, kwargs):
    num_samples = 2
    stack_size = 3
    length = 7

    with self.cached_session():
      testing_utils.layer_test(
          keras.layers.SeparableConv1D,

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 33 Column: 1

                def _run_test(self, kwargs):
    num_samples = 2
    stack_size = 3
    length = 7

    with self.cached_session():
      testing_utils.layer_test(
          keras.layers.SeparableConv1D,
          kwargs=kwargs,

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 35 Column: 1

                  stack_size = 3
    length = 7

    with self.cached_session():
      testing_utils.layer_test(
          keras.layers.SeparableConv1D,
          kwargs=kwargs,
          input_shape=(num_samples, length, stack_size))


            

Reported by Pylint.

Bad indentation. Found 6 spaces, expected 12
Style

Line: 36 Column: 1

                  length = 7

    with self.cached_session():
      testing_utils.layer_test(
          keras.layers.SeparableConv1D,
          kwargs=kwargs,
          input_shape=(num_samples, length, stack_size))

  @parameterized.named_parameters(

            

Reported by Pylint.

keras/layers/preprocessing/benchmarks/normalization_adapt_benchmark.py
72 issues
Unable to import 'tensorflow'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Benchmark for Keras text vectorization preprocessing layer's adapt method."""

import tensorflow as tf

import time

import numpy as np


            

Reported by Pylint.

Unable to import 'keras'
Error

Line: 23 Column: 1

              
import numpy as np

import keras
from keras.layers.preprocessing import normalization

tf.compat.v1.enable_v2_behavior()



            

Reported by Pylint.

Unable to import 'keras.layers.preprocessing'
Error

Line: 24 Column: 1

              import numpy as np

import keras
from keras.layers.preprocessing import normalization

tf.compat.v1.enable_v2_behavior()


def reduce_fn(state, values):

            

Reported by Pylint.

standard import "import time" should be placed before "import tensorflow as tf"
Error

Line: 19 Column: 1

              
import tensorflow as tf

import time

import numpy as np

import keras
from keras.layers.preprocessing import normalization

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 30 Column: 1

              

def reduce_fn(state, values):
  """tf.data.Dataset-friendly implementation of mean and variance."""
  k, n, ex, ex2 = state
  # If this is the first iteration, we pick the first value to be 'k',
  # which helps with precision - we assume that k is close to an average
  # value and calculate mean and variance with respect to that.
  k = tf.cond(tf.equal(n, 0), lambda: values[0], lambda: k)

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 31 Column: 1

              
def reduce_fn(state, values):
  """tf.data.Dataset-friendly implementation of mean and variance."""
  k, n, ex, ex2 = state
  # If this is the first iteration, we pick the first value to be 'k',
  # which helps with precision - we assume that k is close to an average
  # value and calculate mean and variance with respect to that.
  k = tf.cond(tf.equal(n, 0), lambda: values[0], lambda: k)


            

Reported by Pylint.

Variable name "n" doesn't conform to snake_case naming style
Error

Line: 31 Column: 6

              
def reduce_fn(state, values):
  """tf.data.Dataset-friendly implementation of mean and variance."""
  k, n, ex, ex2 = state
  # If this is the first iteration, we pick the first value to be 'k',
  # which helps with precision - we assume that k is close to an average
  # value and calculate mean and variance with respect to that.
  k = tf.cond(tf.equal(n, 0), lambda: values[0], lambda: k)


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 35 Column: 1

                # If this is the first iteration, we pick the first value to be 'k',
  # which helps with precision - we assume that k is close to an average
  # value and calculate mean and variance with respect to that.
  k = tf.cond(tf.equal(n, 0), lambda: values[0], lambda: k)

  sum_v = tf.reduce_sum(values, axis=0)
  sum_v2 = tf.reduce_sum(tf.square(values), axis=0)
  ones = tf.ones_like(values, dtype=tf.int32)
  batch_size = tf.reduce_sum(ones, axis=0)

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 37 Column: 1

                # value and calculate mean and variance with respect to that.
  k = tf.cond(tf.equal(n, 0), lambda: values[0], lambda: k)

  sum_v = tf.reduce_sum(values, axis=0)
  sum_v2 = tf.reduce_sum(tf.square(values), axis=0)
  ones = tf.ones_like(values, dtype=tf.int32)
  batch_size = tf.reduce_sum(ones, axis=0)
  batch_size_f = tf.cast(batch_size, tf.float32)


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 38 Column: 1

                k = tf.cond(tf.equal(n, 0), lambda: values[0], lambda: k)

  sum_v = tf.reduce_sum(values, axis=0)
  sum_v2 = tf.reduce_sum(tf.square(values), axis=0)
  ones = tf.ones_like(values, dtype=tf.int32)
  batch_size = tf.reduce_sum(ones, axis=0)
  batch_size_f = tf.cast(batch_size, tf.float32)

  ex = 0 + sum_v - tf.multiply(batch_size_f, k)

            

Reported by Pylint.

keras/layers/recurrent_v2_test.py
72 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 20 Column: 1

              See also: lstm_v2_test.py, gru_v2_test.py.
"""

import tensorflow.compat.v2 as tf

import os
from absl.testing import parameterized
import numpy as np


            

Reported by Pylint.

Unable to import 'absl.testing'
Error

Line: 23 Column: 1

              import tensorflow.compat.v2 as tf

import os
from absl.testing import parameterized
import numpy as np

import keras
from keras import keras_parameterized
from keras import testing_utils

            

Reported by Pylint.

Module 'numpy.random' has no 'RandomState' member
Error

Line: 116 Column: 9

                def test_ragged(self, layer):
    vocab_size = 100
    inputs = tf.ragged.constant(
        np.random.RandomState(0).randint(0, vocab_size, [128, 25]))
    embedder = embeddings.Embedding(input_dim=vocab_size, output_dim=16)
    embedded_inputs = embedder(inputs)
    lstm = layer(32)
    lstm(embedded_inputs)


            

Reported by Pylint.

standard import "import os" should be placed before "import tensorflow.compat.v2 as tf"
Error

Line: 22 Column: 1

              
import tensorflow.compat.v2 as tf

import os
from absl.testing import parameterized
import numpy as np

import keras
from keras import keras_parameterized

            

Reported by Pylint.

Missing class docstring
Error

Line: 34 Column: 1

              

@keras_parameterized.run_all_keras_modes
class RNNV2Test(keras_parameterized.TestCase):

  @parameterized.parameters([rnn_v2.LSTM, rnn_v2.GRU])
  def test_device_placement(self, layer):
    if not tf.test.is_gpu_available():
      self.skipTest('Need GPU for testing.')

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 36 Column: 1

              @keras_parameterized.run_all_keras_modes
class RNNV2Test(keras_parameterized.TestCase):

  @parameterized.parameters([rnn_v2.LSTM, rnn_v2.GRU])
  def test_device_placement(self, layer):
    if not tf.test.is_gpu_available():
      self.skipTest('Need GPU for testing.')
    vocab_size = 20
    embedding_dim = 10

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 37 Column: 1

              class RNNV2Test(keras_parameterized.TestCase):

  @parameterized.parameters([rnn_v2.LSTM, rnn_v2.GRU])
  def test_device_placement(self, layer):
    if not tf.test.is_gpu_available():
      self.skipTest('Need GPU for testing.')
    vocab_size = 20
    embedding_dim = 10
    batch_size = 8

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 37 Column: 3

              class RNNV2Test(keras_parameterized.TestCase):

  @parameterized.parameters([rnn_v2.LSTM, rnn_v2.GRU])
  def test_device_placement(self, layer):
    if not tf.test.is_gpu_available():
      self.skipTest('Need GPU for testing.')
    vocab_size = 20
    embedding_dim = 10
    batch_size = 8

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 38 Column: 1

              
  @parameterized.parameters([rnn_v2.LSTM, rnn_v2.GRU])
  def test_device_placement(self, layer):
    if not tf.test.is_gpu_available():
      self.skipTest('Need GPU for testing.')
    vocab_size = 20
    embedding_dim = 10
    batch_size = 8
    timestep = 12

            

Reported by Pylint.

Bad indentation. Found 6 spaces, expected 12
Style

Line: 39 Column: 1

                @parameterized.parameters([rnn_v2.LSTM, rnn_v2.GRU])
  def test_device_placement(self, layer):
    if not tf.test.is_gpu_available():
      self.skipTest('Need GPU for testing.')
    vocab_size = 20
    embedding_dim = 10
    batch_size = 8
    timestep = 12
    units = 5

            

Reported by Pylint.

keras/distribute/simple_models.py
72 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""A simple functional keras model with one layer."""

import tensorflow.compat.v2 as tf

import numpy as np

import keras
from keras.distribute import model_collection_base

            

Reported by Pylint.

Unused argument 'kwargs'
Error

Line: 40 Column: 1

              class SimpleFunctionalModel(model_collection_base.ModelAndInput):
  """A simple functional model and its inputs."""

  def get_model(self, **kwargs):
    output_name = 'output_1'

    x = keras.layers.Input(shape=(3,), dtype=tf.float32)
    y = keras.layers.Dense(5, dtype=tf.float32, name=output_name)(x)


            

Reported by Pylint.

Unused argument 'kwargs'
Error

Line: 65 Column: 1

              class SimpleSequentialModel(model_collection_base.ModelAndInput):
  """A simple sequential model and its inputs."""

  def get_model(self, **kwargs):
    output_name = 'output_1'

    model = keras.Sequential()
    y = keras.layers.Dense(
        5, dtype=tf.float32, name=output_name, input_dim=3)

            

Reported by Pylint.

Method 'get_config' is abstract in class 'Model' but is not overridden
Error

Line: 87 Column: 1

                  return _BATCH_SIZE


class _SimpleModel(keras.Model):

  def __init__(self):
    super(_SimpleModel, self).__init__()
    self._dense_layer = keras.layers.Dense(5, dtype=tf.float32)


            

Reported by Pylint.

Parameters differ from overridden 'call' method
Error

Line: 93 Column: 3

                  super(_SimpleModel, self).__init__()
    self._dense_layer = keras.layers.Dense(5, dtype=tf.float32)

  def call(self, inputs):
    return self._dense_layer(inputs)


class SimpleSubclassModel(model_collection_base.ModelAndInput):
  """A simple subclass model and its data."""

            

Reported by Pylint.

Unused argument 'kwargs'
Error

Line: 100 Column: 1

              class SimpleSubclassModel(model_collection_base.ModelAndInput):
  """A simple subclass model and its data."""

  def get_model(self, **kwargs):
    model = _SimpleModel()
    optimizer = gradient_descent.SGD(learning_rate=0.001)
    model.compile(
        loss='mse',
        metrics=['mae'],

            

Reported by Pylint.

Unused argument 'kwargs'
Error

Line: 131 Column: 1

              class SimpleTFModuleModel(model_collection_base.ModelAndInput):
  """A simple model based on tf.Module and its data."""

  def get_model(self, **kwargs):
    model = _SimpleModule()
    return model

  def get_data(self):
    return _get_data_for_simple_models()

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 29 Column: 1

              

def _get_data_for_simple_models():
  x_train = tf.constant(np.random.rand(1000, 3), dtype=tf.float32)
  y_train = tf.constant(np.random.rand(1000, 5), dtype=tf.float32)
  x_predict = tf.constant(
      np.random.rand(1000, 3), dtype=tf.float32)

  return x_train, y_train, x_predict

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 30 Column: 1

              
def _get_data_for_simple_models():
  x_train = tf.constant(np.random.rand(1000, 3), dtype=tf.float32)
  y_train = tf.constant(np.random.rand(1000, 5), dtype=tf.float32)
  x_predict = tf.constant(
      np.random.rand(1000, 3), dtype=tf.float32)

  return x_train, y_train, x_predict


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 31 Column: 1

              def _get_data_for_simple_models():
  x_train = tf.constant(np.random.rand(1000, 3), dtype=tf.float32)
  y_train = tf.constant(np.random.rand(1000, 5), dtype=tf.float32)
  x_predict = tf.constant(
      np.random.rand(1000, 3), dtype=tf.float32)

  return x_train, y_train, x_predict



            

Reported by Pylint.

keras/layers/preprocessing/benchmarks/index_lookup_adapt_benchmark.py
71 issues
Unable to import 'tensorflow'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Benchmark for Keras text vectorization preprocessing layer's adapt method."""

import tensorflow as tf

import collections
import itertools
import random
import string

            

Reported by Pylint.

Unable to import 'keras'
Error

Line: 27 Column: 1

              
import numpy as np

import keras
from keras.layers.preprocessing import index_lookup

tf.compat.v1.enable_v2_behavior()



            

Reported by Pylint.

Unable to import 'keras.layers.preprocessing'
Error

Line: 28 Column: 1

              import numpy as np

import keras
from keras.layers.preprocessing import index_lookup

tf.compat.v1.enable_v2_behavior()


# word_gen creates random sequences of ASCII letters (both lowercase and upper).

            

Reported by Pylint.

standard import "import collections" should be placed before "import tensorflow as tf"
Error

Line: 19 Column: 1

              
import tensorflow as tf

import collections
import itertools
import random
import string
import time


            

Reported by Pylint.

standard import "import itertools" should be placed before "import tensorflow as tf"
Error

Line: 20 Column: 1

              import tensorflow as tf

import collections
import itertools
import random
import string
import time

import numpy as np

            

Reported by Pylint.

standard import "import random" should be placed before "import tensorflow as tf"
Error

Line: 21 Column: 1

              
import collections
import itertools
import random
import string
import time

import numpy as np


            

Reported by Pylint.

standard import "import string" should be placed before "import tensorflow as tf"
Error

Line: 22 Column: 1

              import collections
import itertools
import random
import string
import time

import numpy as np

import keras

            

Reported by Pylint.

standard import "import time" should be placed before "import tensorflow as tf"
Error

Line: 23 Column: 1

              import itertools
import random
import string
import time

import numpy as np

import keras
from keras.layers.preprocessing import index_lookup

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 35 Column: 1

              
# word_gen creates random sequences of ASCII letters (both lowercase and upper).
# The number of unique strings is ~2,700.
def word_gen():
  for _ in itertools.count(1):
    yield "".join(random.choice(string.ascii_letters) for i in range(2))


def get_top_k(dataset, k):

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 36 Column: 1

              # word_gen creates random sequences of ASCII letters (both lowercase and upper).
# The number of unique strings is ~2,700.
def word_gen():
  for _ in itertools.count(1):
    yield "".join(random.choice(string.ascii_letters) for i in range(2))


def get_top_k(dataset, k):
  """Python implementation of vocabulary building using a defaultdict."""

            

Reported by Pylint.

keras/utils/kpl_test_utils.py
71 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Test related utilities for KPL + tf.distribute."""

import tensorflow.compat.v2 as tf

import random
import tempfile

import keras

            

Reported by Pylint.

Bad option value 'g-long-lambda'
Error

Line: 104 Column: 1

                          "label": tf.TensorSpec([1], tf.string)
        }).shuffle(100).batch(32)

    train_dataset = raw_dataset.map(lambda x: (  # pylint: disable=g-long-lambda
        {
            "features": feature_mapper(x["features"])
        }, label_mapper(x["label"])))
    return train_dataset


            

Reported by Pylint.

standard import "import random" should be placed before "import tensorflow.compat.v2 as tf"
Error

Line: 19 Column: 1

              
import tensorflow.compat.v2 as tf

import random
import tempfile

import keras
from keras.layers.preprocessing import string_lookup


            

Reported by Pylint.

standard import "import tempfile" should be placed before "import tensorflow.compat.v2 as tf"
Error

Line: 20 Column: 1

              import tensorflow.compat.v2 as tf

import random
import tempfile

import keras
from keras.layers.preprocessing import string_lookup



            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 27 Column: 1

              

class DistributeKplTestUtils(tf.test.TestCase):
  """Utils for test of tf.distribute + KPL."""
  FEATURE_VOCAB = [
      "avenger", "ironman", "batman", "hulk", "spiderman", "kingkong",
      "wonder_woman"
  ]
  LABEL_VOCAB = ["yes", "no"]

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 28 Column: 1

              
class DistributeKplTestUtils(tf.test.TestCase):
  """Utils for test of tf.distribute + KPL."""
  FEATURE_VOCAB = [
      "avenger", "ironman", "batman", "hulk", "spiderman", "kingkong",
      "wonder_woman"
  ]
  LABEL_VOCAB = ["yes", "no"]


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 32 Column: 1

                    "avenger", "ironman", "batman", "hulk", "spiderman", "kingkong",
      "wonder_woman"
  ]
  LABEL_VOCAB = ["yes", "no"]

  def define_kpls_for_training(self, use_adapt):
    """Function that defines KPL used for unit tests of tf.distribute.

    Args:

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 34 Column: 1

                ]
  LABEL_VOCAB = ["yes", "no"]

  def define_kpls_for_training(self, use_adapt):
    """Function that defines KPL used for unit tests of tf.distribute.

    Args:
      use_adapt: if adapt will be called. False means there will be precomputed
        statistics.

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 35 Column: 1

                LABEL_VOCAB = ["yes", "no"]

  def define_kpls_for_training(self, use_adapt):
    """Function that defines KPL used for unit tests of tf.distribute.

    Args:
      use_adapt: if adapt will be called. False means there will be precomputed
        statistics.


            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 47 Column: 1

                    label_mapper: similar to feature_mapper, but maps label to index.

    """
    if use_adapt:
      feature_lookup_layer = (
          string_lookup.StringLookup(
              num_oov_indices=1))
      feature_lookup_layer.adapt(self.FEATURE_VOCAB)
      label_lookup_layer = (

            

Reported by Pylint.

keras/layers/preprocessing/benchmarks/hashing_benchmark.py
70 issues
Unable to import 'tensorflow'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Benchmark for Keras hashing preprocessing layer."""

import tensorflow as tf

import itertools
import random
import string
import time

            

Reported by Pylint.

Unable to import 'keras'
Error

Line: 26 Column: 1

              
import numpy as np

import keras
from keras.layers.preprocessing import hashing

tf.compat.v1.enable_v2_behavior()



            

Reported by Pylint.

Unable to import 'keras.layers.preprocessing'
Error

Line: 27 Column: 1

              import numpy as np

import keras
from keras.layers.preprocessing import hashing

tf.compat.v1.enable_v2_behavior()


# word_gen creates random sequences of ASCII letters (both lowercase and upper).

            

Reported by Pylint.

standard import "import itertools" should be placed before "import tensorflow as tf"
Error

Line: 19 Column: 1

              
import tensorflow as tf

import itertools
import random
import string
import time

import numpy as np

            

Reported by Pylint.

standard import "import random" should be placed before "import tensorflow as tf"
Error

Line: 20 Column: 1

              import tensorflow as tf

import itertools
import random
import string
import time

import numpy as np


            

Reported by Pylint.

standard import "import string" should be placed before "import tensorflow as tf"
Error

Line: 21 Column: 1

              
import itertools
import random
import string
import time

import numpy as np

import keras

            

Reported by Pylint.

standard import "import time" should be placed before "import tensorflow as tf"
Error

Line: 22 Column: 1

              import itertools
import random
import string
import time

import numpy as np

import keras
from keras.layers.preprocessing import hashing

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 34 Column: 1

              
# word_gen creates random sequences of ASCII letters (both lowercase and upper).
# The number of unique strings is ~2,700.
def word_gen():
  for _ in itertools.count(1):
    yield "".join(random.choice(string.ascii_letters) for i in range(2))


class BenchmarkLayer(tf.test.Benchmark):

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 35 Column: 1

              # word_gen creates random sequences of ASCII letters (both lowercase and upper).
# The number of unique strings is ~2,700.
def word_gen():
  for _ in itertools.count(1):
    yield "".join(random.choice(string.ascii_letters) for i in range(2))


class BenchmarkLayer(tf.test.Benchmark):
  """Benchmark the layer forward pass."""

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 36 Column: 1

              # The number of unique strings is ~2,700.
def word_gen():
  for _ in itertools.count(1):
    yield "".join(random.choice(string.ascii_letters) for i in range(2))


class BenchmarkLayer(tf.test.Benchmark):
  """Benchmark the layer forward pass."""


            

Reported by Pylint.

keras/layers/preprocessing/benchmarks/category_crossing_benchmark.py
69 issues
Unable to import 'tensorflow'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Benchmark for Keras categorical_encoding preprocessing layer."""

import tensorflow as tf

import itertools
import time

import numpy as np

            

Reported by Pylint.

Unable to import 'keras'
Error

Line: 24 Column: 1

              
import numpy as np

import keras
from keras.layers.preprocessing import category_crossing

tf.compat.v1.enable_v2_behavior()



            

Reported by Pylint.

Unable to import 'keras.layers.preprocessing'
Error

Line: 25 Column: 1

              import numpy as np

import keras
from keras.layers.preprocessing import category_crossing

tf.compat.v1.enable_v2_behavior()


# word_gen creates random sequences of ASCII letters (both lowercase and upper).

            

Reported by Pylint.

standard import "import itertools" should be placed before "import tensorflow as tf"
Error

Line: 19 Column: 1

              
import tensorflow as tf

import itertools
import time

import numpy as np

import keras

            

Reported by Pylint.

standard import "import time" should be placed before "import tensorflow as tf"
Error

Line: 20 Column: 1

              import tensorflow as tf

import itertools
import time

import numpy as np

import keras
from keras.layers.preprocessing import category_crossing

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 32 Column: 1

              
# word_gen creates random sequences of ASCII letters (both lowercase and upper).
# The number of unique strings is ~2,700.
def int_gen():
  for _ in itertools.count(1):
    yield (np.random.randint(0, 5, (1,)), np.random.randint(0, 7, (1,)))


class BenchmarkLayer(tf.test.Benchmark):

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 33 Column: 1

              # word_gen creates random sequences of ASCII letters (both lowercase and upper).
# The number of unique strings is ~2,700.
def int_gen():
  for _ in itertools.count(1):
    yield (np.random.randint(0, 5, (1,)), np.random.randint(0, 7, (1,)))


class BenchmarkLayer(tf.test.Benchmark):
  """Benchmark the layer forward pass."""

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 34 Column: 1

              # The number of unique strings is ~2,700.
def int_gen():
  for _ in itertools.count(1):
    yield (np.random.randint(0, 5, (1,)), np.random.randint(0, 7, (1,)))


class BenchmarkLayer(tf.test.Benchmark):
  """Benchmark the layer forward pass."""


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 38 Column: 1

              

class BenchmarkLayer(tf.test.Benchmark):
  """Benchmark the layer forward pass."""

  def run_dataset_implementation(self, batch_size):
    num_repeats = 5
    starts = []
    ends = []

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 40 Column: 3

              class BenchmarkLayer(tf.test.Benchmark):
  """Benchmark the layer forward pass."""

  def run_dataset_implementation(self, batch_size):
    num_repeats = 5
    starts = []
    ends = []
    for _ in range(num_repeats):
      ds = tf.data.Dataset.from_generator(

            

Reported by Pylint.