tensorflow/models

View on GitHub
official/projects/triviaqa/inputs.py

Summary

Maintainability
C
1 day
Test Coverage

File inputs.py has 442 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: Minor
Found in official/projects/triviaqa/inputs.py - About 6 hrs to fix

    Function features_map_fn has 11 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def features_map_fn(features, local_radius, relative_pos_max_distance,
    Severity: Major
    Found in official/projects/triviaqa/inputs.py - About 1 hr to fix

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

      def _flatten_dims(tensor: tf.Tensor,
                        first_dim: Optional[int] = 0,
                        last_dim: Optional[int] = -1,
                        name: Optional[Text] = None) -> tf.Tensor:
        """Flattens the given span of dimensions in `tensor`.
      Severity: Minor
      Found in official/projects/triviaqa/inputs.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 features_map_fn has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      def features_map_fn(features, local_radius, relative_pos_max_distance,
                          use_hard_g2l_mask, padding_id, eos_id, null_id, cls_id,
                          sep_id, sequence_length, global_sequence_length):
        """Make features."""
        batch_size = tf.get_static_value(features['token_ids'].shape[0])
      Severity: Minor
      Found in official/projects/triviaqa/inputs.py - About 1 hr to fix

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

        def read_batches(data_dir,
        Severity: Major
        Found in official/projects/triviaqa/inputs.py - About 50 mins to fix

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

          def _pad_to_multiple(tensor: tf.Tensor,
          Severity: Minor
          Found in official/projects/triviaqa/inputs.py - About 45 mins to fix

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

              def _make_relative_id_pattern(
                  self, window_size: Union[int, tf.Tensor]) -> tf.Tensor:
                """Helper for making the relative id pattern for a particular window size.
            
                For example, if `max_distance` is 3, `ignore_direction` is False, and
            Severity: Minor
            Found in official/projects/triviaqa/inputs.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 _pad_to_multiple has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

            def _pad_to_multiple(tensor: tf.Tensor,
                                 factor: Union[int, tf.Tensor],
                                 axis: int,
                                 mode: Optional[Text] = 'CONSTANT',
                                 constant_values=0,
            Severity: Minor
            Found in official/projects/triviaqa/inputs.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