Skip to content

Commit

Permalink
Support addition of new properties on existing models (Azure#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
samvaity authored Sep 17, 2020
1 parent c91a102 commit c487890
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
@Immutable
public final class RecognizedForm {

private float formTypeConfidence;
private String modelId;
/*
* A map of the fields recognized from the input document.
* For models trained with labels, this is the training-time label of the field. For models trained with forms
Expand Down Expand Up @@ -90,4 +92,13 @@ public FormPageRange getPageRange() {
public List<FormPage> getPages() {
return this.pages;
}

public float getFormTypeConfidence() {
return formTypeConfidence;
}

public String getModelId() {
return modelId;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
@Fluent
public final class TrainingOptions {
private String displayName;
private static final Duration DEFAULT_POLL_INTERVAL = Duration.ofSeconds(5);
private Duration pollInterval = DEFAULT_POLL_INTERVAL;
private TrainingFileFilter trainingFileFilter;
Expand Down Expand Up @@ -60,4 +61,13 @@ public TrainingOptions setPollInterval(final Duration pollInterval) {
this.pollInterval = pollInterval == null ? DEFAULT_POLL_INTERVAL : pollInterval;
return this;
}

public String getDisplayName() {
return displayName;
}

public TrainingOptions setDisplayName(final String displayName) {
this.displayName = displayName;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public static void main(String[] args) {
for (int i = 0; i < recognizedForms.size(); i++) {
final RecognizedForm form = recognizedForms.get(i);
System.out.printf("----------- Recognized custom form info for page %d -----------%n", i);
System.out.printf("Model Id used for recognizing this form: %s%n", form.getModelId());
System.out.printf("Form type: %s%n", form.getFormType());
System.out.printf("Form type confidence: %s%n", form.getFormTypeConfidence());
form.getFields().forEach((label, formField) ->
// label data is populated if you are using a model trained with unlabeled data,
// since the service needs to make predictions for labels if not explicitly given to it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import com.azure.ai.formrecognizer.models.FormRecognizerOperationResult;
import com.azure.ai.formrecognizer.training.FormTrainingClient;
import com.azure.ai.formrecognizer.training.FormTrainingClientBuilder;
import com.azure.ai.formrecognizer.training.models.TrainingOptions;
import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.util.Context;
import com.azure.core.util.polling.SyncPoller;

/**
Expand Down Expand Up @@ -36,12 +38,14 @@ public static void main(String[] args) {
// Train custom model
String trainingFilesUrl = "{SAS_URL_of_your_container_in_blob_storage}";
// The shared access signature (SAS) Url of your Azure Blob Storage container with your forms.
SyncPoller<FormRecognizerOperationResult, CustomFormModel> trainingPoller = client.beginTraining(trainingFilesUrl, true);
SyncPoller<FormRecognizerOperationResult, CustomFormModel> trainingPoller = client.beginTraining(trainingFilesUrl, true,
new TrainingOptions().setDisplayName("user_friendly_model_name"), Context.NONE);

CustomFormModel customFormModel = trainingPoller.getFinalResult();

// Model Info
System.out.printf("Model Id: %s%n", customFormModel.getModelId());
System.out.printf("Model display name: %s%n", customFormModel.getDisplayName());
System.out.printf("Model Status: %s%n", customFormModel.getModelStatus());
System.out.printf("Training started on: %s%n", customFormModel.getTrainingStartedOn());
System.out.printf("Training completed on: %s%n%n", customFormModel.getTrainingCompletedOn());
Expand Down

0 comments on commit c487890

Please sign in to comment.