tensorflow/models

View on GitHub
official/nlp/data/tagging_data_lib.py

Summary

Maintainability
C
1 day
Test Coverage

File tagging_data_lib.py has 335 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/nlp/data/tagging_data_lib.py - About 4 hrs to fix

    Function _tokenize_example has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    def _tokenize_example(example, max_length, tokenizer, text_preprocessing=None):
      """Tokenizes words and breaks long example into short ones."""
      # Needs additional [CLS] and [SEP] tokens.
      max_length = max_length - 2
      new_examples = []
    Severity: Minor
    Found in official/nlp/data/tagging_data_lib.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 _read_one_file has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def _read_one_file(file_name, label_list):
      """Reads one file and returns a list of `InputExample` instances."""
      lines = tf.io.gfile.GFile(file_name, "r").readlines()
      examples = []
      label_id_map = {label: i for i, label in enumerate(label_list)}
    Severity: Minor
    Found in official/nlp/data/tagging_data_lib.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 generate_tf_record_from_data_file has 8 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def generate_tf_record_from_data_file(processor, data_dir, tokenizer,
    Severity: Major
    Found in official/nlp/data/tagging_data_lib.py - About 1 hr to fix

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

      def token_classification_meta_data(train_data_size,
      Severity: Major
      Found in official/nlp/data/tagging_data_lib.py - About 50 mins to fix

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

        def write_example_to_file(examples,
        Severity: Minor
        Found in official/nlp/data/tagging_data_lib.py - About 35 mins to fix

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

            def get_train_examples(self, data_dir):
              examples = _read_one_file(
                  os.path.join(data_dir, "train-en.tsv"), self.get_labels())
              if not self.only_use_en_train:
                for language in self.supported_languages:
          Severity: Minor
          Found in official/nlp/data/tagging_data_lib.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

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

            def get_dev_examples(self, data_dir):
              examples = _read_one_file(
                  os.path.join(data_dir, "dev-en.tsv"), self.get_labels())
              if not self.only_use_en_dev:
                for language in self.supported_languages:
          Severity: Minor
          Found in official/nlp/data/tagging_data_lib.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

          There are no issues that match your filters.

          Category
          Status