-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
35 lines (29 loc) · 1.03 KB
/
config.py
File metadata and controls
35 lines (29 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from pathlib import Path
def get_config():
return{
"batch_size": 8,
"num_epochs": 20,
"lr": 10**-4,
"seq_len": 350,
"d_model": 512,
"datasource": "opus_books",
"lang_src": "en",
"lang_tgt": "it",
"model_folder": "weights",
"model_basename": "transformer_model_",
"preload": None,
"tokenizer_file": "tokenizer_{0}.json",
"experiment_name": "run/tmodel"
}
def get_weights_file_path(config, epoch:str):
model_folder = f"{config['datasource']}_config['model_folder']"
model_filename = f"{config['model_basename']}{epoch}.pt"
return str(Path('.')/model_folder/model_filename)
def latest_weights_file_path(config):
model_folder = f"{config['datasource']}_config['model_folder']"
model_filename = f"{config['model_basename']}*.pt"
weights_files = list(Path(model_folder).glob(model_filename))
if len(weights_files) == 0:
return None
weights_files.sort()
return str(weights_files[-1])