Keywords

At a glance

The keywords model ranks noun phrases extracted from an input document, based on how relevant they are within the document. For example, in the text:

Anna went to school at University of California Santa Cruz.
Anna joined the university in 2015.

a Keywords model may decide that the noun phrases Anna and University of California Santa Cruz are more relevant than school and university.

Class definition
watson_nlp.workflows.keywords.text_rank.TextRank

For language support, see Supported languages.

Pretrained models

Model names are listed below.

Model ID Container Image
keywords_text-rank-workflow_lang_ar_stock cp.icr.io/cp/ai/watson-nlp_keywords_text-rank-workflow_lang_ar_stock:1.4.1
keywords_text-rank-workflow_lang_cs_stock cp.icr.io/cp/ai/watson-nlp_keywords_text-rank-workflow_lang_cs_stock:1.4.1
keywords_text-rank-workflow_lang_da_stock cp.icr.io/cp/ai/watson-nlp_keywords_text-rank-workflow_lang_da_stock:1.4.1
keywords_text-rank-workflow_lang_de_stock cp.icr.io/cp/ai/watson-nlp_keywords_text-rank-workflow_lang_de_stock:1.4.1
keywords_text-rank-workflow_lang_en_stock cp.icr.io/cp/ai/watson-nlp_keywords_text-rank-workflow_lang_en_stock:1.4.1
keywords_text-rank-workflow_lang_es_stock cp.icr.io/cp/ai/watson-nlp_keywords_text-rank-workflow_lang_es_stock:1.4.1
keywords_text-rank-workflow_lang_fi_stock cp.icr.io/cp/ai/watson-nlp_keywords_text-rank-workflow_lang_fi_stock:1.4.1
keywords_text-rank-workflow_lang_fr_stock cp.icr.io/cp/ai/watson-nlp_keywords_text-rank-workflow_lang_fr_stock:1.4.1
keywords_text-rank-workflow_lang_he_stock cp.icr.io/cp/ai/watson-nlp_keywords_text-rank-workflow_lang_he_stock:1.4.1
keywords_text-rank-workflow_lang_hi_stock cp.icr.io/cp/ai/watson-nlp_keywords_text-rank-workflow_lang_hi_stock:1.4.1
keywords_text-rank-workflow_lang_it_stock cp.icr.io/cp/ai/watson-nlp_keywords_text-rank-workflow_lang_it_stock:1.4.1
keywords_text-rank-workflow_lang_ja_stock cp.icr.io/cp/ai/watson-nlp_keywords_text-rank-workflow_lang_ja_stock:1.4.1
keywords_text-rank-workflow_lang_ko_stock cp.icr.io/cp/ai/watson-nlp_keywords_text-rank-workflow_lang_ko_stock:1.4.1
keywords_text-rank-workflow_lang_nb_stock cp.icr.io/cp/ai/watson-nlp_keywords_text-rank-workflow_lang_nb_stock:1.4.1
keywords_text-rank-workflow_lang_nl_stock cp.icr.io/cp/ai/watson-nlp_keywords_text-rank-workflow_lang_nl_stock:1.4.1
keywords_text-rank-workflow_lang_nn_stock cp.icr.io/cp/ai/watson-nlp_keywords_text-rank-workflow_lang_nn_stock:1.4.1
keywords_text-rank-workflow_lang_pl_stock cp.icr.io/cp/ai/watson-nlp_keywords_text-rank-workflow_lang_pl_stock:1.4.1
keywords_text-rank-workflow_lang_pt_stock cp.icr.io/cp/ai/watson-nlp_keywords_text-rank-workflow_lang_pt_stock:1.4.1
keywords_text-rank-workflow_lang_ro_stock cp.icr.io/cp/ai/watson-nlp_keywords_text-rank-workflow_lang_ro_stock:1.4.1
keywords_text-rank-workflow_lang_ru_stock cp.icr.io/cp/ai/watson-nlp_keywords_text-rank-workflow_lang_ru_stock:1.4.1
keywords_text-rank-workflow_lang_sk_stock cp.icr.io/cp/ai/watson-nlp_keywords_text-rank-workflow_lang_sk_stock:1.4.1
keywords_text-rank-workflow_lang_sv_stock cp.icr.io/cp/ai/watson-nlp_keywords_text-rank-workflow_lang_sv_stock:1.4.1
keywords_text-rank-workflow_lang_tr_stock cp.icr.io/cp/ai/watson-nlp_keywords_text-rank-workflow_lang_tr_stock:1.4.1
keywords_text-rank-workflow_lang_zh-cn_stock cp.icr.io/cp/ai/watson-nlp_keywords_text-rank-workflow_lang_zh-cn_stock:1.4.1

Running models

The Keywords model request accepts the following fields:

Field Type Required
Optional
Repeated
Description
raw_document watson_core_data_model.nlp.RawDocument required The input document on which to perform Keywords predictions
limit int32 optional The maximum number of predicted keywords. If not specified then the limit on the number of predicted keywords defaults to None

Example requests

REST API

curl -s \
  "http://localhost:8080/v1/watson.runtime.nlp.v1/NlpService/KeywordsPredict" \
  -H "accept: application/json" \
  -H "content-type: application/json" \
  -H "Grpc-Metadata-mm-model-id: keywords_text-rank-workflow_lang_en_stock" \
  -d '{ "raw_document": { "text": "Anna went to school at University of California Santa Cruz. Anna joined the university in 2015." }, "limit": 2 }'

Response

{"keywords":[
    {"text":"University of California Santa Cruz","relevance":0.912354,"mentions":[
        {"begin":23,"end":58,"text":"University of California Santa Cruz"}],"count":1},
    {"text":"Anna","relevance":0.88892,"mentions":[
        {"begin":0,"end":4,"text":"Anna"},{"begin":60,"end":64,"text":"Anna"}],"count":2}],
  "producerId":{"name":"Keywords Text Rank Workflow","version":"0.0.1"}}

Python

import grpc

from watson_nlp_runtime_client import (
    common_service_pb2,
    common_service_pb2_grpc,
    syntax_types_pb2,
)

channel = grpc.insecure_channel("localhost:8085")

stub = common_service_pb2_grpc.NlpServiceStub(channel)

request = common_service_pb2.KeywordsRequest(
    raw_document=syntax_types_pb2.RawDocument(text="Anna went to school at University of California Santa Cruz. Anna joined the university in 2015."),
    limit=2
)

  response = stub.KeywordsPredict(
    request, metadata=[("mm-model-id", "keywords_text-rank-workflow_lang_en_stock")]
)

print(response)

Response

keywords {
  text: "University of California Santa Cruz"
  relevance: 0.912354
  mentions {
    begin: 23
    end: 58
    text: "University of California Santa Cruz"
  }
  count: 1
}
keywords {
  text: "Anna"
  relevance: 0.88892
  mentions {
    end: 4
    text: "Anna"
  }
  mentions {
    begin: 60
    end: 64
    text: "Anna"
  }
  count: 2
}
producer_id {
  name: "Keywords Text Rank Workflow"
  version: "0.0.1"
}