tensorflow/models

View on GitHub
official/nlp/modeling/layers/kernel_attention.py

Summary

Maintainability
F
3 days
Test Coverage

File kernel_attention.py has 695 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2024 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: Major
Found in official/nlp/modeling/layers/kernel_attention.py - About 1 day to fix

    Function expplus has 44 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    def expplus(data_orig,
                other_data,
                is_query,
                projection_matrix=None,
                numerical_stabilizer=0.000001,
    Severity: Minor
    Found in official/nlp/modeling/layers/kernel_attention.py - About 1 hr to fix

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

        def __init__(self,
      Severity: Major
      Found in official/nlp/modeling/layers/kernel_attention.py - About 1 hr to fix

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

          def call(self, query, value, key=None, attention_mask=None, cache=None,
                   training=False):
            """Compute attention with kernel mechanism.
        
            Args:
        Severity: Minor
        Found in official/nlp/modeling/layers/kernel_attention.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 _compute_attention has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

          def _compute_attention(self,
                                 query,
                                 key,
                                 value,
                                 feature_transform,
        Severity: Minor
        Found in official/nlp/modeling/layers/kernel_attention.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 _compute_attention has 9 arguments (exceeds 4 allowed). Consider refactoring.
        Open

          def _compute_attention(self,
        Severity: Major
        Found in official/nlp/modeling/layers/kernel_attention.py - About 1 hr to fix

          Function expplus has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

          def expplus(data_orig,
                      other_data,
                      is_query,
                      projection_matrix=None,
                      numerical_stabilizer=0.000001,
          Severity: Minor
          Found in official/nlp/modeling/layers/kernel_attention.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 causal_windowed_performer_attention has 8 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def causal_windowed_performer_attention(query_matrix,
          Severity: Major
          Found in official/nlp/modeling/layers/kernel_attention.py - About 1 hr to fix

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

            def expplus(data_orig,
            Severity: Major
            Found in official/nlp/modeling/layers/kernel_attention.py - About 1 hr to fix

              Function causal_windowed_performer_attention has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              def causal_windowed_performer_attention(query_matrix,
                                                      key_matrix,
                                                      value_matrix,
                                                      chunk_length,
                                                      window_length,
              Severity: Minor
              Found in official/nlp/modeling/layers/kernel_attention.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 call has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                def call(self, query, value, key=None, attention_mask=None, cache=None,
              Severity: Minor
              Found in official/nlp/modeling/layers/kernel_attention.py - About 45 mins to fix

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

                def _generalized_kernel(x, y, is_query, projection_matrix, f, h):
                Severity: Minor
                Found in official/nlp/modeling/layers/kernel_attention.py - About 45 mins to fix

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

                    def __init__(self,
                                 feature_transform="exp",
                                 num_random_features=256,
                                 seed=0,
                                 redraw=False,
                  Severity: Minor
                  Found in official/nlp/modeling/layers/kernel_attention.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 create_projection_matrix has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                  def create_projection_matrix(m, d, seed=None):
                    r"""Constructs the matrix of random projections.
                  
                    Constructs a matrix of random orthogonal projections. Each projection vector
                    has direction chosen uniformly at random length taken from the
                  Severity: Minor
                  Found in official/nlp/modeling/layers/kernel_attention.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

                  There are no issues that match your filters.

                  Category
                  Status