Skip to content

explanation_artifact

Explanation result as an Artifact.

Classes:

Name Description
ExplanationArtifact

ExplanationArtifact object.

ExplanationArtifact #

ExplanationArtifact object.

This object should never be built manually. It is not allowed to update an instance of it as it is also saved remotely. It is still safe to update name and description attributes.

Parameters:

Name Type Description Default

id #

str
required

created_at #

str
required

created_by #

str
required

updated_at #

str
required

updated_by #

str
required

project_id #

str
required

hash_ #

str
required

private #

str
required

name #

str
required

description #

str
required

core_version #

str
required

project #

str
required

input_steps #

str
required

output_steps #

str
required

type_ #

str
required

trained_model_checkpoint_id #

str
required

datasets #

str
required

filter_ #

str
required

trained_model_checkpoint #

str
required

Attributes:

Name Type Description
additional_properties str

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

Methods:

Name Description
__setattr__

Set attribute.

__repr__

Get class representation without results, accessible with results attribute.

load_all

Load all explanations of the current project.

get_by_id

Get Explanation artifact by its ID.

get_by_name

Get Explanation artifact by its name.

delete

Delete the current object remotely.

Compute and return the visualisation link.

__setattr__(attr: str, value: object) -> None #

Set attribute.

Source code in src/xpdeep/explain/explanation_artifact.py
@initialized_client_verification
@initialized_project_verification
def __setattr__(self, attr: str, value: object) -> None:
    """Set attribute."""
    if attr in {"name", "description"} and hasattr(self, attr):
        with ClientFactory.CURRENT.get()() as client:
            update_explanation_artifact.sync(
                Project.CURRENT.get().model.id,
                object.__getattribute__(self, "id"),
                client=client,
                body=ExplanationArtifactUpdate(
                    type_="EXPLANATION",
                    name=value if attr == "name" else None,  # type: ignore[arg-type]
                    description=value if attr == "description" else None,  # type: ignore[arg-type]
                ),
            )
    elif hasattr(self, attr) and attr != "additional_properties":
        message = f'Updating attribute "{attr}" is not allowed'
        raise AttributeError(message)

    object.__setattr__(self, attr, value)

__repr__() -> str #

Get class representation without results, accessible with results attribute.

Source code in src/xpdeep/explain/explanation_artifact.py
@initialized_client_verification
@initialized_project_verification
def __repr__(self) -> str:
    """Get class representation without results, accessible with `results` attribute."""
    attributes_to_show = ["created_at", "id", "name", "project_id", "visualisation_link"]
    table = {attr: getattr(self, attr) for attr in attributes_to_show}
    return pformat(table, indent=4, width=100)

load_all(type_: Literal['all', 'global', 'local'] = 'all') -> list[ExplanationArtifact] #

Load all explanations of the current project.

Parameters:

Name Type Description Default
type_ #
Literal["all", "global", "local"] default "all"

Specify which kind of explanations to load.

'all'
Source code in src/xpdeep/explain/explanation_artifact.py
@classmethod
@initialized_client_verification
@initialized_project_verification
def load_all(cls, type_: Literal["all", "global", "local"] = "all") -> list["ExplanationArtifact"]:
    """Load all explanations of the current project.

    Parameters
    ----------
    type_ : Literal["all", "global", "local"] default "all"
        Specify which kind of explanations to load.
    """
    explanation_artifacts = [cls.from_dict(select_one.to_dict()) for select_one in cls._load()]

    if type_ == "global":
        return [
            explanation_artifact
            for explanation_artifact in explanation_artifacts
            if explanation_artifact.filter_ is None
        ]
    if type_ == "local":
        return [
            explanation_artifact
            for explanation_artifact in explanation_artifacts
            if explanation_artifact.filter_ is not None
        ]
    return explanation_artifacts

get_by_id(explanation_id: str) -> ExplanationArtifact #

Get Explanation artifact by its ID.

Parameters:

Name Type Description Default
explanation_id #
str

The ID of the explanation artifact to retrieve.

required
Source code in src/xpdeep/explain/explanation_artifact.py
@classmethod
@initialized_client_verification
@initialized_project_verification
def get_by_id(cls, explanation_id: str) -> "ExplanationArtifact":
    """Get Explanation artifact by its ID.

    Parameters
    ----------
    explanation_id : str
        The ID of the explanation artifact to retrieve.
    """
    try:
        return cls.from_dict(next(iter(cls._load(explanation_id=explanation_id))).to_dict())
    except StopIteration as err:
        message = f"No Explanation artifact found for the explanation ID: {explanation_id}"
        raise NotSavedError(message) from err

get_by_name(explanation_name: str) -> ExplanationArtifact #

Get Explanation artifact by its name.

Parameters:

Name Type Description Default
explanation_name #
str

The name of the explanation artifact to retrieve.

required
Source code in src/xpdeep/explain/explanation_artifact.py
@classmethod
@initialized_client_verification
@initialized_project_verification
def get_by_name(cls, explanation_name: str) -> "ExplanationArtifact":
    """Get Explanation artifact by its name.

    Parameters
    ----------
    explanation_name : str
        The name of the explanation artifact to retrieve.
    """
    try:
        return cls.from_dict(next(iter(cls._load(explanation_name=explanation_name))).to_dict())
    except StopIteration as err:
        message = f"No Explanation artifact found for the explanation name: {explanation_name}"
        raise NotSavedError(message) from err

delete() -> None #

Delete the current object remotely.

Source code in src/xpdeep/explain/explanation_artifact.py
@initialized_client_verification
@initialized_project_verification
def delete(self) -> None:
    """Delete the current object remotely."""
    with ClientFactory.CURRENT.get()() as client:
        delete_one_explanation_artifact.sync(
            Project.CURRENT.get().model.id,
            self.id,
            client=client,
        )