Class DemoEmbeddings

java.lang.Object
org.apache.lucene.demo.knn.DemoEmbeddings

public class DemoEmbeddings extends Object
This class provides computeEmbedding(String) and computeEmbedding(Reader) for calculating "semantic" embedding vectors for textual input.
  • Constructor Details

    • DemoEmbeddings

      public DemoEmbeddings(KnnVectorDict vectorDict)
      Sole constructor
      Parameters:
      vectorDict - a token to vector dictionary
  • Method Details

    • computeEmbedding

      public float[] computeEmbedding(String input) throws IOException
      Tokenize and lower-case the input, look up the tokens in the dictionary, and sum the token vectors. Unrecognized tokens are ignored. The resulting vector is normalized to unit length.
      Parameters:
      input - the input to analyze
      Returns:
      the KnnVector for the input
      Throws:
      IOException
    • computeEmbedding

      public float[] computeEmbedding(Reader input) throws IOException
      Tokenize and lower-case the input, look up the tokens in the dictionary, and sum the token vectors. Unrecognized tokens are ignored. The resulting vector is normalized to unit length.
      Parameters:
      input - the input to analyze
      Returns:
      the KnnVector for the input
      Throws:
      IOException