From 517cf76b98e6b951384a4a925af04d9ff246d9ee Mon Sep 17 00:00:00 2001 From: claudiu_daniel_hromei <38636-claudiu_daniel_hromei@users.noreply.gitlab.aicrowd.com> Date: Sun, 29 Jan 2023 15:36:14 +0100 Subject: [PATCH] updated for italian version --- grut.py | 2 +- huricParser.py | 2 +- requirements.txt | 2 +- train.sh | 6 +++--- trainer.py | 17 +++++++++++------ 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/grut.py b/grut.py index 94c578b..076efec 100644 --- a/grut.py +++ b/grut.py @@ -58,7 +58,7 @@ def defineTrainArguments(n_fold, use_cuda, epochs, targetType, modelName, modelV # Optional argument parser.add_argument('-mn','--model_name', type=str, - help='model name. Default "' + str(modelName) + '". Define only in train mode.') + help='model name. Choices: ["bart", "mbart", "t5", "mt5"], Default "' + str(modelName) + '". Define only in train mode.') # Optional argument parser.add_argument('-mv','--model_variant', type=str, diff --git a/huricParser.py b/huricParser.py index 96ed638..15c1faa 100644 --- a/huricParser.py +++ b/huricParser.py @@ -300,7 +300,7 @@ def parseMap(self, entities, lexicalGroundings, lexicalizedMap: bool): def computeLexicalGroundingsANDparseMap(self, entities, sentence, map_type, entityRetrievalType, lexicalReferences = "all", thresholdW2V = 0.5, thresholdLDIST = 0.8): - print("computeLexicalGroundingsANDparseMap") + # print("computeLexicalGroundingsANDparseMap") entities_list = [] atoms = {} diff --git a/requirements.txt b/requirements.txt index 15cde54..f00c5b2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ numpy==1.22.2 pandas==1.4.1 scikit_learn==1.1.3 seqeval==1.2.2 -simpletransformers==0.63.4 +simpletransformers==0.63.9 spacy==3.3.1 torch==1.10.2 transformers==4.16.2 diff --git a/train.sh b/train.sh index 4248db8..87698e1 100644 --- a/train.sh +++ b/train.sh @@ -1,9 +1,9 @@ #!/bin/sh # BART_base - nohup python -u main.py train -mn bart -mv base -t SRL -bs 32 -uc True -ep 50 -nf 10 -tt SRL > logs/testing_verbose_with_prints_bart_base.out + nohup python -u grut.py train -mn bart -mv base -t SRL -bs 32 -uc True -ep 50 -nf 10 -tt SRL > logs/testing_verbose_with_prints_bart_base.out # GRUT - nohup python -u main.py train -mn bart -mv base -t SRL -bs 32 -uc True -ep 50 -nf 10 -tt SRL -gr half -map lmd > logs/testing_verbose_with_prints_grut.out + nohup python -u grut.py train -mn bart -mv base -t SRL -bs 32 -uc True -ep 50 -nf 10 -tt SRL -gr half -map lmd > logs/testing_verbose_with_prints_grut.out # GRUT_LU - nohup python -u main.py train -mn bart -mv base -t SRL -bs 32 -uc True -ep 50 -nf 10 -tt SRL -gr half -map lmd -alut True > logs/testing_verbose_with_prints_grut_lu.out + nohup python -u grut.py train -mn bart -mv base -t SRL -bs 32 -uc True -ep 50 -nf 10 -tt SRL -gr half -map lmd -alut True > logs/testing_verbose_with_prints_grut_lu.out diff --git a/trainer.py b/trainer.py index 9efb4ca..a45b20f 100644 --- a/trainer.py +++ b/trainer.py @@ -52,7 +52,7 @@ def __init__(self, lan: Language, model = 'bart', model_variant = 'base', task = self.model_args.gradient_accumulation_steps = 2 self.model_args.early_stopping_patience = patience self.model_args.early_stopping_delta = 1e-4 #0.005 - elif model == "bart": + elif model == "bart" or model == "mbart": self.model_args = Seq2SeqArgs() self.model_args.fp16 = False self.model_args.optimizer = "AdamW" #"Adafactor" @@ -60,7 +60,10 @@ def __init__(self, lan: Language, model = 'bart', model_variant = 'base', task = self.model_args.learning_rate = learning_rate self.model_args.eval_batch_size = batch_size self.model_args.train_batch_size = batch_size - self.model_name = 'facebook/bart-' + model_variant + if model == "bart": + self.model_name = 'facebook/bart-' + model_variant + else: + self.model_name = 'facebook/mbart-large-cc25' self.model_args.gradient_accumulation_steps = 2 self.model_args.early_stopping_patience = patience self.model_args.early_stopping_delta = 1e-4 #0.001 @@ -111,7 +114,7 @@ def train_saving_all_folds_models(self, num_folds, quick_train = False, addMap = else: lutype = "" - kfold_folder_name = self.model + '_' + self.lan.value + "_" + map_type + "_" + grounding + "grounding_" + entityRetrievalType + "_" + lexicalReferences + "LexicalReferences" + lutype + kfold_folder_name = self.lan.value + "/" + self.model + '_' + "_" + map_type + "_" + grounding + "grounding_" + entityRetrievalType + "_" + lexicalReferences + "LexicalReferences" + lutype kfold_folder_name += "_" + date_time kfold_base_dir = model_folder_name + '/' + kfold_folder_name + '/' hp = HuricParser(self.lan) @@ -125,7 +128,6 @@ def train_saving_all_folds_models(self, num_folds, quick_train = False, addMap = hp.writeHuricSentences("./data/huric/", "./data/huric_sentences_" + self.lan.value + ".csv") df = pd.read_csv("./data/huric_sentences_" + self.lan.value + ".csv") - # if quick_train is True, take 100 examples and quick train if quick_train: @@ -258,13 +260,16 @@ def train_saving_all_folds_models(self, num_folds, quick_train = False, addMap = eval_df['prefix'] = [self.task] * len(eval_df['input_text'].tolist()) train_df['prefix'] = [self.task] * len(train_df['input_text'].tolist()) - elif self.model in ["bart"]: + elif self.model in ["bart", "mbart"]: model = Seq2SeqModel( - encoder_decoder_type="bart", + encoder_decoder_type=self.model, encoder_decoder_name=self.model_name, args=self.model_args, use_cuda=cuda_available ) + + print(allData.head()) + quit() print("_______________STARTING TO TRAIN_______________") model_train_out = model.train_model(train_df, eval_data=eval_df)