File model.py
has 360 lines of code (exceeds 250 allowed). Consider refactoring. Open
# -*- coding: utf-8 -*-
# Автор: Гусев Илья
# Описание: Модель PoS-теггера на основе BiLSTM.
from typing import List, Tuple
Function evaluate
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def evaluate(self, file_names, val_idx, train_config: TrainConfig, build_config: BuildModelConfig) -> None:
"""
Оценка на val выборке.
:param file_names: файлы выборки.
- Read upRead up
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 build
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def build(self, config: BuildModelConfig, word_embeddings=None):
"""
Описание модели.
:param config: конфиг модели.
- Read upRead up
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 build
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def build(self, config: BuildModelConfig, word_embeddings=None):
"""
Описание модели.
:param config: конфиг модели.
Function load_train
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def load_train(self, config: BuildModelConfig, model_config_path: str=None, model_weights_path: str=None):
with open(model_config_path, "r", encoding='utf-8') as f:
if config.use_crf:
from keras_contrib.layers import CRF
custom_objects = {'ReversedLSTM': ReversedLSTM, 'CRF': CRF}
- Read upRead up
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 prepare
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def prepare(self, gram_dump_path_input: str, gram_dump_path_output: str,
Function predict_probabilities
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def predict_probabilities(self, sentences: List[List[str]], batch_size: int,
build_config: BuildModelConfig) -> List[List[List[float]]]:
"""
Предсказание полных PoS-тегов по предложению с вероятностями всех вариантов.
- Read upRead up
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 prepare
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def prepare(self, gram_dump_path_input: str, gram_dump_path_output: str,
word_vocabulary_dump_path: str, char_set_dump_path: str,
file_names: List[str] = None) -> None:
"""
Подготовка векторизатора грамматических значений и словаря слов по корпусу.
- Read upRead up
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 count_samples
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def count_samples(file_names: List[str]):
"""
Считает количество предложений в выборке.
:param file_names: файлы выборки.
- Read upRead up
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 train
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def train(self, file_names: List[str], train_config: TrainConfig, build_config: BuildModelConfig) -> None:
np.random.seed(train_config.random_seed)
sample_counter = self.count_samples(file_names)
train_idx, val_idx = self.get_split(sample_counter, train_config.val_part)
for big_epoch in range(train_config.epochs_num):
- Read upRead up
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"