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

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

Properties

compiled: boolean
featureIds?: Matrix
featureToId?: FeatureToId
getContextPairs: (this: any, __namedParameters: { inputMatrix: Matrix; numberOfFeatures: number; tf?: any; window_size?: number }) => Promise<{ context_length: number; emptyXVector: any; emptyYVector: any; x: Matrix; y: Matrix }>

Type declaration

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

      • this: any
      • __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: (this: any, __namedParameters: { PAD?: string; initialFeatureToId?: FeatureToId; initialIdToFeature?: IdToFeature; inputMatrixFeatures: Corpus }) => Promise<{ featureIds: number[][]; featureToId: {}; idToFeature: IdToFeature; numberOfFeatures: number }>

Type declaration

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

      • this: any
      • __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: (...args: any[]) => any

Type declaration

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

      • Rest ...args: any[]

      Returns any

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[]

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

Type declaration

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

      • x_timeseries: undefined | NestedArray<any>

      Returns Shape

idToFeature?: IdToFeature
importedEmbeddings?: boolean
layers?: TensorScriptLayers
loss?: number
model: any
numberOfFeatures?: number
reshape: (...args: any[]) => any

Type declaration

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

      • Rest ...args: any[]

      Returns any

settings: TensorScriptOptions
tf: any
tokenizer: any
trained: boolean
type: string
xShape?: number[]
yShape?: number[]

Methods

  • calculate(): Promise<any>
  • compileModel(__namedParameters?: { layers?: DenseLayer[] }): void
  • Parameters

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

    Returns void

  • exportConfiguration(): TensorScriptContext
  • 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(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(__namedParameters: { epoch: number }): Promise<{ loss: number }>
  • Parameters

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

    Returns Promise<{ loss: number }>

  • generateLayers(this: FeatureEmbedding, x_matrix: Matrix, y_matrix: Matrix, layers?: TensorScriptLayers): void
  • importConfiguration(configuration: TensorScriptContext): void
  • 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(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(options: string): Promise<any>
  • predict(options?: PredictionOptions): Promise<any>
  • 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(options: string): Promise<any>
  • train(x_matrix: Matrix, y_matrix: Matrix, layers?: DenseLayer[]): Promise<any>
  • Asynchronously trains tensorflow model

    Parameters

    • x_matrix: Matrix
    • y_matrix: Matrix
    • Optional layers: DenseLayer[]

    Returns Promise<any>

    returns trained tensorflow model

  • 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 }>

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

    • this: any
    • __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(this: any, __namedParameters: { PAD?: string; initialFeatureToId?: FeatureToId; initialIdToFeature?: IdToFeature; inputMatrixFeatures: Corpus }): Promise<{ featureIds: number[][]; featureToId: {}; idToFeature: IdToFeature; numberOfFeatures: number }>
  • Parameters

    • this: any
    • __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(matrix?: any): Shape
  • getMergedArray(base?: Vector, merger?: Vector, append?: boolean, truncate?: boolean): any[]
  • Parameters

    • base: Vector = []
    • merger: Vector = []
    • append: boolean = false
    • truncate: boolean = true

    Returns any[]

  • 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