Package org.fnlp.ml.types

Examples of org.fnlp.ml.types.Instance


//          System.out.println(content);
//        }
      }
     
      if (firstColumnList.size() > 0){
        cur = new Instance(seq, labels);
        //debug
//        cur.setSource(firstColumnList.toString());
      }
      seq = null;
      labels = null;
View Full Code Here


  }

  public static void main(String[] args) {
        SequenceReader sr = new SequenceReader("example-data/sequence/train.txt",true);
//    SequenceReader sr = new SequenceReader("example-data/sequence/test0.txt",false);
    Instance inst = null;
    int count = 0;
    while (sr.hasNext()) {
      inst = sr.next();
      System.out.print(".");
      inst = null;
View Full Code Here

    String[][] predictSet = new String[testSet.size()][];
    String[][] goldSet = new String[testSet.size()][];
    LabelAlphabet la = cl.getAlphabetFactory().DefaultLabelAlphabet();
    for (int i = 0; i < testSet.size(); i++) {
      Instance carrier = testSet.get(i);
      int[] pred = (int[]) cl.classify(carrier).getLabel(0);
      if (hasLabel) {
        len += pred.length;
        float e = loss.calc(carrier.getTarget(), pred);
        error += e;
        if(e != 0)
          senError++;

      }
      predictSet[i] = la.lookupString(pred);
      if(hasLabel)
        goldSet[i] = la.lookupString((int[])carrier.getTarget());
    }

    long endtime = System.currentTimeMillis();
    System.out.println("总时间:\t" + (endtime - starttime) / 1000.0);
    System.out.println("抽取特征时间:\t" + (featuretime - starttime) / 1000.0);
View Full Code Here

  private void dothis() throws Exception{   
    list = new LinkedList<Instance>();
    Entity ss = null;Entity s2 =null;
    EntityGroup eg = null;
    FeatureGeter fp = null;
    Instance in = null;
    Iterator it =null;
    List<String> newdata = null;
    while(ll.size()>0){ 
      ss=(Entity)ll.poll();         
      it= ll.iterator();       
      while(it.hasNext()){
        s2 = (Entity)it.next();       
        eg = new EntityGroup(ss,s2);
        fp = new FeatureGeter(eg);
        String[] tokens = this.intArrayToString(fp.getFeatrue()).split("\\t+|\\s+");
        newdata= Arrays.asList(tokens);
        in = new Instance(newdata,null);
        in.setSource(eg);
        list.add(in);               
     
    }
  }
View Full Code Here

    StringBuffer sb = null;
    EntityGroup eg1 = null;
    EntityGroup eg2 = null;

   
    Instance in1 = null;
    Instance in2 = null;
    Iterator<Instance> it = null;
    if(ll.size()==0)
      ts = new TreeSet<Entity>();
    while(ll.size()>0){
      in1 = ll.poll();
      ts=new TreeSet<Entity>();
      sb = new StringBuffer();
      sb.append("<  ");
      eg1= (EntityGroup) in1.getSource();
      ts.add(eg1.antecedent);
      ts.add(eg1.anaphor);
      do{
        if(llst.size()>0){
          in1 = llst.poll();
          eg1= (EntityGroup) in1.getSource();
        }
        it = ll.iterator();
        while(it.hasNext()){         
          in2 = (Instance) it.next();
          eg2 = (EntityGroup) in2.getSource();
          if(eg1.antecedent.start == eg2.antecedent.start||eg1.anaphor.start == eg2.antecedent.start){
            ts.add(eg2.anaphor);
            llst.add(in2);
            it.remove();
          }
View Full Code Here

    pclassifier =Linear.loadFrom(modelFile);
  }

  public TPredict<String> classify(String str){
    Pipe p = pclassifier.getPipe();
    Instance inst = new Instance(str);
    try {
      //特征转换
      if(prePipe!=null)
        prePipe.addThruPipe(inst);
      p.addThruPipe(inst);
View Full Code Here

      }
      List<String>[] str1 = new List[list1.size()];
      String[] str2 = new String[list1.size()];
      Iterator it = list1.iterator();
      while(it.hasNext()){
        Instance in = (Instance) it.next();
        str1[i] = (List<String>) in.getData();
        str2[i] = (String) in.getTarget();
        i++;
      }
      for(int k = 0;k<str2.length;k++)
      {
        if(str2[k].equals("1"))
View Full Code Here

      System.out.println("Testing Bayes"+percents_cs[test]+"...");
      if(test!=0)
        bayes.fS_CS(percents_cs[test]);
      int count=0;
      for(int i=0;i<testset.size();i++){
        Instance data = testset.getInstance(i);
        Integer gold = (Integer) data.getTarget();
        Predict<String> pres=bayes.classify(data, Type.STRING, 3);
        String pred_label=pres.getLabel();
        String gold_label = bayes.getLabel(gold);
       
        if(pred_label.equals(gold_label)){
          count++;
        }
        else{
          flag=i;
//          System.err.println(gold_label+"->"+pred_label+" : "+testset.getInstance(i).getTempData());
//          for(int j=0;j<3;j++)
//            System.out.println(pres.getLabel(j)+":"+pres.getScore(j));
        }
      }
      counts_cs[test]=count;
      System.out.println("Bayes Precision("+percents_cs[test]+"):"
      +((float)count/testset.size())+"("+count+"/"+testset.size()+")");
    }
    bayes.noFeatureSelection();
    float[] percents_csmax=new float[]{1.0f,0.9f,0.8f,0.7f,0.5f,0.3f,0.2f,0.1f};
    int[] counts_csmax=new int[10];
    for(int test=0;test<percents_csmax.length;test++){
      System.out.println("Testing Bayes"+percents_csmax[test]+"...");
      if(test!=0)
        bayes.fS_CS_Max(percents_csmax[test]);
      int count=0;
      for(int i=0;i<testset.size();i++){
        Instance data = testset.getInstance(i);
        Integer gold = (Integer) data.getTarget();
        Predict<String> pres=bayes.classify(data, Type.STRING, 3);
        String pred_label=pres.getLabel();
        String gold_label = bayes.getLabel(gold);
       
        if(pred_label.equals(gold_label)){
          count++;
        }
        else{
//          System.err.println(gold_label+"->"+pred_label+" : "+testset.getInstance(i).getTempData());
//          for(int j=0;j<3;j++)
//            System.out.println(pres.getLabel(j)+":"+pres.getScore(j));
        }
      }
      counts_csmax[test]=count;
      System.out.println("Bayes Precision("+percents_csmax[test]+"):"
      +((float)count/testset.size())+"("+count+"/"+testset.size()+")");
    }
    bayes.noFeatureSelection();
    float[] percents_ig=new float[]{1.0f,0.9f,0.8f,0.7f,0.5f,0.3f,0.2f,0.1f};
    int[] counts_ig=new int[10];
    for(int test=0;test<percents_ig.length;test++){
      System.out.println("Testing Bayes"+percents_ig[test]+"...");
      if(test!=0)
        bayes.fS_IG(percents_ig[test]);
      int count=0;
      for(int i=0;i<testset.size();i++){
        Instance data = testset.getInstance(i);
        Integer gold = (Integer) data.getTarget();
        Predict<String> pres=bayes.classify(data, Type.STRING, 3);
        String pred_label=pres.getLabel();
        String gold_label = bayes.getLabel(gold);
       
        if(pred_label.equals(gold_label)){
View Full Code Here

    ArrayList words = new ArrayList<String>();
    ArrayList pos = new ArrayList<String>();
    String[] s = Sentenizer.split(src);
    try {
      for (int i = 0; i < s.length; i++) {
        Instance inst = new Instance(s[i]);
        doProcess(inst);
        int[] pred = (int[]) getClassifier().classify(inst).getLabel(0);
        String[] target = labels.lookupString(pred);
        List[] res = Seq2ArrayWithTag.format(inst, target);
        words.addAll(res[0]);
View Full Code Here

  public String tag(String src) {
    String[] sents = Sentenizer.split(src);
    String tag = "";
    try {
      for (int i = 0; i < sents.length; i++) {
        Instance inst = new Instance(sents[i]);
        String[] preds = _tag(inst);
        String s = Seq2StrWithTag.format(inst, preds);
        tag += s;
        if (i < sents.length - 1)
          tag += delim;
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.