deeplearning4j/deeplearning4j

View on GitHub
deeplearning4j/deeplearning4j-nlp-parent/deeplearning4j-nlp/src/main/java/org/deeplearning4j/models/embeddings/reader/impl/BasicModelUtils.java

Summary

Maintainability
D
2 days
Test Coverage

File BasicModelUtils.java has 304 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*
 *  ******************************************************************************
 *  *
 *  *
 *  * This program and the accompanying materials are made available under the

    Method wordsNearestSum has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        @Override
        public Collection<String> wordsNearestSum(INDArray words, int top) {
    
            if (lookupTable instanceof InMemoryLookupTable) {
                InMemoryLookupTable l = (InMemoryLookupTable) lookupTable;

    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

    Method wordsNearest has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        @Override
        public Collection<String> wordsNearest(INDArray words, int top) {
            words = adjustRank(words);
    
            if (lookupTable instanceof InMemoryLookupTable) {

    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

    Method wordsNearest has 34 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        @Override
        public Collection<String> wordsNearest(INDArray words, int top) {
            words = adjustRank(words);
    
            if (lookupTable instanceof InMemoryLookupTable) {

      Method accuracy has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          @Override
          public Map<String, Double> accuracy(List<String> questions) {
              Map<String, Double> accuracy = new HashMap<>();
              Counter<String> right = new Counter<>();
              String analogyType = "";

        Method wordsNearestSum has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            @Override
            public Collection<String> wordsNearestSum(INDArray words, int top) {
        
                if (lookupTable instanceof InMemoryLookupTable) {
                    InMemoryLookupTable l = (InMemoryLookupTable) lookupTable;

          Method wordsNearest has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              public Collection<String> wordsNearest(@NonNull Collection<String> positive, @NonNull Collection<String> negative,
                              int top) {
                  // Check every word is in the model
                  for (String p : SetUtils.union(new HashSet<>(positive), new HashSet<>(negative))) {
                      if (!vocabCache.containsWord(p)) {

          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

          Method accuracy has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              @Override
              public Map<String, Double> accuracy(List<String> questions) {
                  Map<String, Double> accuracy = new HashMap<>();
                  Counter<String> right = new Counter<>();
                  String analogyType = "";

          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

          Method getTopN has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              private List<Double> getTopN(INDArray vec, int N) {
                  ArrayComparator comparator = new ArrayComparator();
                  PriorityQueue<Double[]> queue = new PriorityQueue<>(vec.rows(), comparator);
          
                  for (int j = 0; j < vec.length(); j++) {

          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

          Method adjustRank has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              protected INDArray adjustRank(INDArray words) {
                  if (lookupTable instanceof InMemoryLookupTable) {
                      InMemoryLookupTable l = (InMemoryLookupTable) lookupTable;
          
                      INDArray syn0 = l.getSyn0();

          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

          Method compare has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                  @Override
                  public int compare(WordSimilarity o1, WordSimilarity o2) {
                      if (Double.isNaN(o1.getSimilarity()) && Double.isNaN(o2.getSimilarity())) {
                          return 0;
                      } else if (Double.isNaN(o1.getSimilarity()) && !Double.isNaN(o2.getSimilarity())) {

          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

          Method compare has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                  @Override
                  public int compare(Double[] o1, Double[] o2) {
                      if (Double.isNaN(o1[0]) && Double.isNaN(o2[0])) {
                          return 0;
                      } else if (Double.isNaN(o1[0]) && !Double.isNaN(o2[0])) {

          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

          Method similarity has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              @Override
              public double similarity(@NonNull String label1, @NonNull String label2) {
                  if (label1 == null || label2 == null) {
                      log.debug("LABELS: " + label1 + ": " + (label1 == null ? "null" : EXISTS) + ";" + label2 + " vec2:"
                                      + (label2 == null ? "null" : EXISTS));

          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 method.
          Open

                  return Transforms.cosineSim(vec1, vec2);

            Avoid too many return statements within this method.
            Open

                        return 1.0;

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

                  private List<Double> getTopN(INDArray vec, int N) {
                      ArrayComparator comparator = new ArrayComparator();
                      PriorityQueue<Double[]> queue = new PriorityQueue<>(vec.rows(), comparator);
              
                      for (int j = 0; j < vec.length(); j++) {
              deeplearning4j/deeplearning4j-nlp-parent/deeplearning4j-nlp/src/main/java/org/deeplearning4j/models/paragraphvectors/ParagraphVectors.java on lines 692..716

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

              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 (word != null && !word.equals("UNK") && !word.equals("STOP")) {
                                  INDArray otherVec = lookupTable.vector(word);
                                  double sim = Transforms.cosineSim(words, otherVec);
              
                                  result.add(new WordSimilarity(word, sim));
              deeplearning4j/deeplearning4j-nlp-parent/deeplearning4j-nlp/src/main/java/org/deeplearning4j/models/paragraphvectors/ParagraphVectors.java on lines 672..677

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

              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

                      for (String s : vocabCache.words()) {
                          INDArray otherVec = lookupTable.vector(s);
                          double sim = Transforms.cosineSim(words, otherVec);
                          distances.incrementCount(s, (float) sim);
                      }
              deeplearning4j/deeplearning4j-nlp-parent/deeplearning4j-nlp/src/main/java/org/deeplearning4j/models/embeddings/reader/impl/BasicModelUtils.java on lines 376..380

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

              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

                      for (String s : vocabCache.words()) {
                          INDArray otherVec = lookupTable.vector(s);
                          double sim = Transforms.cosineSim(words, otherVec);
                          distances.incrementCount(s, (float) sim);
                      }
              deeplearning4j/deeplearning4j-nlp-parent/deeplearning4j-nlp/src/main/java/org/deeplearning4j/models/embeddings/reader/impl/BasicModelUtils.java on lines 293..297

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

              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 (!normalized) {
                              synchronized (this) {
                                  if (!normalized) {
                                      syn0.diviColumnVector(syn0.norm2(1));
                                      normalized = true;
              deeplearning4j/deeplearning4j-nlp-parent/deeplearning4j-nlp/src/main/java/org/deeplearning4j/models/paragraphvectors/ParagraphVectors.java on lines 655..662

              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

              There are no issues that match your filters.

              Category
              Status