Skip to content

Commit

Permalink
Merge pull request #638 from mv1388/code-style-improvement
Browse files Browse the repository at this point in the history
Code style fix
  • Loading branch information
mv1388 committed Oct 31, 2020
2 parents 9177a87 + c51bfe8 commit dc52418
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion aitoolbox/experiment/experiment_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def __init__(self, project_name, experiment_name,
BaseFullExperimentS3Saver.__init__(self, keras_model_saver, project_name, experiment_name,
bucket_name=bucket_name, cloud_dir_prefix=cloud_dir_prefix,
local_model_result_folder_path=local_model_result_folder_path)


# class FullTensorFlowExperimentS3Saver(BaseFullExperimentS3Saver):
# def __init__(self, project_name, experiment_name,
Expand Down
2 changes: 1 addition & 1 deletion aitoolbox/experiment/training_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def __init__(self, has_validation=True, strict_content_check=False):
In many ways the object can be used with the same API as a normal python dict. However, for the need of
tracking performance in the TrainLoop TrainingHistory offers additional functions handling the input, output
and quality assurance of the stored results.
Args:
has_validation: if train history should by default include 'val_loss'. This is needed when train loops
by default evaluate loss on validation set when such a set is available.
Expand Down
1 change: 0 additions & 1 deletion aitoolbox/nlp/dataset/HotpotQA/HotpotQA.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def get_dataset_local_copy(local_dataset_folder_path, protect_local_folder=True)
Returns:
None
"""
dataset_fetcher = HotpotQADatasetFetcher(bucket_name='dataset-store', local_dataset_folder_path=local_dataset_folder_path)
dataset_fetcher.fetch_dataset(protect_local_folder=protect_local_folder)
6 changes: 4 additions & 2 deletions aitoolbox/nlp/experiment_evaluation/NLP_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,10 @@ def __init__(self, y_true, y_predicted, lowercase=False, source_sents=None, outp
def calculate_metric(self):
BLEUSentenceScoreMetric.check_transl_sent_num_match([self.y_true, self.y_predicted])

sentence_bleu_results = [bleu.get_moses_multi_bleu([' '.join(true_t)], [' '.join(pred_t)], lowercase=self.lowercase)
for true_t, pred_t in zip(self.y_true, self.y_predicted)]
sentence_bleu_results = [
bleu.get_moses_multi_bleu([' '.join(true_t)], [' '.join(pred_t)], lowercase=self.lowercase)
for true_t, pred_t in zip(self.y_true, self.y_predicted)
]

if self.output_text_dir is not None:
BLEUSentenceScoreMetric.dump_translation_text_to_disk(self.source_sents,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def build_FastQA_RNN_concat_model_GLOVE(RNN, story_maxlen, query_maxlen, vocab_s
# local_model_result_folder_path = '/home/ec2-user/project/model_results'

m_saver = KerasS3ModelSaver(local_model_result_folder_path=local_model_result_folder_path)
s3_model_path, experiment_timestamp, _ = m_saver.save_model(model=model,
s3_model_path, experiment_timestamp, _ = m_saver.save_model(model=model,
project_name='QA_QAngaroo', experiment_name='separate_files2',
protect_existing_folder=True)
print(s3_model_path)
Expand Down
2 changes: 0 additions & 2 deletions examples/misc_examples/torchtrain_MT_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@


"""
Based on:
https://github.com/bentrevett/pytorch-seq2seq/blob/master/4%20-%20Packed%20Padded%20Sequences%2C%20Masking%20and%20Inference.ipynb
"""


Expand Down
2 changes: 1 addition & 1 deletion tests/test_experiment/test_local_experiment_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def save_experiment_options(self, save_true_pred_labels, separate_files):
os.path.join(results_path, f'results_{exp_dir_name}_{current_time}.p'),
os.path.join(results_path, f'hyperparams_{exp_dir_name}_{current_time}.p'),
os.path.join(results_path, f'train_history_{exp_dir_name}_{current_time}.p')]

if save_true_pred_labels:
saved_paths_true.append(os.path.join(results_path, f'true_pred_labels_{exp_dir_name}_{current_time}.p'))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def save_model_local(self, checkpoint_model, epoch):
exp_dir_name = 'experimentSubDirPT'
current_time = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d_%H-%M-%S')
model_name_true = f'model_{exp_dir_name}_{current_time}_E{epoch}.pth'

project_path = os.path.join(THIS_DIR, project_dir_name)
exp_path = os.path.join(project_path, f'{exp_dir_name}_{current_time}')
model_path = os.path.join(exp_path, 'checkpoint_model' if checkpoint_model else 'model')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_result_package_prepare(self):
y_test = result_pkg.y_true
y_pred = result_pkg.y_predicted
metadata = result_pkg.additional_results['additional_results']

r = []
for i in range(1, len(dummy_val_loader) + 1):
r += [i] * 64
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils/test_dict_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class TestFlattenDict(unittest.TestCase):
def test_flatten_dict(self):
input_dict = {'bla': 12, 'www': 455, 'pppp': 4004}
self.assertEqual(dict_util.flatten_dict(input_dict), input_dict)

input_dict_1_level = {'bla': {'uuu': 334, 'www': 1010}, 'rogue': {'ppp': 123}}
self.assertEqual(dict_util.flatten_dict(input_dict_1_level),
{'bla_uuu': 334, 'bla_www': 1010, 'rogue_ppp': 123})
Expand Down
4 changes: 2 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def get_predictions(self, batch_data, device):
x, y = batch_data
pred_y, _ = self(x)
return pred_y, y, {}


def keras_dummy_model():
from keras.models import Sequential
Expand Down Expand Up @@ -237,7 +237,7 @@ def get_loss(self, model, batch_data, criterion, device):
Returns:
PyTorch loss
"""
"""
return self.dummy_batch

def get_loss_eval(self, model, batch_data, criterion, device):
Expand Down

0 comments on commit dc52418

Please sign in to comment.