public PerceptronModelWriter(AbstractModel model) { Object[] data = model.getDataStructures(); this.numOutcomes = model.getNumOutcomes(); PARAMS = (Context[]) data[0]; Map<String, Context> pmap = (Map<String, Context>) data[1]; OUTCOME_LABELS = (String[]) data[2]; PARAMS = new Context[pmap.size()]; PRED_LABELS = new String[pmap.size()]; int i = 0; for (Map.Entry<String, Context> pred : pmap.entrySet()) { PRED_LABELS[i] = pred.getKey(); PARAMS[i] = pred.getValue(); i++; } }
protected void validatePOSDictionary(POSDictionary posDict, AbstractModel posModel) throws InvalidFormatException { Set<String> dictTags = new HashSet<>(); for (String word : posDict) { Collections.addAll(dictTags, posDict.getTags(word)); } Set<String> modelTags = new HashSet<>(); for (int i = 0; i < posModel.getNumOutcomes(); i++) { modelTags.add(posModel.getOutcome(i)); } if (!modelTags.containsAll(dictTags)) { StringBuilder unknownTag = new StringBuilder(); for (String d : dictTags) { if (!modelTags.contains(d)) { unknownTag.append(d).append(" "); } } throw new InvalidFormatException("Tag dictionary contains tags " + "which are unknown by the model! The unknown tags are: " + unknownTag.toString()); } }
private void init(AbstractModel model, DataOutputStream dos) { if (model.getModelType() == ModelType.Perceptron) { delegateWriter = new BinaryPerceptronModelWriter(model, dos); } else if (model.getModelType() == ModelType.Maxent) { delegateWriter = new BinaryGISModelWriter(model, dos); } else if (model.getModelType() == ModelType.MaxentQn) { delegateWriter = new BinaryQNModelWriter(model, dos); } if (model.getModelType() == ModelType.NaiveBayes) { delegateWriter = new BinaryNaiveBayesModelWriter(model, dos); } }
public GISModelWriter(AbstractModel model) { Object[] data = model.getDataStructures(); @SuppressWarnings("unchecked") Map<String, Context> pmap = (Map<String, Context>) data[1]; OUTCOME_LABELS = (String[]) data[2]; PARAMS = new Context[pmap.size()]; PRED_LABELS = new String[pmap.size()]; int i = 0; for (Map.Entry<String, Context> pred : pmap.entrySet()) { PRED_LABELS[i] = pred.getKey(); PARAMS[i] = pred.getValue(); i++; } }
public AbstractModel(Context[] params, String[] predLabels, String[] outcomeNames) { init(predLabels, params, outcomeNames); this.evalParams = new EvalParameters(params, outcomeNames.length); }
@Test public void testModelEquals() throws IOException { TrainingParameters trainParams = new TrainingParameters(); trainParams.put(AbstractTrainer.ALGORITHM_PARAM, PerceptronTrainer.PERCEPTRON_VALUE); trainParams.put(AbstractTrainer.CUTOFF_PARAM, 1); trainParams.put("UseSkippedAveraging", true); EventTrainer trainer = TrainerFactory.getEventTrainer(trainParams, null); AbstractModel modelA = (AbstractModel) trainer.train(PrepAttachDataUtil.createTrainingStream()); AbstractModel modelB = (AbstractModel) trainer.train(PrepAttachDataUtil.createTrainingStream()); Assert.assertEquals(modelA, modelB); Assert.assertEquals(modelA.hashCode(), modelB.hashCode()); }
Map<String, Context> predMap = (Map<String, Context>)smoothedModel.getDataStructures()[1]; trainer = TrainerFactory.getEventTrainer(params, reportMap); AbstractModel unsmoothedModel = (AbstractModel)trainer.train(eventStream); predMap = (Map<String, Context>)unsmoothedModel.getDataStructures()[1];
public AbstractModel(Context[] params, String[] predLabels, String[] outcomeNames) { init(predLabels, params, outcomeNames); this.evalParams = new EvalParameters(params, outcomeNames.length); }
public NaiveBayesModelWriter(AbstractModel model) { Object[] data = model.getDataStructures(); this.numOutcomes = model.getNumOutcomes(); PARAMS = (Context[]) data[0]; @SuppressWarnings("unchecked") Map<String, Context> pmap = (Map<String, Context>) data[1]; OUTCOME_LABELS = (String[]) data[2]; PARAMS = new Context[pmap.size()]; PRED_LABELS = new String[pmap.size()]; int i = 0; for (Map.Entry<String, Context> pred : pmap.entrySet()) { PRED_LABELS[i] = pred.getKey(); PARAMS[i] = pred.getValue(); i++; } }
protected void validatePOSDictionary(POSDictionary posDict, AbstractModel posModel) throws InvalidFormatException { Set<String> dictTags = new HashSet<>(); for (String word : posDict) { Collections.addAll(dictTags, posDict.getTags(word)); } Set<String> modelTags = new HashSet<>(); for (int i = 0; i < posModel.getNumOutcomes(); i++) { modelTags.add(posModel.getOutcome(i)); } if (!modelTags.containsAll(dictTags)) { StringBuilder unknownTag = new StringBuilder(); for (String d : dictTags) { if (!modelTags.contains(d)) { unknownTag.append(d).append(" "); } } throw new InvalidFormatException("Tag dictionary contains tags " + "which are unknown by the model! The unknown tags are: " + unknownTag.toString()); } }
public GISModelWriter(AbstractModel model) { Object[] data = model.getDataStructures(); @SuppressWarnings("unchecked") Map<String, Context> pmap = (Map<String, Context>) data[1]; OUTCOME_LABELS = (String[]) data[2]; PARAMS = new Context[pmap.size()]; PRED_LABELS = new String[pmap.size()]; int i = 0; for (Map.Entry<String, Context> pred : pmap.entrySet()) { PRED_LABELS[i] = pred.getKey(); PARAMS[i] = pred.getValue(); i++; } }
private void init(AbstractModel model, EncryptedDataOutputStream dos) { if (model.getModelType() == ModelType.Perceptron) { delegateWriter = new BinaryPerceptronModelWriter(model, dos); } else if (model.getModelType() == ModelType.Maxent) { delegateWriter = new BinaryGISModelWriter(model, dos); } else if (model.getModelType() == ModelType.MaxentQn) { delegateWriter = new BinaryQNModelWriter(model, dos); } if (model.getModelType() == ModelType.NaiveBayes) { delegateWriter = new BinaryNaiveBayesModelWriter(model, dos); } }
public AbstractModel(Context[] params, String[] predLabels, String[] outcomeNames) { init(predLabels, params, outcomeNames); this.evalParams = new EvalParameters(params, outcomeNames.length); }
public PerceptronModelWriter(AbstractModel model) { Object[] data = model.getDataStructures(); this.numOutcomes = model.getNumOutcomes(); PARAMS = (Context[]) data[0]; Map<String, Context> pmap = (Map<String, Context>) data[1]; OUTCOME_LABELS = (String[]) data[2]; PARAMS = new Context[pmap.size()]; PRED_LABELS = new String[pmap.size()]; int i = 0; for (Map.Entry<String, Context> pred : pmap.entrySet()) { PRED_LABELS[i] = pred.getKey(); PARAMS[i] = pred.getValue(); i++; } }
protected void validatePOSDictionary(POSDictionary posDict, AbstractModel posModel) throws InvalidFormatException { Set<String> dictTags = new HashSet<>(); for (String word : posDict) { Collections.addAll(dictTags, posDict.getTags(word)); } Set<String> modelTags = new HashSet<>(); for (int i = 0; i < posModel.getNumOutcomes(); i++) { modelTags.add(posModel.getOutcome(i)); } if (!modelTags.containsAll(dictTags)) { StringBuilder unknownTag = new StringBuilder(); for (String d : dictTags) { if (!modelTags.contains(d)) { unknownTag.append(d).append(" "); } } throw new InvalidFormatException("Tag dictionary contains tags " + "which are unknown by the model! The unknown tags are: " + unknownTag.toString()); } }
public GISModelWriter(AbstractModel model) { Object[] data = model.getDataStructures(); @SuppressWarnings("unchecked") Map<String, Context> pmap = (Map<String, Context>) data[1]; OUTCOME_LABELS = (String[]) data[2]; PARAMS = new Context[pmap.size()]; PRED_LABELS = new String[pmap.size()]; int i = 0; for (Map.Entry<String, Context> pred : pmap.entrySet()) { PRED_LABELS[i] = pred.getKey(); PARAMS[i] = pred.getValue(); i++; } }
private void init(AbstractModel model, DataOutputStream dos) { if (model.getModelType() == ModelType.Perceptron) { delegateWriter = new BinaryPerceptronModelWriter(model, dos); } else if (model.getModelType() == ModelType.Maxent) { delegateWriter = new BinaryGISModelWriter(model, dos); } else if (model.getModelType() == ModelType.MaxentQn) { delegateWriter = new BinaryQNModelWriter(model, dos); } if (model.getModelType() == ModelType.NaiveBayes) { delegateWriter = new BinaryNaiveBayesModelWriter(model, dos); } }
public PerceptronModelWriter(AbstractModel model) { Object[] data = model.getDataStructures(); this.numOutcomes = model.getNumOutcomes(); PARAMS = (Context[]) data[0]; Map<String, Context> pmap = (Map<String, Context>) data[1]; OUTCOME_LABELS = (String[]) data[2]; PARAMS = new Context[pmap.size()]; PRED_LABELS = new String[pmap.size()]; int i = 0; for (Map.Entry<String, Context> pred : pmap.entrySet()) { PRED_LABELS[i] = pred.getKey(); PARAMS[i] = pred.getValue(); i++; } }
.getArtifact(FeaturizerModel.FEATURIZER_MODEL_ENTRY_NAME); for (int i = 0; i < posModel.getNumOutcomes(); i++) { modelTags.add(posModel.getOutcome(i));
public NaiveBayesModelWriter(AbstractModel model) { Object[] data = model.getDataStructures(); this.numOutcomes = model.getNumOutcomes(); PARAMS = (Context[]) data[0]; @SuppressWarnings("unchecked") Map<String, Context> pmap = (Map<String, Context>) data[1]; OUTCOME_LABELS = (String[]) data[2]; PARAMS = new Context[pmap.size()]; PRED_LABELS = new String[pmap.size()]; int i = 0; for (Map.Entry<String, Context> pred : pmap.entrySet()) { PRED_LABELS[i] = pred.getKey(); PARAMS[i] = pred.getValue(); i++; } }