Cloud Translation - Advanced API 사용
모델 학습이 정상적으로 끝나면 Cloud Translation - Advanced API translateText
메서드를 사용하여 콘텐츠를 번역할 수 있습니다. Cloud Translation - Advanced API에서 용어집 및 일괄 번역 요청을 사용할 수 있습니다.
REST
프로젝트에 Cloud AutoML API를 사용 설정했는지 확인하세요. 이렇게 해야 AutoML API에서 AutoML 모델을 사용할 수 있습니다. API를 사용 설정하려면 이 시작하기 문서를 참조하세요.요청 데이터를 사용하기 전에 다음을 바꿉니다.
- project-number-or-id: Google Cloud 프로젝트 번호 또는 ID
HTTP 메서드 및 URL:
POST https://translation.googleapis.com/v3/projects/project-number-or-id/locations/us-central1:translateText
JSON 요청 본문:
{ "model": "projects/project-number-or-id/locations/us-central1/models/TRL1395675701985363739", "sourceLanguageCode": "en", "targetLanguageCode": "ru", "contents": ["Dr. Watson, please discard your trash. You've shared unsolicited email with me. Let's talk about spam and importance ranking in a confidential mode."] }
요청을 보내려면 다음 옵션 중 하나를 선택합니다.
curl
요청 본문을 request.json
파일에 저장하고 다음 명령어를 실행합니다.
curl -X POST \
-H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://translation.googleapis.com/v3/projects/project-number-or-id/locations/us-central1:translateText"
PowerShell
요청 본문을 request.json
파일에 저장하고 다음 명령어를 실행합니다.
$cred = gcloud auth application-default print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://translation.googleapis.com/v3/projects/project-number-or-id/locations/us-central1:translateText" | Select-Object -Expand Content
다음과 비슷한 JSON 응답이 표시됩니다.
{ "translation": { "translatedText": "Доктор Ватсон, пожалуйста, откажитесь от своего мусора. Вы поделились нежелательной электронной почтой со мной. Давайте поговорим о спаме и важности рейтинга в конфиденциальном режиме.", "model": "projects/project-number/locations/us-central1/models/TRL1395675701985363739" } }
Go
Java
Node.js
Python
추가 언어
C#: 클라이언트 라이브러리 페이지의 C# 설정 안내를 따른 후 .NET용 AutoML 번역 참조 문서를 참조하세요.
PHP: 클라이언트 라이브러리 페이지의 PHP 설정 안내를 따른 후 PHP용 AutoML 번역 참조 문서를 참조하세요.
Ruby: 클라이언트 라이브러리 페이지의 Ruby 설정 안내를 따른 다음 Ruby용 AutoML 번역 참조 문서를 참조하세요.
AutoML Translation 사용
AutoML Translation을 사용하여 커스텀 모델로 콘텐츠를 번역할 수도 있습니다.
웹 UI
Google Cloud Console에서 AutoML Translation 모델 페이지로 이동합니다.
사용하려는 모델이 다른 프로젝트에 있는 경우 제목 표시줄의 프로젝트 선택기에서 프로젝트를 선택합니다.
모델 목록에서 텍스트를 번역하는 데 사용할 모델을 선택합니다.
모델의 예측 탭을 클릭합니다.
텍스트 상자에 번역할 콘텐츠를 입력한 다음 번역을 클릭합니다.
커스텀 모델의 결과를 Cloud Translation - Advanced에서 기본적으로 사용하는 기본 모델(Google NMT 모델)과 비교할 수 있습니다.
REST
요청 데이터를 사용하기 전에 다음을 바꿉니다.
- model-name: 모델의 전체 이름입니다. 프로젝트 이름과 위치가 포함됩니다. 모델 이름의 예를 들면
projects/project-id/locations/us-central1/models/model-id
입니다. - source-language-text: 출발어에서 도착어로 번역하려는 텍스트
- project-id: Google Cloud Platform 프로젝트 ID
HTTP 메서드 및 URL:
POST https://automl.googleapis.com/v1/model-name:predict
JSON 요청 본문:
{ "payload" : { "textSnippet": { "content": "source-language-text" } } }
요청을 보내려면 다음 옵션 중 하나를 선택합니다.
curl
요청 본문을 request.json
파일에 저장하고 다음 명령어를 실행합니다.
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-id" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://automl.googleapis.com/v1/model-name:predict"
PowerShell
요청 본문을 request.json
파일에 저장하고 다음 명령어를 실행합니다.
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-id" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://automl.googleapis.com/v1/model-name:predict" | Select-Object -Expand Content
다음과 비슷한 JSON 응답이 표시됩니다.
{ "payload": [ { "translation": { "translatedContent": { "content": "target-language-text" } } } ] }
Go
Java
Node.js
Python
이 코드 예시를 실행하려면 우선 Python 클라이언트 라이브러리를 설치해야 합니다.model_full_id
매개변수는 모델의 전체 이름입니다. 예를 들면projects/434039606874/locations/us-central1/models/3745331181667467569
입니다.
추가 언어
C#: 클라이언트 라이브러리 페이지의 C# 설정 안내를 따른 후 .NET용 AutoML 번역 참조 문서를 참조하세요.
PHP: 클라이언트 라이브러리 페이지의 PHP 설정 안내를 따른 후 PHP용 AutoML 번역 참조 문서를 참조하세요.
Ruby: 클라이언트 라이브러리 페이지의 Ruby 설정 안내를 따른 다음 Ruby용 AutoML 번역 참조 문서를 참조하세요.