tensorflow/models

View on GitHub
official/recommendation/data_pipeline.py

Summary

Maintainability
F
3 days
Test Coverage

File data_pipeline.py has 752 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2024 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Severity: Major
Found in official/recommendation/data_pipeline.py - About 1 day to fix

    Function __init__ has 38 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      def __init__(
    Severity: Major
    Found in official/recommendation/data_pipeline.py - About 4 hrs to fix

      Function data_generator has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

        def data_generator(self, epochs_between_evals):
          """Yields examples during local training."""
          assert not self._stream_files
          assert self._is_training or epochs_between_evals == 1
      
      
      Severity: Minor
      Found in official/recommendation/data_pipeline.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function __init__ has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def __init__(
            self,
            maximum_number_epochs,  # type: int
            num_users,  # type: int
            num_items,  # type: int
      Severity: Minor
      Found in official/recommendation/data_pipeline.py - About 1 hr to fix

        Function get_dataset has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

          def get_dataset(self, batch_size, epochs_between_evals):
            """Construct the dataset to be used for training and eval.
        
            For local training, data is provided through Dataset.from_generator. For
            remote training (TPUs) the data is first serialized to files and then sent
        Severity: Minor
        Found in official/recommendation/data_pipeline.py - About 55 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function __init__ has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

          def __init__(self,
        Severity: Minor
        Found in official/recommendation/data_pipeline.py - About 45 mins to fix

          Function make_input_fn has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def make_input_fn(self, batch_size):
              """Create an input_fn which checks for batch size consistency."""
          
              def input_fn(params):
                """Returns batches for training."""
          Severity: Minor
          Found in official/recommendation/data_pipeline.py - About 35 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function __init__ has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def __init__(
                self,
                maximum_number_epochs,  # type: int
                num_users,  # type: int
                num_items,  # type: int
          Severity: Minor
          Found in official/recommendation/data_pipeline.py - About 35 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function make_input_fn has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def make_input_fn(is_training):
              """Construct training input_fn that uses synthetic data."""
          
              def input_fn(params):
                """Returns dummy input batches for training."""
          Severity: Minor
          Found in official/recommendation/data_pipeline.py - About 25 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

              inner_bounds = np.argwhere(self._train_pos_users[1:] -
                                         self._train_pos_users[:-1])[:, 0] + 1
          Severity: Major
          Found in official/recommendation/data_pipeline.py and 1 other location - About 1 hr to fix
          official/recommendation/data_pipeline.py on lines 893..894

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 48.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

              inner_bounds = np.argwhere(self._train_pos_users[1:] -
                                         self._train_pos_users[:-1])[:, 0] + 1
          Severity: Major
          Found in official/recommendation/data_pipeline.py and 1 other location - About 1 hr to fix
          official/recommendation/data_pipeline.py on lines 830..831

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 48.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

                  labels = tf.cast(
                      tf.random.uniform([batch_size, 1],
                                        dtype=tf.int32,
                                        minval=0,
                                        maxval=2), tf.bool)
          Severity: Major
          Found in official/recommendation/data_pipeline.py and 2 other locations - About 55 mins to fix
          official/recommendation/data_pipeline.py on lines 755..759
          official/recommendation/data_pipeline.py on lines 771..775

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 37.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

                  dupe_mask = tf.cast(
                      tf.random.uniform([batch_size, 1],
                                        dtype=tf.int32,
                                        minval=0,
                                        maxval=2), tf.bool)
          Severity: Major
          Found in official/recommendation/data_pipeline.py and 2 other locations - About 55 mins to fix
          official/recommendation/data_pipeline.py on lines 755..759
          official/recommendation/data_pipeline.py on lines 760..764

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 37.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

                  valid_point_mask = tf.cast(
                      tf.random.uniform([batch_size, 1],
                                        dtype=tf.int32,
                                        minval=0,
                                        maxval=2), tf.bool)
          Severity: Major
          Found in official/recommendation/data_pipeline.py and 2 other locations - About 55 mins to fix
          official/recommendation/data_pipeline.py on lines 760..764
          official/recommendation/data_pipeline.py on lines 771..775

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 37.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          There are no issues that match your filters.

          Category
          Status