RasaHQ/rasa_core

View on GitHub
rasa/core/policies/tf_utils.py

Summary

Maintainability
F
3 days
Test Coverage

File tf_utils.py has 679 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from collections import namedtuple
import tensorflow as tf


class TimedNTM(object):
Severity: Major
Found in rasa/core/policies/tf_utils.py - About 1 day to fix

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

        def call(self, inputs, state):
            """Perform a step of attention-wrapped RNN.
    
            The order has changed:
            - Step 1: Calculate attention inputs based on the previous cell state
    Severity: Minor
    Found in rasa/core/policies/tf_utils.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 17 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, cell,
    Severity: Major
    Found in rasa/core/policies/tf_utils.py - About 2 hrs to fix

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

          def __init__(self, cell,
                       attention_mechanism,
                       sequence_len,
                       attn_shift_range=0,
                       sparse_attention=False,
      Severity: Minor
      Found in rasa/core/policies/tf_utils.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 11 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(self,
      Severity: Major
      Found in rasa/core/policies/tf_utils.py - About 1 hr to fix

        Function _compute_time_attention has 9 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def _compute_time_attention(attention_mechanism, attn_inputs, attention_state,
        Severity: Major
        Found in rasa/core/policies/tf_utils.py - About 1 hr to fix

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

              def __call__(self, attn_inputs, scores, scores_state, mask):
                  # apply exponential moving average with interpolation gate weight
                  # to scores from previous time which are equal to probs at this point
                  # different from original NTM where it is applied after softmax
                  i_g = self._inter_gate(attn_inputs)
          Severity: Minor
          Found in rasa/core/policies/tf_utils.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 zero_state has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def zero_state(self, batch_size, dtype):
                  """Modified  from tensorflow's zero_state
                      see there for description of the parameters"""
          
                  # use AttentionWrapperState from superclass
          Severity: Minor
          Found in rasa/core/policies/tf_utils.py - About 45 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 _new_next_cell_state has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def _new_next_cell_state(self, prev_all_cell_states,
          Severity: Minor
          Found in rasa/core/policies/tf_utils.py - About 35 mins to fix

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

                def state_size(self):
                    """The `state_size` property of `TimeAttentionWrapper`.
                    Returns:
                        A `TimeAttentionWrapperState` tuple containing shapes
                        used by this object.
            Severity: Minor
            Found in rasa/core/policies/tf_utils.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 call has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def call(self, inputs, state):
                    """LSTM cell with layer normalization and recurrent dropout."""
                    c, h = state
                    args = tf.concat([inputs, h], 1)
                    concat = self._linear(args)
            Severity: Minor
            Found in rasa/core/policies/tf_utils.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 2 locations. Consider refactoring.
            Open

                    if (not isinstance(self._keep_prob, float)) or self._keep_prob < 1:
                        new_h = tf.nn.dropout(new_h, self._keep_prob, seed=self._seed)
            Severity: Major
            Found in rasa/core/policies/tf_utils.py and 1 other location - About 2 hrs to fix
            rasa/core/policies/tf_utils.py on lines 919..920

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

            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

                    if (not isinstance(self._keep_prob, float)) or self._keep_prob < 1:
                        g = tf.nn.dropout(g, self._keep_prob, seed=self._seed)
            Severity: Major
            Found in rasa/core/policies/tf_utils.py and 1 other location - About 2 hrs to fix
            rasa/core/policies/tf_utils.py on lines 933..934

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

            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

                                tf.TensorArray(dtype, size=self._sequence_len + 1,
                                               dynamic_size=False,
                                               clear_after_read=False
                                               ).write(0, zero_state.cell_state.c),
            Severity: Minor
            Found in rasa/core/policies/tf_utils.py and 1 other location - About 50 mins to fix
            rasa/core/policies/tf_utils.py on lines 462..465

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

            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

                                tf.TensorArray(dtype, size=self._sequence_len + 1,
                                               dynamic_size=False,
                                               clear_after_read=False
                                               ).write(0, zero_state.cell_state.h)
            Severity: Minor
            Found in rasa/core/policies/tf_utils.py and 1 other location - About 50 mins to fix
            rasa/core/policies/tf_utils.py on lines 458..461

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

            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