Cloud Translation
The need for Machine Translation has been around since modern computing. Just like people learn languages it started out as a one to one process. If I want to say the word book in Spanish, looking it up would return the word libro. This process was known as Rule-Based that mapped a word to word meaning a word in one language has a direct connection to a word in a different language.
Google moved to improve translation and moved to a process called Statistical Machine Translation or SMT. It would analyze documents for patterns that would address the robotic or disjointed results that rule-based produced. It was based upon the “Rosetta Stone” approach.
Advances in Machine learning led to the move toward Neural Networks which were designed to mimic the human brain. It uses mathematical processes to recognize patterns in data.
Neural Machine Translation takes advantage of the move toward neural networks by translating entire sentences based on the meaning of the sentences instead of the straight statistical mapping mapping.
The research paper Attention Is All You Need by Google was a key development in the advancement of AI. Focusing on analyzing entire blocks of texts to resolve the issue of forgetting the beginning of long sentences.
The solution focuses on the importance of weights of words that can provide more clarity on the meaning of the sentences instead of direct literal translation of the specific words. Process entire blocks of text instead of the one word at a time method.
Neural Machine Translation
Cloud Translation API
Cloud hosted tool used for language translation.
Does not store data and each request will contain all necessary information to complete.
Can automatically detect the language you wish to translate from.
To use you need to enable the cloud translation api
gcloud services enable translate.googleapis.com
Next you need to install the translate python modules
pip install google-cloud-translate
We need to tell the program the
project_id you are using.
location global is the default.
parent Format: projects/{project-id}/locations/{location-id}.
contexts text of what you want translated.
mine-type format of output from translation.
Target_language_code symbol of language you want translated to e.g. es for spanish.
=================================================
from google.cloud import translate
project_id = "cloud-project-examples"
client = translate.TranslationServiceClient()
location = "global"
parent = f"projects/{project_id}/locations/{location}"
def translate_text(text):
response = client.translate_text(
request={
"parent": parent,
"contents": [text],
"mime_type": "text/plain",
"target_language_code": "es",
}
)
for translation in response.translations:
print(f"Text to translate from: {text}")
print(f"Text translated to: {translation.translated_text}")
print(f"Language translated to: {translation.detected_language_code}")
if __name__ == "__main__":
phrase = "Do you speak Spanish?"
translate_text(phrase)
========================================================
Results:
john_iacovacci1@cloudshell:~/translate (cloud-project-examples)$ python3 trans-exam.py
Text to translate from: Do you speak Spanish?
Text translated to: ¿Hablas español?
Language translated to: en
john_iacovacci1@cloudshell:~/translate (cloud-project-examples)$
No comments:
Post a Comment