Skip to content

create_document_classifier async

create_document_classifier(
    document_classifier_name: ComprehendArnName,
    data_access_role_arn: IamRoleArn,
    input_data_config: DocumentClassifierInputDataConfig,
    language_code: LanguageCode,
    *,
    config_overrides: Optional[AsyncComprehendClientConfig] = None,
    version_name: Optional[VersionName] = None,
    tags: Optional[TagList] = None,
    output_data_config: Optional[DocumentClassifierOutputDataConfig] = None,
    client_request_token: Optional[ClientRequestTokenString] = None,
    volume_kms_key_id: Optional[KmsKeyId] = None,
    vpc_config: Optional[VpcConfig] = None,
    mode: Optional[DocumentClassifierMode] = None,
    model_kms_key_id: Optional[KmsKeyId] = None,
    model_policy: Optional[Policy] = None,
) -> CreateDocumentClassifierResponse

Creates a new document classifier that you can use to categorize documents. To create a classifier, you provide a set of training documents that are labeled with the categories that you want to use. For more information, see Training classifier models in the Comprehend Developer Guide.

Parameters:

  • document_classifier_name (ComprehendArnName) –

    The name of the document classifier.

  • version_name (Optional[VersionName], default: None ) –

    The version name given to the newly created classifier. Version names can have a maximum of 256 characters. Alphanumeric characters, hyphens (-) and underscores (_) are allowed. The version name must be unique among all models with the same classifier name in the Amazon Web Services account/Amazon Web Services Region.

  • data_access_role_arn (IamRoleArn) –

    The Amazon Resource Name (ARN) of the IAM role that grants Amazon Comprehend read access to your input data.

  • tags (Optional[TagList], default: None ) –

    Tags to associate with the document classifier. A tag is a key-value pair that adds as a metadata to a resource used by Amazon Comprehend. For example, a tag with "Sales" as the key might be added to a resource to indicate its use by the sales department.

  • input_data_config (DocumentClassifierInputDataConfig) –

    Specifies the format and location of the input data for the job.

  • output_data_config (Optional[DocumentClassifierOutputDataConfig], default: None ) –

    Specifies the location for the output files from a custom classifier job. This parameter is required for a request that creates a native document model.

  • client_request_token (Optional[ClientRequestTokenString], default: None ) –

    A unique identifier for the request. If you don't set the client request token, Amazon Comprehend generates one.

  • language_code (LanguageCode) –

    The language of the input documents. You can specify any of the languages supported by Amazon Comprehend. All documents must be in the same language.

  • volume_kms_key_id (Optional[KmsKeyId], default: None ) –

    ID for the Amazon Web Services Key Management Service (KMS) key that Amazon Comprehend uses to encrypt data on the storage volume attached to the ML compute instance(s) that process the analysis job. The VolumeKmsKeyId can be either of the following formats:

    • KMS Key ID: "1234abcd-12ab-34cd-56ef-1234567890ab"

    • Amazon Resource Name (ARN) of a KMS Key: "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"

  • vpc_config (Optional[VpcConfig], default: None ) –

    Configuration parameters for an optional private Virtual Private Cloud (VPC) containing the resources you are using for your custom classifier. For more information, see Amazon VPC.

  • mode (Optional[DocumentClassifierMode], default: None ) –

    Indicates the mode in which the classifier will be trained. The classifier can be trained in multi-class (single-label) mode or multi-label mode. Multi-class mode identifies a single class label for each document and multi-label mode identifies one or more class labels for each document. Multiple labels for an individual document are separated by a delimiter. The default delimiter between labels is a pipe (|).

  • model_kms_key_id (Optional[KmsKeyId], default: None ) –

    ID for the KMS key that Amazon Comprehend uses to encrypt trained custom models. The ModelKmsKeyId can be either of the following formats:

    • KMS Key ID: "1234abcd-12ab-34cd-56ef-1234567890ab"

    • Amazon Resource Name (ARN) of a KMS Key: "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"

  • model_policy (Optional[Policy], default: None ) –

    The resource-based policy to attach to your custom document classifier model. You can use this policy to allow another Amazon Web Services account to import your custom model.

    Provide your policy as a JSON body that you enter as a UTF-8 encoded string without line breaks. To provide valid JSON, enclose the attribute names and values in double quotes. If the JSON body is also enclosed in double quotes, then you must escape the double quotes that are inside the policy:

    "{\"attribute\": \"value\", \"attribute\": [\"value\"]}"

    To avoid escaping quotes, you can use single quotes to enclose the policy and double quotes to enclose the JSON names and values:

    '{"attribute": "value", "attribute": ["value"]}'

Raises:

Source code in docs_src/capo_comprehend/_services/async_comprehend.py
async def create_document_classifier(
    self,
    document_classifier_name: "capo_comprehend.types.comprehend_arn_name.ComprehendArnName",
    data_access_role_arn: "capo_comprehend.types.iam_role_arn.IamRoleArn",
    input_data_config: "capo_comprehend.types.document_classifier_input_data_config.DocumentClassifierInputDataConfig",
    language_code: "capo_comprehend.types.language_code.LanguageCode",
    *,
    config_overrides: Optional[AsyncComprehendClientConfig] = None,
    version_name: Optional["capo_comprehend.types.version_name.VersionName"] = None,
    tags: Optional["capo_comprehend.types.tag_list.TagList"] = None,
    output_data_config: Optional[
        "capo_comprehend.types.document_classifier_output_data_config.DocumentClassifierOutputDataConfig"
    ] = None,
    client_request_token: Optional[
        "capo_comprehend.types.client_request_token_string.ClientRequestTokenString"
    ] = None,
    volume_kms_key_id: Optional["capo_comprehend.types.kms_key_id.KmsKeyId"] = None,
    vpc_config: Optional["capo_comprehend.types.vpc_config.VpcConfig"] = None,
    mode: Optional[
        "capo_comprehend.types.document_classifier_mode.DocumentClassifierMode"
    ] = None,
    model_kms_key_id: Optional["capo_comprehend.types.kms_key_id.KmsKeyId"] = None,
    model_policy: Optional["capo_comprehend.types.policy.Policy"] = None,
) -> "capo_comprehend.types.create_document_classifier_response.CreateDocumentClassifierResponse":
    r"""<p>Creates a new document classifier that you can use to categorize documents. To create a classifier, you provide a set of training documents that are labeled with the categories that you want to use. For more information, see <a href="https://docs.aws.amazon.com/comprehend/latest/dg/training-classifier-model.html">Training classifier models</a> in the Comprehend Developer Guide. </p>

    Args:
        document_classifier_name: <p>The name of the document classifier.</p>
        version_name: <p>The version name given to the newly created classifier. Version names can have a maximum of 256 characters. Alphanumeric characters, hyphens (-) and underscores (_) are allowed. The version name must be unique among all models with the same classifier name in the Amazon Web Services account/Amazon Web Services Region.</p>
        data_access_role_arn: <p>The Amazon Resource Name (ARN) of the IAM role that grants Amazon Comprehend read access to your input data.</p>
        tags: <p>Tags to associate with the document classifier. A tag is a key-value pair that adds as a metadata to a resource used by Amazon Comprehend. For example, a tag with "Sales" as the key might be added to a resource to indicate its use by the sales department. </p>
        input_data_config: <p>Specifies the format and location of the input data for the job.</p>
        output_data_config: <p>Specifies the location for the output files from a custom classifier job. This parameter is required for a request that creates a native document model.</p>
        client_request_token: <p>A unique identifier for the request. If you don't set the client request token, Amazon Comprehend generates one.</p>
        language_code: <p>The language of the input documents. You can specify any of the languages supported by Amazon Comprehend. All documents must be in the same language.</p>
        volume_kms_key_id: <p>ID for the Amazon Web Services Key Management Service (KMS) key that Amazon Comprehend uses to encrypt data on the storage volume attached to the ML compute instance(s) that process the analysis job. The VolumeKmsKeyId can be either of the following formats:</p> <ul> <li> <p>KMS Key ID: <code>"1234abcd-12ab-34cd-56ef-1234567890ab"</code> </p> </li> <li> <p>Amazon Resource Name (ARN) of a KMS Key: <code>"arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"</code> </p> </li> </ul>
        vpc_config: <p>Configuration parameters for an optional private Virtual Private Cloud (VPC) containing the resources you are using for your custom classifier. For more information, see <a href="https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html">Amazon VPC</a>. </p>
        mode: <p>Indicates the mode in which the classifier will be trained. The classifier can be trained in multi-class (single-label) mode or multi-label mode. Multi-class mode identifies a single class label for each document and multi-label mode identifies one or more class labels for each document. Multiple labels for an individual document are separated by a delimiter. The default delimiter between labels is a pipe (|).</p>
        model_kms_key_id: <p>ID for the KMS key that Amazon Comprehend uses to encrypt trained custom models. The ModelKmsKeyId can be either of the following formats:</p> <ul> <li> <p>KMS Key ID: <code>"1234abcd-12ab-34cd-56ef-1234567890ab"</code> </p> </li> <li> <p>Amazon Resource Name (ARN) of a KMS Key: <code>"arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"</code> </p> </li> </ul>
        model_policy: <p>The resource-based policy to attach to your custom document classifier model. You can use this policy to allow another Amazon Web Services account to import your custom model.</p> <p>Provide your policy as a JSON body that you enter as a UTF-8 encoded string without line breaks. To provide valid JSON, enclose the attribute names and values in double quotes. If the JSON body is also enclosed in double quotes, then you must escape the double quotes that are inside the policy:</p> <p> <code>"{\"attribute\": \"value\", \"attribute\": [\"value\"]}"</code> </p> <p>To avoid escaping quotes, you can use single quotes to enclose the policy and double quotes to enclose the JSON names and values:</p> <p> <code>'{"attribute": "value", "attribute": ["value"]}'</code> </p>

    Raises:
        capo_comprehend.errors.internal_server_exception.InternalServerException: <p>An internal server error occurred. Retry your request.</p>
        capo_comprehend.errors.invalid_request_exception.InvalidRequestException: <p>The request is invalid.</p>
        capo_comprehend.errors.kms_key_validation_exception.KmsKeyValidationException: <p>The KMS customer managed key (CMK) entered cannot be validated. Verify the key and re-enter it.</p>
        capo_comprehend.errors.resource_in_use_exception.ResourceInUseException: <p>The specified resource name is already in use. Use a different name and try your request again.</p>
        capo_comprehend.errors.resource_limit_exceeded_exception.ResourceLimitExceededException: <p>The maximum number of resources per account has been exceeded. Review the resources, and then try your request again.</p>
        capo_comprehend.errors.too_many_requests_exception.TooManyRequestsException: <p>The number of requests exceeds the limit. Resubmit your request later.</p>
        capo_comprehend.errors.too_many_tags_exception.TooManyTagsException: <p>The request contains more tags than can be associated with a resource (50 tags per resource). The maximum number of tags includes both existing tags and those included in your current request. </p>
        capo_comprehend.errors.unsupported_language_exception.UnsupportedLanguageException: <p>Amazon Comprehend can't process the language of the input text. For a list of supported languages, <a href="https://docs.aws.amazon.com/comprehend/latest/dg/supported-languages.html">Supported languages</a> in the Comprehend Developer Guide. </p>
        capo_comprehend.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_comprehend.types.create_document_classifier_request.CreateDocumentClassifierRequest]",
    ) -> AsyncOperationResponse[
        "capo_comprehend.types.create_document_classifier_response.CreateDocumentClassifierResponse"
    ]:
        import capo_comprehend._operations.comprehend_20171127.create_document_classifier

        (
            output,
            http_response,
        ) = await capo_comprehend._operations.comprehend_20171127.create_document_classifier.async_create_document_classifier(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateDocumentClassifier")
    )
    input_: capo_comprehend.types.create_document_classifier_request.CreateDocumentClassifierRequest = {
        "document_classifier_name": document_classifier_name,
        "data_access_role_arn": data_access_role_arn,
        "input_data_config": input_data_config,
        "language_code": language_code,
    }
    if version_name is not None:
        input_["version_name"] = version_name
    if tags is not None:
        input_["tags"] = tags
    if output_data_config is not None:
        input_["output_data_config"] = output_data_config
    if client_request_token is None:
        client_request_token = str(uuid.uuid4())
    input_["client_request_token"] = client_request_token
    if volume_kms_key_id is not None:
        input_["volume_kms_key_id"] = volume_kms_key_id
    if vpc_config is not None:
        input_["vpc_config"] = vpc_config
    if mode is not None:
        input_["mode"] = mode
    if model_kms_key_id is not None:
        input_["model_kms_key_id"] = model_kms_key_id
    if model_policy is not None:
        input_["model_policy"] = model_policy

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output