@modelx/model
Version:
Deep Learning Classification, LSTM Time Series, Regression and Multi-Layered Perceptrons with Tensorflow
179 lines (178 loc) • 5.82 kB
TypeScript
import { TensorScriptOptions, TensorScriptProperties, Matrix, Vector, TensorScriptLayers, PredictionOptions, DenseLayer, Corpus } from './model_interface';
import { BaseNeuralNetwork } from './base_neural_network';
export declare type LabeledWeight = {
[index: string]: Matrix;
};
export declare type IdToFeature = {
[index: number]: string | number;
};
export declare type FeatureToId = {
[index: string]: number;
};
/**
* use a corpus to generate features from an embedding layer with Tensorflow
* @class FeatureEmbedding
* @implements {BaseNeuralNetwork}
*/
export declare class FeatureEmbedding extends BaseNeuralNetwork {
layers?: TensorScriptLayers;
featureToId?: FeatureToId;
idToFeature?: IdToFeature;
featureIds?: Matrix;
numberOfFeatures?: number;
loss?: number;
importedEmbeddings?: boolean;
static getFeatureDataSet(this: any, { inputMatrixFeatures, PAD, initialIdToFeature, initialFeatureToId, }: {
inputMatrixFeatures: Corpus;
PAD?: string;
initialIdToFeature?: IdToFeature;
initialFeatureToId?: FeatureToId;
}): Promise<{
featureToId: {
[x: string]: number;
};
idToFeature: IdToFeature;
featureIds: number[][];
numberOfFeatures: number;
}>;
static getMergedArray(base?: Vector, merger?: Vector, append?: boolean, truncate?: boolean): any[];
/**
*/
static getContextPairs(this: any, { inputMatrix, numberOfFeatures, window_size, tf, }: {
inputMatrix: Matrix;
numberOfFeatures: number;
window_size?: number;
tf?: any;
}): Promise<{
context_length: number;
emptyXVector: any;
emptyYVector: any;
x: Matrix;
y: Matrix;
}>;
getMergedArray: typeof FeatureEmbedding.getMergedArray;
getFeatureDataSet: typeof FeatureEmbedding.getFeatureDataSet;
getContextPairs: typeof FeatureEmbedding.getContextPairs;
constructor(options?: TensorScriptOptions, properties?: TensorScriptProperties);
/**
* Adds dense layers to tensorflow classification model
* @override
* @param {Array<Array<number>>} x_matrix - independent variables
* @param {Array<Array<number>>} y_matrix - dependent variables
* @param {Array<Object>} layers - model dense layer parameters
*/
generateLayers(this: FeatureEmbedding, x_matrix: Matrix, y_matrix: Matrix, layers?: TensorScriptLayers): void;
trainOnBatch({ x_input_matrix, y_output_matrix, epoch, trainingLoss, inputVectorIndex, inputVectorLength, }: {
x_input_matrix: Matrix;
y_output_matrix: Matrix;
epoch: number;
trainingLoss: number;
inputVectorIndex?: number;
inputVectorLength?: number;
}): Promise<{
loss: number;
}>;
generateBatch({ epoch }: {
epoch: number;
}): Promise<{
loss: number;
}>;
exportEmbeddings(): Promise<{
featureToId: FeatureToId | undefined;
idToFeature: IdToFeature | undefined;
featureIds: Matrix | undefined;
numberOfFeatures: number | undefined;
labeledWeights: {
[index: string]: Vector;
};
}>;
importEmbeddings({ featureToId, idToFeature, featureIds, numberOfFeatures, labeledWeights, addNewWeights, inputMatrixFeatures, fixImportedWeights, }: {
featureToId?: FeatureToId;
idToFeature?: IdToFeature;
featureIds?: Matrix;
numberOfFeatures?: number;
labeledWeights: LabeledWeights;
addNewWeights?: boolean;
fixImportedWeights?: boolean;
inputMatrixFeatures?: Corpus;
}): Promise<void>;
compileModel({ layers, }?: {
layers?: DenseLayer[];
}): void;
train(x_matrix: Matrix, y_matrix: Matrix, layers?: DenseLayer[]): Promise<any>;
calculate(): Promise<any>;
predict(options?: PredictionOptions): Promise<any>;
/**
* Converts matrix of layer weights into labeled features
* @example
const weights = [
[1.5,1,4,1.6,3.5],
[4.3,3.2,5.5,6.5]
]
FeatureEmbeddingInstance.labelWeights(weights) //=>
weights = {
car:[1.5,1,4,1.6,3.5],
boat:[4.3,3.2,5.5,6.5]
}
*/
labelWeights(weights: Matrix): {
[index: string]: Vector;
};
/**
* Uses tSNE to reduce dimensionality of features
* @example
const weights = [
[1.5,1,4,1.6,3.5],
[4.3,3.2,5.5,6.5]
]
FeatureEmbeddingInstance.reduceWeights(weights) //=>
[
[1,2],
[2,3],
]
*/
reduceWeights(weights: Matrix, options?: any): Promise<any>;
/**
* Uses either cosineProximity or Eucledian distance to rank similarity
@example
//weights = [ [1,2,3,], [1,2,2], [0,-1,3] ]
//labeledWeights = [ {car:[1,2,3,],tesla:[1,2,2],boat:[0,-1,3]}]
FeatureEmbeddingInstance.findSimilarFeatures(weights,{features:['car'], limit:2,}) //=>
{
car:[
{
comparedFeature: 'tesla',
proximity: -0.5087087154388428,
distance: 0.03015853278338909
},
{
comparedFeature: 'boat',
proximity: -0.3032159209251404,
distance: 0.036241017282009125
},
]
}
*/
findSimilarFeatures(weights: Matrix, options?: SimilarFeatureOptions): Promise<SimilarFeatures>;
}
export declare type LabeledWeights = {
[index: string]: Vector;
};
export declare enum SimilarityMetric {
DISTANCE = "distance",
PROXIMITY = "proximity"
}
export declare type SimilarFeatureOptions = {
features?: string[];
limit?: number;
labeledWeights?: LabeledWeights;
metric?: SimilarityMetric;
};
export declare type SimilarFeatures = {
[index: string]: SimilarFeature[];
};
export declare type SimilarFeature = {
comparedFeature: string;
distance: number;
proximity: number;
};