Skip to content

Commit 291ac3a

Browse files
authored
CU-8698gkrqa: Add argument to allow specifying the changes warrenting a model save (#525)
1 parent e880cf2 commit 291ac3a

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

medcat/cat.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,12 @@ def get_model_card(self, as_dict: bool = False):
210210
else:
211211
return json.dumps(card, indent=2, sort_keys=False)
212212

213-
def _versioning(self, force_rehash: bool = False):
213+
def _versioning(self, force_rehash: bool = False,
214+
change_description: Optional[str] = None):
214215
# Check version info and do not allow without it
216+
date_today = date.today().strftime("%d %B %Y")
217+
if change_description is not None:
218+
self.config.version.description += f"\n[{date_today}] {change_description}"
215219
if self.config.version.description == 'No description':
216220
logger.warning("Please consider populating the version information [description, performance, location, ontology] in cat.config.version")
217221

@@ -222,14 +226,17 @@ def _versioning(self, force_rehash: bool = False):
222226
if version.id is not None:
223227
version.history.append(version['id'])
224228
version.id = m
225-
version.last_modified = date.today().strftime("%d %B %Y")
229+
version.last_modified = date_today
226230
version.cdb_info = self.cdb.make_stats()
227231
version.meta_cats = [meta_cat.get_model_card(as_dict=True) for meta_cat in self._meta_cats]
228232
version.medcat_version = __version__
229233
logger.warning("Please consider updating [description, performance, location, ontology] in cat.config.version")
230234

231-
def create_model_pack(self, save_dir_path: str, model_pack_name: str = DEFAULT_MODEL_PACK_NAME, force_rehash: bool = False,
232-
cdb_format: str = 'dill') -> str:
235+
def create_model_pack(self, save_dir_path: str,
236+
model_pack_name: str = DEFAULT_MODEL_PACK_NAME,
237+
force_rehash: bool = False,
238+
change_description: Optional[str] = None,
239+
cdb_format: str = 'dill') -> str:
233240
"""Will crete a .zip file containing all the models in the current running instance
234241
of MedCAT. This is not the most efficient way, for sure, but good enough for now.
235242
@@ -240,6 +247,8 @@ def create_model_pack(self, save_dir_path: str, model_pack_name: str = DEFAULT_M
240247
The model pack name. Defaults to DEFAULT_MODEL_PACK_NAME.
241248
force_rehash (bool):
242249
Force recalculation of hash. Defaults to `False`.
250+
change_description (Optional[str]):
251+
The description of the change due to which a save is required. Defaults to None.
243252
cdb_format (str):
244253
The format of the saved CDB in the model pack.
245254
The available formats are:
@@ -254,7 +263,7 @@ def create_model_pack(self, save_dir_path: str, model_pack_name: str = DEFAULT_M
254263
# Spacy model always should be just the name, but during loading it can be reset to path
255264
self.config.general.spacy_model = os.path.basename(self.config.general.spacy_model)
256265
# Versioning
257-
self._versioning(force_rehash)
266+
self._versioning(force_rehash, change_description)
258267
model_pack_name += "_{}".format(self.config.version.id)
259268

260269
logger.warning("This will save all models into a zip file, can take some time and require quite a bit of disk space.")

0 commit comments

Comments
 (0)