tensorflow/models

View on GitHub
research/seq_flow_lite/layers/qrnn_layers.py

Summary

Maintainability
D
2 days
Test Coverage

File qrnn_layers.py has 352 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2020 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: Minor
Found in research/seq_flow_lite/layers/qrnn_layers.py - About 4 hrs to fix

    Function _qrnn_pooling has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

      def _qrnn_pooling(self, multipler, constant):
        """Pooling step computes the internal states for all timesteps."""
        assert multipler.get_shape().as_list() == constant.get_shape().as_list()
    
        gate_static_shape = multipler.get_shape().as_list()
    Severity: Minor
    Found in research/seq_flow_lite/layers/qrnn_layers.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 __init__ has 9 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      def __init__(self,
    Severity: Major
    Found in research/seq_flow_lite/layers/qrnn_layers.py - About 1 hr to fix

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

        def __init__(self,
      Severity: Major
      Found in research/seq_flow_lite/layers/qrnn_layers.py - About 1 hr to fix

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

          def __init__(self,
        Severity: Major
        Found in research/seq_flow_lite/layers/qrnn_layers.py - About 1 hr to fix

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

            def __init__(self,
          Severity: Major
          Found in research/seq_flow_lite/layers/qrnn_layers.py - About 50 mins to fix

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

              def __init__(self,
            Severity: Minor
            Found in research/seq_flow_lite/layers/qrnn_layers.py - About 35 mins to fix

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

                def _create_qrnn_pooling_unidirectional(self, gates, mask):
                  """Create QRNN Pooling in either forward or backward direction."""
                  m1, c1, outgate = self._qrnn_preprocess(gates)
              
                  # For inference zero padding will not be used. Hence sequence length is
              Severity: Minor
              Found in research/seq_flow_lite/layers/qrnn_layers.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

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

                def _qrnn_preprocess(self, gates):
                  """Preprocess the gate inputs to the pooling layer."""
                  assert self.num_gates == len(gates)
                  dim = lambda tensor, index: tensor.get_shape().as_list()[index]
              
              
              Severity: Minor
              Found in research/seq_flow_lite/layers/qrnn_layers.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

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

                    self.backward = QRNNUnidirectionalWithBottleneck(
              Severity: Major
              Found in research/seq_flow_lite/layers/qrnn_layers.py and 3 other locations - About 35 mins to fix
              research/seq_flow_lite/layers/qrnn_layers.py on lines 342..342
              research/seq_flow_lite/layers/qrnn_layers.py on lines 351..351
              research/seq_flow_lite/layers/qrnn_layers.py on lines 363..363

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

                    self.forward = QRNNUnidirectional(
              Severity: Major
              Found in research/seq_flow_lite/layers/qrnn_layers.py and 3 other locations - About 35 mins to fix
              research/seq_flow_lite/layers/qrnn_layers.py on lines 351..351
              research/seq_flow_lite/layers/qrnn_layers.py on lines 363..363
              research/seq_flow_lite/layers/qrnn_layers.py on lines 372..372

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

                    self.backward = QRNNUnidirectional(
              Severity: Major
              Found in research/seq_flow_lite/layers/qrnn_layers.py and 3 other locations - About 35 mins to fix
              research/seq_flow_lite/layers/qrnn_layers.py on lines 342..342
              research/seq_flow_lite/layers/qrnn_layers.py on lines 363..363
              research/seq_flow_lite/layers/qrnn_layers.py on lines 372..372

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

                    self.forward = QRNNUnidirectionalWithBottleneck(
              Severity: Major
              Found in research/seq_flow_lite/layers/qrnn_layers.py and 3 other locations - About 35 mins to fix
              research/seq_flow_lite/layers/qrnn_layers.py on lines 342..342
              research/seq_flow_lite/layers/qrnn_layers.py on lines 351..351
              research/seq_flow_lite/layers/qrnn_layers.py on lines 372..372

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

                  if self.parameters.mode not in [base_layers.PREDICT, base_layers.TFLITE]:
                    inputs = inputs * mask3
              Severity: Major
              Found in research/seq_flow_lite/layers/qrnn_layers.py and 6 other locations - About 30 mins to fix
              research/seq_flow_lite/layers/transformer_layers.py on lines 270..271
              research/seq_flow_lite/layers/transformer_layers.py on lines 275..276
              research/seq_flow_lite/layers/transformer_layers.py on lines 289..290
              research/seq_flow_lite/layers/transformer_layers.py on lines 294..295
              research/seq_flow_lite/layers/transformer_layers.py on lines 464..465
              research/seq_flow_lite/layers/transformer_layers.py on lines 491..492

              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

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

                  post_conv_out = [
                      layer(gates[i]) for i, layer in enumerate(self.post_conv_layers)
              Severity: Minor
              Found in research/seq_flow_lite/layers/qrnn_layers.py and 2 other locations - About 30 mins to fix
              official/nlp/modeling/layers/reuse_attention.py on lines 599..600
              research/seq_flow_lite/layers/qrnn_layers.py on lines 322..322

              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

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

                  gates = [layer(pre_conv_out[i]) for i, layer in enumerate(self.gate_layers)]
              Severity: Minor
              Found in research/seq_flow_lite/layers/qrnn_layers.py and 2 other locations - About 30 mins to fix
              official/nlp/modeling/layers/reuse_attention.py on lines 599..600
              research/seq_flow_lite/layers/qrnn_layers.py on lines 323..324

              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