Class FtTextClassification

java.lang.Object
ai.djl.nn.AbstractBaseBlock
ai.djl.nn.AbstractSymbolBlock
ai.djl.fasttext.FtAbstractBlock
ai.djl.fasttext.zoo.nlp.textclassification.FtTextClassification
All Implemented Interfaces:
ai.djl.nn.Block, ai.djl.nn.SymbolBlock, AutoCloseable

public class FtTextClassification extends FtAbstractBlock
A FtAbstractBlock for Application.NLP.TEXT_CLASSIFICATION.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     

    Fields inherited from class ai.djl.fasttext.FtAbstractBlock

    fta, modelFile

    Fields inherited from class ai.djl.nn.AbstractBaseBlock

    inputNames, inputShapes, outputDataTypes, version
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a FtTextClassification.
  • Method Summary

    Modifier and Type
    Method
    Description
    ai.djl.modality.Classifications
    Returns the classifications of the input text.
    ai.djl.modality.Classifications
    classify(String text, int topK)
    Returns top K classifications of the input text.
    fit(FtTrainingConfig config, ai.djl.training.dataset.RawDataset<Path> dataset)
    Trains the fastText model.
    protected ai.djl.ndarray.NDList
    forwardInternal(ai.djl.training.ParameterStore parameterStore, ai.djl.ndarray.NDList inputs, boolean training, ai.djl.util.PairList<String,Object> params)
     
    Returns the fasttext label prefix.
    ai.djl.training.TrainingResult
    Returns the results of training, or null if not trained.
    Converts the block into the equivalent FtWordEmbeddingBlock.

    Methods inherited from class ai.djl.fasttext.FtAbstractBlock

    close, embedWord, getDirectParameters, getModelFile

    Methods inherited from class ai.djl.nn.AbstractSymbolBlock

    getChildren, getOutputShapes

    Methods inherited from class ai.djl.nn.AbstractBaseBlock

    beforeInitialize, cast, clear, describeInput, forward, forward, forwardInternal, getInputShapes, getOutputDataTypes, getParameters, initialize, initializeChildBlocks, isInitialized, loadMetadata, loadParameters, prepare, readInputShapes, saveInputShapes, saveMetadata, saveParameters, setInitializer, setInitializer, setInitializer, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface ai.djl.nn.Block

    cast, clear, describeInput, forward, forward, forward, freezeParameters, freezeParameters, getInputShapes, getOutputDataTypes, getOutputShapes, getParameters, initialize, isInitialized, loadParameters, saveParameters, setInitializer, setInitializer, setInitializer

    Methods inherited from interface ai.djl.nn.SymbolBlock

    describeOutput, removeLastBlock
  • Field Details

  • Constructor Details

    • FtTextClassification

      public FtTextClassification(FtWrapper fta, String labelPrefix)
      Constructs a FtTextClassification.
      Parameters:
      fta - the FtWrapper containing the "fasttext model"
      labelPrefix - the prefix to use for labels
  • Method Details

    • fit

      public static FtTextClassification fit(FtTrainingConfig config, ai.djl.training.dataset.RawDataset<Path> dataset) throws IOException
      Trains the fastText model.
      Parameters:
      config - the training configuration to use
      dataset - the training dataset
      Returns:
      the result of the training
      Throws:
      IOException - when IO operation fails in loading a resource
    • getLabelPrefix

      public String getLabelPrefix()
      Returns the fasttext label prefix.
      Returns:
      the fasttext label prefix
    • getTrainingResult

      public ai.djl.training.TrainingResult getTrainingResult()
      Returns the results of training, or null if not trained.
      Returns:
      the results of training, or null if not trained
    • forwardInternal

      protected ai.djl.ndarray.NDList forwardInternal(ai.djl.training.ParameterStore parameterStore, ai.djl.ndarray.NDList inputs, boolean training, ai.djl.util.PairList<String,Object> params)
      Specified by:
      forwardInternal in class ai.djl.nn.AbstractBaseBlock
    • toWordEmbedding

      public FtWordEmbeddingBlock toWordEmbedding()
      Converts the block into the equivalent FtWordEmbeddingBlock.
      Returns:
      the equivalent FtWordEmbeddingBlock
    • classify

      public ai.djl.modality.Classifications classify(String text)
      Returns the classifications of the input text.
      Parameters:
      text - the input text to be classified
      Returns:
      classifications of the input text
    • classify

      public ai.djl.modality.Classifications classify(String text, int topK)
      Returns top K classifications of the input text.
      Parameters:
      text - the input text to be classified
      topK - the value of K
      Returns:
      classifications of the input text