Utils
unimol_tools.utils contains the utils related to the model, such as metrics and logger.
Metrics
unimol_tools.utils.metrics contains the metrics included in the model.
- class unimol_tools.utils.metrics.Metrics(task=None, metrics_str=None, **params)[source]
Class for calculating metrics for different tasks.
- Parameters:
task – The task type. Supported tasks are ‘regression’, ‘multilabel_regression’, ‘classification’, ‘multilabel_classification’, and ‘multiclass’.
metrics_str – Comma-separated string of metric names. If provided, only the specified metrics will be calculated. If not provided or an empty string, default metrics for the task will be used.
- cal_classification_metric(label, predict, nan_value=-1.0, threshold=None)[source]
- Parameters:
label – the labels of the dataset.
predict – the predict values of the model.
Logger
unimol_tools.utils.base_logger.py control the logger.
- class unimol_tools.utils.base_logger.PackagePathFilter(name='')[source]
A custom logging filter for adding the relative path to the log record.
- class unimol_tools.utils.base_logger.Logger(*args, **kwargs)[source]
A custom logger class that provides logging functionality to console and file.
- class unimol_tools.utils.base_logger.HighlightFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]
- format(record)[source]
Format the specified record as text.
The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.
Config
unimol_tools.utils.config_handler.py manages the config input file.
- class unimol_tools.utils.config_handler.YamlHandler(file_path)[source]
A clss to read and write the yaml file
- __init__(file_path)[source]
A custom logger class that provides logging functionality to console and file.
- Parameters:
file_path – (str) The yaml file path of the config.
Padding
unimol_tools.utils.util.py contain some padding methods.
- unimol_tools.utils.util.pad_1d_tokens(values, pad_idx, left_pad=False, pad_to_length=None, pad_to_multiple=1)[source]
padding one dimension tokens inputs.
- Parameters:
values – A list of 1d tensors.
pad_idx – The padding index.
left_pad – Whether to left pad the tensors. Defaults to False.
pad_to_length – The desired length of the padded tensors. Defaults to None.
pad_to_multiple – The multiple to pad the tensors to. Defaults to 1.
- Returns:
A padded 1d tensor as a torch.Tensor.
- unimol_tools.utils.util.pad_2d(values, pad_idx, dim=1, left_pad=False, pad_to_length=None, pad_to_multiple=1)[source]
padding two dimension tensor inputs.
- Parameters:
values – A list of 2d tensors.
pad_idx – The padding index.
left_pad – Whether to pad on the left side. Defaults to False.
pad_to_length – The length to pad the tensors to. If None, the maximum length in the list is used. Defaults to None.
pad_to_multiple – The multiple to pad the tensors to. Defaults to 1.
- Returns:
A padded 2d tensor as a torch.Tensor.
- unimol_tools.utils.util.pad_coords(values, pad_idx, dim=3, left_pad=False, pad_to_length=None, pad_to_multiple=1)[source]
padding two dimension tensor coords which the third dimension is 3.
- Parameters:
values – A list of 1d tensors.
pad_idx – The value used for padding.
left_pad – Whether to pad on the left side. Defaults to False.
pad_to_length – The desired length of the padded tensor. Defaults to None.
pad_to_multiple – The multiple to pad the tensor to. Defaults to 1.
- Returns:
A padded 2d coordinate tensor as a torch.Tensor.