pulsatrix 1.1.0
Loading...
Searching...
No Matches
pulsatrix::PointCloud Class Reference

A set of points in R^dimension, built from activation batches. More...

#include <point_cloud.hpp>

Public Member Functions

 PointCloud (PointCloudOptions options={})
 An empty cloud.
 
void add (const Tensor &batch)
 Adds one batch.
 
void add (const ActivationSnapshot &snapshot, NodeId node)
 Adds one forward pass's activations at a node.
 
int64_t size () const
 The number of points.
 
int64_t dimension () const
 Each point's number of coordinates; 0 until the first batch.
 
int64_t samples () const
 The number of samples added, over every batch.
 
const PointCloudOptions & options () const
 The settings it was built with.
 
const std::vector< float > & values () const
 The points, row-major: size() rows of dimension() values.
 
const std::vector< PointOrigin > & origins () const
 Where each point came from, in the same order as values().
 
Tensor ToTensor (DeviceBackend *backend) const
 The points as a (size(), dimension()) tensor.
 

Detailed Description

A set of points in R^dimension, built from activation batches.

Add batches with add(); each is a tensor with the batch on its first axis. The first batch fixes the dimension, and every later one must give points of the same dimension. Batches may differ in their number of positions, so texts of different lengths can be added one by one.

Points are stored on the host as float32, as the activations were; ToTensor() places them on a backend for the distance computation.

model->set_hidden_state_hook([&](int64_t position, const Tensor& h) {
if (position == 6) cloud.add(h); // (1, tokens, width): one point per token
return h;
});
for (const auto& text : corpus) (void)model->forward(Encode(text));
// cloud.size() points of cloud.dimension() = width; cloud.origins()[i] says which text and token.
A set of points in R^dimension, built from activation batches.
Definition point_cloud.hpp:86
N-dimensional tensor. Owns its data buffer exclusively; a DeviceBackend* is injected (not owned) – th...
Definition tensor.hpp:29
@ PerPosition
One point per position (token, pixel): the feature axis is its coordinates.

Constructor & Destructor Documentation

◆ PointCloud()

pulsatrix::PointCloud::PointCloud ( PointCloudOptions  options = {})
explicit

An empty cloud.

Exceptions
std::invalid_argumentif options.pooling is out of range.

Member Function Documentation

◆ add() [1/2]

void pulsatrix::PointCloud::add ( const ActivationSnapshot &  snapshot,
NodeId  node 
)

Adds one forward pass's activations at a node.

Parameters
nodeOne of snapshot.node_ids().
Exceptions
std::invalid_argumentas add(const Tensor&) does.

◆ add() [2/2]

void pulsatrix::PointCloud::add ( const Tensor &  batch)

Adds one batch.

Parameters
batchshape (batch, ...). For every pooling but Flatten it needs a feature axis: rank 2 or more, with options().feature_axis not the batch axis. A rank-2 tensor has one position per sample.
Exceptions
std::invalid_argumentif batch has rank below 2, an empty dimension, a NaN or infinity, a feature axis out of range or on the batch axis, or points of a different dimension from the batches before it. A batch that throws adds nothing.

◆ dimension()

int64_t pulsatrix::PointCloud::dimension ( ) const
inline

Each point's number of coordinates; 0 until the first batch.

◆ options()

const PointCloudOptions & pulsatrix::PointCloud::options ( ) const
inline

The settings it was built with.

◆ origins()

const std::vector< PointOrigin > & pulsatrix::PointCloud::origins ( ) const
inline

Where each point came from, in the same order as values().

◆ samples()

int64_t pulsatrix::PointCloud::samples ( ) const
inline

The number of samples added, over every batch.

◆ size()

int64_t pulsatrix::PointCloud::size ( ) const
inline

The number of points.

◆ ToTensor()

Tensor pulsatrix::PointCloud::ToTensor ( DeviceBackend *  backend) const

The points as a (size(), dimension()) tensor.

Exceptions
std::invalid_argumentif the cloud is empty.

◆ values()

const std::vector< float > & pulsatrix::PointCloud::values ( ) const
inline

The points, row-major: size() rows of dimension() values.


The documentation for this class was generated from the following file: