tensorflow/models

View on GitHub
official/legacy/bert/input_pipeline.py

Summary

Maintainability
D
2 days
Test Coverage

Function create_pretrain_dataset has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

def create_pretrain_dataset(input_patterns,
                            seq_length,
                            max_predictions_per_seq,
                            batch_size,
                            is_training=True,
Severity: Minor
Found in official/legacy/bert/input_pipeline.py - About 2 hrs 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 create_squad_dataset has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

def create_squad_dataset(file_path,
                         seq_length,
                         batch_size,
                         is_training=True,
                         input_pipeline_context=None):
Severity: Minor
Found in official/legacy/bert/input_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 create_pretrain_dataset has 9 arguments (exceeds 4 allowed). Consider refactoring.
Open

def create_pretrain_dataset(input_patterns,
Severity: Major
Found in official/legacy/bert/input_pipeline.py - About 1 hr to fix

    Function create_classifier_dataset has 8 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def create_classifier_dataset(file_path,
    Severity: Major
    Found in official/legacy/bert/input_pipeline.py - About 1 hr to fix

      Function create_squad_dataset has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def create_squad_dataset(file_path,
      Severity: Minor
      Found in official/legacy/bert/input_pipeline.py - About 35 mins to fix

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

        def decode_record(record, name_to_features):
          """Decodes a record to a TensorFlow example."""
          example = tf.io.parse_single_example(record, name_to_features)
        
          # tf.Example only supports tf.int64, but the TPU only supports tf.int32.
        Severity: Major
        Found in official/legacy/bert/input_pipeline.py and 2 other locations - About 5 hrs to fix
        official/legacy/xlnet/data_utils.py on lines 61..73
        official/projects/nhnet/input_pipeline.py on lines 20..32

        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 91.

        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

          if isinstance(input_file, str) or len(input_file) == 1:
            options = tf.data.Options()
            options.experimental_distribute.auto_shard_policy = (
                tf.data.experimental.AutoShardPolicy.OFF)
            d = d.with_options(options)
        Severity: Major
        Found in official/legacy/bert/input_pipeline.py and 1 other location - About 3 hrs to fix
        official/legacy/xlnet/data_utils.py on lines 106..110

        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 63.

        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

          name_to_features = {
              'input_ids': tf.io.FixedLenFeature([seq_length], tf.int64),
              'input_mask': tf.io.FixedLenFeature([seq_length], tf.int64),
              'segment_ids': tf.io.FixedLenFeature([seq_length], tf.int64),
              'label_ids': tf.io.FixedLenFeature([], label_type),
        Severity: Major
        Found in official/legacy/bert/input_pipeline.py and 1 other location - About 3 hrs to fix
        official/nlp/data/classifier_data_lib_test.py on lines 80..84

        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 63.

        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 2 locations. Consider refactoring.
        Open

          name_to_features = {
              'input_ids': tf.io.FixedLenFeature([seq_length], tf.int64),
              'input_mask': tf.io.FixedLenFeature([seq_length], tf.int64),
              'segment_ids': tf.io.FixedLenFeature([seq_length], tf.int64),
        Severity: Major
        Found in official/legacy/bert/input_pipeline.py and 1 other location - About 2 hrs to fix
        official/legacy/bert/serving.py on lines 112..116

        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 52.

        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 5 locations. Consider refactoring.
        Open

          if input_pipeline_context and input_pipeline_context.num_input_pipelines > 1:
            dataset = dataset.shard(input_pipeline_context.num_input_pipelines,
                                    input_pipeline_context.input_pipeline_id)
        Severity: Major
        Found in official/legacy/bert/input_pipeline.py and 4 other locations - About 35 mins to fix
        official/legacy/bert/input_pipeline.py on lines 93..95
        official/legacy/bert/input_pipeline.py on lines 222..224
        official/legacy/bert/input_pipeline.py on lines 267..269
        official/legacy/xlnet/data_utils.py on lines 698..700

        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 33.

        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 5 locations. Consider refactoring.
        Open

          if input_pipeline_context and input_pipeline_context.num_input_pipelines > 1:
            dataset = dataset.shard(input_pipeline_context.num_input_pipelines,
                                    input_pipeline_context.input_pipeline_id)
        Severity: Major
        Found in official/legacy/bert/input_pipeline.py and 4 other locations - About 35 mins to fix
        official/legacy/bert/input_pipeline.py on lines 93..95
        official/legacy/bert/input_pipeline.py on lines 173..175
        official/legacy/bert/input_pipeline.py on lines 222..224
        official/legacy/xlnet/data_utils.py on lines 698..700

        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 33.

        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 5 locations. Consider refactoring.
        Open

          if input_pipeline_context and input_pipeline_context.num_input_pipelines > 1:
            dataset = dataset.shard(input_pipeline_context.num_input_pipelines,
                                    input_pipeline_context.input_pipeline_id)
        Severity: Major
        Found in official/legacy/bert/input_pipeline.py and 4 other locations - About 35 mins to fix
        official/legacy/bert/input_pipeline.py on lines 93..95
        official/legacy/bert/input_pipeline.py on lines 173..175
        official/legacy/bert/input_pipeline.py on lines 267..269
        official/legacy/xlnet/data_utils.py on lines 698..700

        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 33.

        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 5 locations. Consider refactoring.
        Open

          if input_pipeline_context and input_pipeline_context.num_input_pipelines > 1:
            dataset = dataset.shard(input_pipeline_context.num_input_pipelines,
                                    input_pipeline_context.input_pipeline_id)
        Severity: Major
        Found in official/legacy/bert/input_pipeline.py and 4 other locations - About 35 mins to fix
        official/legacy/bert/input_pipeline.py on lines 173..175
        official/legacy/bert/input_pipeline.py on lines 222..224
        official/legacy/bert/input_pipeline.py on lines 267..269
        official/legacy/xlnet/data_utils.py on lines 698..700

        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 33.

        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 2 locations. Consider refactoring.
        Open

          d = d.map(
              lambda record: decode_record(record, name_to_features),
              num_parallel_calls=tf.data.experimental.AUTOTUNE)
        Severity: Minor
        Found in official/legacy/bert/input_pipeline.py and 1 other location - About 30 mins to fix
        official/legacy/xlnet/data_utils.py on lines 98..100

        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 32.

        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