tensorflow/models

View on GitHub
official/legacy/xlnet/squad_utils.py

Summary

Maintainability
F
1 mo
Test Coverage

Function convert_examples_to_features has a Cognitive Complexity of 128 (exceeds 5 allowed). Consider refactoring.
Open

def convert_examples_to_features(examples, sp_model, max_seq_length, doc_stride,
                                 max_query_length, is_training, output_fn,
                                 uncased):
  """Loads a data file into a list of `InputBatch`s."""

Severity: Minor
Found in official/legacy/xlnet/squad_utils.py - About 2 days 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

File squad_utils.py has 735 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/legacy/xlnet/squad_utils.py - About 1 day to fix

    Function write_predictions has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
    Open

    def write_predictions(all_examples, all_features, all_results, n_best_size,
                          max_answer_length, output_prediction_file,
                          output_nbest_file, output_null_log_odds_file, orig_data,
                          start_n_top, end_n_top):
      """Writes final predictions to the json file and log-odds of null if needed."""
    Severity: Minor
    Found in official/legacy/xlnet/squad_utils.py - About 1 day 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 _convert_index has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

    def _convert_index(index, pos, M=None, is_start=True):
      """Converts index."""
      if index[pos] is not None:
        return index[pos]
      N = len(index)
    Severity: Minor
    Found in official/legacy/xlnet/squad_utils.py - About 4 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 read_squad_examples has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    def read_squad_examples(input_file, is_training):
      """Reads a SQuAD json file into a list of SquadExample."""
      with tf.io.gfile.GFile(input_file, "r") as reader:
        input_data = json.load(reader)["data"]
    
    
    Severity: Minor
    Found in official/legacy/xlnet/squad_utils.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 find_best_thresh has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    def find_best_thresh(preds, scores, na_probs, qid_to_has_ans):
      """Finds best threshold."""
      num_no_ans = sum(1 for k in qid_to_has_ans if not qid_to_has_ans[k])
      cur_score = num_no_ans
      best_score = cur_score
    Severity: Minor
    Found in official/legacy/xlnet/squad_utils.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 15 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      def __init__(self,
    Severity: Major
    Found in official/legacy/xlnet/squad_utils.py - About 1 hr to fix

      Function get_raw_scores has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

      def get_raw_scores(dataset, preds):
        """Gets exact scores and f1 scores."""
        exact_scores = {}
        f1_scores = {}
        for article in dataset:
      Severity: Minor
      Found in official/legacy/xlnet/squad_utils.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 write_predictions has 11 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def write_predictions(all_examples, all_features, all_results, n_best_size,
      Severity: Major
      Found in official/legacy/xlnet/squad_utils.py - About 1 hr to fix

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

        def convert_examples_to_features(examples, sp_model, max_seq_length, doc_stride,
        Severity: Major
        Found in official/legacy/xlnet/squad_utils.py - About 1 hr to fix

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

          def create_eval_data(spm_basename,
          Severity: Major
          Found in official/legacy/xlnet/squad_utils.py - About 1 hr to fix

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

            def find_all_best_thresh(main_eval, preds, exact_raw, f1_raw, na_probs,
            Severity: Minor
            Found in official/legacy/xlnet/squad_utils.py - About 45 mins to fix

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

                def __init__(self,
              Severity: Minor
              Found in official/legacy/xlnet/squad_utils.py - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                          if length > max_answer_length:
                            continue
                
                
                Severity: Major
                Found in official/legacy/xlnet/squad_utils.py - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                            if not is_impossible:
                              answer = qa["answers"][0]
                              orig_answer_text = answer["text"]
                              start_position = answer["answer_start"]
                            else:
                  Severity: Major
                  Found in official/legacy/xlnet/squad_utils.py - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                              if not feature.token_is_max_context.get(start_index, False):
                                continue
                              if end_index < start_index:
                    Severity: Major
                    Found in official/legacy/xlnet/squad_utils.py - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                if end_index < start_index:
                                  continue
                                length = end_index - start_index + 1
                      Severity: Major
                      Found in official/legacy/xlnet/squad_utils.py - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                  if (len(qa["answers"]) != 1) and (not is_impossible):
                                    raise ValueError(
                                        "For training, each question should have exactly 1 answer.")
                                  if not is_impossible:
                        Severity: Major
                        Found in official/legacy/xlnet/squad_utils.py - About 45 mins to fix

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

                          def _check_is_max_context(doc_spans, cur_span_index, position):
                            """Check if this is the "max context" doc span for the token."""
                          
                            # Because of the sliding window approach taken to scoring documents, a single
                            # token can appear in multiple documents. E.g.
                          Severity: Minor
                          Found in official/legacy/xlnet/squad_utils.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

                          Avoid deeply nested control flow statements.
                          Open

                                    if end_index >= feature.paragraph_len - 1:
                                      continue
                          
                          
                          Severity: Major
                          Found in official/legacy/xlnet/squad_utils.py - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                      if start_index >= feature.paragraph_len - 1:
                                        continue
                                      if end_index >= feature.paragraph_len - 1:
                            Severity: Major
                            Found in official/legacy/xlnet/squad_utils.py - About 45 mins to fix

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

                              def _compute_softmax(scores):
                                """Computes softmax probability over raw logits."""
                                if not scores:
                                  return []
                              
                              
                              Severity: Minor
                              Found in official/legacy/xlnet/squad_utils.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

                              Avoid too many return statements within this function.
                              Open

                                  return index[front]
                              Severity: Major
                              Found in official/legacy/xlnet/squad_utils.py - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                        return M - 1
                                Severity: Major
                                Found in official/legacy/xlnet/squad_utils.py - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                        return index[front] + 1
                                  Severity: Major
                                  Found in official/legacy/xlnet/squad_utils.py - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                            return index[front] + 1
                                    Severity: Major
                                    Found in official/legacy/xlnet/squad_utils.py - About 30 mins to fix

                                      Avoid too many return statements within this function.
                                      Open

                                            return index[rear] - 1
                                      Severity: Major
                                      Found in official/legacy/xlnet/squad_utils.py - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                              return index[front]
                                        Severity: Major
                                        Found in official/legacy/xlnet/squad_utils.py - About 30 mins to fix

                                          Avoid too many return statements within this function.
                                          Open

                                                return index[rear]
                                          Severity: Major
                                          Found in official/legacy/xlnet/squad_utils.py - About 30 mins to fix

                                            Function make_qid_to_has_ans has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                            Open

                                            def make_qid_to_has_ans(dataset):
                                              qid_to_has_ans = {}
                                              for article in dataset:
                                                for p in article["paragraphs"]:
                                                  for qa in p["qas"]:
                                            Severity: Minor
                                            Found in official/legacy/xlnet/squad_utils.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

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

                                            def _convert_index(index, pos, M=None, is_start=True):
                                              """Converts index."""
                                              if index[pos] is not None:
                                                return index[pos]
                                              N = len(index)
                                            Severity: Major
                                            Found in official/legacy/xlnet/squad_utils.py and 1 other location - About 4 days to fix
                                            official/nlp/data/squad_lib_sp.py on lines 165..200

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

                                            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

                                                def _lcs_match(max_dist):
                                                  """LCS match."""
                                                  f.fill(0)
                                                  g.clear()
                                            
                                            
                                            Severity: Major
                                            Found in official/legacy/xlnet/squad_utils.py and 1 other location - About 3 days to fix
                                            official/nlp/data/squad_lib_sp.py on lines 263..292

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

                                            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

                                            def _check_is_max_context(doc_spans, cur_span_index, position):
                                              """Check if this is the "max context" doc span for the token."""
                                            
                                              # Because of the sliding window approach taken to scoring documents, a single
                                              # token can appear in multiple documents. E.g.
                                            Severity: Major
                                            Found in official/legacy/xlnet/squad_utils.py and 2 other locations - About 1 day to fix
                                            official/nlp/data/squad_lib.py on lines 514..548
                                            official/nlp/data/squad_lib_sp.py on lines 579..613

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

                                            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

                                                while i >= 0 and j >= 0:
                                                  if (i, j) not in g:
                                                    break
                                                  if g[(i, j)] == 2:
                                                    orig_to_chartok_index[i] = j
                                            Severity: Major
                                            Found in official/legacy/xlnet/squad_utils.py and 1 other location - About 1 day to fix
                                            official/nlp/data/squad_lib_sp.py on lines 306..316

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

                                            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

                                            class InputFeatures(object):
                                              """A single set of features of data."""
                                            
                                              def __init__(self,
                                                           unique_id,
                                            Severity: Major
                                            Found in official/legacy/xlnet/squad_utils.py and 1 other location - About 1 day to fix
                                            official/legacy/xlnet/run_squad.py on lines 61..94

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

                                            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

                                            def _compute_softmax(scores):
                                              """Computes softmax probability over raw logits."""
                                              if not scores:
                                                return []
                                            
                                            
                                            Severity: Major
                                            Found in official/legacy/xlnet/squad_utils.py and 2 other locations - About 1 day to fix
                                            official/nlp/data/squad_lib.py on lines 913..933
                                            official/nlp/data/squad_lib_sp.py on lines 868..888

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

                                            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

                                            def normalize_answer(s):
                                              """Lower text and remove punctuation, articles and extra whitespace."""
                                            
                                              def remove_articles(text):
                                                regex = re.compile(r"\b(a|an|the)\b", re.UNICODE)
                                            Severity: Major
                                            Found in official/legacy/xlnet/squad_utils.py and 1 other location - About 1 day to fix
                                            official/nlp/tools/squad_evaluate_v2_0.py on lines 42..54

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

                                            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

                                                if is_training and not example.is_impossible:
                                                  start_position = example.start_position
                                                  end_position = start_position + len(example.orig_answer_text) - 1
                                            
                                                  start_chartok_pos = _convert_index(
                                            Severity: Major
                                            Found in official/legacy/xlnet/squad_utils.py and 1 other location - About 6 hrs to fix
                                            official/nlp/data/squad_lib_sp.py on lines 343..354

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

                                            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 3 locations. Consider refactoring.
                                            Open

                                                while start_offset < len(all_doc_tokens):
                                                  length = len(all_doc_tokens) - start_offset
                                                  if length > max_tokens_for_doc:
                                                    length = max_tokens_for_doc
                                                  doc_spans.append(_DocSpan(start=start_offset, length=length))
                                            Severity: Major
                                            Found in official/legacy/xlnet/squad_utils.py and 2 other locations - About 5 hrs to fix
                                            official/nlp/data/squad_lib.py on lines 307..314
                                            official/nlp/data/squad_lib_sp.py on lines 372..379

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

                                            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

                                              for qid in qid_list:
                                                if qid not in scores:
                                                  continue
                                                if qid_to_has_ans[qid]:
                                                  diff = scores[qid]
                                            Severity: Major
                                            Found in official/legacy/xlnet/squad_utils.py and 1 other location - About 5 hrs to fix
                                            official/nlp/tools/squad_evaluate_v2_0.py on lines 188..200

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

                                            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

                                                for (i, entry) in enumerate(nbest):
                                                  output = collections.OrderedDict()
                                                  output["text"] = entry.text
                                                  output["probability"] = probs[i]
                                                  output["start_log_prob"] = entry.start_log_prob
                                            Severity: Major
                                            Found in official/legacy/xlnet/squad_utils.py and 2 other locations - About 5 hrs to fix
                                            official/nlp/data/squad_lib.py on lines 749..755
                                            official/nlp/data/squad_lib_sp.py on lines 805..811

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

                                            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

                                                for i in range(len(para_tokens)):
                                                  start_chartok_pos = tok_start_to_chartok_index[i]
                                                  end_chartok_pos = tok_end_to_chartok_index[i]
                                                  start_orig_pos = _convert_index(
                                                      chartok_to_orig_index, start_chartok_pos, N, is_start=True)
                                            Severity: Major
                                            Found in official/legacy/xlnet/squad_utils.py and 1 other location - About 4 hrs to fix
                                            official/nlp/data/squad_lib_sp.py on lines 325..334

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

                                            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

                                            def make_qid_to_has_ans(dataset):
                                              qid_to_has_ans = {}
                                              for article in dataset:
                                                for p in article["paragraphs"]:
                                                  for qa in p["qas"]:
                                            Severity: Major
                                            Found in official/legacy/xlnet/squad_utils.py and 1 other location - About 3 hrs to fix
                                            official/nlp/tools/squad_evaluate_v2_0.py on lines 33..39

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

                                            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

                                                for _ in range(2):
                                                  _lcs_match(max_dist)
                                                  if f[N - 1, M - 1] > 0.8 * N:
                                                    break
                                                  max_dist *= 2
                                            Severity: Major
                                            Found in official/legacy/xlnet/squad_utils.py and 1 other location - About 3 hrs to fix
                                            official/nlp/data/squad_lib_sp.py on lines 297..301

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

                                            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

                                                      if not is_impossible:
                                                        answer = qa["answers"][0]
                                                        orig_answer_text = answer["text"]
                                                        start_position = answer["answer_start"]
                                                      else:
                                            Severity: Major
                                            Found in official/legacy/xlnet/squad_utils.py and 1 other location - About 2 hrs to fix
                                            official/nlp/data/squad_lib_sp.py on lines 145..151

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

                                            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 all(
                                                    v is None for v in orig_to_chartok_index) or f[N - 1, M - 1] < 0.8 * N:
                                            Severity: Major
                                            Found in official/legacy/xlnet/squad_utils.py and 1 other location - About 2 hrs to fix
                                            official/nlp/data/squad_lib_sp.py on lines 318..319

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

                                            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

                                                  feature = InputFeatures(
                                            Severity: Major
                                            Found in official/legacy/xlnet/squad_utils.py and 1 other location - About 1 hr to fix
                                            research/object_detection/core/preprocessor.py on lines 1784..1784

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

                                            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

                                              def __init__(self,
                                                           qas_id,
                                                           question_text,
                                                           paragraph_text,
                                                           orig_answer_text=None,
                                            Severity: Major
                                            Found in official/legacy/xlnet/squad_utils.py and 2 other locations - About 1 hr to fix
                                            research/adversarial_text/layers.py on lines 105..111
                                            research/vid2depth/reader.py on lines 37..44

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

                                            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

                                                    logging.info(
                                                        "token_is_max_context: %s", " ".join([
                                                            "%d:%s" % (x, y)
                                                            for (x, y) in six.iteritems(token_is_max_context)
                                            Severity: Major
                                            Found in official/legacy/xlnet/squad_utils.py and 2 other locations - About 1 hr to fix
                                            official/nlp/data/squad_lib.py on lines 411..413
                                            official/nlp/data/squad_lib.py on lines 415..418

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

                                            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

                                                    gold_answers = [
                                                        a["text"] for a in qa["answers"] if normalize_answer(a["text"])
                                            Severity: Minor
                                            Found in official/legacy/xlnet/squad_utils.py and 1 other location - About 55 mins to fix
                                            official/nlp/tools/squad_evaluate_v2_0.py on lines 91..92

                                            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

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

                                                      if (len(qa["answers"]) != 1) and (not is_impossible):
                                                        raise ValueError(
                                            Severity: Major
                                            Found in official/legacy/xlnet/squad_utils.py and 2 other locations - About 50 mins to fix
                                            official/nlp/data/squad_lib.py on lines 209..210
                                            official/nlp/data/squad_lib_sp.py on lines 142..143

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

                                            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 3 locations. Consider refactoring.
                                            Open

                                              with tf.io.gfile.GFile(input_file, "r") as reader:
                                                input_data = json.load(reader)["data"]
                                            Severity: Major
                                            Found in official/legacy/xlnet/squad_utils.py and 2 other locations - About 40 mins to fix
                                            official/nlp/data/squad_lib.py on lines 165..166
                                            official/nlp/data/squad_lib_sp.py on lines 118..119

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

                                            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

                                                prelim_predictions = sorted(
                                                    prelim_predictions,
                                                    key=lambda x: (x.start_log_prob + x.end_log_prob),
                                            Severity: Minor
                                            Found in official/legacy/xlnet/squad_utils.py and 2 other locations - About 30 mins to fix
                                            official/nlp/data/squad_lib.py on lines 677..679
                                            official/nlp/data/squad_lib_sp.py on lines 743..745

                                            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