Home > Mobile >  ML Studio language studio failing to detect the source language
ML Studio language studio failing to detect the source language

Time:07-29

I am running a program in python to detect a language and translate that to English using azure machine learning studio. The code block mentioned below throwing error when trying to detect the language.

Error 0002: Failed to parse parameter.

def sample_detect_language():
    print(
        "This sample statement will be translated to english from any other foreign language"
       
    )
    
    from azure.core.credentials import AzureKeyCredential
    from azure.ai.textanalytics import TextAnalyticsClient

    endpoint = os.environ["AZURE_LANGUAGE_ENDPOINT"]
    key = os.environ["AZURE_LANGUAGE_KEY"]

    text_analytics_client = TextAnalyticsClient(endpoint=endpoint)
    documents = [
        """
        The feedback was awesome
        """,
        """
        la recensione è stata fantastica
        """
    ]

    result = text_analytics_client.detect_language(documents)
    reviewed_docs = [doc for doc in result if not doc.is_error]

    print("Check the languages we got review")

    for idx, doc in enumerate(reviewed_docs):
        print("Number#{} is in '{}', which has ISO639-1 name '{}'\n".format(
            idx, doc.primary_language.name, doc.primary_language.iso6391_name
        ))
        if doc.is_error:
            print(doc.id, doc.error)
    
    print(
        "Storing reviews and mapping to their respective ISO639-1 name "
        
    )

    review_to_language = {}
    for idx, doc in enumerate(reviewed_docs):
        review_to_language[documents[idx]] = doc.primary_language.iso6391_name


if __name__ == '__main__':
    sample_detect_language()

Any help to solve the issue is appreciated.

CodePudding user response:

The issue was raised because of missing the called parameters in the function. While doing language detection in machine learning studio, we need to assign end point and key credentials. In the code mentioned above, endpoint details were mentioned, but missed AzureKeyCredential.

endpoint = os.environ["AZURE_LANGUAGE_ENDPOINT"]
key = os.environ["AZURE_LANGUAGE_KEY"]
text_analytics_client = TextAnalyticsClient(endpoint=endpoint)

replace the above line with the code block mentioned below

text_analytics_client = TextAnalyticsClient(endpoint=endpoint, credential= AzureKeyCredential(key))
  • Related