tensorflow/models

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

Summary

Maintainability
D
2 days
Test Coverage

File preprocess.py has 439 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/preprocess.py - About 6 hrs to fix

    Function _make_features has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

      def _make_features(self, stride_index: int, paragraph_texts: List[Text],
                         paragraphs: List[Paragraph],
                         question_answer_evidence: QuestionAnswerEvidence,
                         ids: List[int],
                         paragraph_offset: int) -> Tuple[int, Features]:
    Severity: Minor
    Found in official/projects/triviaqa/preprocess.py - About 3 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 _handle_exceptional_examples has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

    def _handle_exceptional_examples(
        features: Features,
        processor: spm.SentencePieceProcessor) -> List[AnswerSpan]:
      """Special cases in data."""
      if features.id == 'qw_6687--Viola.txt':
    Severity: Minor
    Found in official/projects/triviaqa/preprocess.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 process has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

      def process(
          self,
          element: Tuple[Text, List[Features]],
          answer_sets: Dict[Text, Set[Text]],
      ) -> Generator[Tuple[Features, List[AnswerSpan]], None, None]:
    Severity: Minor
    Found in official/projects/triviaqa/preprocess.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 make_pipeline has 9 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def make_pipeline(root: beam.Pipeline, question_answers: List[QuestionAnswer],
    Severity: Major
    Found in official/projects/triviaqa/preprocess.py - About 1 hr to fix

      Function read_question_answers has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      def read_question_answers(json_path: Text) -> List[QuestionAnswer]:
        """Read question answers."""
        with gfile.GFile(json_path) as f:
          data = json.load(f)['Data']
        question_answers = []
      Severity: Minor
      Found in official/projects/triviaqa/preprocess.py - About 55 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 realign_answer_span has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      def realign_answer_span(features: Features, answer_set: Optional[Set[Text]],
                              processor: spm.SentencePieceProcessor,
                              span: AnswerSpan) -> Optional[AnswerSpan]:
        """Align answer span to text with given tokens."""
        i = bisect.bisect_left(features.token_offsets, span.begin)
      Severity: Minor
      Found in official/projects/triviaqa/preprocess.py - About 55 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 _make_features has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

        def _make_features(self, stride_index: int, paragraph_texts: List[Text],
      Severity: Minor
      Found in official/projects/triviaqa/preprocess.py - About 45 mins to fix

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

        def make_paragraph(
        Severity: Minor
        Found in official/projects/triviaqa/preprocess.py - About 35 mins to fix

          Avoid too many return statements within this function.
          Open

              return spans
          Severity: Major
          Found in official/projects/triviaqa/preprocess.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

              return []
            Severity: Major
            Found in official/projects/triviaqa/preprocess.py - About 30 mins to fix

              There are no issues that match your filters.

              Category
              Status