-
Notifications
You must be signed in to change notification settings - Fork 3.2k
improve docs and samples for glossaries and custom models #18587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kristapratico
merged 26 commits into
Azure:main
from
mshaban-msft:17918/improve_docs_for_custom_models_and_glossaries
Aug 24, 2021
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
8d44b33
update the readme
5896feb
update readme file
954e5c8
added custom translation samples
4f58138
fix 'no-locale' thing in links
82bed3d
update glossary docs
004a63c
update glossaries
112e76a
link to sample glossaries instead of writing code in readme
60ca5a9
update custom model sample linking
b3e7054
remove relative linking in readme
f40b92e
make subheadings in bold text to be more readable
b56efc2
conform with 'Document Translation' naming
89b4407
disambiguate container sas url
8dc37a3
capitaliz Azure name
a7bcb2f
remove misplaced period
214e3d8
update samples -> custom model
30832e4
update async sample -> custom model
037ee8f
remove localization from url
45cfbad
update readme with new file types for glossaries
44c35a4
adding sample glossaries -> xlf
ae14c79
white space
d67e48e
use simplified single input method
4e79c24
update 'job' terminology
8dc50da
update azure-core naming
c5aa5eb
update glossary blob file reference name
b1476eb
link to supported glossaries table
e41a22d
remove locale from url
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
sdk/translation/azure-ai-translation-document/samples/assets/glossary_sample.csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| skull,le crâne | ||
| body,corps | ||
| heart,cœur | ||
| lungs,poumons |
4 changes: 4 additions & 0 deletions
4
sdk/translation/azure-ai-translation-document/samples/assets/glossary_sample.tsv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| skull le crâne | ||
| body corps | ||
| heart cœur | ||
| lungs poumons |
23 changes: 23 additions & 0 deletions
23
sdk/translation/azure-ai-translation-document/samples/assets/glossary_sample.xlf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 http://docs.oasis-open.org/xliff/v1.2/os/xliff-core-1.2-strict.xsd"> | ||
| <file original="EN-TA.tmx" source-language="en-US" target-language="fr-FR" datatype="xml"> | ||
| <body> | ||
| <trans-unit id="1" datatype="plaintext"> | ||
| <source>skull</source> | ||
| <target state="translated">le crâne</target> | ||
| </trans-unit> | ||
| <trans-unit id="2" datatype="plaintext"> | ||
| <source>body</source> | ||
| <target state="translated">corps</target> | ||
| </trans-unit> | ||
| <trans-unit id="3" datatype="plaintext"> | ||
| <source>heart</source> | ||
| <target state="translated">cœur</target> | ||
| </trans-unit> | ||
| <trans-unit id="4" datatype="plaintext"> | ||
| <source>lungs</source> | ||
| <target state="translated">poumons</target> | ||
| </trans-unit> | ||
| </body> | ||
| </file> | ||
| </xliff> |
82 changes: 82 additions & 0 deletions
82
...-translation-document/samples/async_samples/sample_translation_with_custom_model_async.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # coding=utf-8 | ||
| # ------------------------------------ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
| # ------------------------------------ | ||
|
|
||
| """ | ||
| FILE: sample_translation_with_custom_model_async.py | ||
|
|
||
| DESCRIPTION: | ||
| This sample demonstrates how to create a translation operation and apply custom azure translation model when doing the translation. | ||
|
|
||
| To set up your containers for translation and generate SAS tokens to your containers (or files) | ||
| with the appropriate permissions, see the README. | ||
|
|
||
| USAGE: | ||
| python sample_translation_with_custom_model_async.py | ||
|
|
||
| Set the environment variables with your own values before running the sample: | ||
| 1) AZURE_DOCUMENT_TRANSLATION_ENDPOINT - the endpoint to your Document Translation resource. | ||
| 2) AZURE_DOCUMENT_TRANSLATION_KEY - your Document Translation API key. | ||
| 3) AZURE_SOURCE_CONTAINER_URL - the container SAS URL to your source container which has the documents | ||
| to be translated. | ||
| 4) AZURE_TARGET_CONTAINER_URL - the container SAS URL to your target container where the translated documents | ||
| will be written. | ||
| 5) AZURE_CUSTOM_MODEL_ID - the URL to your Azure custom translation model. | ||
| """ | ||
|
|
||
| import asyncio | ||
|
|
||
|
|
||
| async def sample_translation_with_custom_model_async(): | ||
| import os | ||
| from azure.core.credentials import AzureKeyCredential | ||
| from azure.ai.translation.document.aio import DocumentTranslationClient | ||
|
|
||
| endpoint = os.environ["AZURE_DOCUMENT_TRANSLATION_ENDPOINT"] | ||
| key = os.environ["AZURE_DOCUMENT_TRANSLATION_KEY"] | ||
| source_container_url = os.environ["AZURE_SOURCE_CONTAINER_URL"] | ||
| target_container_url = os.environ["AZURE_TARGET_CONTAINER_URL"] | ||
| custom_model_id = os.environ["AZURE_CUSTOM_MODEL_ID"] | ||
|
|
||
| client = DocumentTranslationClient(endpoint, AzureKeyCredential(key)) | ||
|
|
||
|
|
||
|
|
||
| async with client: | ||
| poller = await client.begin_translation( | ||
| source_container_url, | ||
| target_container_url, | ||
| "es", | ||
| category_id=custom_model_id | ||
| ) | ||
| result = await poller.result() | ||
|
|
||
| print("Operation status: {}".format(result.status)) | ||
| print("Operation created on: {}".format(result.created_on)) | ||
| print("Operation last updated on: {}".format(result.last_updated_on)) | ||
| print("Total number of translations on documents: {}".format(result.documents_total_count)) | ||
|
|
||
| print("\nOf total documents...") | ||
| print("{} failed".format(result.documents_failed_count)) | ||
| print("{} succeeded".format(result.documents_succeeded_count)) | ||
|
|
||
| doc_results = client.list_all_document_statuses(result.id) | ||
| async for document in doc_results: | ||
| print("Document ID: {}".format(document.id)) | ||
| print("Document status: {}".format(document.status)) | ||
| if document.status == "Succeeded": | ||
| print("Source document location: {}".format(document.source_document_url)) | ||
| print("Translated document location: {}".format(document.translated_document_url)) | ||
| print("Translated to language: {}\n".format(document.translate_to)) | ||
| else: | ||
| print("Error Code: {}, Message: {}\n".format(document.error.code, document.error.message)) | ||
|
|
||
|
|
||
| async def main(): | ||
| await sample_translation_with_custom_model_async() | ||
|
|
||
| if __name__ == '__main__': | ||
| loop = asyncio.get_event_loop() | ||
| loop.run_until_complete(main()) |
75 changes: 75 additions & 0 deletions
75
...translation/azure-ai-translation-document/samples/sample_translation_with_custom_model.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # coding=utf-8 | ||
| # ------------------------------------ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
| # ------------------------------------ | ||
|
|
||
| """ | ||
| FILE: sample_translation_with_custom_model.py | ||
|
|
||
| DESCRIPTION: | ||
| This sample demonstrates how to create a translation operation and apply custom azure translation model when doing the translation. | ||
|
|
||
| To set up your containers for translation and generate SAS tokens to your containers (or files) | ||
| with the appropriate permissions, see the README. | ||
|
|
||
| USAGE: | ||
| python sample_translation_with_custom_model.py | ||
|
|
||
| Set the environment variables with your own values before running the sample: | ||
| 1) AZURE_DOCUMENT_TRANSLATION_ENDPOINT - the endpoint to your Document Translation resource. | ||
| 2) AZURE_DOCUMENT_TRANSLATION_KEY - your Document Translation API key. | ||
| 3) AZURE_SOURCE_CONTAINER_URL - the container SAS URL to your source container which has the documents | ||
| to be translated. | ||
| 4) AZURE_TARGET_CONTAINER_URL - the container SAS URL to your target container where the translated documents | ||
| will be written. | ||
| 5) AZURE_CUSTOM_MODEL_ID - the URL to your Azure custom translation model. | ||
| """ | ||
|
|
||
|
|
||
| def sample_translation_with_custom_model(): | ||
| import os | ||
| from azure.core.credentials import AzureKeyCredential | ||
| from azure.ai.translation.document import ( | ||
| DocumentTranslationClient | ||
| ) | ||
|
|
||
| endpoint = os.environ["AZURE_DOCUMENT_TRANSLATION_ENDPOINT"] | ||
| key = os.environ["AZURE_DOCUMENT_TRANSLATION_KEY"] | ||
| source_container_url = os.environ["AZURE_SOURCE_CONTAINER_URL"] | ||
| target_container_url = os.environ["AZURE_TARGET_CONTAINER_URL"] | ||
| custom_model_id = os.environ["AZURE_CUSTOM_MODEL_ID"] | ||
|
|
||
| client = DocumentTranslationClient(endpoint, AzureKeyCredential(key)) | ||
|
|
||
| poller = client.begin_translation( | ||
| source_container_url, | ||
| target_container_url, | ||
| "es", | ||
| category_id=custom_model_id | ||
| ) | ||
| result = poller.result() | ||
|
|
||
| print("Operation status: {}".format(result.status)) | ||
| print("Operation created on: {}".format(result.created_on)) | ||
| print("Operation last updated on: {}".format(result.last_updated_on)) | ||
| print("Total number of translations on documents: {}".format(result.documents_total_count)) | ||
|
|
||
| print("\nOf total documents...") | ||
| print("{} failed".format(result.documents_failed_count)) | ||
| print("{} succeeded".format(result.documents_succeeded_count)) | ||
|
|
||
| doc_results = client.list_all_document_statuses(result.id) | ||
| for document in doc_results: | ||
| print("Document ID: {}".format(document.id)) | ||
| print("Document status: {}".format(document.status)) | ||
| if document.status == "Succeeded": | ||
| print("Source document location: {}".format(document.source_document_url)) | ||
| print("Translated document location: {}".format(document.translated_document_url)) | ||
| print("Translated to language: {}\n".format(document.translate_to)) | ||
| else: | ||
| print("Error Code: {}, Message: {}\n".format(document.error.code, document.error.message)) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| sample_translation_with_custom_model() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.