Model Metadata¶
- jlnn.storage.metadata.load_metadata(filepath: str | Path) Dict[str, Any][source]¶
Retrieves and deserializes metadata from a JSON file.
This function is typically called during model reconstruction or when exporting the network to symbolic rules. It allows the ‘export’ module to label the trained weights with their corresponding real-world names.
- Parameters:
filepath (Union[str, Path]) – Path to the source .json file.
- Returns:
The metadata dictionary containing model configuration.
- Return type:
Dict[str, Any]
- Raises:
FileNotFoundError – If the specified metadata file does not exist.
json.JSONDecodeError – If the file is not a valid JSON.
- jlnn.storage.metadata.save_metadata(metadata: Dict[str, Any], filepath: str | Path)[source]¶
Serializes and saves model configuration metadata to a JSON file.
In the context of Logical Neural Networks (LNN), metadata is essential for mapping the numerical indices of the network back to their symbolic meanings (e.g., mapping input index 0 to the predicate ‘is_red’). This function ensures that the conceptual structure of the model is preserved alongside the trained weights.
- Parameters:
metadata (Dict[str, Any]) – A dictionary containing metadata such as: - ‘predicate_names’: List of strings labeling the input features. - ‘logic_semantics’: The t-norm type used (e.g., ‘lukasiewicz’). - ‘model_version’: Versioning for tracking experiments.
filepath (Union[str, Path]) – Destination path for the .json file. The directory tree will be created automatically if it doesn’t exist.
Example
>>> meta = {"predicates": ["low_temp", "high_pressure"], "version": 1.0} >>> save_metadata(meta, "storage/model_meta.json")
Metadata in JLNN serves as a bridge between the numerical world of neural networks and the symbolic world of logic. Without metadata, learned weights would be just a list of numbers without knowledge of which predicate (e.g., “Temperature”) they belong to.
Metadata Structure:¶
A typical .json file contains:
* predicate_names: List of names of input sensors/facts.
* logic_semantics: Information about the used semantics (e.g., ‘lukasiewicz’).
* version: Model version for tracking experiments.