Detect Key Phrases Using Amazon Comprehend Service

The Amazon Comprehend Service - a natural language processing service - can be used to detect the important key phrases used within a document. Currently it can detect key phrases from Enlish and Spanish languages.

The key phrase detection could be important to discover key phrases from a document and to for example to build automatic tags for a document.

The detect phrases function can be easily used from within a lambda function. Below is an example of its use using NodeJS.

        var AWS = require('aws-sdk');
        var comprehend = new AWS.Comprehend({apiVersion: '2017-11-27'});
        exports.handler = (event, context, callback) => {
            var params = {
                LanguageCode: 'en', /* required */
                Text: event.text /* required */
            comprehend.detectKeyPhrases(params, function(err, data) {
                if (err) console.log(err, err.stack); // an error occurred
                else     console.log(data);           // successful response

Below is a sample output from the above function.

            { Score: 0.9355272650718689,
                Text: 'only a few disparate tools and services',
                BeginOffset: 247,
                EndOffset: 286 },
            { Score: 0.8913902044296265,
                Text: 'late 2003',
                BeginOffset: 296,
                EndOffset: 305 },
            { Score: 0.9996188282966614,
                Text: 'the AWS concept',
                BeginOffset: 307,
                EndOffset: 322 } ...

Note that phrase, a score showing the confidence level and the position on where the text occurs is displayed.