Search in sources :

Example 16 with Corpora

use of com.ibm.watson.speech_to_text.v1.model.Corpora in project java-sdk by watson-developer-cloud.

the class SpeechToText method trainAcousticModel.

/**
 * Train a custom acoustic model.
 *
 * <p>Initiates the training of a custom acoustic model with new or changed audio resources. After
 * adding or deleting audio resources for a custom acoustic model, use this method to begin the
 * actual training of the model on the latest audio data. The custom acoustic model does not
 * reflect its changed data until you train it. You must use credentials for the instance of the
 * service that owns a model to train it.
 *
 * <p>The training method is asynchronous. Training time depends on the cumulative amount of audio
 * data that the custom acoustic model contains and the current load on the service. When you
 * train or retrain a model, the service uses all of the model's audio data in the training.
 * Training a custom acoustic model takes approximately as long as the length of its cumulative
 * audio data. For example, it takes approximately 2 hours to train a model that contains a total
 * of 2 hours of audio. The method returns an HTTP 200 response code to indicate that the training
 * process has begun.
 *
 * <p>You can monitor the status of the training by using the [Get a custom acoustic
 * model](#getacousticmodel) method to poll the model's status. Use a loop to check the status
 * once a minute. The method returns an `AcousticModel` object that includes `status` and
 * `progress` fields. A status of `available` indicates that the custom model is trained and ready
 * to use. The service cannot train a model while it is handling another request for the model.
 * The service cannot accept subsequent training requests, or requests to add new audio resources,
 * until the existing training request completes.
 *
 * <p>You can use the optional `custom_language_model_id` parameter to specify the GUID of a
 * separately created custom language model that is to be used during training. Train with a
 * custom language model if you have verbatim transcriptions of the audio files that you have
 * added to the custom model or you have either corpora (text files) or a list of words that are
 * relevant to the contents of the audio files. For training to succeed, both of the custom models
 * must be based on the same version of the same base model, and the custom language model must be
 * fully trained and available.
 *
 * <p>**Note:** Acoustic model customization is supported only for use with previous-generation
 * models. It is not supported for next-generation models.
 *
 * <p>**See also:** * [Train the custom acoustic
 * model](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-acoustic#trainModel-acoustic)
 * * [Using custom acoustic and custom language models
 * together](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-useBoth#useBoth)
 *
 * <p>### Training failures
 *
 * <p>Training can fail to start for the following reasons: * The service is currently handling
 * another request for the custom model, such as another training request or a request to add
 * audio resources to the model. * The custom model contains less than 10 minutes or more than 200
 * hours of audio data. * You passed a custom language model with the `custom_language_model_id`
 * query parameter that is not in the available state. A custom language model must be fully
 * trained and available to be used to train a custom acoustic model. * You passed an incompatible
 * custom language model with the `custom_language_model_id` query parameter. Both custom models
 * must be based on the same version of the same base model. * The custom model contains one or
 * more invalid audio resources. You can correct the invalid audio resources or set the `strict`
 * parameter to `false` to exclude the invalid resources from the training. The model must contain
 * at least one valid resource for training to succeed.
 *
 * @param trainAcousticModelOptions the {@link TrainAcousticModelOptions} containing the options
 *     for the call
 * @return a {@link ServiceCall} with a result of type {@link TrainingResponse}
 */
public ServiceCall<TrainingResponse> trainAcousticModel(TrainAcousticModelOptions trainAcousticModelOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(trainAcousticModelOptions, "trainAcousticModelOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("customization_id", trainAcousticModelOptions.customizationId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/acoustic_customizations/{customization_id}/train", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("speech_to_text", "v1", "trainAcousticModel");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (trainAcousticModelOptions.customLanguageModelId() != null) {
        builder.query("custom_language_model_id", String.valueOf(trainAcousticModelOptions.customLanguageModelId()));
    }
    ResponseConverter<TrainingResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<TrainingResponse>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) TrainingResponse(com.ibm.watson.speech_to_text.v1.model.TrainingResponse)

Example 17 with Corpora

use of com.ibm.watson.speech_to_text.v1.model.Corpora in project java-sdk by watson-developer-cloud.

the class SpeechToText method getCorpus.

/**
 * Get a corpus.
 *
 * <p>Gets information about a corpus from a custom language model. The information includes the
 * name, status, and total number of words for the corpus. _For custom models that are based on
 * previous-generation models_, it also includes the number of out-of-vocabulary (OOV) words from
 * the corpus. You must use credentials for the instance of the service that owns a model to list
 * its corpora.
 *
 * <p>**See also:** [Listing corpora for a custom language
 * model](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-manageCorpora#listCorpora).
 *
 * @param getCorpusOptions the {@link GetCorpusOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Corpus}
 */
public ServiceCall<Corpus> getCorpus(GetCorpusOptions getCorpusOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getCorpusOptions, "getCorpusOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("customization_id", getCorpusOptions.customizationId());
    pathParamsMap.put("corpus_name", getCorpusOptions.corpusName());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/customizations/{customization_id}/corpora/{corpus_name}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("speech_to_text", "v1", "getCorpus");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<Corpus> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Corpus>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Corpus(com.ibm.watson.speech_to_text.v1.model.Corpus)

Aggregations

RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)5 Corpora (com.ibm.watson.developer_cloud.speech_to_text.v1.model.Corpora)5 Corpora (com.ibm.watson.speech_to_text.v1.model.Corpora)5 HashMap (java.util.HashMap)5 MockResponse (okhttp3.mockwebserver.MockResponse)5 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)5 Test (org.junit.Test)5 ListCorporaOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.ListCorporaOptions)4 ListCorporaOptions (com.ibm.watson.speech_to_text.v1.model.ListCorporaOptions)4 File (java.io.File)4 Test (org.testng.annotations.Test)4 AddCorpusOptions (com.ibm.watson.speech_to_text.v1.model.AddCorpusOptions)3 Corpus (com.ibm.watson.speech_to_text.v1.model.Corpus)3 GetCorpusOptions (com.ibm.watson.speech_to_text.v1.model.GetCorpusOptions)3 Words (com.ibm.watson.speech_to_text.v1.model.Words)3 Ignore (org.junit.Ignore)3 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)2 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)2 AddCorpusOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.AddCorpusOptions)2 AddWordOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.AddWordOptions)2