Connect with us

Amazon

Create a dashboard with SEC text for financial NLP in Amazon SageMaker JumpStart

Amazon SageMaker JumpStart helps you quickly and easily get started with machine learning (ML) and provides a set of solutions for the most common use cases that can be trained and deployed readily with just a few clicks. JumpStart also includes a collection of multimodal financial text analysis tools, including example notebooks, text models, and…

Published

on

[]Amazon SageMaker JumpStart helps you quickly and easily get started with machine learning (ML) and provides a set of solutions for the most common use cases that can be trained and deployed readily with just a few clicks. JumpStart also includes a collection of multimodal financial text analysis tools, including example notebooks, text models, and solutions, which use APIs from a JumpStart SDK. This post demonstrates how to use these APIs to create dashboards from Securities Exchange Commission (SEC) filings. For more examples of working with the JumpStart SDK, see Finance.

[]SEC filings are very important in finance. Companies file these reports with the SEC, which notifies the world about their business conditions and the future outlook of the companies. Because of their potential predictive value, these filings are good sources of information for many people, ranging from your average high-school investor to executives of large financial corporations. These filings are freely available to all investors. Although these SEC filings are publicly available to anyone, downloading parsed filings and constructing a clean dataset with added features is a time-consuming exercise, even for good technologists. We make this possible in a few API calls.

[]There are numerous types of filings, but the three that we focus on here are 10-Ks, 10-Qs, 8-Ks. 10-Ks are annual reports of the company and are quite detailed. 10-Qs are quarterly reports, except in the quarter in which a 10-K is filed and are less detailed than 10-Ks. Finally, 8-Ks are filed any time there is a change in business conditions that is material and needs to be reported. Numerous 8-Ks can be filed throughout the year. The functionality we discuss in this post provides an overall dashboard to represent these three types of filings with attribute scoring. We use specialized word lists derived from natural language processing (NLP) techniques to score the actual texts of these filings for several characteristics like risk, uncertainty, readability, litigiousness, and sentiment, providing accessible numbers to represent these traits. With this dashboard, anybody can pull up information and related statistics about any companies they have an interest in, and digest it in a useful way, rather than read voluminous filings that are often 50–100 thousand words in length.

[]This post demonstrates how to do the following in a notebook titled Dashboarding SEC Filings available from SageMaker JumpStart:

  1. Retrieve parsed 10-K, 10-Q, 8-K filings. Retrieving these filings from SEC’s EDGAR service is complicated, and parsing these forms into plaintext for further analysis can be very time-consuming. You now have the ability to create a curated dataset in a single API call.
  2. Create separate dataframes for each of the three types of forms, along with separate columns for each extracted section.
  3. Combines two or more sections of the 10-K forms. We implement this (as shown in the following sections) and save the combined text in a column called text2score. We demonstrate how to use the NLP scoring API to add numerical scores as new columns or features that may be used to construct a dashboard.
  4. Add a column with a summary of the text2score column.
  5. Prepare a final dataframe that can be used as input for a dashboard.
  6. Prepare an interactive (in the browser) data table.

[]One of the features of this dashboarding process shown in the notebook is breaking out the long SEC filings into separate sections, each of which deals with different aspects of a company’s reporting. This makes accessing and processing parts of the text of each filing easily available to investors or their algorithms.

Financial NLP

[]Financial NLP is a subset of the rapidly increasing use of ML in finance, but it is the largest. The starting point for a vast amount of financial NLP is text in SEC filings. SEC filings report different types of information related to various events involving companies. For the full list of SEC forms, see Forms List.

[]SEC filings are widely used by financial services companies as a source of information about companies in order to make trading, lending, investment, and risk management decisions. They contain forward-looking information that helps with forecasts and are written with a view to the future. In addition, in recent times, the value of historical time series data has degraded, since economies have been structurally transformed by trade wars, pandemics, and political upheavals. Therefore, text as a source of forward-looking information has been increasing in relevance.

[]There has been an exponential growth in downloads of SEC filings. How to Talk When a Machine is Listening: Corporate Disclosure in the Age of AI reports that the number of machine downloads of corporate 10-K and 10-Q filings increased from 360,861 in 2003 to 165,318,719 in 2016.

[]A vast body of academic and practitioner research is based on financial text, a significant portion of which is based on SEC filings. A recent review article summarizing this work is Textual Analysis in Finance (2020).

[]We describe how a user can quickly retrieve a set of forms, break them into sections, score the text in each section using the provided word lists, and then prepare dashboard elements to analyze the data.

[]This post shows how to curate a dataset of SEC filings with a single API call. This can save financial analysts weeks of work in creating a pipeline to download and curate SEC text, especially given its huge scale.

Install the smjsindustry library

[]We deliver the APIs through the smjsindustry client library. The first step requires pip installing a Python package that interacts with a SageMaker processing container. The retrieval, parsing, transforming, and scoring of text is a complex process and uses many different algorithms and packages. To make this seamless and stable for the user, the functionality is packaged into an Amazon Simple Storage Service (Amazon S3) bucket. For installation and maintenance of the workflow, this approach reduces your effort to a pip install followed by a single API call.

[]The following code blocks copy the wheel file to install the smjsindustry library. It also downloads a synthetic example dataset and dependencies to demonstrate the functionality of curating the TabText dataframe.

# Download scripts from S3 notebook_artifact_bucket = ‘jumpstart-cache-alpha-us-west-2’ notebook_sdk_prefix = ‘smfinance-notebook-dependency/smjsindustry’ notebook_script_prefix = ‘smfinance-notebook-data/sec-dashboard’ # Download smjsindustry SDK sdk_bucket = f’s3://{notebook_artifact_bucket}/{notebook_sdk_prefix}’ !aws s3 sync $sdk_bucket ./ # Download helper scripts scripts_bucket = f’s3://{notebook_artifact_bucket}/{notebook_script_prefix}’ !aws s3 sync $scripts_bucket ./sec-dashboard !pip install –no-index smjsindustry-1.0.0-py3-none-any.whl []This also installs all the necessary packages and APIs that are needed to construct the financial NLP dataset.

Special functions

[]We created various helper functions to enable sectioning the SEC forms, each of which has their own sectioning structure, with sections assigned item numbers. The following code invokes various helper functions needed to parse out the various sections in the 10-K, 10-Q, and 8-K forms:

%run sec-dashboard/SEC_Section_Extraction_Functions.ipynb []After this, import the necessary libraries as follows:

%pylab inline import boto3 import pandas as pd import sagemaker pd.get_option(“display.max_columns”, None) import smjsindustry from smjsindustry.finance import utils from smjsindustry import NLPScoreType, NLPSCORE_NO_WORD_LIST from smjsindustry import NLPScorerConfig, JaccardSummarizerConfig, KMedoidsSummarizerConfig from smjsindustry import Summarizer, NLPScorer from smjsindustry.finance.processor import DataLoader, SECXMLFilingParser from smjsindustry.finance.processor_config import EDGARDataSetConfig []Next, we load the S3 bucket from the SageMaker session:

# Prepare the SageMaker session’s default S3 bucket # and a folder to store processed data session = sagemaker.Session() bucket = session.default_bucket() secdashboard_processed_folder=’jumpstart_industry_secdashboard_processed’ []Note that we have loaded the SageMaker Python SDK Boto3 and classes from smfinance. You’re now ready to download SEC filings for curating your text dataframe. As we discuss next, this is done in a single API call.

Download the filings you want to work with

[]Downloading SEC filings is done from the SEC’s Electronic Data Gathering, Analysis, and Retrieval (EDGAR) website, which provides open data access. EDGAR is the primary system under the SEC for companies and others submitting documents under the Securities Act of 1933, the Securities Exchange Act of 1934, the Trust Indenture Act of 1939, and the Investment Company Act of 1940. EDGAR contains millions of company and individual filings. The system processes about 3,000 filings per day, serves up 3,000 terabytes of data to the public annually, and accommodates 40,000 new filers per year on average. For more information, see Accessing EDGAR Data. In this section, we provide a single API call that creates a dataset in a few lines of code, for any period of time and for a large number of tickers.

[]We wrapped the retrieval functionality into a SageMaker processing container and provide an example notebook in JumpStart so you can download a dataset of filings with metadata such as dates and parsed plaintext, which you can then use for ML using other SageMaker tools. You only need to specify a date range and a list of ticker symbols, and this API does the rest.

[]The extracted dataframe is written to Amazon S3 storage as a CSV file.

[]The following API specifies the machine to be used and the volume size. It also specifies the tickers or CIK codes for the companies to be covered, as well as the three form types (10-K, 10-Q, 8-K) to retrieve. The date range is also specified as well as the file name (CSV) where the retrieved filings are stored.

[]The API is in three parts:

  • The top part specifies the following:
    • The tickers or SEC CIK codes for the companies whose forms are being retrieved
    • The SEC forms types (in this case 10-K, 10-Q, 8-K)
    • Date range of forms by filing date
    • The output CSV file and S3 bucket to store the dataset
  • The middle section shows how to assign system resources and has default values in place
  • The last part runs the API

[]This kicks off the processing job running in a SageMaker container and makes sure that even a very large retrieval can run without the notebook connection.

%%time dataset_config = EDGARDataSetConfig( tickers_or_ciks=[‘amzn’, ‘goog’, ‘27904’, ‘fb’, ‘msft’, ‘uber’, ‘nflx’], # list of stock tickers or CIKs form_types=[’10-K’, ’10-Q’, ‘8-K’], # list of SEC form types filing_date_start=’2019-01-01′, # starting filing date filing_date_end=’2020-12-31′, # ending filing date email_as_user_agent=’test-user@test.com’) # user agent email data_loader = DataLoader( role=sagemaker.get_execution_role(), # loading job execution role instance_count=1, # instances number, limit varies with instance type instance_type=’ml.c5.2xlarge’, # instance type volume_size_in_gb=30, # size in GB of the EBS volume to use volume_kms_key=None, # KMS key for the processing volume output_kms_key=None, # KMS key ID for processing job outputs max_runtime_in_seconds=None, # timeout in seconds. Default is 24 hours. sagemaker_session=sagemaker.Session(), # session object tags=None) # a list of key-value pairs data_loader.load( dataset_config, ‘s3://{}/{}’.format(S3_BUCKET_NAME, S3_FOLDER_NAME), # output s3 prefix (both bucket and folder names are required) ‘dataset_10k_10q_8k_2019_2021.csv’, # output file name wait=True, logs=True) []This example notebook uses data obtained from the SEC EDGAR database. Note that you are responsible for complying with EDGAR’s access terms and conditions. For more information, see Accessing EDGAR Data.

[]For this post, we downloaded three types of filings for seven companies for a period of 2 years. The completed dataset is stored in Amazon S3 as a CSV file titled 10k_10q_8k_2019_2021.csv. You can copy the file from the S3 bucket into your notebook instance and read it into a pandas dataframe to see the curated dataset:

client = boto3.client(‘s3’) client.download_file(S3_BUCKET_NAME, ‘{}/{}’.format(S3_FOLDER_NAME, ’10k_10q_8k_2019_2021.csv’), ’10k_10q_8k_2019_2021.csv’) df_forms = pd.read_csv(’10k_10q_8k_2019_2021.csv’) df_forms []The following screenshot shows our results.

[]

[]The dataset has 248 rows and 6 columns. The column text contains the full plaintext of the filing. The column mdna is for the Management Discussion and Analysis section and is only present in the 10-K and 10-Q forms, not in the 8-K form.

Create the dataframe for the extracted item sections from the 10-K filings

[]Next, we create the dataframe for the extracted item sections.

  1. Subset the dataframe for the 10-K filings.
  2. Extract the sections for each 10-K filing and put them in columns in a separate dataframe.
  3. Merge this dataframe with the dataframe from Step 1.

[]You can examine the cells in the following dataframe to see the text from each section:

df = pd.read_csv(’10k_10q_8k_2019_2021.csv’) df_10K = df[df.form_type == “10-K”] # Construct the DataFrame row by row. items_10K = pd.DataFrame(columns = columns_10K, dtype=object) # for i in range(len(df)): for i in df_10K.index: form_text = df_10K.text[i] item_iter = get_form_items(form_text, “10-K”) items_10K.loc[i] = items_to_df_row(item_iter, columns_10K, “10-K”) items_10K.rename(columns=header_mappings_10K, inplace=True) df_10K = pd.merge(df_10K, items_10K, left_index=True, right_index=True) df_10K.head(10) []The following screenshot shows our results.

[]

[]Visit the example notebook Dashboarding SEC Filings in JumpStart to see similar section extraction for the 10-Q and 8-K forms. For the latter, not all sections are populated. This is because 8-K forms are usually filed for reporting one type of material event that impacts a company, such as Bankruptcy/Receivership, Termination of a Material Definitive Agreement, Regulation FD Disclosure, and so on.

NLP scoring of the forms for specific sections

[]Financial text has been scored using word lists for some time. For a comprehensive review, see Textual Analysis in Finance.

[]The smjsindustry library provides 11 NLP score types by default: positive, negative, litigious, polarity, risk, readability, fraud, safe, certainty, uncertainty, and sentiment. Each score (except readability and sentiment) has its own word list, which is used for scanning and matching with an input text dataset.

[]NLP scoring delivers a score as the fraction of words in a document that are in the relevant scoring word lists. You can provide your own custom word list to calculate the NLP scores. Some scores like readability use standard formulae such as the Gunning-Fog score. Sentiment scores are based on the VADER library.

[]These NLP scores are added as new numerical columns to the text dataframe; this creates a multimodal dataframe, which is a mixture of tabular data and long-form text, called TabText. When submitting this multimodal dataframe for ML, it’s a good idea to normalize the columns of NLP scores (usually with standard normalization or min-max scaling).

[]You can automatically score any chosen text column using the tools in JumpStart. We demonstrate this with the following code example. We combine the MD&A section (Item 7) and the Risk section (Item 7A), and then apply NLP scoring. We compute 11 additional columns for various types of scores.

[]To begin, earmark the text for NLP scoring by creating a new column that combines two columns into a single column called text2score. A new file is saved in your Amazon S3 bucket.

df_10K[“text2score”] = [i+’ ‘+j for i,j in zip(df_10K[“Management’s Discussion and Analysis of Financial Condition and Results of Operations”], df_10K[“Quantitative and Qualitative Disclosures about Market Risk”])] df_10K[[‘ticker’,’text2score’]].to_csv(‘text2score.csv’, index=False) client.upload_file(‘text2score.csv’, S3_BUCKET_NAME, ‘{}/{}’.format(S3_FOLDER_NAME, ‘text2score.csv’)) []NLP scoring can be slow for massive documents such as SEC filings, which contain anywhere from 20,000–100,000 words. Matching to long word lists (usually 200 words or more) can be time-consuming.

[]The input to the API requires the following:

  • Specification of system resources, such as the number and type of machine instances to be used
  • What NLP scores to generate, each one resulting in a new column in the dataframe
  • The S3 bucket and file name in which to store the enhanced dataframe as a CSV file
  • A section that kicks off the API

[]The output file name used in the following example is all_scores.csv, but you can change this to any other file name. It’s stored in the S3 bucket and then, as shown in the following code, we copy it into SageMaker Studio to process it into a dashboard.

[]The API call is as follows:

%%time import smjsindustry from smjsindustry import NLPScoreType, NLPSCORE_NO_WORD_LIST from smjsindustry import NLPScorer from smjsindustry import NLPScorerConfig score_type_list = list( NLPScoreType(score_type, []) for score_type in NLPScoreType.DEFAULT_SCORE_TYPES if score_type not in NLPSCORE_NO_WORD_LIST ) score_type_list.extend([NLPScoreType(score_type, None) for score_type in NLPSCORE_NO_WORD_LIST]) nlp_scorer_config = NLPScorerConfig(score_type_list) nlp_score_processor = NLPScorer( sagemaker.get_execution_role(), # loading job execution role 1, # instances number, limit varies with instance type ‘ml.c5.18xlarge’, # ec2 instance type to run the loading job volume_size_in_gb=30, # size in GB of the EBS volume to use volume_kms_key=None, # KMS key for the processing volume output_kms_key=None, # KMS key ID for processing job outputs max_runtime_in_seconds=None, # timeout in seconds. Default is 24 hours. sagemaker_session=sagemaker.Session(), # session object tags=None) # a list of key-value pairs nlp_score_processor.calculate( nlp_scorer_config, “text2score”, # input column ‘s3://{}/{}/{}’.format(S3_BUCKET_NAME, S3_FOLDER_NAME, ‘text2score.csv’), # input from s3 bucket ‘s3://{}/{}’.format(S3_BUCKET_NAME, S3_FOLDER_NAME), # output s3 prefix (both bucket and folder names are required) ‘all_scores.csv’ # output file name ) []The API allocates rows of the dataframe to the chosen machine instance, and the processing logs show the progress of the session.

[]We write the file to Amazon S3. Now let’s look at the dataframe.

client.download_file(S3_BUCKET_NAME, ‘{}/{}’.format(S3_FOLDER_NAME, ‘all_scores.csv’), ‘all_scores.csv’) qdf = pd.read_csv(‘all_scores.csv’) qdf.head() []For example, the readability score mentions the number of years of schooling needed to read the material. The higher this value, the lower the readability.

[]

Add a column with summaries of the text being scored

[]We can further enhance the dataframe with summaries of the target text column. As an example, we used the abstractive summarizer from Hugging Face. Because this summarizer can only accommodate roughly 300 words of text, it’s not directly applicable to our text, which is much longer (thousands of words). Therefore, we applied the Hugging Face summarizer to groups of paragraphs and pulled it all together to make a single summary. This happens automatically in the summary function in the following code.

[]The dataframe is now extended with an additional summary column. Note that an abstractive summarizer restructures the text and loses the original sentences. This is in contrast to an extractive summarizer, which retains the original sentence structure.

[]The code for this is as follows:

%%time qdf[‘summary’] = ” for i in range(len(qdf)): qdf.loc[i,’summary’] = fullSummary(qdf.loc[i,’text2score’]) print(i, end=’..’) qdf []You can see the new column added in the following screenshot.

[]

Prepare a dashboard of an interactive screening table and visualize the data

[]After you curate this dataframe, wouldn’t it be great to interact with it? This can be done in a few lines of code. We need the R programming language, specifically the DT package to get this working. We use this last CSV file to construct the screening table. The file stock_sec_scores.csv is the same as all_scores.csv except without the text2score and summary columns.

[]Use the following code in R to construct the dashboard:

# R codeimport subprocess ret_code=subprocess.call([‘/usr/bin/Rscript’, ‘sec-dashboard/Dashboard.R’]) []This is saved as an HTML file, and you can choose the file in Studio and open it in your browser. Then you can filter, sort, and search the table interactively in your browser. Both search boxes and sliders provide interactivity.

[]The following is a sample table with example numbers, which are only for illustration.

[]

[]A comparison of scores from two documents is obtained using a radar plot, for which the function createRadarChart is provided in the helper notebook. This is useful to compare two SEC filings using their normalized (min-max scaling) NLP scores. The scores are normalized using min-max scaling on each NLP score. See the following code:

scores = pd.read_csv(‘stock_sec_scores.csv’) #Choose whichever filings you want to compare for for the 2nd and 3rd parameter createRadarChart(scores, 2, 9) []The radar plot shows the overlap (and consequently, the difference) between documents on various attributes.

[]

Conclusion

[]In this post, we showed how to curate a dataset of SEC filings, use NLP for feature engineering on the dataset, and present the features in a dashboard.

[]To get started, you can refer to the example notebook in JumpStart titled Dashboarding SEC Filings. You can also refer to the example notebook in JumpStart titled Create a TabText Dataset of SEC Filings in a Single API Call, which contains more details of SEC forms retrieval, summarization, and NLP scoring.

[]For an overview of financial ML tools in JumpStart, see Amazon SageMaker JumpStart introduces new multimodal (long-form text, tabular) financial analysis tools.

[]For related blog posts with use cases to start with, see Use SEC text for ratings classification using multimodal ML in Amazon SageMaker JumpStart and Use pre-trained financial language models for transfer learning in Amazon SageMaker JumpStart.

[]For additional documentation, see SageMaker JumpStart Industry Python SDK and Amazon SageMaker JumpStart Industry.

[]Important:

  1. This post is for demonstrative purposes only. It is not financial advice and should not be relied on as financial or investment advice.
  2. This post uses data obtained from the SEC EDGAR database. You are responsible for complying with EDGAR’s access terms and conditions.

[]About the Authors

[]

[]Derrick Zhang is a Software Development Engineer at Amazon SageMaker. He focuses on building machine learning tools and products for customers.

[]Daniel Zhu is a Software Development Engineer Intern at Amazon SageMaker. He is currently a third-year Computer Science major at UC Berkeley, with a focus on machine learning.

[]Bodhisatta Saha  is a high-school senior at the Harker School in San Jose, California. He enjoys working on software projects in the areas of social benefit, finance, and natural language.

[]Dr. Sanjiv Das is an Amazon Scholar and the Terry Professor of Finance and Data Science at Santa Clara University. He holds post-graduate degrees in Finance (M.Phil and PhD from New York University) and Computer Science (MS from UC Berkeley), and an MBA from the Indian Institute of Management, Ahmedabad. Prior to being an academic, he worked in the derivatives business in the Asia-Pacific region as a Vice President at Citibank. He works on multimodal machine learning in the area of financial applications.



Source

Continue Reading
Click to comment

Leave a Reply

Your email address will not be published.

Amazon

AWS Week in Review – May 16, 2022

This post is part of our Week in Review series. Check back each week for a quick roundup of interesting news and announcements from AWS! I had been on the road for the last five weeks and attended many of the AWS Summits in Europe. It was great to talk to so many of you…

Published

on

By

This post is part of our Week in Review series. Check back each week for a quick roundup of interesting news and announcements from AWS!

I had been on the road for the last five weeks and attended many of the AWS Summits in Europe. It was great to talk to so many of you in person. The Serverless Developer Advocates are going around many of the AWS Summits with the Serverlesspresso booth. If you attend an event that has the booth, say “Hi ” to my colleagues, and have a coffee while asking all your serverless questions. You can find all the upcoming AWS Summits in the events section at the end of this post.

Last week’s launches
Here are some launches that got my attention during the previous week.

AWS Step Functions announced a new console experience to debug your state machine executions – Now you can opt-in to the new console experience of Step Functions, which makes it easier to analyze, debug, and optimize Standard Workflows. The new page allows you to inspect executions using three different views: graph, table, and event view, and add many new features to enhance the navigation and analysis of the executions. To learn about all the features and how to use them, read Ben’s blog post.

Example on how the Graph View looks

Example on how the Graph View looks

AWS Lambda now supports Node.js 16.x runtime – Now you can start using the Node.js 16 runtime when you create a new function or update your existing functions to use it. You can also use the new container image base that supports this runtime. To learn more about this launch, check Dan’s blog post.

AWS Amplify announces its Android library designed for Kotlin – The Amplify Android library has been rewritten for Kotlin, and now it is available in preview. This new library provides better debugging capacities and visibility into underlying state management. And it is also using the new AWS SDK for Kotlin that was released last year in preview. Read the What’s New post for more information.

Three new APIs for batch data retrieval in AWS IoT SiteWise – With this new launch AWS IoT SiteWise now supports batch data retrieval from multiple asset properties. The new APIs allow you to retrieve current values, historical values, and aggregated values. Read the What’s New post to learn how you can start using the new APIs.

AWS Secrets Manager now publishes secret usage metrics to Amazon CloudWatch – This launch is very useful to see the number of secrets in your account and set alarms for any unexpected increase or decrease in the number of secrets. Read the documentation on Monitoring Secrets Manager with Amazon CloudWatch for more information.

For a full list of AWS announcements, be sure to keep an eye on the What’s New at AWS page.

Other AWS News
Some other launches and news that you may have missed:

IBM signed a deal with AWS to offer its software portfolio as a service on AWS. This allows customers using AWS to access IBM software for automation, data and artificial intelligence, and security that is built on Red Hat OpenShift Service on AWS.

Podcast Charlas Técnicas de AWS – If you understand Spanish, this podcast is for you. Podcast Charlas Técnicas is one of the official AWS podcasts in Spanish. This week’s episode introduces you to Amazon DynamoDB and shares stories on how different customers use this database service. You can listen to all the episodes directly from your favorite podcast app or the podcast web page.

AWS Open Source News and Updates – Ricardo Sueiras, my colleague from the AWS Developer Relation team, runs this newsletter. It brings you all the latest open-source projects, posts, and more. Read edition #112 here.

Upcoming AWS Events
It’s AWS Summits season and here are some virtual and in-person events that might be close to you:

You can register for re:MARS to get fresh ideas on topics such as machine learning, automation, robotics, and space. The conference will be in person in Las Vegas, June 21–24.

That’s all for this week. Check back next Monday for another Week in Review!

— Marcia



Source

Continue Reading

Amazon

Personalize your machine translation results by using fuzzy matching with Amazon Translate

A person’s vernacular is part of the characteristics that make them unique. There are often countless different ways to express one specific idea. When a firm communicates with their customers, it’s critical that the message is delivered in a way that best represents the information they’re trying to convey. This becomes even more important when…

Published

on

By

A person’s vernacular is part of the characteristics that make them unique. There are often countless different ways to express one specific idea. When a firm communicates with their customers, it’s critical that the message is delivered in a way that best represents the information they’re trying to convey. This becomes even more important when it comes to professional language translation. Customers of translation systems and services expect accurate and highly customized outputs. To achieve this, they often reuse previous translation outputs—called translation memory (TM)—and compare them to new input text. In computer-assisted translation, this technique is known as fuzzy matching. The primary function of fuzzy matching is to assist the translator by speeding up the translation process. When an exact match can’t be found in the TM database for the text being translated, translation management systems (TMSs) often have the option to search for a match that is less than exact. Potential matches are provided to the translator as additional input for final translation. Translators who enhance their workflow with machine translation capabilities such as Amazon Translate often expect fuzzy matching data to be used as part of the automated translation solution.

In this post, you learn how to customize output from Amazon Translate according to translation memory fuzzy match quality scores.

Translation Quality Match

The XML Localization Interchange File Format (XLIFF) standard is often used as a data exchange format between TMSs and Amazon Translate. XLIFF files produced by TMSs include source and target text data along with match quality scores based on the available TM. These scores—usually expressed as a percentage—indicate how close the translation memory is to the text being translated.

Some customers with very strict requirements only want machine translation to be used when match quality scores are below a certain threshold. Beyond this threshold, they expect their own translation memory to take precedence. Translators often need to apply these preferences manually either within their TMS or by altering the text data. This flow is illustrated in the following diagram. The machine translation system processes the translation data—text and fuzzy match scores— which is then reviewed and manually edited by translators, based on their desired quality thresholds. Applying thresholds as part of the machine translation step allows you to remove these manual steps, which improves efficiency and optimizes cost.

Machine Translation Review Flow

Figure 1: Machine Translation Review Flow

The solution presented in this post allows you to enforce rules based on match quality score thresholds to drive whether a given input text should be machine translated by Amazon Translate or not. When not machine translated, the resulting text is left to the discretion of the translators reviewing the final output.

Solution Architecture

The solution architecture illustrated in Figure 2 leverages the following services:

  • Amazon Simple Storage Service – Amazon S3 buckets contain the following content:
    • Fuzzy match threshold configuration files
    • Source text to be translated
    • Amazon Translate input and output data locations
  • AWS Systems Manager – We use Parameter Store parameters to store match quality threshold configuration values
  • AWS Lambda – We use two Lambda functions:
    • One function preprocesses the quality match threshold configuration files and persists the data into Parameter Store
    • One function automatically creates the asynchronous translation jobs
  • Amazon Simple Queue Service – An Amazon SQS queue triggers the translation flow as a result of new files coming into the source bucket

Solution Architecture Diagram

Figure 2: Solution Architecture

You first set up quality thresholds for your translation jobs by editing a configuration file and uploading it into the fuzzy match threshold configuration S3 bucket. The following is a sample configuration in CSV format. We chose CSV for simplicity, although you can use any format. Each line represents a threshold to be applied to either a specific translation job or as a default value to any job.

default, 75 SourceMT-Test, 80

The specifications of the configuration file are as follows:

  • Column 1 should be populated with the name of the XLIFF file—without extension—provided to the Amazon Translate job as input data.
  • Column 2 should be populated with the quality match percentage threshold. For any score below this value, machine translation is used.
  • For all XLIFF files whose name doesn’t match any name listed in the configuration file, the default threshold is used—the line with the keyword default set in Column 1.

Auto-generated parameter in Systems Manager Parameter Store

Figure 3: Auto-generated parameter in Systems Manager Parameter Store

When a new file is uploaded, Amazon S3 triggers the Lambda function in charge of processing the parameters. This function reads and stores the threshold parameters into Parameter Store for future usage. Using Parameter Store avoids performing redundant Amazon S3 GET requests each time a new translation job is initiated. The sample configuration file produces the parameter tags shown in the following screenshot.

The job initialization Lambda function uses these parameters to preprocess the data prior to invoking Amazon Translate. We use an English-to-Spanish translation XLIFF input file, as shown in the following code. It contains the initial text to be translated, broken down into what is referred to as segments, represented in the source tags.

Consent Form CONSENT FORM FORMULARIO DE CONSENTIMIENTO Screening Visit: Screening Visit Selección

The source text has been pre-matched with the translation memory beforehand. The data contains potential translation alternatives—represented as tags—alongside a match quality attribute, expressed as a percentage. The business rule is as follows:

  • Segments received with alternative translations and a match quality below the threshold are untouched or empty. This signals to Amazon Translate that they must be translated.
  • Segments received with alternative translations with a match quality above the threshold are pre-populated with the suggested target text. Amazon Translate skips those segments.

Let’s assume the quality match threshold configured for this job is 80%. The first segment with 99% match quality isn’t machine translated, whereas the second segment is, because its match quality is below the defined threshold. In this configuration, Amazon Translate produces the following output:

Consent Form FORMULARIO DE CONSENTIMIENTO CONSENT FORM FORMULARIO DE CONSENTIMIENTO Screening Visit: Visita de selección Screening Visit Selección

In the second segment, Amazon Translate overwrites the target text initially suggested (Selección) with a higher quality translation: Visita de selección.

One possible extension to this use case could be to reuse the translated output and create our own translation memory. Amazon Translate supports customization of machine translation using translation memory thanks to the parallel data feature. Text segments previously machine translated due to their initial low-quality score could then be reused in new translation projects.

In the following sections, we walk you through the process of deploying and testing this solution. You use AWS CloudFormation scripts and data samples to launch an asynchronous translation job personalized with a configurable quality match threshold.

Prerequisites

For this walkthrough, you must have an AWS account. If you don’t have an account yet, you can create and activate one.

Launch AWS CloudFormation stack

  1. Choose Launch Stack:
  2. For Stack name, enter a name.
  3. For ConfigBucketName, enter the S3 bucket containing the threshold configuration files.
  4. For ParameterStoreRoot, enter the root path of the parameters created by the parameters processing Lambda function.
  5. For QueueName, enter the SQS queue that you create to post new file notifications from the source bucket to the job initialization Lambda function. This is the function that reads the configuration file.
  6. For SourceBucketName, enter the S3 bucket containing the XLIFF files to be translated. If you prefer to use a preexisting bucket, you need to change the value of the CreateSourceBucket parameter to No.
  7. For WorkingBucketName, enter the S3 bucket Amazon Translate uses for input and output data.
  8. Choose Next.

    Figure 4: CloudFormation stack details

  9. Optionally on the Stack Options page, add key names and values for the tags you may want to assign to the resources about to be created.
  10. Choose Next.
  11. On the Review page, select I acknowledge that this template might cause AWS CloudFormation to create IAM resources.
  12. Review the other settings, then choose Create stack.

AWS CloudFormation takes several minutes to create the resources on your behalf. You can watch the progress on the Events tab on the AWS CloudFormation console. When the stack has been created, you can see a CREATE_COMPLETE message in the Status column on the Overview tab.

Test the solution

Let’s go through a simple example.

  1. Download the following sample data.
  2. Unzip the content.

There should be two files: an .xlf file in XLIFF format, and a threshold configuration file with .cfg as the extension. The following is an excerpt of the XLIFF file.

English to French sample file extract

Figure 5: English to French sample file extract

  1. On the Amazon S3 console, upload the quality threshold configuration file into the configuration bucket you specified earlier.

The value set for test_En_to_Fr is 75%. You should be able to see the parameters on the Systems Manager console in the Parameter Store section.

  1. Still on the Amazon S3 console, upload the .xlf file into the S3 bucket you configured as source. Make sure the file is under a folder named translate (for example, /translate/test_En_to_Fr.xlf).

This starts the translation flow.

  1. Open the Amazon Translate console.

A new job should appear with a status of In Progress.

Auto-generated parameter in Systems Manager Parameter Store

Figure 6: In progress translation jobs on Amazon Translate console

  1. Once the job is complete, click into the job’s link and consult the output. All segments should have been translated.

All segments should have been translated. In the translated XLIFF file, look for segments with additional attributes named lscustom:match-quality, as shown in the following screenshot. These custom attributes identify segments where suggested translation was retained based on score.

Custom attributes identifying segments where suggested translation was retained based on score

Figure 7: Custom attributes identifying segments where suggested translation was retained based on score

These were derived from the translation memory according to the quality threshold. All other segments were machine translated.

You have now deployed and tested an automated asynchronous translation job assistant that enforces configurable translation memory match quality thresholds. Great job!

Cleanup

If you deployed the solution into your account, don’t forget to delete the CloudFormation stack to avoid any unexpected cost. You need to empty the S3 buckets manually beforehand.

Conclusion

In this post, you learned how to customize your Amazon Translate translation jobs based on standard XLIFF fuzzy matching quality metrics. With this solution, you can greatly reduce the manual labor involved in reviewing machine translated text while also optimizing your usage of Amazon Translate. You can also extend the solution with data ingestion automation and workflow orchestration capabilities, as described in Speed Up Translation Jobs with a Fully Automated Translation System Assistant.

About the Authors

Narcisse Zekpa is a Solutions Architect based in Boston. He helps customers in the Northeast U.S. accelerate their adoption of the AWS Cloud, by providing architectural guidelines, design innovative, and scalable solutions. When Narcisse is not building, he enjoys spending time with his family, traveling, cooking, and playing basketball.

Dimitri Restaino is a Solutions Architect at AWS, based out of Brooklyn, New York. He works primarily with Healthcare and Financial Services companies in the North East, helping to design innovative and creative solutions to best serve their customers. Coming from a software development background, he is excited by the new possibilities that serverless technology can bring to the world. Outside of work, he loves to hike and explore the NYC food scene.



Source

Continue Reading

Amazon

Enhance the caller experience with hints in Amazon Lex

We understand speech input better if we have some background on the topic of conversation. Consider a customer service agent at an auto parts wholesaler helping with orders. If the agent knows that the customer is looking for tires, they’re more likely to recognize responses (for example, “Michelin”) on the phone. Agents often pick up…

Published

on

By

We understand speech input better if we have some background on the topic of conversation. Consider a customer service agent at an auto parts wholesaler helping with orders. If the agent knows that the customer is looking for tires, they’re more likely to recognize responses (for example, “Michelin”) on the phone. Agents often pick up such clues or hints based on their domain knowledge and access to business intelligence dashboards. Amazon Lex now supports a hints capability to enhance the recognition of relevant phrases in a conversation. You can programmatically provide phrases as hints during a live interaction to influence the transcription of spoken input. Better recognition drives efficient conversations, reduces agent handling time, and ultimately increases customer satisfaction.

In this post, we review the runtime hints capability and use it to implement verification of callers based on their mother’s maiden name.

Overview of the runtime hints capability

You can provide a list of phrases or words to help your bot with the transcription of speech input. You can use these hints with built-in slot types such as first and last names, street names, city, state, and country. You can also configure these for your custom slot types.

You can use the capability to transcribe names that may be difficult to pronounce or understand. For example, in the following sample conversation, we use it to transcribe the name “Loreck.”

Conversation 1

IVR: Welcome to ACME bank. How can I help you today?

Caller: I want to check my account balance.

IVR: Sure. Which account should I pull up?

Caller: Checking

IVR: What is the account number?

Caller: 1111 2222 3333 4444

IVR: For verification purposes, what is your mother’s maiden name?

Caller: Loreck

IVR: Thank you. The balance on your checking account is 123 dollars.

Words provided as hints are preferred over other similar words. For example, in the second sample conversation, the runtime hint (“Smythe”) is selected over a more common transcription (“Smith”).

Conversation 2

IVR: Welcome to ACME bank. How can I help you today?

Caller: I want to check my account balance.

IVR: Sure. Which account should I pull up?

Caller: Checking

IVR: What is the account number?

Caller: 5555 6666 7777 8888

IVR: For verification purposes, what is your mother’s maiden name?

Caller: Smythe

IVR: Thank you. The balance on your checking account is 456 dollars.

If the name doesn’t match the runtime hint, you can fail the verification and route the call to an agent.

Conversation 3

IVR: Welcome to ACME bank. How can I help you today?

Caller: I want to check my account balance.

IVR: Sure. Which account should I pull up?

Caller: Savings

IVR: What is the account number?

Caller: 5555 6666 7777 8888

IVR: For verification purposes, what is your mother’s maiden name?

Caller: Jane

IVR: There is an issue with your account. For support, you will be forwarded to an agent.

Solution overview

Let’s review the overall architecture for the solution (see the following diagram):

  • We use an Amazon Lex bot integrated with an Amazon Connect contact flow to deliver the conversational experience.
  • We use a dialog codehook in the Amazon Lex bot to invoke an AWS Lambda function that provides the runtime hint at the previous turn of the conversation.
  • For the purposes of this post, the mother’s maiden name data used for authentication is stored in an Amazon DynamoDB table.
  • After the caller is authenticated, the control is passed to the bot to perform transactions (for example, check balance)

In addition to the Lambda function, you can also send runtime hints to Amazon Lex V2 using the PutSession, RecognizeText, RecognizeUtterance, or StartConversation operations. The runtime hints can be set at any point in the conversation and are persisted at every turn until cleared.

Deploy the sample Amazon Lex bot

To create the sample bot and configure the runtime phrase hints, perform the following steps. This creates an Amazon Lex bot called BankingBot, and one slot type (accountNumber).

  1. Download the Amazon Lex bot.
  2. On the Amazon Lex console, choose Actions, Import.
  3. Choose the file BankingBot.zip that you downloaded, and choose Import.
  4. Choose the bot BankingBot on the Amazon Lex console.
  5. Choose the language English (GB).
  6. Choose Build.
  7. Download the supporting Lambda code.
  8. On the Lambda console, create a new function and select Author from scratch.
  9. For Function name, enter BankingBotEnglish.
  10. For Runtime, choose Python 3.8.
  11. Choose Create function.
  12. In the Code source section, open lambda_function.py and delete the existing code.
  13. Download the function code and open it in a text editor.
  14. Copy the code and enter it into the empty function code field.
  15. Choose deploy.
  16. On the Amazon Lex console, select the bot BankingBot.
  17. Choose Deployment and then Aliases, then choose the alias TestBotAlias.
  18. On the Aliases page, choose Languages and choose English (GB).
  19. For Source, select the bot BankingBotEnglish.
  20. For Lambda version or alias, enter $LATEST.
  21. On the DynamoDB console, choose Create table.
  22. Provide the name as customerDatabase.
  23. Provide the partition key as accountNumber.
  24. Add an item with accountNumber: “1111222233334444” and mothersMaidenName “Loreck”.
  25. Add item with accountNumber: “5555666677778888” and mothersMaidenName “Smythe”.
  26. Make sure the Lambda function has permissions to read from the DynamoDB table customerDatabase.
  27. On the Amazon Connect console, choose Contact flows.
  28. In the Amazon Lex section, select your Amazon Lex bot and make it available for use in the Amazon Connect contact flow.
  29. Download the contact flow to integrate with the Amazon Lex bot.
  30. Choose the contact flow to load it into the application.
  31. Make sure the right bot is configured in the “Get Customer Input” block.
  32. Choose a queue in the “Set working queue” block.
  33. Add a phone number to the contact flow.
  34. Test the IVR flow by calling in to the phone number.

Test the solution

You can now call in to the Amazon Connect phone number and interact with the bot.

Conclusion

Runtime hints allow you to influence the transcription of words or phrases dynamically in the conversation. You can use business logic to identify the hints as the conversation evolves. Better recognition of the user input allows you to deliver an enhanced experience. You can configure runtime hints via the Lex V2 SDK. The capability is available in all AWS Regions where Amazon Lex operates in the English (Australia), English (UK), and English (US) locales.

To learn more, refer to runtime hints.

About the Authors

Kai Loreck is a professional services Amazon Connect consultant. He works on designing and implementing scalable customer experience solutions. In his spare time, he can be found playing sports, snowboarding, or hiking in the mountains.

Anubhav Mishra is a Product Manager with AWS. He spends his time understanding customers and designing product experiences to address their business challenges.

Sravan Bodapati is an Applied Science Manager at AWS Lex. He focuses on building cutting edge Artificial Intelligence and Machine Learning solutions for AWS customers in ASR and NLP space. In his spare time, he enjoys hiking, learning economics, watching TV shows and spending time with his family.



Source

Continue Reading

Trending

Copyright © 2021 Today's Digital.