rasa/utils/tensorflow/models.py

Summary

Maintainability
D
2 days
Test Coverage
A
96%

File models.py has 738 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import time
import random
import tensorflow as tf
import numpy as np
import logging
Severity: Major
Found in rasa/utils/tensorflow/models.py - About 1 day to fix

    Function batch_to_model_data_format has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

        def batch_to_model_data_format(
            batch: MaybeNestedBatchData,
            data_signature: Dict[Text, Dict[Text, List[FeatureSignature]]],
        ) -> Dict[Text, Dict[Text, List[tf.Tensor]]]:
            """Convert input batch tensors into batch data format.
    Severity: Minor
    Found in rasa/utils/tensorflow/models.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 _check_if_sparse_feature_sizes_decreased has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def _check_if_sparse_feature_sizes_decreased(
            new_sparse_feature_sizes: Dict[Text, Dict[Text, List[int]]],
            old_sparse_feature_sizes: Dict[Text, Dict[Text, List[int]]],
        ) -> None:
            """Checks if the sizes of sparse features have decreased during fine-tuning.
    Severity: Minor
    Found in rasa/utils/tensorflow/models.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 _calculate_entity_loss has 7 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def _calculate_entity_loss(
    Severity: Major
    Found in rasa/utils/tensorflow/models.py - About 50 mins to fix

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

          def load(
      Severity: Minor
      Found in rasa/utils/tensorflow/models.py - About 45 mins to fix

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

            def __init__(
        Severity: Minor
        Found in rasa/utils/tensorflow/models.py - About 35 mins to fix

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

              def _prepare_ffnn_layer(
          Severity: Minor
          Found in rasa/utils/tensorflow/models.py - About 35 mins to fix

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

                def _rasa_predict(
                    self, batch_in: Tuple[np.ndarray, ...]
                ) -> Dict[Text, Union[np.ndarray, Dict[Text, Any]]]:
                    """Custom prediction method that builds tf graph on the first call.
            
            
            Severity: Minor
            Found in rasa/utils/tensorflow/models.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 _sparse_feature_sizes_have_increased has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def _sparse_feature_sizes_have_increased(
                    new_sparse_feature_sizes: Dict[Text, Dict[Text, List[int]]],
                    old_sparse_feature_sizes: Dict[Text, Dict[Text, List[int]]],
                ) -> bool:
                    """Checks if the sizes of sparse features have increased during fine-tuning.
            Severity: Minor
            Found in rasa/utils/tensorflow/models.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

            There are no issues that match your filters.

            Category
            Status