box_embeddings.parameterizations.delta_box_tensor

Implementation of min-delta box parameterization.

Module Contents

class MinDeltaBoxTensor(data: Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]], beta: float = 1.0, threshold: float = 20)

Bases: box_embeddings.parameterizations.box_tensor.BoxTensor

Unconstrained min-delta box tensor.

For input of the shape (…, 2, box_dim), this parameterization defines z=w, and Z=w + delta, where w and delta come from the -2th dimension of the input. It uses softplus to keep the delta positive.

property kwargs(self) Dict

Configuration attribute values

Returns

Dict

property args(self) Tuple

Configuration attribute as Tuple

Returns

Tuple

property Z(self) torch.Tensor

Top right coordinate as Tensor

Returns

top right corner

Return type

Tensor

classmethod W(cls: Type[box_embeddings.parameterizations.box_tensor.TBoxTensor], z: torch.Tensor, Z: torch.Tensor, beta: float = 1.0, threshold: float = 20.0) torch.Tensor

Given (z,Z), it returns one set of valid box weights W, such that Box(W) = (z,Z).

The min coordinate is stored as is: W[…,0,:] = z W[…,1,:] = softplus_inverse(Z-z)

The max coordinate is transformed

Parameters
  • z – Lower left coordinate of shape (…, hidden_dims)

  • Z – Top right coordinate of shape (…, hidden_dims)

  • beta – TODO

  • threshold – TODO

Returns

Parameters of the box. In base class implementation, this

will have shape (…, 2, hidden_dims).

Return type

Tensor

classmethod from_vector(cls, vector: torch.Tensor, beta: float = 1.0, threshold: float = 20) box_embeddings.parameterizations.box_tensor.BoxTensor

Creates a box for a vector. In this base implementation the vector is split into two pieces and these are used as z and delta.

Parameters
  • vector – tensor

  • beta – beta parameter for softplus for delta. Depending on the universe box and your inputs ranges, you might want to change this. Higher values of beta will make softplus harder and bring it close to ReLU.

  • threshold – parameter for the softplus for delta

Returns

A BoxTensor

Raises

ValueError – if last dimension is not even