classify_document
async
¶
classify_document(
endpoint_arn: DocumentClassifierEndpointArn,
*,
config_overrides: Optional[AsyncComprehendClientConfig] = None,
text: Optional[CustomerInputString] = None,
bytes: Optional[SemiStructuredDocumentBlob] = None,
document_reader_config: Optional[DocumentReaderConfig] = None,
) -> ClassifyDocumentResponse
Creates a classification request to analyze a single document in real-time. ClassifyDocument supports the following model types:
-
Custom classifier - a custom model that you have created and trained. For input, you can provide plain text, a single-page document (PDF, Word, or image), or Amazon Textract API output. For more information, see Custom classification in the Amazon Comprehend Developer Guide.
-
Prompt safety classifier - Amazon Comprehend provides a pre-trained model for classifying input prompts for generative AI applications. For input, you provide English plain text input. For prompt safety classification, the response includes only the
Classesfield. For more information about prompt safety classifiers, see Prompt safety classification in the Amazon Comprehend Developer Guide.
If the system detects errors while processing a page in the input document, the API response includes an Errors field that describes the errors.
If the system detects a document-level error in your input document, the API returns an InvalidRequestException error response. For details about this exception, see Errors in semi-structured documents in the Comprehend Developer Guide.
Parameters:
-
text(Optional[CustomerInputString], default:None) –The document text to be analyzed. If you enter text using this parameter, do not use the
Bytesparameter. -
endpoint_arn(DocumentClassifierEndpointArn) –The Amazon Resource Number (ARN) of the endpoint.
For prompt safety classification, Amazon Comprehend provides the endpoint ARN. For more information about prompt safety classifiers, see Prompt safety classification in the Amazon Comprehend Developer Guide
For custom classification, you create an endpoint for your custom model. For more information, see Using Amazon Comprehend endpoints.
-
bytes(Optional[SemiStructuredDocumentBlob], default:None) –Use the
Bytesparameter to input a text, PDF, Word or image file.When you classify a document using a custom model, you can also use the
Bytesparameter to input an Amazon TextractDetectDocumentTextorAnalyzeDocumentoutput file.To classify a document using the prompt safety classifier, use the
Textparameter for input.Provide the input document as a sequence of base64-encoded bytes. If your code uses an Amazon Web Services SDK to classify documents, the SDK may encode the document file bytes for you.
The maximum length of this field depends on the input document type. For details, see Inputs for real-time custom analysis in the Comprehend Developer Guide.
If you use the
Bytesparameter, do not use theTextparameter. -
document_reader_config(Optional[DocumentReaderConfig], default:None) –Provides configuration parameters to override the default actions for extracting text from PDF documents and image files.
Raises:
-
InternalServerException–An internal server error occurred. Retry your request.
-
InvalidRequestException–The request is invalid.
-
ResourceUnavailableException–The specified resource is not available. Check the resource and try your request again.
-
TextSizeLimitExceededException–The size of the input text exceeds the limit. Use a smaller document.
-
UnknownServiceError–The service returned an error code this client does not model.
Source code in docs_src/capo_comprehend/_services/async_comprehend.py
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 | |