rasa/utils/tensorflow/rasa_layers.py

Summary

Maintainability
D
2 days
Test Coverage
A
99%

File rasa_layers.py has 868 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import tensorflow as tf
import numpy as np
from typing import Text, List, Dict, Any, Union, Optional, Tuple, Callable

from rasa.shared.nlu.constants import TEXT
Severity: Major
Found in rasa/utils/tensorflow/rasa_layers.py - About 2 days to fix

    Function adjust_sparse_layers_for_incremental_training has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def adjust_sparse_layers_for_incremental_training(
            self,
            new_sparse_feature_sizes: Dict[Text, Dict[Text, List[int]]],
            old_sparse_feature_sizes: Dict[Text, Dict[Text, List[int]]],
            reg_lambda: float,
    Severity: Minor
    Found in rasa/utils/tensorflow/rasa_layers.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 prepare_transformer_layer has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

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

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

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

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

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

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

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

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

                def _prepare_sequence_sentence_concat(
                    self, attribute: Text, config: Dict[Text, Any]
                ) -> None:
                    """Sets up combining sentence- and sequence-level features (if needed).
            
            
            Severity: Minor
            Found in rasa/utils/tensorflow/rasa_layers.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 _features_as_token_ids has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def _features_as_token_ids(
                    self, features: List[Union[tf.Tensor, tf.SparseTensor]]
                ) -> Optional[tf.Tensor]:
                    """Creates dense labels (token IDs) used for negative sampling in MLM."""
                    # If there are dense features, we use them as labels - taking the first dense
            Severity: Minor
            Found in rasa/utils/tensorflow/rasa_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

            There are no issues that match your filters.

            Category
            Status