pulsatrix 1.1.0
Loading...
Searching...
No Matches
html.hpp
Go to the documentation of this file.
1
7#pragma once
8
9#include <cstdint>
10#include <string>
11#include <vector>
12
13#include "pulsatrix/json.hpp"
16#include "pulsatrix/viz/svg.hpp" // IceStyle, PartialDependenceSvgOptions
17
18namespace pulsatrix {
19
21inline constexpr const char* kVegaVersion = "6.4.0";
22inline constexpr const char* kVegaLiteVersion = "6.4.3";
23inline constexpr const char* kVegaEmbedVersion = "7.3.0";
24
26enum class HtmlScripts {
29 Cdn,
32 Inline,
33};
34
40 std::string script_dir;
42 int width = 640;
44 std::string title;
45};
46
47// ---- Vega-Lite specifications ---------------------------------------------------------------
48// The charts as Vega-Lite specs, for embedding in your own page or notebook. Each throws
49// std::invalid_argument for the same problems as its SVG counterpart (svg.hpp).
50
53[[nodiscard]] JsonValue ToVegaLiteBarChart(const AttributionDocument& doc, int top_k = 10, const HtmlOptions& options = {});
56[[nodiscard]] JsonValue ToVegaLiteWaterfall(const AttributionDocument& doc, float baseline_value,
57 const HtmlOptions& options = {});
60[[nodiscard]] JsonValue ToVegaLiteHeatmap(const HeatmapDocument& doc, const HtmlOptions& options = {});
63[[nodiscard]] JsonValue ToVegaLiteBeeswarm(const std::vector<AttributionDocument>& docs,
64 const std::vector<int64_t>& feature_indices, const HtmlOptions& options = {});
68 const PartialDependenceSvgOptions& pd = {},
69 const HtmlOptions& options = {});
71[[nodiscard]] JsonValue ToVegaLiteTornado(const SensitivityDocument& doc, int top_k = 10, const HtmlOptions& options = {});
74[[nodiscard]] JsonValue ToVegaLiteCounterfactual(const CounterfactualDocument& doc, int max_rows = 12,
75 const HtmlOptions& options = {});
78[[nodiscard]] JsonValue ToVegaLiteCounterfactualSet(const std::vector<CounterfactualDocument>& docs,
79 const HtmlOptions& options = {});
82[[nodiscard]] JsonValue ToVegaLiteMorris(const MorrisDocument& doc, const HtmlOptions& options = {});
84[[nodiscard]] JsonValue ToVegaLiteSobol(const SobolDocument& doc, int top_k = 10, const HtmlOptions& options = {});
88[[nodiscard]] JsonValue ToVegaLiteProjection(const ProjectionDocument& doc, const HtmlOptions& options = {});
91[[nodiscard]] JsonValue ToVegaLiteTrainingLog(const TrainingLogDocument& doc, const HtmlOptions& options = {});
94[[nodiscard]] JsonValue ToVegaLiteFeatureHistogram(const FeatureDashboardDocument& doc, const HtmlOptions& options = {});
98[[nodiscard]] JsonValue ToVegaLiteSeries(const SeriesDocument& doc, const SeriesViewOptions& view = {},
99 const HtmlOptions& options = {});
100
101// ---- Pages ------------------------------------------------------------------------------------
102
106[[nodiscard]] std::string VegaLitePage(const JsonValue& spec, const std::string& heading, const HtmlOptions& options = {},
107 const std::string& extra_html = "");
108
109[[nodiscard]] std::string RenderBarChartHtml(const AttributionDocument& doc, int top_k = 10, const HtmlOptions& options = {});
110[[nodiscard]] std::string RenderWaterfallHtml(const AttributionDocument& doc, float baseline_value,
111 const HtmlOptions& options = {});
112[[nodiscard]] std::string RenderHeatmapHtml(const HeatmapDocument& doc, const HtmlOptions& options = {});
113[[nodiscard]] std::string RenderBeeswarmHtml(const std::vector<AttributionDocument>& docs,
114 const std::vector<int64_t>& feature_indices, const HtmlOptions& options = {});
115[[nodiscard]] std::string RenderPartialDependenceHtml(const PartialDependenceDocument& doc,
116 const PartialDependenceSvgOptions& pd = {},
117 const HtmlOptions& options = {});
118[[nodiscard]] std::string RenderTornadoHtml(const SensitivityDocument& doc, int top_k = 10, const HtmlOptions& options = {});
119[[nodiscard]] std::string RenderCounterfactualHtml(const CounterfactualDocument& doc, int max_rows = 12,
120 const HtmlOptions& options = {});
121[[nodiscard]] std::string RenderCounterfactualSetHtml(const std::vector<CounterfactualDocument>& docs,
122 const HtmlOptions& options = {});
123[[nodiscard]] std::string RenderMorrisHtml(const MorrisDocument& doc, const HtmlOptions& options = {});
124[[nodiscard]] std::string RenderSobolHtml(const SobolDocument& doc, int top_k = 10, const HtmlOptions& options = {});
125[[nodiscard]] std::string RenderProjectionHtml(const ProjectionDocument& doc, const HtmlOptions& options = {});
126[[nodiscard]] std::string RenderSeriesHtml(const SeriesDocument& doc, const SeriesViewOptions& view = {},
127 const HtmlOptions& options = {});
128[[nodiscard]] std::string RenderTrainingLogHtml(const TrainingLogDocument& doc, const HtmlOptions& options = {});
132[[nodiscard]] std::string RenderFeatureDashboardHtml(const FeatureDashboardDocument& doc, const HtmlOptions& options = {},
133 const std::string& extra_html = "");
134
142[[nodiscard]] std::string RenderTokenRelevanceHtml(const TokenRelevanceDocument& doc, const HtmlOptions& options = {});
143
144} // namespace pulsatrix
One JSON value: null, a boolean, a number, a string, an array or an object.
Definition json.hpp:22
Versioned JSON documents (pulsatrix.<kind>.v1) that every renderer reads.
A small strict JSON value, parser and deterministic writer (RFC 8259).
Definition acquisition_functions.hpp:16
JsonValue ToVegaLiteWaterfall(const AttributionDocument &doc, float baseline_value, const HtmlOptions &options={})
A waterfall from baseline_value through the features' contributions to the prediction (ToWaterfallSte...
JsonValue ToVegaLiteSeries(const SeriesDocument &doc, const SeriesViewOptions &view={}, const HtmlOptions &options={})
A series document (VIZ-9): one zoomable chart per panel, stacked, each a line per series with points ...
JsonValue ToVegaLiteMorris(const MorrisDocument &doc, const HtmlOptions &options={})
Morris screening: mu* against sigma per feature, with mu*'s confidence interval and the sigma = mu* l...
std::string RenderSeriesHtml(const SeriesDocument &doc, const SeriesViewOptions &view={}, const HtmlOptions &options={})
TopKResult top_k(const Tensor &input, int64_t k, bool largest=true)
Selects the k largest (or smallest) entries of every row along the last dimension.
constexpr const char * kVegaLiteVersion
Definition html.hpp:22
std::string RenderHeatmapHtml(const HeatmapDocument &doc, const HtmlOptions &options={})
std::string RenderCounterfactualHtml(const CounterfactualDocument &doc, int max_rows=12, const HtmlOptions &options={})
JsonValue ToVegaLiteFeatureHistogram(const FeatureDashboardDocument &doc, const HtmlOptions &options={})
A feature's activation histogram (the dashboard's chart; RenderFeatureDashboardHtml adds the top exam...
std::string RenderFeatureDashboardHtml(const FeatureDashboardDocument &doc, const HtmlOptions &options={}, const std::string &extra_html="")
The feature's statistics, its activation histogram, and its top examples with each token shaded by it...
std::string RenderPartialDependenceHtml(const PartialDependenceDocument &doc, const PartialDependenceSvgOptions &pd={}, const HtmlOptions &options={})
JsonValue ToVegaLiteTornado(const SensitivityDocument &doc, int top_k=10, const HtmlOptions &options={})
A tornado chart of the top_k features with the largest swing.
JsonValue ToVegaLiteCounterfactualSet(const std::vector< CounterfactualDocument > &docs, const HtmlOptions &options={})
Several counterfactuals of one input: a grid of features (rows) by counterfactuals (columns),...
std::string RenderTornadoHtml(const SensitivityDocument &doc, int top_k=10, const HtmlOptions &options={})
JsonValue ToVegaLiteCounterfactual(const CounterfactualDocument &doc, int max_rows=12, const HtmlOptions &options={})
The changed features of a counterfactual, costliest first, as bars of their change in scale units; th...
JsonValue ToVegaLiteBeeswarm(const std::vector< AttributionDocument > &docs, const std::vector< int64_t > &feature_indices, const HtmlOptions &options={})
One row per feature in feature_indices: every document's value for it, spread so points don't overlap...
constexpr const char * kVegaEmbedVersion
Definition html.hpp:23
std::string RenderWaterfallHtml(const AttributionDocument &doc, float baseline_value, const HtmlOptions &options={})
std::string RenderBarChartHtml(const AttributionDocument &doc, int top_k=10, const HtmlOptions &options={})
std::string RenderSobolHtml(const SobolDocument &doc, int top_k=10, const HtmlOptions &options={})
std::string RenderBeeswarmHtml(const std::vector< AttributionDocument > &docs, const std::vector< int64_t > &feature_indices, const HtmlOptions &options={})
JsonValue ToVegaLiteHeatmap(const HeatmapDocument &doc, const HtmlOptions &options={})
A heatmap: diverging around zero when any value is negative, Viridis otherwise. Non-finite cells are ...
std::string RenderTrainingLogHtml(const TrainingLogDocument &doc, const HtmlOptions &options={})
HtmlScripts
How a page gets the Vega libraries.
Definition html.hpp:26
@ Inline
Copied into the page from script_dir, so it works offline and can be mailed as one file (about 830 KB...
@ Cdn
From the jsDelivr CDN, pinned to the versions above and checked with Subresource Integrity hashes....
JsonValue ToVegaLiteProjection(const ProjectionDocument &doc, const HtmlOptions &options={})
A projection as a zoomable scatter plot, colored as RenderProjectionSvg colors it,...
JsonValue ToVegaLiteTrainingLog(const TrainingLogDocument &doc, const HtmlOptions &options={})
A training log: one zoomable line chart per scalar tag, and one histogram per histogram tag.
constexpr const char * kVegaVersion
The versions of Vega, Vega-Lite and vega-embed the pages load (BSD-3-Clause).
Definition html.hpp:21
std::string RenderTokenRelevanceHtml(const TokenRelevanceDocument &doc, const HtmlOptions &options={})
The text with each piece (token or word) on a background colored by its relevance,...
std::string RenderCounterfactualSetHtml(const std::vector< CounterfactualDocument > &docs, const HtmlOptions &options={})
std::string RenderProjectionHtml(const ProjectionDocument &doc, const HtmlOptions &options={})
JsonValue ToVegaLitePartialDependence(const PartialDependenceDocument &doc, const PartialDependenceSvgOptions &pd={}, const HtmlOptions &options={})
A partial dependence plot: ICE curves under the average, and a rug of the instances' feature values....
JsonValue ToVegaLiteSobol(const SobolDocument &doc, int top_k=10, const HtmlOptions &options={})
Sobol indices: first-order bars in front of total-order ones, with confidence whiskers.
std::string VegaLitePage(const JsonValue &spec, const std::string &heading, const HtmlOptions &options={}, const std::string &extra_html="")
A complete page that draws spec with vega-embed, which adds the PNG/SVG export menu.
std::string RenderMorrisHtml(const MorrisDocument &doc, const HtmlOptions &options={})
JsonValue ToVegaLiteBarChart(const AttributionDocument &doc, int top_k=10, const HtmlOptions &options={})
Horizontal bars of the top_k features with the largest |attribution|, colored by sign on the SVG rend...
The series document (VIZ-9): measured points with optional intervals, for sweeps and trade-off curves...
pulsatrix.attribution.v1: an Attribution's values, shape, method and metadata.
Definition document.hpp:58
pulsatrix.counterfactual.v1: an input, its counterfactual, and what reaching the target cost (CFS-5).
Definition document.hpp:316
pulsatrix.feature_dashboard.v1: one learned feature (for example a sparse autoencoder unit) with its ...
Definition document.hpp:204
pulsatrix.heatmap.v1: a row-major grid of values with optional axis labels.
Definition document.hpp:79
Options for every HTML view.
Definition html.hpp:36
std::string title
Replaces the view's own title when not empty.
Definition html.hpp:44
std::string script_dir
With HtmlScripts::Inline: a directory holding vega.min.js, vega-lite.min.js and vega-embed....
Definition html.hpp:40
HtmlScripts scripts
Definition html.hpp:37
int width
The chart's width in pixels.
Definition html.hpp:42
pulsatrix.morris.v1: Morris screening statistics per feature (CFS-4).
Definition document.hpp:350
pulsatrix.partial_dependence.v1: a partial dependence curve over one feature, with the individual (IC...
Definition document.hpp:239
Options for RenderPartialDependenceSvg.
Definition svg.hpp:107
pulsatrix.projection.v1: inputs placed in a few dimensions (INT-5), such as their first principal com...
Definition document.hpp:398
pulsatrix.sensitivity.v1: how one output moves when each input feature, alone, goes to a low and a hi...
Definition document.hpp:285
Definition series.hpp:50
Options for RenderSeriesSvg().
Definition series.hpp:74
pulsatrix.sobol.v1: first- and total-order Sobol indices per feature (CFS-4).
Definition document.hpp:365
pulsatrix.token_relevance.v1: relevance scores over the pieces of a text, in reading order....
Definition document.hpp:104
pulsatrix.training_log.v1: scalar series and the latest histogram per tag.
Definition document.hpp:168
Dependency-free SVG figures from viz documents: bar, waterfall, heatmap, token strip,...