Package com.clearnlp.classification.model

Examples of com.clearnlp.classification.model.SparseModel


  public void predict(String testFile, String outputFile, String modelFile, byte vectorType) throws Exception
  {
    BufferedReader    fin = UTInput.createBufferedFileReader(testFile);
    PrintStream      fout = UTOutput.createPrintBufferedFileStream(outputFile);
    ObjectInputStream  in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(modelFile)));
    SparseModel    pModel = null;
    StringModel    sModel = null;
   
    switch (vectorType)
    {
    case AbstractTrainSpace.VECTOR_SPARSE:
      pModel = (SparseModel)in.readObject(); break;
    case AbstractTrainSpace.VECTOR_STRING:
      sModel = (StringModel)in.readObject(); break;
    }
   
    in.close();
   
    boolean hasWeight = AbstractTrainSpace.hasWeight(vectorType, testFile);
    int correct = 0, total = 0;
    StringPrediction r = null;
    String line, label = null;
   
    System.out.print("Predicting");
   
    while ((line = fin.readLine()) != null)
    {
      if (vectorType == AbstractTrainSpace.VECTOR_SPARSE)
      {
        Pair<String,SparseFeatureVector> sp = SparseTrainSpace.toInstance(line, hasWeight);
        r = pModel.predictBest(sp.o2);
        label = sp.o1;
      }
      else
      {
        StringInstance ss = StringTrainSpace.toInstance(line, hasWeight);
View Full Code Here


   * Constructs a train space containing sparse vectors.
   * @param hasWeight {@code true} if features are assigned with different weights.
   */
  public SparseTrainSpace(boolean hasWeight)
  {
    super(new SparseModel(), hasWeight);
    s_model = (SparseModel)m_model;
    s_ys    = new ArrayList<String>();
  }
View Full Code Here

  public void predict(String testFile, String outputFile, String modelFile, byte vectorType) throws Exception
  {
    BufferedReader    fin = UTInput.createBufferedFileReader(testFile);
    PrintStream      fout = UTOutput.createPrintBufferedFileStream(outputFile);
    ObjectInputStream  in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(modelFile)));
    SparseModel    pModel = null;
    StringModel    sModel = null;
   
    switch (vectorType)
    {
    case AbstractTrainSpace.VECTOR_SPARSE:
      pModel = (SparseModel)in.readObject(); break;
    case AbstractTrainSpace.VECTOR_STRING:
      sModel = (StringModel)in.readObject(); break;
    }
   
    in.close();
   
    boolean hasWeight = AbstractTrainSpace.hasWeight(vectorType, testFile);
    int correct = 0, total = 0;
    StringPrediction r = null;
    String line, label = null;
   
    System.out.print("Predicting");
   
    while ((line = fin.readLine()) != null)
    {
      if (vectorType == AbstractTrainSpace.VECTOR_SPARSE)
      {
        Pair<String,SparseFeatureVector> sp = SparseTrainSpace.toInstance(line, hasWeight);
        r = pModel.predictBest(sp.o2);
        label = sp.o1;
      }
      else
      {
        StringInstance ss = StringTrainSpace.toInstance(line, hasWeight);
View Full Code Here

TOP

Related Classes of com.clearnlp.classification.model.SparseModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.