AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
与 AWS SDK或ListDocumentClassifiers
一起使用 CLI
以下代码示例演示如何使用 ListDocumentClassifiers
。
操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:
- CLI
-
- AWS CLI
-
列出所有文档分类器
以下
list-document-classifiers
示例列出所有经过训练和正在训练的文档分类器模型。aws comprehend list-document-classifiers
输出:
{ "DocumentClassifierPropertiesList": [ { "DocumentClassifierArn": "arn:aws:comprehend:us-west-2:111122223333:document-classifier/exampleclassifier1", "LanguageCode": "en", "Status": "TRAINED", "SubmitTime": "2023-06-13T19:04:15.735000+00:00", "EndTime": "2023-06-13T19:42:31.752000+00:00", "TrainingStartTime": "2023-06-13T19:08:20.114000+00:00", "TrainingEndTime": "2023-06-13T19:41:35.080000+00:00", "InputDataConfig": { "DataFormat": "COMPREHEND_CSV", "S3Uri": "s3://DOC-EXAMPLE-BUCKET/trainingdata" }, "OutputDataConfig": {}, "ClassifierMetadata": { "NumberOfLabels": 3, "NumberOfTrainedDocuments": 5016, "NumberOfTestDocuments": 557, "EvaluationMetrics": { "Accuracy": 0.9856, "Precision": 0.9919, "Recall": 0.9459, "F1Score": 0.9673, "MicroPrecision": 0.9856, "MicroRecall": 0.9856, "MicroF1Score": 0.9856, "HammingLoss": 0.0144 } }, "DataAccessRoleArn": "arn:aws:iam::111122223333:role/service-role/AmazonComprehendServiceRole-testorle", "Mode": "MULTI_CLASS" }, { "DocumentClassifierArn": "arn:aws:comprehend:us-west-2:111122223333:document-classifier/exampleclassifier2", "LanguageCode": "en", "Status": "TRAINING", "SubmitTime": "2023-06-13T21:20:28.690000+00:00", "InputDataConfig": { "DataFormat": "COMPREHEND_CSV", "S3Uri": "s3://DOC-EXAMPLE-BUCKET/trainingdata" }, "OutputDataConfig": {}, "DataAccessRoleArn": "arn:aws:iam::111122223333:role/service-role/AmazonComprehendServiceRole-testorle", "Mode": "MULTI_CLASS" } ] }
有关更多信息,请参阅《Amazon Comprehend 开发人员指南》中的创建和管理自定义模型。
-
有关API详细信息,请参阅 “ListDocumentClassifiers AWS CLI
命令参考”。
-
- Python
-
- SDK适用于 Python (Boto3)
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 class ComprehendClassifier: """Encapsulates an Amazon Comprehend custom classifier.""" def __init__(self, comprehend_client): """ :param comprehend_client: A Boto3 Comprehend client. """ self.comprehend_client = comprehend_client self.classifier_arn = None def list(self): """ Lists custom classifiers for the current account. :return: The list of classifiers. """ try: response = self.comprehend_client.list_document_classifiers() classifiers = response["DocumentClassifierPropertiesList"] logger.info("Got %s classifiers.", len(classifiers)) except ClientError: logger.exception( "Couldn't get classifiers.", ) raise else: return classifiers
-
有关API详细信息,请参阅ListDocumentClassifiers中的 AWS SDKPython (Boto3) API 参考。
-
ListDocumentClassificationJobs
ListTopicsDetectionJobs