Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
53dbe88
Merge branch 'main-upd' into develop
nbirillo May 17, 2021
16937ba
Add possibility to evaluate csv files
nbirillo May 17, 2021
136ed89
Filter solutions by language
nbirillo May 17, 2021
78e7201
Optimize evaluation script, fix tests
nbirillo May 18, 2021
48e3408
Add readme, add distribute grades
nbirillo May 18, 2021
80ea546
Added project template for Java
GirZ0n May 18, 2021
db30732
Added DatasetMarker
GirZ0n May 18, 2021
995aaea
Add tests
nbirillo May 18, 2021
30859c0
Add diffs finder between two dfs
nbirillo May 18, 2021
f21cdf8
Delete unnecessary files
nbirillo May 18, 2021
8c85e36
Code refactoring
GirZ0n May 18, 2021
b1fa21b
Added some words
GirZ0n May 18, 2021
216aef4
Merge branch 'qodana' into roberta-model
dariadiatlova May 19, 2021
ee9e4fe
merge prep
dariadiatlova May 19, 2021
61d7199
fixed merge conflicts
dariadiatlova May 19, 2021
a56eeae
Fixed merge conflict
dariadiatlova May 19, 2021
5929f46
Small code refactoring
GirZ0n May 19, 2021
1a34b50
Added new requirements
GirZ0n May 19, 2021
ecbcdf4
Added ID to ColumnName
GirZ0n May 19, 2021
92f9a8a
Added README.md
GirZ0n May 20, 2021
3ef6a42
Added default value for --chunk-size
GirZ0n May 20, 2021
3f028bd
Merge remote-tracking branch 'origin/qodana' into qodana
GirZ0n May 20, 2021
7cd79e0
parse qodana output
nbirillo May 20, 2021
5c4b85a
Merge remote-tracking branch 'origin/develop' into develop
nbirillo May 20, 2021
ec6b477
Merge branch 'develop' into qodana
nbirillo May 20, 2021
a8b80c0
Update README.md
GirZ0n May 20, 2021
75cac7b
Change qodana scipt output
nbirillo May 20, 2021
dd9d502
Merge remote-tracking branch 'origin/develop' into qodana
GirZ0n May 20, 2021
6915254
Merge remote-tracking branch 'origin/qodana' into qodana
nbirillo May 20, 2021
f0c098b
Merge branch 'qodana' into fix/qodana-output
nbirillo May 20, 2021
c428b78
Fix a bug with qodana
nbirillo May 21, 2021
8489c9d
Fix a bug with path to the gradle project
nbirillo May 21, 2021
395cc6f
Add a script for filtering inspections
nbirillo May 21, 2021
371f985
Fixed PR issues
GirZ0n May 22, 2021
0dab1b7
Fix/qodana output (#33)
nbirillo May 22, 2021
f9b418d
Added is_java function
GirZ0n May 23, 2021
96c0518
1) Added copy_directory and copy_file functions;
GirZ0n May 23, 2021
38a936a
Removed python_on_whales dependency
GirZ0n May 23, 2021
235e60f
Fixed some PR issues
GirZ0n May 23, 2021
5faa46c
Merge branch 'fix/qodana-output' into qodana
GirZ0n May 23, 2021
e7c01a9
Merge branch 'qodana' into qodana-handlers
GirZ0n May 23, 2021
082ca6d
Qoadana handlers/get unique inspections (#35)
nbirillo May 24, 2021
e413678
Update README.md
dariadiatlova May 24, 2021
2b054f8
Added train, evaluationa and dataset preprocessing script for dataset
dariadiatlova May 27, 2021
f6b869d
resolve merge conflicts
dariadiatlova May 28, 2021
f1e7961
resolve merge conflicts
dariadiatlova May 28, 2021
57d796b
fix merge conflicts
dariadiatlova May 28, 2021
6b9f493
updates req and whitelist
dariadiatlova May 28, 2021
9de5a23
added option to set parameter in encode_data script
dariadiatlova May 28, 2021
3b82f8d
improved dataset class
dariadiatlova May 29, 2021
b41531d
updated requirenments
dariadiatlova May 30, 2021
979a918
updated whitelist
dariadiatlova May 30, 2021
ef62341
changed acc on f1 score and refactoring
dariadiatlova May 30, 2021
cff3619
updated whitelist
dariadiatlova May 30, 2021
26106e9
fixed typing and styles
dariadiatlova May 30, 2021
9902efb
fixed style
dariadiatlova May 30, 2021
cfa2bd4
fixed style
dariadiatlova May 30, 2021
521b168
fixed dataset type
dariadiatlova May 30, 2021
cdb68ca
removed extra to(device)
dariadiatlova May 30, 2021
09a51db
small architecture changes
dariadiatlova May 31, 2021
6b438b8
fixed styles
dariadiatlova May 31, 2021
dfa44fa
small changes in help section
dariadiatlova May 31, 2021
e56d9c5
fixed help section and added readme
dariadiatlova May 31, 2021
1ac4408
Update README.md
dariadiatlova May 31, 2021
1681db2
small fixe in the help section of train config
dariadiatlova May 31, 2021
7e6901e
small fix – added short name in train config
dariadiatlova May 31, 2021
363ccd0
changed full name
dariadiatlova May 31, 2021
84e7dc8
Variable names refactoring
dariadiatlova May 31, 2021
7cd3bb0
Added README
dariadiatlova May 31, 2021
4787f3e
Update README.md
dariadiatlova May 31, 2021
17bec35
Update README.md
dariadiatlova May 31, 2021
31b9c7f
Update README.md
dariadiatlova May 31, 2021
d57938a
Update README.md
dariadiatlova May 31, 2021
f2e9d18
Variable name refactoring
dariadiatlova May 31, 2021
7caa477
Merge remote-tracking branch 'origin/roberta-model' into roberta-model
dariadiatlova May 31, 2021
d66001c
Update README.md
dariadiatlova May 31, 2021
9643a38
Update README.md
dariadiatlova May 31, 2021
c0a9488
Update evaluation_config.py
dariadiatlova May 31, 2021
c21dec0
fixed gpu usage
dariadiatlova May 31, 2021
4b379ba
fixed label choice while computing metric
dariadiatlova May 31, 2021
aa20d14
updated metric class instance
dariadiatlova May 31, 2021
4b634a4
updated f1-score computation
dariadiatlova May 31, 2021
30188d4
updated metric
dariadiatlova May 31, 2021
7e6d6a8
fixed df shape
Jun 1, 2021
685c894
debugging - small fix
dariadiatlova Jun 1, 2021
e339944
small fix - debugging
dariadiatlova Jun 1, 2021
bb554f6
merge preparation
dariadiatlova Jun 3, 2021
21abcdc
fix merge conflicts
dariadiatlova Jun 3, 2021
94a3689
updated whitelist
dariadiatlova Jun 3, 2021
28734ae
Merge branch 'develop' into roberta-model
dariadiatlova Jun 3, 2021
ecaa988
Merge branch 'develop' into roberta-model
nbirillo Jun 4, 2021
982faa6
Fix merge conflicts
nbirillo Jun 4, 2021
c682448
moved model folder and added links to README.md
dariadiatlova Jun 5, 2021
87c13c7
Merge remote-tracking branch 'origin/roberta-model' into roberta-model
dariadiatlova Jun 5, 2021
f76d52b
fixed merge conflicts
dariadiatlova Jun 5, 2021
c77e9c3
fixed line length
dariadiatlova Jun 5, 2021
e230057
added trailing comma
dariadiatlova Jun 5, 2021
350d171
added description section to the readme.md
dariadiatlova Jun 5, 2021
28d40a5
added description for batch_size and num_classes
dariadiatlova Jun 5, 2021
b0700e0
updated paths in readme
dariadiatlova Jun 5, 2021
555d338
added ModelCommonArguments class
dariadiatlova Jun 6, 2021
6a51681
fixed styles
dariadiatlova Jun 6, 2021
f6e3e74
split evaluation script into 2 functions
dariadiatlova Jun 6, 2021
a2b7a0d
added import for typing
dariadiatlova Jun 6, 2021
de3fdb0
extended whitelist
dariadiatlova Jun 6, 2021
6b999f4
resolved arguments naming conflict
dariadiatlova Jun 6, 2021
298fdc3
changed dtype in dataset dataframe
dariadiatlova Jun 6, 2021
2f5cf3c
fixed type issue while reading dataset
dariadiatlova Jun 6, 2021
f3786f4
added examples to the readme
dariadiatlova Jun 6, 2021
2baf137
extended description in readme.md
dariadiatlova Jun 6, 2021
72ed326
added description to the MultilabelTrainer class
dariadiatlova Jun 6, 2021
0e7be42
added description to the preprocessing module
dariadiatlova Jun 6, 2021
fcbf01d
added constant variable names for Measurer class
dariadiatlova Jun 7, 2021
7be1da6
explained one-hot-encoding
dariadiatlova Jun 7, 2021
98acc20
added docs to the context functions and specified return type
dariadiatlova Jun 7, 2021
0f2128e
typo refactoring
dariadiatlova Jun 7, 2021
92dc75c
added option to compute f1-score by classes
dariadiatlova Jun 7, 2021
1b816be
custom metric debugging
dariadiatlova Jun 7, 2021
af0d8fb
custom metric debugging
dariadiatlova Jun 7, 2021
c1b496e
custom metric debugging
dariadiatlova Jun 7, 2021
8a68089
custom metric debugging
dariadiatlova Jun 7, 2021
473d623
resolve merge conflicts
dariadiatlova Jun 7, 2021
2074e24
fixed line length
dariadiatlova Jun 7, 2021
29cbb4d
added logger for f1 score
dariadiatlova Jun 7, 2021
7200b11
added description
dariadiatlova Jun 7, 2021
fcc68d5
added new line import
dariadiatlova Jun 7, 2021
c4e2e54
added new return type
dariadiatlova Jun 7, 2021
ddee437
added option to save f1 scores to the file
dariadiatlova Jun 7, 2021
20e9302
added description of the save metric option to the README.md
dariadiatlova Jun 7, 2021
928e766
fixed file names for report
dariadiatlova Jun 7, 2021
6458799
Update README.md
dariadiatlova Jun 7, 2021
9ca35ac
added column with inspections indices
dariadiatlova Jun 7, 2021
7e2ba8c
delete unnecessary requirements.txt
dariadiatlova Jun 9, 2021
f686b5c
fixed typing
dariadiatlova Jun 9, 2021
f244e41
name refactoring
dariadiatlova Jun 9, 2021
5b7de2a
created separate class for Seed value
dariadiatlova Jun 9, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
pip install -r requirements.txt
pip install -r requirements-test.txt
pip install -r requirements-evaluation.txt
pip install -r requirements-roberta.txt
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
Expand Down
6 changes: 6 additions & 0 deletions requirements-roberta.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tqdm==4.49.0
scikit-learn~=0.24.2
transformers==4.6.1
tokenizers==0.10.2
torch==1.8.1
wandb==0.10.31
118 changes: 118 additions & 0 deletions src/python/evaluation/qodana/imitation_model/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Qodana imitation model
## Description
The general purpose of the model is to simulate the behavior of [`Qodana`](https://github.com/JetBrains/Qodana/tree/main) –
a code quality monitoring tool that identifies and suggests fixes for bugs, security vulnerabilities, duplications, and imperfections.

Motivation for developing a model:
- acceleration of the code analysis process by training the model to recognize a certain class of errors;
- the ability to run the model on separate files without the need to create a project (for example, for the Java language)


## Architecture
[`RobertaForSequenceClassification`](https://huggingface.co/transformers/model_doc/roberta.html#robertaforsequenceclassification) model with [`BCEWithLogitsLoss`](https://pytorch.org/docs/stable/generated/torch.nn.BCEWithLogitsLoss.html) solve multilabel classification task.

Model outputs is a tensor of size: `batch_size` x `num_classes`. Where `batch_size` is the number of training examples utilized in one iteration,
and `num_classes` is the number of error types met in the dataset. By model class here, we mean a unique error type.
Class probabilities are received by taking `sigmoid` and final predictions are computed by comparing the probability of each class with the `threshold`.

As classes might be unbalanced the used metric is `f1-score`.
## What it does

Model has two use cases:
- It can be trained to predict a unique number of errors in a **block** of code, unfixed length.

**Example**:

code | inspections
--- | ---
|`import java.util.Scanner; class Main {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);// put your code here int num = scanner.nextInt(); System.out.println((num / 10 ) % 10);}}`| 1, 2|


- It can be trained to predict a unique number of errors in a **line** of code.

**Example**

code | inspections
--- | ---
|`import java.util.Scanner;`| 0|
|`\n`|0|
|`class Main {`|1|
|`public static void main(String[] args`) {|1|
|`Scanner scanner = new Scanner(System.in);`|0|
|`// put your code here`|0|
|`int num = scanner.nextInt();`|0|
|`System.out.println((num / 10 ) % 10);`|2|
|`}`|0|
|`}`|0|


## Data preprocessing

Please address to the [`following documentation`](src/python/evaluation/qodana) for labeling dataset and to the [`following documentation`](preprocessing) to preprocess data for model training and evaluation afterwards.

After completing the 3d preprocessing step you should have 3 folders:
`train`, `val`, `test` with `train.csv`, `val.csv` and `test.csv` respectively.

Each file has the same structure, it should consist of 4+ columns:
- `id` – solutions id;
- `code` – line od code or block of code;
- `lang` - language version;
- `0`, `1`, `2` ... `n` – several columns, equal to the unique number of errors detected by Qodana in the dataset.
The values in the columns are binary numbers: `1` if inspection is detected and `0` otherwise.


## How to train the model

Run [`train.py`](train.py) script from the command line with the following arguments:

Required arguments:

- `train_dataset_path` ‑ path to the `train.csv` – file that consists of samples
that model will use for training.

- `val_dataset_path` ‑ path to the `val.csv` – file that consists of samples
that model will use for evaluation during training.

Both files are received by running [`split_dataset.py`](preprocessing/split_dataset.py) script and has the structure as described above.

Optional arguments:

Argument | Description
--- | ---
|**‑o**, **‑‑output_directory_path**| Path to the directory where model weights will be saved. If not set, folder will be created in the `train` folder where `train.csv` dataset is stored.|
|**‑c**, **‑‑context_length**| Sequence length or embedding size of tokenized samples. Available values are any `positive integers`. **Default is 40**.|
|**‑e**, **‑‑epoch**| Number of epochs to train model. **Default is 2**.|
|**‑bs**, **‑‑batch_size**| Batch size for training and validation dataset. Available values are any `positive integers`. **Default is 16**.|
|**‑lr**, **‑‑learning_rate**| Optimizer learning rate. **Default is 2e-5**.|
|**‑w**, **‑‑weight_decay**| Weight decay parameter for an optimizer. **Default is 0.01**.|
|**&#8209;th**, **&#8209;&#8209;threshold**| Is used to compute predictions. Available values: 0 < `threshold` < 1. If the probability of inspection is greater than `threshold`, sample will be classified with the inspection. **Default is 0.5**.|
|**&#8209;ws**, **&#8209;&#8209;warm_up_steps**| A number of steps when optimizer uses constant learning rate before applying scheduler policy. **Default is 300**.|
|**&#8209;sl**, **&#8209;&#8209;save_limit**| Total amount of checkpoints limit. Default is 1.|

To inspect the rest of default training parameters please, address to the [`TrainingArguments`](common/train_config.py).

## How to evaluate model

Run [`evaluation.py`](evaluation.py) script from the command line with the following arguments:

Required arguments:

`test_dataset_path` &#8209; path to the `test.csv` received by running [`split_dataset.py`](preprocessing/split_dataset.py) script.

`model_weights_directory_path` &#8209; path to the folder where trained model weights are saved.

Optional arguments:

Argument | Description
--- | ---
|**&#8209;o**, **&#8209;&#8209;output_directory_path**| Path to the directory where labeled dataset will be saved. Default is the `test` folder.|
|**&#8209;c**, **&#8209;&#8209;context_length**| Sequence length or embedding size of tokenized samples. Available values are any `positive integers`. **Default is 40**.|
|**&#8209;sf**, **&#8209;&#8209;save_f1_score**| If enabled report with f1 scores by classes will be saved to the `csv` file in the parent directory of labeled dataset. **Disabled by default**.|
|**&#8209;bs**, **&#8209;&#8209;batch_size**| The number of training examples utilized in one training and validation iteration. Available values are any `positive integers`. **Default is 16**.|
|**&#8209;th**, **&#8209;&#8209;threshold**| Is used to compute predictions. Available values: 0 < `threshold` < 1. If the probability of inspection is greater than `threshold`, sample will be classified with the inspection. **Default is 0.5**.|

Output is a `predictions.csv` file with the column names matches the number of classes. Each sample has a binary label:

- `0` &#8209; if the model didn't found an error in a sample.

- `1` &#8209; if the error was found in a sample.
3 changes: 3 additions & 0 deletions src/python/evaluation/qodana/imitation_model/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from src.python import MAIN_FOLDER

MODEL_FOLDER = MAIN_FOLDER.parent / 'python/imitation_model'
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import argparse

from src.python.evaluation.qodana.imitation_model.common.util import ModelCommonArgument
from src.python.review.common.file_system import Extension


def configure_arguments(parser: argparse.ArgumentParser) -> None:
parser.add_argument('test_dataset_path',
type=str,
help='Path to the dataset received by either'
f' src.python.evaluation.qodana.fragment_to_inspections_list{Extension.PY.value}'
'or src.python.evaluation.qodana.fragment_to_inspections_list_line_by_line'
f'{Extension.PY.value}script.')

parser.add_argument('model_weights_directory_path',
type=str,
help='Path to the directory where trained imitation_model weights are stored.')

parser.add_argument('-o', '--output_directory_path',
default=None,
type=str,
help='Path to the directory where labeled dataset will be saved. Default is the parent folder'
'of test_dataset_path.')

parser.add_argument('-sf', '--save_f1_score',
default=None,
action="store_true",
help=f'If enabled report with f1 scores by class will be saved to the {Extension.CSV.value}'
' File will be saved to the labeled dataset parent directory. Default is False.')

parser.add_argument(ModelCommonArgument.CONTEXT_LENGTH.value.short_name,
ModelCommonArgument.CONTEXT_LENGTH.value.long_name,
type=int,
default=40,
help=ModelCommonArgument.CONTEXT_LENGTH.value.description)

parser.add_argument(ModelCommonArgument.BATCH_SIZE.value.short_name,
ModelCommonArgument.BATCH_SIZE.value.long_name,
type=int,
default=8,
help=ModelCommonArgument.BATCH_SIZE.value.description)

parser.add_argument(ModelCommonArgument.THRESHOLD.value.short_name,
ModelCommonArgument.THRESHOLD.value.long_name,
type=float,
default=0.5,
help=ModelCommonArgument.THRESHOLD.value.description)
41 changes: 41 additions & 0 deletions src/python/evaluation/qodana/imitation_model/common/metric.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import logging.config
from typing import Optional

import torch
from sklearn.metrics import multilabel_confusion_matrix
from src.python.evaluation.qodana.imitation_model.common.util import MeasurerArgument

logger = logging.getLogger(__name__)


class Measurer:
def __init__(self, threshold: float):
self.threshold = threshold

def get_f1_score(self, predictions: torch.tensor, targets: torch.tensor) -> Optional[float]:
confusion_matrix = multilabel_confusion_matrix(targets, predictions)
false_positives = sum(score[0][1] for score in confusion_matrix)
false_negatives = sum(score[1][0] for score in confusion_matrix)
true_positives = sum(score[1][1] for score in confusion_matrix)
try:
f1_score = true_positives / (true_positives + 1 / 2 * (false_positives + false_negatives))
return f1_score
except ZeroDivisionError:
logger.error("No values of the class present in the dataset.")
# return None to make it clear after printing what classes are missing in the datasets
return None

def compute_metric(self, evaluation_predictions: torch.tensor) -> dict:
logits, targets = evaluation_predictions
prediction_probabilities = torch.from_numpy(logits).sigmoid()
predictions = torch.where(prediction_probabilities > self.threshold, 1, 0)
return {MeasurerArgument.F1_SCORE.value: self.get_f1_score(predictions, torch.tensor(targets))}

def f1_score_by_classes(self, predictions: torch.tensor, targets: torch.tensor) -> dict:
unique_classes = range(len(targets[0]))
f1_scores_by_classes = {}
for unique_class in unique_classes:
class_mask = torch.where(targets[:, unique_class] == 1)
f1_scores_by_classes[str(unique_class)] = self.get_f1_score(predictions[class_mask[0], unique_class],
targets[class_mask[0], unique_class])
return f1_scores_by_classes
118 changes: 118 additions & 0 deletions src/python/evaluation/qodana/imitation_model/common/train_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import argparse

import torch
from src.python.evaluation.qodana.imitation_model.common.util import (
DatasetColumnArgument,
ModelCommonArgument,
SeedArgument,
)
from transformers import Trainer, TrainingArguments


class MultilabelTrainer(Trainer):
""" By default RobertaForSequence classification does not support
multi-label classification.

Target and logits tensors should be represented as torch.FloatTensor of shape (1,).
https://huggingface.co/transformers/model_doc/roberta.html#transformers.RobertaForSequenceClassification

To fine-tune the model for the multi-label classification task we can simply modify the trainer by
changing its loss function. https://huggingface.co/transformers/main_classes/trainer.html
"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def compute_loss(self, model, inputs, return_outputs=False):
labels = inputs.pop(DatasetColumnArgument.LABELS.value)
outputs = model(**inputs)
logits = outputs.logits
loss_bce = torch.nn.BCEWithLogitsLoss()
loss = loss_bce(logits.view(-1, self.model.config.num_labels),
labels.float().view(-1, self.model.config.num_labels))

return (loss, outputs) if return_outputs else loss


def configure_arguments(parser: argparse.ArgumentParser) -> None:
parser.add_argument('train_dataset_path',
type=str,
help='Path to the train dataset.')

parser.add_argument('val_dataset_path',
type=str,
help='Path to the dataset received by either')

parser.add_argument('-wp', '--trained_weights_directory_path',
default=None,
type=str,
help='Path to the directory where to save imitation_model weights. Default is the directory'
'where train dataset is.')

parser.add_argument(ModelCommonArgument.CONTEXT_LENGTH.value.short_name,
ModelCommonArgument.CONTEXT_LENGTH.value.long_name,
type=int,
default=40,
help=ModelCommonArgument.CONTEXT_LENGTH.value.description)

parser.add_argument(ModelCommonArgument.BATCH_SIZE.value.short_name,
ModelCommonArgument.BATCH_SIZE.value.long_name,
type=int,
default=16,
help=ModelCommonArgument.BATCH_SIZE.value.description)

parser.add_argument(ModelCommonArgument.THRESHOLD.value.short_name,
ModelCommonArgument.THRESHOLD.value.long_name,
type=float,
default=0.5,
help=ModelCommonArgument.THRESHOLD.value.description)

parser.add_argument('-lr', '--learning_rate',
type=int,
default=2e-5,
help='Learning rate.')

parser.add_argument('-wd', '--weight_decay',
type=int,
default=0.01,
help='Wight decay parameter for optimizer.')

parser.add_argument('-e', '--epoch',
type=int,
default=1,
help='Number of epochs to train imitation_model.')

parser.add_argument('-ws', '--warm_up_steps',
type=int,
default=300,
help='Number of steps used for a linear warmup, default is 300.')

parser.add_argument('-sl', '--save_limit',
type=int,
default=1,
help='Total amount of checkpoints limit. Default is 1.')


class TrainingArgs:
def __init__(self, args):
self.args = args

def get_training_args(self, val_steps_to_be_made):
return TrainingArguments(num_train_epochs=self.args.epoch,
per_device_train_batch_size=self.args.batch_size,
per_device_eval_batch_size=self.args.batch_size,
learning_rate=self.args.learning_rate,
warmup_steps=self.args.warm_up_steps,
weight_decay=self.args.weight_decay,
save_total_limit=self.args.save_limit,
output_dir=self.args.trained_weights_directory_path,
overwrite_output_dir=True,
load_best_model_at_end=True,
greater_is_better=True,
save_steps=val_steps_to_be_made,
eval_steps=val_steps_to_be_made,
logging_steps=val_steps_to_be_made,
evaluation_strategy=DatasetColumnArgument.STEPS.value,
logging_strategy=DatasetColumnArgument.STEPS.value,
seed=SeedArgument.SEED.value,
report_to=[DatasetColumnArgument.WANDB.value])
46 changes: 46 additions & 0 deletions src/python/evaluation/qodana/imitation_model/common/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from enum import Enum, unique

from src.python.common.tool_arguments import ArgumentsInfo


@unique
class DatasetColumnArgument(Enum):
ID = 'id'
IN_ID = 'inspection_id'
INSPECTIONS = 'inspections'
INPUT_IDS = 'input_ids'
LABELS = 'labels'
DATASET_PATH = 'dataset_path'
STEPS = 'steps'
WEIGHTS = 'weights'
WANDB = 'wandb'


@unique
class SeedArgument(Enum):
SEED = 42


@unique
class CustomTokens(Enum):
NOC = '[NOC]' # no context token to add when there are no lines for the context


@unique
class ModelCommonArgument(Enum):
THRESHOLD = ArgumentsInfo('-th', '--threshold',
'If the probability of inspection on code sample is greater than threshold,'
'inspection id will be assigned to the sample. '
'Default is 0.5.')

CONTEXT_LENGTH = ArgumentsInfo('-cl', '--context_length',
'Sequence length of 1 sample after tokenization, default is 40.')

BATCH_SIZE = ArgumentsInfo('-bs', '--batch_size',
'Batch size – default values are 16 for training and 8 for evaluation mode.')


@unique
class MeasurerArgument(Enum):
F1_SCORE = 'f1_score'
F1_SCORES_BY_CLS = 'f1_scores_by_class'
Empty file.
Loading