public void predict(Sentence sentence, boolean showSegmentConfidence) throws JNETException {
    if (trained == false || model == null) {
      throw new JNETException(
          "No model available. Train or load trained model first.");
    }

    Pipe myPipe = model.getInputPipe();
    Instance inst = new Instance(sentence, "", "", "", myPipe);
    Sequence input = (Sequence) inst.getData();
    Sequence output = model.viterbiPath(input).output();

    if (output.size() != sentence.getUnits().size()) {
      throw new JNETException("Wrong number of labels predicted.");
    }

    // calculate performance on segments
    double[] conf = null;
    if (showSegmentConfidence) { 
      conf = getSegmentConfidence(input, output);
    }

    
    // now add the label to the unit object
    for (int i = 0; i < sentence.getUnits().size(); i++) {
      Unit unit = sentence.get(i);
      unit.setLabel((String) output.get(i));
      if (showSegmentConfidence) {
        unit.setConfidence(conf[i]);
      }
    }

  }