@maxr0ssi/embedding-lab 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/dist/EmbeddingExplorer.d.ts +7 -0
- package/dist/EmbeddingExplorer.d.ts.map +1 -0
- package/dist/components/InputPanel/CustomInput.d.ts +8 -0
- package/dist/components/InputPanel/CustomInput.d.ts.map +1 -0
- package/dist/components/InputPanel/ExamplePicker.d.ts +2 -0
- package/dist/components/InputPanel/ExamplePicker.d.ts.map +1 -0
- package/dist/components/InputPanel/InputPanel.d.ts +2 -0
- package/dist/components/InputPanel/InputPanel.d.ts.map +1 -0
- package/dist/components/InputPanel/WordBar.d.ts +3 -0
- package/dist/components/InputPanel/WordBar.d.ts.map +1 -0
- package/dist/components/InspectorPanel/DimensionComparison.d.ts +12 -0
- package/dist/components/InspectorPanel/DimensionComparison.d.ts.map +1 -0
- package/dist/components/InspectorPanel/InspectorPanel.d.ts +2 -0
- package/dist/components/InspectorPanel/InspectorPanel.d.ts.map +1 -0
- package/dist/components/InspectorPanel/NeighborOverlay.d.ts +17 -0
- package/dist/components/InspectorPanel/NeighborOverlay.d.ts.map +1 -0
- package/dist/components/InspectorPanel/NeighborTable.d.ts +10 -0
- package/dist/components/InspectorPanel/NeighborTable.d.ts.map +1 -0
- package/dist/components/PlotPanel/DimensionPicker.d.ts +5 -0
- package/dist/components/PlotPanel/DimensionPicker.d.ts.map +1 -0
- package/dist/components/PlotPanel/ModeToggle.d.ts +2 -0
- package/dist/components/PlotPanel/ModeToggle.d.ts.map +1 -0
- package/dist/components/PlotPanel/PlotPanel.d.ts +2 -0
- package/dist/components/PlotPanel/PlotPanel.d.ts.map +1 -0
- package/dist/data/examples/index.d.ts +10 -0
- package/dist/data/examples/index.d.ts.map +1 -0
- package/dist/embedding-lab.cjs.js +1961 -0
- package/dist/embedding-lab.css +1 -0
- package/dist/embedding-lab.es.js +64723 -0
- package/dist/hooks/useThemeColors.d.ts +16 -0
- package/dist/hooks/useThemeColors.d.ts.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/lib/api.d.ts +8 -0
- package/dist/lib/api.d.ts.map +1 -0
- package/dist/lib/plotly-custom.d.ts +7 -0
- package/dist/lib/plotly-custom.d.ts.map +1 -0
- package/dist/math/dimensionAnalysis.d.ts +15 -0
- package/dist/math/dimensionAnalysis.d.ts.map +1 -0
- package/dist/math/distance.d.ts +27 -0
- package/dist/math/distance.d.ts.map +1 -0
- package/dist/math/projection.d.ts +7 -0
- package/dist/math/projection.d.ts.map +1 -0
- package/dist/store/actions.d.ts +2 -0
- package/dist/store/actions.d.ts.map +1 -0
- package/dist/store/embeddingStore.d.ts +13 -0
- package/dist/store/embeddingStore.d.ts.map +1 -0
- package/dist/store/selectors.d.ts +31 -0
- package/dist/store/selectors.d.ts.map +1 -0
- package/dist/types.d.ts +161 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads key CSS custom-property values so Plotly traces can match the host
|
|
3
|
+
* app's active theme (dark vs light mode).
|
|
4
|
+
*
|
|
5
|
+
* Reacts to `html.light-mode` class toggling via MutationObserver.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useThemeColors(): {
|
|
8
|
+
isLight: boolean;
|
|
9
|
+
accent: string;
|
|
10
|
+
text: string;
|
|
11
|
+
surfaceBase: string;
|
|
12
|
+
surfaceElevated: string;
|
|
13
|
+
surfaceGlass: string;
|
|
14
|
+
error: string;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=useThemeColors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useThemeColors.d.ts","sourceRoot":"","sources":["../../src/hooks/useThemeColors.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,cAAc;;;;;;;;EA4B7B"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { EmbeddingResponse } from '../types';
|
|
2
|
+
interface ComputeOptions {
|
|
3
|
+
model?: string;
|
|
4
|
+
includeLayers?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare function computeEmbeddings(apiBaseUrl: string, texts: string[], options?: ComputeOptions, apiKey?: string): Promise<EmbeddingResponse>;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/lib/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD,UAAU,cAAc;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EAAE,EACf,OAAO,GAAE,cAAmB,EAC5B,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,iBAAiB,CAAC,CAwB5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plotly-custom.d.ts","sourceRoot":"","sources":["../../src/lib/plotly-custom.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,MAAM,MAAM,oBAAoB,CAAC;AAMxC,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Compute variance of an array of numbers. */
|
|
2
|
+
export declare function variance(values: number[]): number;
|
|
3
|
+
/** Compute excess kurtosis. Returns 0 for constant values. */
|
|
4
|
+
export declare function kurtosis(values: number[]): number;
|
|
5
|
+
/** Fisher's separation score (between-group / within-group variance). */
|
|
6
|
+
export declare function separationScore(values: number[], labels: string[]): number;
|
|
7
|
+
/** Return the flattest (lowest-variance) dimension indices. */
|
|
8
|
+
export declare function getFlatDimensions(vectors: number[][], topK?: number): number[];
|
|
9
|
+
/** Rank dimensions by a composite interestingness score. */
|
|
10
|
+
export declare function getInterestingDimensions(vectors: number[][], topK?: number, groupLabels?: string[]): {
|
|
11
|
+
dim: number;
|
|
12
|
+
score: number;
|
|
13
|
+
reason: string;
|
|
14
|
+
}[];
|
|
15
|
+
//# sourceMappingURL=dimensionAnalysis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dimensionAnalysis.d.ts","sourceRoot":"","sources":["../../src/math/dimensionAnalysis.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAIjD;AAED,8DAA8D;AAC9D,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAQjD;AAED,yEAAyE;AACzE,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,EAAE,EAChB,MAAM,EAAE,MAAM,EAAE,GACf,MAAM,CAwBR;AAED,+DAA+D;AAC/D,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,SAAI,GAAG,MAAM,EAAE,CAUzE;AAED,4DAA4D;AAC5D,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,MAAM,EAAE,EAAE,EACnB,IAAI,SAAK,EACT,WAAW,CAAC,EAAE,MAAM,EAAE,GACrB;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAAE,CA+ClD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Cosine similarity between two vectors. Returns 0 for zero-length vectors. */
|
|
2
|
+
export declare function cosineSimilarity(a: number[], b: number[]): number;
|
|
3
|
+
/** Euclidean distance between two vectors. */
|
|
4
|
+
export declare function euclideanDistance(a: number[], b: number[]): number;
|
|
5
|
+
/** Per-dimension diff entry. */
|
|
6
|
+
export interface DimDiff {
|
|
7
|
+
dim: number;
|
|
8
|
+
valueA: number;
|
|
9
|
+
valueB: number;
|
|
10
|
+
delta: number;
|
|
11
|
+
contribution: number;
|
|
12
|
+
}
|
|
13
|
+
/** Result of comparing two vectors dimension-by-dimension. */
|
|
14
|
+
export interface DimensionComparison {
|
|
15
|
+
similarity: number;
|
|
16
|
+
totalDims: number;
|
|
17
|
+
topDiffs: DimDiff[];
|
|
18
|
+
bottomDiffs: DimDiff[];
|
|
19
|
+
}
|
|
20
|
+
/** Compare two vectors: cosine similarity + top K dimensions by |delta|. */
|
|
21
|
+
export declare function dimensionDiff(a: number[], b: number[], topK?: number): DimensionComparison;
|
|
22
|
+
/** Find k nearest neighbors by cosine similarity. */
|
|
23
|
+
export declare function kNearestNeighbors(target: number[], vectors: number[][], k: number, excludeIndex?: number): {
|
|
24
|
+
index: number;
|
|
25
|
+
similarity: number;
|
|
26
|
+
}[];
|
|
27
|
+
//# sourceMappingURL=distance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"distance.d.ts","sourceRoot":"","sources":["../../src/math/distance.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAajE;AAED,8CAA8C;AAC9C,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAOlE;AAED,gCAAgC;AAChC,MAAM,WAAW,OAAO;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,8DAA8D;AAC9D,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,WAAW,EAAE,OAAO,EAAE,CAAC;CACxB;AAED,4EAA4E;AAC5E,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,IAAI,SAAI,GAAG,mBAAmB,CA4BrF;AAED,qDAAqD;AACrD,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EAAE,EAChB,OAAO,EAAE,MAAM,EAAE,EAAE,EACnB,CAAC,EAAE,MAAM,EACT,YAAY,CAAC,EAAE,MAAM,GACpB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,EAAE,CAUzC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Normalize a vector to unit length. Returns zero vector for zero input. */
|
|
2
|
+
export declare function normalize(v: number[]): number[];
|
|
3
|
+
/** Subtract vector b from vector a. */
|
|
4
|
+
export declare function subtract(a: number[], b: number[]): number[];
|
|
5
|
+
/** Project each vector onto a direction, returning scalar projections. */
|
|
6
|
+
export declare function projectOntoAxis(vectors: number[][], direction: number[]): number[];
|
|
7
|
+
//# sourceMappingURL=projection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../src/math/projection.ts"],"names":[],"mappings":"AAcA,6EAA6E;AAC7E,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAG/C;AAED,uCAAuC;AACvC,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAE3D;AAED,0EAA0E;AAC1E,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,EAAE,EAAE,EACnB,SAAS,EAAE,MAAM,EAAE,GAClB,MAAM,EAAE,CAEV"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/store/actions.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Dispatch } from 'react';
|
|
2
|
+
import type { EmbeddingState, EmbeddingAction } from '../types';
|
|
3
|
+
export declare const initialState: EmbeddingState;
|
|
4
|
+
export declare function embeddingReducer(state: EmbeddingState, action: EmbeddingAction): EmbeddingState;
|
|
5
|
+
interface EmbeddingContextValue {
|
|
6
|
+
state: EmbeddingState;
|
|
7
|
+
dispatch: Dispatch<EmbeddingAction>;
|
|
8
|
+
}
|
|
9
|
+
export declare const EmbeddingContext: import("react").Context<EmbeddingContextValue | null>;
|
|
10
|
+
export declare function useEmbeddingStore(): EmbeddingContextValue;
|
|
11
|
+
export declare function useEmbeddingReducer(): [EmbeddingState, Dispatch<EmbeddingAction>];
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=embeddingStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embeddingStore.d.ts","sourceRoot":"","sources":["../../src/store/embeddingStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyC,KAAK,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC7E,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EAGhB,MAAM,UAAU,CAAC;AAyClB,eAAO,MAAM,YAAY,EAAE,cAkB1B,CAAC;AAEF,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,cAAc,EACrB,MAAM,EAAE,eAAe,GACtB,cAAc,CAkPhB;AAED,UAAU,qBAAqB;IAC7B,KAAK,EAAE,cAAc,CAAC;IACtB,QAAQ,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC;CACrC;AAED,eAAO,MAAM,gBAAgB,uDAE5B,CAAC;AAEF,wBAAgB,iBAAiB,IAAI,qBAAqB,CAQzD;AAED,wBAAgB,mBAAmB,gDAElC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { EmbeddingState } from '../types';
|
|
2
|
+
import { type DimensionComparison } from '../math/distance';
|
|
3
|
+
/** Get the flat embedding vectors currently displayed (respects activeLayer).
|
|
4
|
+
* When trailIndices is set, only those items respond to activeLayer —
|
|
5
|
+
* reference points always use the last layer so they stay fixed. */
|
|
6
|
+
export declare function getDisplayVectors(state: EmbeddingState): number[][];
|
|
7
|
+
/** Get vectors for the previous layer (activeLayer - 1). Returns null if not applicable. */
|
|
8
|
+
export declare function getPreviousLayerVectors(state: EmbeddingState): number[][] | null;
|
|
9
|
+
/** Compute k-nearest neighbors for a given point index. */
|
|
10
|
+
export declare function getNeighbors(state: EmbeddingState, index: number, k?: number, hiddenIndices?: number[]): {
|
|
11
|
+
index: number;
|
|
12
|
+
text: string;
|
|
13
|
+
similarity: number;
|
|
14
|
+
}[];
|
|
15
|
+
/** Find the most interesting dimensions. */
|
|
16
|
+
export declare function getInterestingDimensions(state: EmbeddingState, topK?: number): {
|
|
17
|
+
dim: number;
|
|
18
|
+
score: number;
|
|
19
|
+
reason: string;
|
|
20
|
+
}[];
|
|
21
|
+
/** Rank ALL dimensions by variance (for spread bars in picker). */
|
|
22
|
+
export declare function getDimensionVariances(state: EmbeddingState): {
|
|
23
|
+
dim: number;
|
|
24
|
+
variance: number;
|
|
25
|
+
normalized: number;
|
|
26
|
+
}[];
|
|
27
|
+
/** Compare two points dimension-by-dimension. Returns null for invalid indices. */
|
|
28
|
+
export declare function getDimensionComparison(state: EmbeddingState, indexA: number, indexB: number): DimensionComparison | null;
|
|
29
|
+
/** Find the flattest dimensions (lowest variance). */
|
|
30
|
+
export declare function getFlatDimensions(state: EmbeddingState, topK?: number): number[];
|
|
31
|
+
//# sourceMappingURL=selectors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../src/store/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAmC,KAAK,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAM7F;;qEAEqE;AACrE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,EAAE,EAAE,CAenE;AAED,4FAA4F;AAC5F,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,EAAE,EAAE,GAAG,IAAI,CAgBhF;AAED,2DAA2D;AAC3D,wBAAgB,YAAY,CAC1B,KAAK,EAAE,cAAc,EACrB,KAAK,EAAE,MAAM,EACb,CAAC,SAAI,EACL,aAAa,GAAE,MAAM,EAAO,GAC3B;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,EAAE,CAiBvD;AAED,4CAA4C;AAC5C,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,cAAc,EACrB,IAAI,SAAK,GACR;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAAE,CAIlD;AAED,mEAAmE;AACnE,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,cAAc,GACpB;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,EAAE,CAwBzD;AAED,mFAAmF;AACnF,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,cAAc,EACrB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACb,mBAAmB,GAAG,IAAI,CAM5B;AAED,sDAAsD;AACtD,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,cAAc,EACrB,IAAI,SAAI,GACP,MAAM,EAAE,CAIV"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
/** Public props for the EmbeddingExplorer component. */
|
|
3
|
+
export interface EmbeddingExplorerProps {
|
|
4
|
+
apiBaseUrl?: string;
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
className?: string;
|
|
7
|
+
initialExample?: string;
|
|
8
|
+
height?: string | number;
|
|
9
|
+
scrollContent?: React.ReactNode;
|
|
10
|
+
hideHeader?: boolean;
|
|
11
|
+
style?: React.CSSProperties;
|
|
12
|
+
}
|
|
13
|
+
/** A single embedded text item. */
|
|
14
|
+
export interface EmbeddingItem {
|
|
15
|
+
text: string;
|
|
16
|
+
index: number;
|
|
17
|
+
embedding: number[] | number[][];
|
|
18
|
+
tokenization: TokenizationInfo;
|
|
19
|
+
target_states?: number[][];
|
|
20
|
+
target_token_index?: number;
|
|
21
|
+
}
|
|
22
|
+
/** Subword tokenization details. */
|
|
23
|
+
export interface TokenizationInfo {
|
|
24
|
+
tokens: string[];
|
|
25
|
+
token_ids: number[];
|
|
26
|
+
offset_mapping: [number, number][];
|
|
27
|
+
}
|
|
28
|
+
/** API response shape. */
|
|
29
|
+
export interface EmbeddingResponse {
|
|
30
|
+
model: string;
|
|
31
|
+
dim: number;
|
|
32
|
+
num_layers: number;
|
|
33
|
+
items: EmbeddingItem[];
|
|
34
|
+
}
|
|
35
|
+
/** Global application state. */
|
|
36
|
+
export interface EmbeddingState {
|
|
37
|
+
status: 'idle' | 'loading' | 'ready' | 'error';
|
|
38
|
+
error: string | null;
|
|
39
|
+
texts: string[];
|
|
40
|
+
mode: 'word' | 'phrase' | 'token';
|
|
41
|
+
items: EmbeddingItem[];
|
|
42
|
+
model: string | null;
|
|
43
|
+
dim: number | null;
|
|
44
|
+
numLayers: number | null;
|
|
45
|
+
selectedIndex: number | null;
|
|
46
|
+
lassoIndices: number[];
|
|
47
|
+
hiddenIndices: number[];
|
|
48
|
+
plot: PlotConfig;
|
|
49
|
+
axes: SemanticAxis[];
|
|
50
|
+
activeLayer: number | null;
|
|
51
|
+
layerStates: Map<number, number[][]> | null;
|
|
52
|
+
activeExampleId: string | null;
|
|
53
|
+
trailIndices: number[] | null;
|
|
54
|
+
}
|
|
55
|
+
/** Plot axis/mode configuration. */
|
|
56
|
+
export interface PlotConfig {
|
|
57
|
+
xDim: number;
|
|
58
|
+
yDim: number;
|
|
59
|
+
zDim: number | null;
|
|
60
|
+
is3D: boolean;
|
|
61
|
+
colorDim: number | null;
|
|
62
|
+
sizeDim: number | null;
|
|
63
|
+
xAxisId: string | null;
|
|
64
|
+
yAxisId: string | null;
|
|
65
|
+
showTrails: boolean;
|
|
66
|
+
activePreset: 'best' | 'flat' | null;
|
|
67
|
+
}
|
|
68
|
+
/** A user-defined semantic axis direction. */
|
|
69
|
+
export interface SemanticAxis {
|
|
70
|
+
id: string;
|
|
71
|
+
label: string;
|
|
72
|
+
positiveIndex: number;
|
|
73
|
+
negativeIndex: number;
|
|
74
|
+
direction: number[];
|
|
75
|
+
}
|
|
76
|
+
/** Reducer action union. */
|
|
77
|
+
export type EmbeddingAction = {
|
|
78
|
+
type: 'SET_TEXTS';
|
|
79
|
+
texts: string[];
|
|
80
|
+
} | {
|
|
81
|
+
type: 'SET_MODE';
|
|
82
|
+
mode: 'word' | 'phrase' | 'token';
|
|
83
|
+
} | {
|
|
84
|
+
type: 'COMPUTE_REQUESTED';
|
|
85
|
+
} | {
|
|
86
|
+
type: 'EMBEDDINGS_RECEIVED';
|
|
87
|
+
response: EmbeddingResponse;
|
|
88
|
+
} | {
|
|
89
|
+
type: 'ADD_ITEMS';
|
|
90
|
+
response: EmbeddingResponse;
|
|
91
|
+
trailCount?: number;
|
|
92
|
+
} | {
|
|
93
|
+
type: 'COMPUTE_FAILED';
|
|
94
|
+
error: string;
|
|
95
|
+
} | {
|
|
96
|
+
type: 'EXAMPLE_LOADED';
|
|
97
|
+
example: PremadeExample;
|
|
98
|
+
} | {
|
|
99
|
+
type: 'SELECT_POINT';
|
|
100
|
+
index: number | null;
|
|
101
|
+
} | {
|
|
102
|
+
type: 'LASSO_SELECT';
|
|
103
|
+
indices: number[];
|
|
104
|
+
} | {
|
|
105
|
+
type: 'SET_PLOT_CONFIG';
|
|
106
|
+
patch: Partial<PlotConfig>;
|
|
107
|
+
} | {
|
|
108
|
+
type: 'ADD_AXIS';
|
|
109
|
+
axis: SemanticAxis;
|
|
110
|
+
} | {
|
|
111
|
+
type: 'REMOVE_AXIS';
|
|
112
|
+
axisId: string;
|
|
113
|
+
} | {
|
|
114
|
+
type: 'SET_ACTIVE_LAYER';
|
|
115
|
+
layer: number | null;
|
|
116
|
+
} | {
|
|
117
|
+
type: 'TOGGLE_HIDDEN';
|
|
118
|
+
index: number;
|
|
119
|
+
} | {
|
|
120
|
+
type: 'REMOVE_ITEM';
|
|
121
|
+
index: number;
|
|
122
|
+
} | {
|
|
123
|
+
type: 'SHOW_ALL';
|
|
124
|
+
} | {
|
|
125
|
+
type: 'RESET';
|
|
126
|
+
};
|
|
127
|
+
/** Schema for pre-computed example JSON files. */
|
|
128
|
+
export interface PremadeExample {
|
|
129
|
+
id: string;
|
|
130
|
+
title: string;
|
|
131
|
+
story: string;
|
|
132
|
+
model: string;
|
|
133
|
+
dim: number;
|
|
134
|
+
numLayers: number;
|
|
135
|
+
texts: string[];
|
|
136
|
+
groups?: string[];
|
|
137
|
+
mode: 'word' | 'phrase' | 'token';
|
|
138
|
+
embeddings: number[][];
|
|
139
|
+
tokenizations: TokenizationInfo[];
|
|
140
|
+
layerStates?: number[][][];
|
|
141
|
+
trailIndices?: number[];
|
|
142
|
+
tokenTarget?: string;
|
|
143
|
+
interestingDims: {
|
|
144
|
+
dim: number;
|
|
145
|
+
score: number;
|
|
146
|
+
reason: string;
|
|
147
|
+
}[];
|
|
148
|
+
recommendedView: {
|
|
149
|
+
xDim: number;
|
|
150
|
+
yDim: number;
|
|
151
|
+
zDim?: number;
|
|
152
|
+
is3D: boolean;
|
|
153
|
+
axes?: {
|
|
154
|
+
label: string;
|
|
155
|
+
positiveText: string;
|
|
156
|
+
negativeText: string;
|
|
157
|
+
direction: number[];
|
|
158
|
+
}[];
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,wDAAwD;AACxD,MAAM,WAAW,sBAAsB;IACrC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAChC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B;AAED,mCAAmC;AACnC,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,EAAE,CAAC;IACjC,YAAY,EAAE,gBAAgB,CAAC;IAC/B,aAAa,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,oCAAoC;AACpC,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,SAAS,EAAE,MAAM,EAAE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IAClE,eAAe,EAAE;QACf,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,OAAO,CAAC;QACd,IAAI,CAAC,EAAE;YACL,KAAK,EAAE,MAAM,CAAC;YACd,YAAY,EAAE,MAAM,CAAC;YACrB,YAAY,EAAE,MAAM,CAAC;YACrB,SAAS,EAAE,MAAM,EAAE,CAAC;SACrB,EAAE,CAAC;KACL,CAAC;CACH"}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@maxr0ssi/embedding-lab",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"registry": "https://registry.npmjs.org",
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/maxr0ssi/embedding-lab.git"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"dev": "vite --port 5176",
|
|
15
|
+
"build": "tsc -b && vite build",
|
|
16
|
+
"build:lib": "vite build --mode lib && tsc -p tsconfig.lib.json",
|
|
17
|
+
"typecheck": "tsc --noEmit",
|
|
18
|
+
"prepublishOnly": "npm run build:lib"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"plotly.js": "^3.3.1",
|
|
22
|
+
"react": "^18.0.0",
|
|
23
|
+
"react-dom": "^18.0.0",
|
|
24
|
+
"react-plotly.js": "^2.6.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/react": "^18.3.12",
|
|
28
|
+
"@types/react-dom": "^18.3.1",
|
|
29
|
+
"@types/react-plotly.js": "^2.6.3",
|
|
30
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
31
|
+
"typescript": "~5.6.3",
|
|
32
|
+
"vite": "^6.0.3"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"react": "^18.0.0",
|
|
36
|
+
"react-dom": "^18.0.0"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist"
|
|
40
|
+
],
|
|
41
|
+
"main": "./dist/embedding-lab.cjs.js",
|
|
42
|
+
"module": "./dist/embedding-lab.es.js",
|
|
43
|
+
"types": "./dist/index.d.ts",
|
|
44
|
+
"exports": {
|
|
45
|
+
".": {
|
|
46
|
+
"types": "./dist/index.d.ts",
|
|
47
|
+
"import": "./dist/embedding-lab.es.js",
|
|
48
|
+
"require": "./dist/embedding-lab.cjs.js"
|
|
49
|
+
},
|
|
50
|
+
"./styles": "./dist/embedding-lab.css"
|
|
51
|
+
}
|
|
52
|
+
}
|