Options
All
  • Public
  • Public/Protected
  • All
Menu

Class FeatureEmbedding

use a corpus to generate features from an embedding layer with Tensorflow

implements

{BaseNeuralNetwork}

Hierarchy

Index

Constructors

constructor

  • new FeatureEmbedding(options?: TensorScriptOptions, properties?: TensorScriptProperties): FeatureEmbedding

Properties

compiled

compiled: boolean

Optional featureIds

featureIds: Matrix

Optional featureToId

featureToId: FeatureToId

getContextPairs

getContextPairs: (__namedParameters: { inputMatrix: Matrix; numberOfFeatures: number; tf?: any; window_size?: number }) => Promise<{ context_length: number; emptyXVector: any; emptyYVector: any; x: Matrix; y: Matrix }>

Type declaration

    • (__namedParameters: { inputMatrix: Matrix; numberOfFeatures: number; tf?: any; window_size?: number }): Promise<{ context_length: number; emptyXVector: any; emptyYVector: any; x: Matrix; y: Matrix }>
    • Parameters

      • __namedParameters: { inputMatrix: Matrix; numberOfFeatures: number; tf?: any; window_size?: number }
        • inputMatrix: Matrix
        • numberOfFeatures: number
        • Optional tf?: any
        • Optional window_size?: number

      Returns Promise<{ context_length: number; emptyXVector: any; emptyYVector: any; x: Matrix; y: Matrix }>

getFeatureDataSet

getFeatureDataSet: (__namedParameters: { PAD?: string; initialFeatureToId?: FeatureToId; initialIdToFeature?: IdToFeature; inputMatrixFeatures: Corpus }) => Promise<{ featureIds: number[][]; featureToId: {}; idToFeature: IdToFeature; numberOfFeatures: number }>

Type declaration

    • (__namedParameters: { PAD?: string; initialFeatureToId?: FeatureToId; initialIdToFeature?: IdToFeature; inputMatrixFeatures: Corpus }): Promise<{ featureIds: number[][]; featureToId: {}; idToFeature: IdToFeature; numberOfFeatures: number }>
    • Parameters

      • __namedParameters: { PAD?: string; initialFeatureToId?: FeatureToId; initialIdToFeature?: IdToFeature; inputMatrixFeatures: Corpus }
        • Optional PAD?: string
        • Optional initialFeatureToId?: FeatureToId
        • Optional initialIdToFeature?: IdToFeature
        • inputMatrixFeatures: Corpus

      Returns Promise<{ featureIds: number[][]; featureToId: {}; idToFeature: IdToFeature; numberOfFeatures: number }>

getInputShape

getInputShape: (...args: any[]) => any

Type declaration

    • (...args: any[]): any
    • Parameters

      • Rest ...args: any[]

      Returns any

getMergedArray

getMergedArray: (base?: Vector, merger?: Vector, append?: boolean, truncate?: boolean) => any[]

Type declaration

    • (base?: Vector, merger?: Vector, append?: boolean, truncate?: boolean): any[]
    • Parameters

      • base: Vector = ...
      • merger: Vector = ...
      • append: boolean = false
      • truncate: boolean = true

      Returns any[]

Optional getTimeseriesShape

getTimeseriesShape: (x_timeseries: undefined | NestedArray<any>) => Shape

Type declaration

    • (x_timeseries: undefined | NestedArray<any>): Shape
    • Parameters

      • x_timeseries: undefined | NestedArray<any>

      Returns Shape

Optional idToFeature

idToFeature: IdToFeature

Optional importedEmbeddings

importedEmbeddings: boolean

Optional layers

layers: TensorScriptLayers

Optional loss

loss: number

model

model: any

Optional numberOfFeatures

numberOfFeatures: number

reshape

reshape: (...args: any[]) => any

Type declaration

    • (...args: any[]): any
    • Parameters

      • Rest ...args: any[]

      Returns any

settings

settings: TensorScriptOptions

tf

tf: any

tokenizer

tokenizer: any

trained

trained: boolean

type

type: string

Optional xShape

xShape: number[]

Optional yShape

yShape: number[]

Methods

calculate

  • calculate(): Promise<any>

compileModel

  • compileModel(__namedParameters?: { layers?: DenseLayer[] }): void
  • Parameters

    • __namedParameters: { layers?: DenseLayer[] } = ...
      • Optional layers?: DenseLayer[]

    Returns void

exportConfiguration

  • exportConfiguration(): TensorScriptContext

exportEmbeddings

  • exportEmbeddings(): Promise<{ featureIds: undefined | Matrix; featureToId: undefined | FeatureToId; idToFeature: undefined | IdToFeature; labeledWeights: {}; numberOfFeatures: undefined | number }>
  • Returns Promise<{ featureIds: undefined | Matrix; featureToId: undefined | FeatureToId; idToFeature: undefined | IdToFeature; labeledWeights: {}; numberOfFeatures: undefined | number }>

findSimilarFeatures

  • findSimilarFeatures(weights: Matrix, options?: SimilarFeatureOptions): Promise<SimilarFeatures>
  • 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 }, ] }

    Parameters

    • weights: Matrix
    • options: SimilarFeatureOptions = ...

    Returns Promise<SimilarFeatures>

generateBatch

  • generateBatch(__namedParameters: { epoch: number }): Promise<{ loss: number }>
  • Parameters

    • __namedParameters: { epoch: number }
      • epoch: number

    Returns Promise<{ loss: number }>

generateLayers

  • generateLayers(x_matrix: Matrix, y_matrix: Matrix, layers?: TensorScriptLayers): void
  • Adds dense layers to tensorflow classification model

    override

    Parameters

    • x_matrix: Matrix

      independent variables

    • y_matrix: Matrix

      dependent variables

    • Optional layers: TensorScriptLayers

      model dense layer parameters

    Returns void

importConfiguration

  • importConfiguration(configuration: TensorScriptContext): void

importEmbeddings

  • importEmbeddings(__namedParameters: { addNewWeights?: boolean; featureIds?: Matrix; featureToId?: FeatureToId; fixImportedWeights?: boolean; idToFeature?: IdToFeature; inputMatrixFeatures?: Corpus; labeledWeights: LabeledWeights; numberOfFeatures?: number }): Promise<void>
  • Parameters

    • __namedParameters: { addNewWeights?: boolean; featureIds?: Matrix; featureToId?: FeatureToId; fixImportedWeights?: boolean; idToFeature?: IdToFeature; inputMatrixFeatures?: Corpus; labeledWeights: LabeledWeights; numberOfFeatures?: number }
      • Optional addNewWeights?: boolean
      • Optional featureIds?: Matrix
      • Optional featureToId?: FeatureToId
      • Optional fixImportedWeights?: boolean
      • Optional idToFeature?: IdToFeature
      • Optional inputMatrixFeatures?: Corpus
      • labeledWeights: LabeledWeights
      • Optional numberOfFeatures?: number

    Returns Promise<void>

labelWeights

  • labelWeights(weights: Matrix): {}
  • 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] }

    Parameters

    • weights: Matrix

    Returns {}

    • [index: string]: Vector

loadModel

  • loadModel(options: string): Promise<any>

predict

  • predict(options?: PredictionOptions): Promise<any>

reduceWeights

  • reduceWeights(weights: Matrix, options?: any): Promise<any>
  • 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], ]

    Parameters

    • weights: Matrix
    • Optional options: any

    Returns Promise<any>

saveModel

  • saveModel(options: string): Promise<any>

train

  • train(x_matrix: Matrix, y_matrix: Matrix, layers?: DenseLayer[]): Promise<any>

trainOnBatch

  • trainOnBatch(__namedParameters: { epoch: number; inputVectorIndex?: number; inputVectorLength?: number; trainingLoss: number; x_input_matrix: Matrix; y_output_matrix: Matrix }): Promise<{ loss: number }>
  • Parameters

    • __namedParameters: { epoch: number; inputVectorIndex?: number; inputVectorLength?: number; trainingLoss: number; x_input_matrix: Matrix; y_output_matrix: Matrix }
      • epoch: number
      • Optional inputVectorIndex?: number
      • Optional inputVectorLength?: number
      • trainingLoss: number
      • x_input_matrix: Matrix
      • y_output_matrix: Matrix

    Returns Promise<{ loss: number }>

Static getContextPairs

  • getContextPairs(__namedParameters: { inputMatrix: Matrix; numberOfFeatures: number; tf?: any; window_size?: number }): Promise<{ context_length: number; emptyXVector: any; emptyYVector: any; x: Matrix; y: Matrix }>
  • Parameters

    • __namedParameters: { inputMatrix: Matrix; numberOfFeatures: number; tf?: any; window_size?: number }
      • inputMatrix: Matrix
      • numberOfFeatures: number
      • Optional tf?: any
      • Optional window_size?: number

    Returns Promise<{ context_length: number; emptyXVector: any; emptyYVector: any; x: Matrix; y: Matrix }>

Static getFeatureDataSet

  • getFeatureDataSet(__namedParameters: { PAD?: string; initialFeatureToId?: FeatureToId; initialIdToFeature?: IdToFeature; inputMatrixFeatures: Corpus }): Promise<{ featureIds: number[][]; featureToId: {}; idToFeature: IdToFeature; numberOfFeatures: number }>
  • Parameters

    • __namedParameters: { PAD?: string; initialFeatureToId?: FeatureToId; initialIdToFeature?: IdToFeature; inputMatrixFeatures: Corpus }
      • Optional PAD?: string
      • Optional initialFeatureToId?: FeatureToId
      • Optional initialIdToFeature?: IdToFeature
      • inputMatrixFeatures: Corpus

    Returns Promise<{ featureIds: number[][]; featureToId: {}; idToFeature: IdToFeature; numberOfFeatures: number }>

Static getInputShape

  • getInputShape(matrix?: any): Shape

Static getMergedArray

  • getMergedArray(base?: Vector, merger?: Vector, append?: boolean, truncate?: boolean): any[]
  • Parameters

    • base: Vector = ...
    • merger: Vector = ...
    • append: boolean = false
    • truncate: boolean = true

    Returns any[]

Static reshape

  • reshape(array: Vector, shape: Shape): Vector | Matrix
  • Reshapes an array

    function
    example

    const array = [ 0, 1, 1, 0, ]; const shape = [2,2]; TensorScriptModelInterface.reshape(array,shape) // => [ [ 0, 1, ], [ 1, 0, ], ];

    Parameters

    • array: Vector

      input array

    • shape: Shape

      shape array

    Returns Vector | Matrix

    returns a matrix with the defined shape