-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
45 lines (32 loc) · 1.27 KB
/
config.py
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
36
37
38
39
40
41
42
43
44
45
from pathlib import Path
from dataclasses import dataclass
from typing import Optional
@dataclass
class Config:
batch_size: int = 8
num_epochs: int = 20
lr: float = 10**-4
seq_len: int = 350
d_model: int = 512
datasource: str = 'news_commentary'
lang_src: str = "en"
lang_tgt: str = "ar"
model_folder: str = "models"
preload: str = "latest"
tokenizer_file: str = "tokenizer_{0}.json"
experiment_name: str = "runs/tmodel"
def get_weights_files_path(self, epoch: str):
return str(Path(self.model_folder).glob(f'checkpoint_{epoch}.pth'))
def latest_weights_file_path(self) -> Optional[str]:
checkpoints = list(Path(self.model_folder).glob('checkpoint_*.pth'))
if checkpoints:
# Extract the epoch number from each checkpoint file name and find the maximum
latest_checkpoint = max(checkpoints, key=lambda x: int(x.stem.split('_')[1]))
return str(latest_checkpoint)
return None
if __name__=="__main__":
config = Config()
weights_file_path = config.get_weights_file_path("10")
print("Specific weights file path:", weights_file_path)
latest_weights = config.latest_weights_file_path()
print("Latest weights file path:", latest_weights)