Package org.fnlp.ml.types

Examples of org.fnlp.ml.types.Instance


    }
    String[] words = cws.tag2Array(src);
    if(words.length==0)
      return null;
    String[] target = null;
    Instance inst = new Instance(words);
    doProcess(inst);
    int[]  pred = (int[]) getClassifier().classify(inst).getLabel(0);
    target = labels.lookupString(pred);

View Full Code Here


    }
    String[] words = cws.tag2Array(src);
    if(words.length==0)
      return src;

    Instance inst = new Instance(words);
    doProcess(inst);
    int[] pred = (int[]) getClassifier().classify(inst).getLabel(0);
    String[] target = labels.lookupString(pred);
    String res = format(words, target);
    return res;
View Full Code Here

  public String[] tagSeged(String[] src) {
    if(src==null || src.length==0)
      return null;
    String[] target=null;
    try {
      Instance inst = new Instance(src);
      doProcess(inst);
      int[] pred = (int[]) getClassifier().classify(inst).getLabel(0);
      target = labels.lookupString(pred);     
    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

public class SimpleFormatter {
  public static String format(InstanceSet testSet, String[][] labelsSet) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < testSet.size(); i++) {
      Instance inst = testSet.getInstance(i);
      String[] labels = labelsSet[i];
      sb.append(format(inst, labels));
      sb.append("\n");
    }
    return sb.toString();
View Full Code Here

   * @return
   */
  public static String format(InstanceSet testSet, String[][] labelsSet, String[][] gold) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < testSet.size(); i++) {
      Instance inst = testSet.getInstance(i);
      String[] labels = labelsSet[i];
      sb.append(format(inst, labels, gold[i]));
      sb.append("\n");
    }
    return sb.toString();
View Full Code Here

public class Seq2StrWithTag {

  public static String format(InstanceSet testSet, String[][] labelsSet) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < testSet.size(); i++) {
      Instance inst = testSet.getInstance(i);
      String[] labels = labelsSet[i];
      sb.append(format(inst, labels));
    }
    return sb.toString();
  }
View Full Code Here

    trainset = new InstanceSet(factory);
   
    for(int i=0;i<data.length;i++){
      ISparseVector sv = new HashSparseVector(data[i],true);
      int l = lf.lookupIndex(target[i]);
      Instance inst = new Instance(sv,l);
      trainset.add(inst);
    }
    lf.setStopIncrement(true);
   
    //构建测试集

    System.out.println("Train Number: " + trainset.size());
    System.out.println("Class Number: " + lf.size());

    float c = 1.0f;
    int round = 10;
   
    BaseGenerator featureGen = new BaseGenerator();
    ZeroOneLoss loss = new ZeroOneLoss();
    Inferencer msolver = new MultiLinearMax(featureGen, lf, null,2);

    PATrainer trainer = new PATrainer(msolver, featureGen, loss, round,c, null);
    Linear pclassifier = trainer.train(trainset, null);
    String modelFile = "./tmp/m.gz";
    pclassifier.saveTo(modelFile);
    pclassifier = null;
   
    System.out.println("分类器测试");
    pclassifier = Linear.loadFrom(modelFile);
    float[] tdata = new float[]{1,0,1};
    ISparseVector sv = new HashSparseVector(tdata,true);
    Instance inst = new Instance(sv);
    String lab = pclassifier.getStringLabel(inst);
    System.out.println("分类结果:\t"+lab);
   

    long end = System.currentTimeMillis();
View Full Code Here

              bl1 = true;
              break;
            }
          }
          if(bl1){
            list.add(new Instance(new EntityGroup(et1,et),flag));
          }
        }
        etLL = new LinkedList<Entity>();
        etLL.add(et);
      }
View Full Code Here

    else
      return null;
  }
  public static void main(String args[]) throws IOException{
    FileGroupReader fgr = new FileGroupReader("F:\\媒体 学习\\研一(下)\\cc");
    EntityGroup eg=null;Instance in = null;int i = 0;int j = 0;
    while(!fgr.list.isEmpty())
    { in=  fgr.list.poll();eg=(EntityGroup) in.getData();
      if(in.getTarget().toString().equals("1")){i++;
      }
      else
        j++; 
   
    System.out.print(i);
View Full Code Here

     * 测试
     */
    System.out.println("类别 : 文本内容");
    System.out.println("===================");
    for(int i=0;i<testset.size();i++){
      Instance data = testset.getInstance(i);
     
      Integer gold = (Integer) data.getTarget();
      String pred_label = cl.getStringLabel(data);
      String gold_label = cl.getLabel(gold);
     
      if(pred_label.equals(gold_label))
        System.out.println(pred_label+" : "+testset.getInstance(i).getSource());
      else
        System.err.println(gold_label+"->"+pred_label+" : "+testset.getInstance(i).getSource());
    }
   
   
    /**
     * 分类器使用
     */
    String str = "韦德:不拿冠军就是失败 詹皇:没拿也不意味失败";
    System.out.println("============\n分类:"+ str);
    Pipe p = cl.getPipe();
    Instance inst = new Instance(str);
    try {
      //特征转换
      p.addThruPipe(inst);
    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

TOP

Related Classes of org.fnlp.ml.types.Instance

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.