

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 사용자 지정 개체 인식기(API) 학습
<a name="train-cer-model"></a>

사용자 지정 개체 인식 모델을 생성하고 학습하려면 Amazon Comprehend [CreateEntityRecognizer](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_CreateEntityRecognizer.html) API 작업을 사용하십시오.

**Topics**
+ [를 사용하여 사용자 지정 개체 인식기 훈련 AWS Command Line Interface](#get-started-api-cer-cli)
+ [를 사용하여 사용자 지정 개체 인식기 훈련 AWS SDK for Java](#get-started-api-cer-java)
+ [Python(Boto3)을 사용한 사용자 지정 개체 인식기 학습](#cer-python)

## 를 사용하여 사용자 지정 개체 인식기 훈련 AWS Command Line Interface
<a name="get-started-api-cer-cli"></a>

다음 예제는 AWS CLI를 사용하여 `CreateEntityRecognizer` 작업 및 기타 관련 API를 사용하는 방법을 보여 줍니다.

Unix, Linux, macOS용 형식으로 지정된 예제입니다. Windows의 경우 각 줄의 끝에 있는 백슬래시(\$1) Unix 연속 문자를 캐럿(^)으로 바꿉니다.

`create-entity-recognizer`CLI 명령을 사용하여 사용자 지정 개체 인식기를 생성합니다. [*입력-데이터-구성 파라미터에 대한 자세한 내용은 Amazon Comprehend API 레퍼런스*의 CreateEntityRecognizer](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_CreateEntityRecognizer.html)를 참조하세요.

```
aws comprehend create-entity-recognizer \
     --language-code en \
     --recognizer-name test-6 \
     --data-access-role-arn "arn:aws:iam::account number:role/service-role/AmazonComprehendServiceRole-role" \
     --input-data-config "EntityTypes=[{Type=PERSON}],Documents={S3Uri=s3://Bucket Name/Bucket Path/documents},
                Annotations={S3Uri=s3://Bucket Name/Bucket Path/annotations}" \
     --region region
```

`list-entity-recognizers` CLI 명령을 사용하여 지역의 모든 개체 인식기를 나열합니다.

```
aws comprehend list-entity-recognizers \
     --region region
```

`describe-entity-recognizer` CLI 명령을 사용하여 사용자 지정 개체 인식기의 작업 상태를 확인합니다.

```
aws comprehend describe-entity-recognizer \
     --entity-recognizer-arn arn:aws:comprehend:region:account number:entity-recognizer/test-6 \
     --region region
```

## 를 사용하여 사용자 지정 개체 인식기 훈련 AWS SDK for Java
<a name="get-started-api-cer-java"></a>

이 예제에서는 Java를 사용하여 사용자 지정 개체 인식기를 생성하고 모델을 학습합니다.

Java를 사용하는 Amazon Comprehend 예제는 [Amazon Comprehend Java](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/example_code/comprehend) 예제를 참조하세요.

## Python(Boto3)을 사용한 사용자 지정 개체 인식기 학습
<a name="cer-python"></a>

Boto3 SDK 인스턴스화: 

```
import boto3
import uuid
comprehend = boto3.client("comprehend", region_name="region")
```

개체 인식기 생성: 

```
response = comprehend.create_entity_recognizer(
    RecognizerName="Recognizer-Name-Goes-Here-{}".format(str(uuid.uuid4())),
    LanguageCode="en",
    DataAccessRoleArn="Role ARN",
    InputDataConfig={
        "EntityTypes": [
            {
                "Type": "ENTITY_TYPE"
            }
        ],
        "Documents": {
            "S3Uri": "s3://Bucket Name/Bucket Path/documents"
        },
        "Annotations": {
            "S3Uri": "s3://Bucket Name/Bucket Path/annotations"
        }
    }
)
recognizer_arn = response["EntityRecognizerArn"]
```

모든 인식기 나열: 

```
response = comprehend.list_entity_recognizers()
```

인식기가 TRAINED 상태에 도달할 때까지 대기: 

```
while True:
    response = comprehend.describe_entity_recognizer(
        EntityRecognizerArn=recognizer_arn
    )

    status = response["EntityRecognizerProperties"]["Status"]
    if "IN_ERROR" == status:
        sys.exit(1)
    if "TRAINED" == status:
        break

    time.sleep(10)
```