일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- GenericGBQException
- youtube data
- integrated gradient
- Airflow
- 상관관계
- chatGPT
- requests
- BigQuery
- Retry
- gather_nd
- airflow subdag
- grad-cam
- Counterfactual Explanations
- API
- TensorFlow
- top_k
- flask
- 유튜브 API
- GCP
- hadoop
- XAI
- 공분산
- tensorflow text
- correlation
- login crawling
- subdag
- spark udf
- API Gateway
- UDF
- session 유지
- Today
- Total
데이터과학 삼학년
[번역 API] Google translate를 이용한 언어 번역 API 사용 본문
구글 번역 api는 크게 두가지로 나눌 수 있다.
-
googletrans api : 오픈 소스 (하루 사용횟수 제한), google translate Ajax API를 사용함
-
15K 의 single text 제한
-
-
google cloud translation api : 구글 클라우드에서 제공하는 api, 무료/유료
Googletrans
Basic Usage
from googletrans import Translator
translator = Translator()
translator.translate('안녕하세요.')
# <Translated src=ko dest=en text=Good evening. pronunciation=Good evening.>
translator.translate('안녕하세요.', dest='ja')
# <Translated src=ko dest=ja text=こんにちは。 pronunciation=Kon'nichiwa.>
translator.translate('veritas lux mea', src='la')
# <Translated src=la dest=en text=The truth is my light pronunciation=The truth is my light>
Customize service URL : domain 주소를 이용하여 번역 가능
from googletrans import Translator
translator = Translator(service_urls=[
'translate.google.com',
'translate.google.co.kr',
])
Advanved Usge (Bulk)
Array를 활용하여 batch 형식으로 번역 가능
translations = translator.translate(['The quick brown fox', 'jumps over', 'the lazy dog'], dest='ko')
for translation in translations:
print(translation.origin, ' -> ', translation.text)
# The quick brown fox -> 빠른 갈색 여우
# jumps over -> 이상 점프
# the lazy dog -> 게으른 개
언어지원 : 약 100여개 언어 지원
Google Cloud Translation
GCP credentials를 설정후 이용 가능
API v2 : googletrans와 거의 비슷하게 작성
from google.cloud import translate_v2 as translate
client = translate.Client()
result = client.translate('안녕하세요', target_language='ja')
print(result['translatedText'])
# こんにちは
API v3
from google.cloud import translate_v3beta1 as translate
client = translate.TranslationServiceClient()
response = client.translate_text(
parent=parent,
contents=["안녕하세요"],
mime_type='text/plain', # mime types: text/plain, text/html
source_language_code='ko',
target_language_code='ja')
for translation in response.translations:
print('Translated Text: {}'.format(translation))
googletrans
Free Google Translate API for Python. Translates totally free of charge.
pypi.org
py-googletrans.readthedocs.io/en/latest/
Googletrans: Free and Unlimited Google translate API for Python — Googletrans 2.4.0 documentation
Googletrans: Free and Unlimited Google translate API for Python Googletrans is a free and unlimited python library that implemented Google Translate API. This uses the Google Translate Ajax API to make calls to such methods as detect and translate. Feature
py-googletrans.readthedocs.io
codechacha.com/ko/python-google-translate/
Python - Google translate(구글 번역) API 사용 방법
구글 번역 API를 사용하는 방법은 googletrans 또는 Google Cloud Translation을 이용하는 것입니다. googletrans는 무료 API이지만 사용 횟수 제한이 있습니다. Google Cloud Translation는 유료이지만 제한이 없습니��
codechacha.com
'Natural Language Processing' 카테고리의 다른 글
[크롤링] 로그인 후 게시판 목차의 링크를 받아와(n page 까지의 게시물 전체 링크) website 크롤링 (0) | 2020.09.10 |
---|---|
[크롤링] 로그인이 필요한 website 크롤링 (2) | 2020.09.09 |
Transfer learning 적용 정리 : universal sentence encoder multilingual (0) | 2020.08.10 |
Transfer Learning (universal-sentence-encoder-multilingual) (0) | 2020.08.10 |
[Text Preprocessing] re를 활용한 문자(한글,영어), 숫자만 가져오기 (0) | 2020.07.21 |