tensorflow/models

View on GitHub
official/nlp/modeling/networks/xlnet_base.py

Summary

Maintainability
F
4 days
Test Coverage

File xlnet_base.py has 582 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/networks/xlnet_base.py - About 1 day to fix

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

      def call(self, inputs):
        """Implements call() for the layer."""
        input_ids = inputs["input_ids"]
        segment_ids = inputs["segment_ids"]
        input_mask = inputs["input_mask"]
    Severity: Minor
    Found in official/nlp/modeling/networks/xlnet_base.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 20 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      def __init__(self,
    Severity: Major
    Found in official/nlp/modeling/networks/xlnet_base.py - About 2 hrs to fix

      Function _compute_positional_encoding has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

      def _compute_positional_encoding(
          attention_type,
          position_encoding_layer,
          hidden_size,
          batch_size,
      Severity: Minor
      Found in official/nlp/modeling/networks/xlnet_base.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 _compute_attention_mask has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

      def _compute_attention_mask(
          input_mask,
          permutation_mask,
          attention_type,
          seq_length,
      Severity: Minor
      Found in official/nlp/modeling/networks/xlnet_base.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_positional_encoding has 9 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def _compute_positional_encoding(
      Severity: Major
      Found in official/nlp/modeling/networks/xlnet_base.py - About 1 hr to fix

        Function __init__ has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def __init__(self,
                       vocab_size,
                       num_layers,
                       hidden_size,
                       num_attention_heads,
        Severity: Minor
        Found in official/nlp/modeling/networks/xlnet_base.py - About 1 hr to fix

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

            def __call__(self,
          Severity: Major
          Found in official/nlp/modeling/networks/xlnet_base.py - About 1 hr to fix

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

            def _compute_attention_mask(
            Severity: Major
            Found in official/nlp/modeling/networks/xlnet_base.py - About 50 mins to fix

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

                  config = {
                      "vocab_size":
                          self._vocab_size,
                      "num_layers":
                          self._num_layers,
              Severity: Major
              Found in official/nlp/modeling/networks/xlnet_base.py and 1 other location - About 4 hrs to fix
              research/object_detection/builders/preprocessor_builder.py on lines 73..111

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

              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 dtype is not None and dtype != tf.float32:
                    forward_position_sequence = tf.cast(forward_position_sequence,
                                                        dtype=dtype)
                    backward_position_sequence = tf.cast(backward_position_sequence,
              Severity: Major
              Found in official/nlp/modeling/networks/xlnet_base.py and 1 other location - About 2 hrs to fix
              official/legacy/xlnet/xlnet_modeling.py on lines 671..673

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

              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

                if dtype is not None and dtype != tf.float32:
                  freq_seq = tf.cast(freq_seq, dtype=dtype)
              Severity: Major
              Found in official/nlp/modeling/networks/xlnet_base.py and 2 other locations - About 1 hr to fix
              official/legacy/xlnet/xlnet_modeling.py on lines 691..692
              official/nlp/modeling/networks/xlnet_base.py on lines 355..356

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

              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

                  if dtype is not None and dtype != tf.float32:
                    forward_position_sequence = tf.cast(
              Severity: Major
              Found in official/nlp/modeling/networks/xlnet_base.py and 2 other locations - About 1 hr to fix
              official/legacy/xlnet/xlnet_modeling.py on lines 691..692
              official/nlp/modeling/networks/xlnet_base.py on lines 310..311

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

              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

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

                  self._inv_freq = 1.0 / (10000.0**(
                      tf.range(0, self._hidden_size, 2.0) / self._hidden_size))
              Severity: Minor
              Found in official/nlp/modeling/networks/xlnet_base.py and 1 other location - About 55 mins to fix
              official/legacy/xlnet/xlnet_modeling.py on lines 110..111

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

              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

                  return self._transformer_xl(
              Severity: Minor
              Found in official/nlp/modeling/networks/xlnet_base.py and 1 other location - About 45 mins to fix
              research/object_detection/builders/box_predictor_builder.py on lines 105..105

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

              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

                elif input_mask is not None and permutation_mask is None:
                  data_mask = input_mask[:, None, :]
                elif input_mask is None and permutation_mask is not None:
                  data_mask = permutation_mask
                else:
              Severity: Minor
              Found in official/nlp/modeling/networks/xlnet_base.py and 1 other location - About 30 mins to fix
              official/legacy/xlnet/xlnet_modeling.py on lines 589..594

              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