Train a custom language model.

        Initiates the training of a custom language model with new resources such as
        corpora, grammars, and custom words. After adding, modifying, or deleting
        resources for a custom language model, use this method to begin the actual
        training of the model on the latest data. You can specify whether the custom
        language model is to be trained with all words from its words resource or only
        with words that were added or modified by the user directly. You must use
        credentials for the instance of the service that owns a model to train it.
        The training method is asynchronous. It can take on the order of minutes to
        complete depending on the amount of data on which the service is being trained and
        the current load on the service. The method returns an HTTP 200 response code to
        indicate that the training process has begun.
        You can monitor the status of the training by using the **Get a custom language
        model** method to poll the model's status. Use a loop to check the status every 10
        seconds. The method returns a `LanguageModel` object that includes `status` and
        `progress` fields. A status of `available` means that the custom model is trained
        and ready to use. The service cannot accept subsequent training requests or
        requests to add new resources until the existing request completes.
        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 a corpus or grammar to the model.
        * No training data have been added to the custom model.
        * One or more words that were added to the custom model have invalid sounds-like
        pronunciations that you must fix.
        **See also:** [Train the custom language
        model](https://cloud.ibm.com/docs/services/speech-to-text/language-create.html#trainModel-language).

        :param str customization_id: The customization ID (GUID) of the custom language
        model that is to be used for the request. You must make the request with
        credentials for the instance of the service that owns the custom model.
        :param str word_type_to_add: The type of words from the custom language model's
        words resource on which to train the model:
        * `all` (the default) trains the model on all new words, regardless of whether
        they were extracted from corpora or grammars or were added or modified by the
        user.
        * `user` trains the model only on new words that were added or modified by the
        user directly. The model is not trained on new words extracted from corpora or
        grammars.
        :param float customization_weight: Specifies a customization weight for the custom
        language model. The customization weight tells the service how much weight to give
        to words from the custom language model compared to those from the base model for
        speech recognition. Specify a value between 0.0 and 1.0; the default is 0.3.
        The default value yields the best performance in general. Assign a higher value if
        your audio makes frequent use of OOV words from the custom model. Use caution when
        setting the weight: a higher value can improve the accuracy of phrases from the
        custom model's domain, but it can negatively affect performance on non-domain
        phrases.
        The value that you assign is used for all recognition requests that use the model.
        You can override it for any recognition request by specifying a customization
        weight for that request.
        :param dict headers: A `dict` containing the request headers
        :return: A `DetailedResponse` containing the result, headers and HTTP status code.
        :rtype: DetailedResponse

def train_language_model(self,
                             customization_id,
                             word_type_to_add=None,
                             customization_weight=None,
                             **kwargs):
        """
        Train a custom language model.

        Initiates the training of a custom language model with new resources such as
        corpora, grammars, and custom words. After adding, modifying, or deleting
        resources for a custom language model, use this method to begin the actual
        training of the model on the latest data. You can specify whether the custom
        language model is to be trained with all words from its words resource or only
        with words that were added or modified by the user directly. You must use
        credentials for the instance of the service that owns a model to train it.
        The training method is asynchronous. It can take on the order of minutes to
        complete depending on the amount of data on which the service is being trained and
        the current load on the service. The method returns an HTTP 200 response code to
        indicate that the training process has begun.
        You can monitor the status of the training by using the **Get a custom language
        model** method to poll the model's status. Use a loop to check the status every 10
        seconds. The method returns a `LanguageModel` object that includes `status` and
        `progress` fields. A status of `available` means that the custom model is trained
        and ready to use. The service cannot accept subsequent training requests or
        requests to add new resources until the existing request completes.
        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 a corpus or grammar to the model.
        * No training data have been added to the custom model.
        * One or more words that were added to the custom model have invalid sounds-like
        pronunciations that you must fix.
        **See also:** [Train the custom language
        model](https://cloud.ibm.com/docs/services/speech-to-text/language-create.html#trainModel-language).

        :param str customization_id: The customization ID (GUID) of the custom language
        model that is to be used for the request. You must make the request with
        credentials for the instance of the service that owns the custom model.
        :param str word_type_to_add: The type of words from the custom language model's
        words resource on which to train the model:
        * `all` (the default) trains the model on all new words, regardless of whether
        they were extracted from corpora or grammars or were added or modified by the
        user.
        * `user` trains the model only on new words that were added or modified by the
        user directly. The model is not trained on new words extracted from corpora or
        grammars.
        :param float customization_weight: Specifies a customization weight for the custom
        language model. The customization weight tells the service how much weight to give
        to words from the custom language model compared to those from the base model for
        speech recognition. Specify a value between 0.0 and 1.0; the default is 0.3.
        The default value yields the best performance in general. Assign a higher value if
        your audio makes frequent use of OOV words from the custom model. Use caution when
        setting the weight: a higher value can improve the accuracy of phrases from the
        custom model's domain, but it can negatively affect performance on non-domain
        phrases.
        The value that you assign is used for all recognition requests that use the model.
        You can override it for any recognition request by specifying a customization
        weight for that request.
        :param dict headers: A `dict` containing the request headers
        :return: A `DetailedResponse` containing the result, headers and HTTP status code.
        :rtype: DetailedResponse
        """

        if customization_id is None:
            raise ValueError('customization_id must be provided')

        headers = {}
        if 'headers' in kwargs:
            headers.update(kwargs.get('headers'))
        sdk_headers = get_sdk_headers('speech_to_text', 'V1',
                                      'train_language_model')
        headers.update(sdk_headers)

        params = {
            'word_type_to_add': word_type_to_add,
            'customization_weight': customization_weight
        }

        url = '/v1/customizations/{0}/train'.format(
            *self._encode_path_vars(customization_id))
        response = self.request(
            method='POST',
            url=url,
            headers=headers,
            params=params,
            accept_json=True)
        return response