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
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 | |