認識テキスト機能の使用

認識テキスト機能は、モデル・リポジトリおよびモデル・デプロイメントとともに、Oracle Machine Learning Servicesのコンポーネントです。

Oracle Machine Learning Servicesでは、REST APIを介して次の認識テキスト機能がサポートされます。
  • トピック検出またはトピック探知
  • キーワード識別
  • サマリー
  • センチメント分析
  • 類似度
  • 特徴抽出

認識テキストでサポートされている言語には、英語(アメリカ)、スペイン語、フランス語およびイタリア語があります。

Linuxユーティリティjqを使用して、JSON出力を読取り可能な形式に解析できます。jqユーティリティは、主要なLinux配布リポジトリのすべてに含まれています。Oracle LinuxおよびRed Hatシステムでは、次のコマンドを使用してインストールされます。
$ sudo yum install jq

ノート:

cURLコマンドでjqを使用しても、HTTPレスポンスは返されません。HTTPレスポンスを返すには、jqコマンドを削除し、curlコマンドに-iフラグを追加します。

1: モデル・エンドポイントのリストの取得

この例では、OML Servicesで提供されるすべての認識テキスト・エンドポイントを返す方法を示します。新しい認識テキスト・エンドポイントは作成できませんが、アクセス権に応じてエンドポイントを参照してスコアリングできます。

次のcURLコマンドを実行して、すべての認識テキスト・エンドポイントのリストを取得します。

curl -X GET --header "Authorization: Bearer ${token}" "<oml-cloud-service-location-url>/omlmod/v1/cognitive-text"

このコマンドは、次の詳細を返します。

{
  "items": [
    {
      "name": "topics",
      "description": "A cognitive text scoring endpoint that returns the most important topics in the provided text list.",
      "links": [
        {
          "rel": "topics",
          "href": "https://adb.us-sanjose-1.oraclecloud.com/omlmod/v1/cognitive-text/topics"
        },
        {
          "rel": "self",
          "href": "https://adb.us-sanjose-1.oraclecloud.com/omlmod/v1/cognitive-text/."
        }
      ]
    },
    {
      "name": "keywords",
      "description": "A cognitive text scoring endpoint that returns the most important keywords in the provided text list.",
      "links": [
        {
          "rel": "keywords",
          "href": "https://adb.us-sanjose-1.oraclecloud.com/omlmod/v1/cognitive-text/keywords"
        },
        {
          "rel": "self",
          "href": "https://adb.us-sanjose-1.oraclecloud.com/omlmod/v1/cognitive-text/."
        }
      ]
    },
    {
      "name": "summary",
      "description": "A cognitive text scoring endpoint that returns the summary of the provided text list.",
      "links": [
        {
          "rel": "summary",
          "href": "https://adb.us-sanjose-1.oraclecloud.com/omlmod/v1/cognitive-text/summary"
        },
        {
          "rel": "self",
          "href": "https://adb.us-sanjose-1.oraclecloud.com/omlmod/v1/cognitive-text/."
        }
      ]
    },
    {
      "name": "similarity",
      "description": "A cognitive text scoring endpoint that returns the similarity of the probe text and a list of texts.",
      "links": [
        {
          "rel": "similarity",
          "href": "https://adb.us-sanjose-1.oraclecloud.com/omlmod/v1/cognitive-text/similarity"
        },
        {
          "rel": "self",
          "href": "https://adb.us-sanjose-1.oraclecloud.com/omlmod/v1/cognitive-text/."
        }
      ]
    },
    {
      "name": "sentiment",
      "description": "A cognitive text scoring endpoint that returns the sentiment of the provided text list.",
      "links": [
        {
          "rel": "sentiment",
          "href": "https://adb.us-sanjose-1.oraclecloud.com/omlmod/v1/cognitive-text/sentiment"
        },
        {
          "rel": "self",
          "href": "https://adb.us-sanjose-1.oraclecloud.com/omlmod/v1/cognitive-text/."
        }
      ]
    },
    {
      "name": "features",
      "description": "A cognitive text scoring endpoint that returns the features of the provided text list.",
      "links": [
        {
          "rel": "features",
          "href": "https://adb.us-sanjose-1.oraclecloud.com/omlmod/v1/cognitive-text/features"
        },
        {
          "rel": "self",
          "href": "https://adb.us-sanjose-1.oraclecloud.com/omlmod/v1/cognitive-text/."
        }
      ]
    }
  ],
  "links": [
    {
      "rel": "self",
      "href": "https://adb.us-sanjose-1.oraclecloud.com/omlmod/v1/cognitive-text"
    }
  ]
}

2: 最も関連性の高いテキスト・キーワードを返す

この例では、テキスト文字列のリストに最も関連性の高いキーワードを返す方法を示します。

パラメータtopNを入力の一部として渡して、ドキュメント当たりの返すキーワード数を決定できます。デフォルトでは、5個のキーワードが返されます。言語パラメータを渡すこともできます。デフォルト値はAMERICANです。サポートされているその他の値は、FRENCHSPANISHおよびITALIANです。キーワードは重みでソートされます。

次のcURLコマンドを実行して、最も関連するキーワードを取得します。
curl -X POST "<oml-cloud-service-location-url>/omlmod/v1/cognitive-text/keywords" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${token}" \
--data '{
  "topN":2,
  "textList":["With Oracle Machine Learning, Oracle moves the algorithms to the data. Oracle runs machine learning within the database, where the data reside. This approach minimizes or eliminates data movement, achieves scalability, preserves data security, and accelerates time-to-model deployment. Oracle delivers parallelized in-database implementations of machine learning algorithms and integration with the leading open source environments R and Python. Oracle Machine Learning delivers the performance, scalability, and automation required by enterprise-scale data science projects ? both on-premises and in the Cloud."]
}' | jq
この例では、パラメータtopN2に設定されています。このコマンドは、次の2つのキーワードとそれぞれの重みを返します。
[
  {
    "text": "With Oracle Machine Learning, Oracle moves the algorithms to the data. Oracle runs machine learning within the database, where the data reside. This approach minimizes or eliminates data movement, achieves scalability, preserves data security, and accelerates time-to-model deployment. Oracle delivers parallelized in-database implementations of machine learning algorithms and integration with the leading open source environments R and Python. Oracle Machine Learning delivers the performance, scalability, and automation required by enterprise-scale data science projects ? both on-premises and in the Cloud.",
    "keywordResults": [
      {
        "keyword": "Oracle",
        "weight": 0.4857284784454714
      },
      {
        "keyword": "algorithms",
        "weight": 0.43990432999766216
      }
    ]
  }
]

3: テキスト・サマリーを返す

この例では、テキスト文字列のリストに対するサマリーを返す方法を示します。パラメータtopNを入力の一部として渡して、ドキュメント当たりの返す文の数を決定できます。デフォルトでは、topN3に設定されます。言語パラメータを渡すこともできます。デフォルト値はAMERICANです。言語パラメータにサポートされているその他の値は、FRENCHSPANISHITALIANです。

ノート:

サマリー内の文は、指定されたテキスト文字列内で出現する順に返されます。
次のcURLコマンドを実行して、指定された文字列のリストのサマリーを返します。
curl -X POST "<oml-cloud-service-location-url>/omlmod/v1/cognitive-text/summary" \
 --header 'Content-Type: application/json' \
 --header "Authorization: Bearer ${token}" \
 --data '{
  "topN":2,
   "textList":["With Oracle Machine Learning, Oracle moves the algorithms to the data. Oracle runs machine learning within the database, where the data reside. This approach minimizes or eliminates data movement, achieves scalability, preserves data security, and accelerates time-to-model deployment. Oracle delivers parallelized in-database implementations of machine learning algorithms and integration with the leading open source environments R and Python. Oracle Machine Learning delivers the performance, scalability, and automation required by enterprise-scale data science projects ? both on-premises and in the Cloud."]
 }' | jq
この例では、パラメータtopN2に設定されています。このコマンドは、次の2つのサマリー詳細とそれぞれの重みを返します。
[
  {
    "text": "With Oracle Machine Learning, Oracle moves the algorithms to the data. Oracle runs machine learning within the database, where the data reside. This approach minimizes or eliminates data movement, achieves scalability, preserves data security, and accelerates time-to-model deployment. Oracle delivers parallelized in-database implementations of machine learning algorithms and integration with the leading open source environments R and Python. Oracle Machine Learning delivers the performance, scalability, and automation required by enterprise-scale data science projects ? both on-premises and in the Cloud.",
    "summaryResults": [
      {
        "sentence": "Oracle delivers parallelized in-database implementations of machine learning algorithms and integration with the leading open source environments R and Python. ",
        "weight": 0.841429024903614
      },
      {
        "sentence": "Oracle Machine Learning delivers the performance, scalability, and automation required by enterprise-scale data science projects ? both on-premises and in the Cloud.",
        "weight": 0.7717966493441589
      }
    ]
  }
]

4: テキスト・センチメントを返す

この例では、指定されたテキスト文字列のリストに対するセンチメントを返す方法を示します。センチメントは、肯定、中立、否定の値の列挙型です。

次のcURLコマンドを実行して、指定されたテキスト文字列のセンチメントを返します。
curl -X POST "<oml-cloud-service-location-url>/omlmod/v1/cognitive-text/sentiment" \
 --header 'Content-Type: application/json' \
 --header "Authorization: Bearer ${token}" \
 --data '{
   "textList":["With Oracle Machine Learning, Oracle moves the algorithms to the data. Oracle runs machine learning within the database, where the data reside. This approach minimizes or eliminates data movement, achieves scalability, preserves data security, and accelerates time-to-model deployment. Oracle delivers parallelized in-database implementations of machine learning algorithms and integration with the leading open source environments R and Python. Oracle Machine Learning delivers the performance, scalability, and automation required by enterprise-scale data science projects ? both on-premises and in the Cloud."]
 }' | jq
このコマンドは、中立、否定および肯定的なセンチメントに対応する次の信頼度スコアを返します。
[
  {
    "text": "With Oracle Machine Learning, Oracle moves the algorithms to the data. Oracle runs machine learning within the database, where the data reside. This approach minimizes or eliminates data movement, achieves scalability, preserves data security, and accelerates time-to-model deployment. Oracle delivers parallelized in-database implementations of machine learning algorithms and integration with the leading open source environments R and Python. Oracle Machine Learning delivers the performance, scalability, and automation required by enterprise-scale data science projects ? both on-premises and in the Cloud.",
    "sentimentResults": [
      {
        "sentiment": "neutral",
        "confidence": 0.7768593976551998
      },
      {
        "sentiment": "negative",
        "confidence": 0.15795427860813646
      },
      {
        "sentiment": "positive",
        "confidence": 0.06518632373666372
      }
    ]
  }
]

5: 最も関連性の高いテキスト・トピックを返す

この例では、テキスト文字列のリストに最も関連性の高いトピックを返す方法を示します。パラメータtopNを入力の一部として渡して、返すトピック数を決定できます。デフォルトでは、2個のトピックが返されます。言語パラメータを渡すこともできます。デフォルト値はAMERICANです。サポートされているその他の値は、FRENCHSPANISHおよびITALIAN.ですトピックは重みでソートされます。

次のcURLコマンドを実行して、指定されたテキスト文字列のリストに最も関連するトピックを返します。
curl -X POST "<oml-cloud-service-location-url>/omlmod/v1/cognitive-text/topics" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${token}" \
--data '{
  "topN":5,
 "textList":["With Oracle Machine Learning, Oracle moves the algorithms to the data. Oracle runs machine learning within the database, where the data reside. This approach minimizes or eliminates data movement, achieves scalability, preserves data security, and accelerates time-to-model deployment. Oracle delivers parallelized in-database implementations of machine learning algorithms and integration with the leading open source environments R and Python. Oracle Machine Learning delivers the performance, scalability, and automation required by enterprise-scale data science projects ? both on-premises and in the Cloud."]
}' | jq
このコマンドは、次に示すように、次のトピックとそれぞれの重みを返します。
[
  {
    "text": "With Oracle Machine Learning, Oracle moves the algorithms to the data. Oracle runs machine learning within the database, where the data reside. This approach minimizes or eliminates data movement, achieves scalability, preserves data security, and accelerates time-to-model deployment. Oracle delivers parallelized in-database implementations of machine learning algorithms and integration with the leading open source environments R and Python. Oracle Machine Learning delivers the performance, scalability, and automation required by enterprise-scale data science projects ? both on-premises and in the Cloud.",
    "topicResults": [
      {
        "topic": "Oracle Database",
        "weight": 0.31551492019770755
      },
      {
        "topic": "Scalability",
        "weight": 0.2526506529399862
      },
      {
        "topic": "Oracle Corporation",
        "weight": 0.2375060259741595
      },
      {
        "topic": "Machine learning",
        "weight": 0.22823082222493368
      },
      {
        "topic": "Analysis of algorithms",
        "weight": 0.1507387699576783
      }
    ]
  }
]

6: テキスト類似度を返す

この例では、POSTリクエストを認識テキスト・エンドポイントに送信して、プローブ・テキストとテキスト文字列のリスト間の意味的類似度を返す方法を示します。昇順の場合はASC、降順の場合はDESCなど、ソート方向を渡すことができます。言語パラメータを渡すこともできます。デフォルト値はAMERICANです。サポートされているその他の値は、FRENCHSPANISHおよびITALIANです。

次のcURLコマンドを実行して、意味的類似度を返します。
curl -X POST "<oml-cloud-service-location-url>/omlmod/v1/cognitive-text/similarity" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${token}" \
--data '{
	"probe":"algorithms",
	"textList":["With Oracle Machine Learning, Oracle moves the algorithms to the data. Oracle runs machine learning within the database, where the data reside. This approach minimizes or eliminates data movement, achieves scalability, preserves data security, and accelerates time-to-model deployment. Oracle delivers parallelized in-database implementations of machine learning algorithms and integration with the leading open source environments R and Python. Oracle Machine Learning delivers the performance, scalability, and automation required by enterprise-scale data science projects ? both on-premises and in the Cloud."],
"sortDirection":"DESC"
}' | jq
このコマンドは、プローブとテキスト文字列間の意味的類似度について0.43990432999766216の値を返します。
[
  {
    "text": "With Oracle Machine Learning, Oracle moves the algorithms to the data. Oracle runs machine learning within the database, where the data reside. This approach minimizes or eliminates data movement, achieves scalability, preserves data security, and accelerates time-to-model deployment. Oracle delivers parallelized in-database implementations of machine learning algorithms and integration with the leading open source environments R and Python. Oracle Machine Learning delivers the performance, scalability, and automation required by enterprise-scale data science projects ? both on-premises and in the Cloud.",
    "similarity": 0.43990432999766216
  }
]

7: テキスト文字列の数値特徴を返す

features APIでは、ドキュメントを1024の浮動小数点数のベクトルとして表すことができます。特徴ベクトルは、テキスト処理で使用できます。たとえば、特徴ベクトルを使用して、ベクトル空間に基づく類似ドキュメントを検索できます。大きいテキスト・コレクションのテキスト処理を類似度の計算に使用されるベクトルのみで事前に実行できるため、コンピュート・リソースを節約できます。

この例では、テキスト文字列のリストに対する数値特徴を返す方法を示します。言語パラメータを渡すことができます。デフォルト値はAMERICANです。サポートされているその他の値は、FRENCHSPANISHおよびITALIANです。

次のcURLコマンドを実行して、指定されたテキスト文字列Oracle Machine Learningに対する数値特徴を返します。
curl -X POST "<oml-cloud-service-location-url>/omlmod/v1/cognitive-text/features" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${token}" \
--data '{
   "textList":["Oracle Machine Learning"]
}' | jq
このコマンドは、テキスト文字列のスコアリング結果を返します。
[
  {
    "text": "Oracle Machine Learning",
    "scoringResults": {
      "weights": [
        -0.01593325924999146,
        0.019103851234810277,
        0.0015129621606790617,
        -0.00757883632513583,
        -0.01606255829444141,
        -0.0184449494100069,
        -0.04012992671536982,
 ...
 ...
 ]
    }
  }
]

8: 認識テキスト・トピックの検出

次のcURLコマンドを実行して、認識テキスト・トピックを検出します:

curl -X POST "<oml-cloud-service-location-url>/omlmod/v1/cognitive-text/topics" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${token}" \
--data '{
  "topN":5,
  "textList":["With Oracle Machine Learning, Oracle moves the algorithms to the data. Oracle runs machine learning within the database, where the data reside. This approach minimizes or eliminates data movement, achieves scalability, preserves data security, and accelerates time-to-model deployment. Oracle delivers parallelized in-database implementations of machine learning algorithms and integration with the leading open source environments R and Python. Oracle Machine Learning delivers the performance, scalability, and automation required by enterprise-scale data science projects both on-premises and in the Cloud."]
}' | jq

この例では、パラメータtopNは5つのトピックを返します。

コマンドは次の出力を返します。

"topicResults": [
      {
        "topic": "Oracle Corporation",
        "weight": 0.19987709210173316
      },
      {
        "topic": "Machine learning",
        "weight": 0.1905437857032045
      },
      {
        "topic": "Scalability",
        "weight": 0.1796066801401289
      },
      {
        "topic": "Data mining",
        "weight": 0.1452028606883496
      },
      {
        "topic": "Analysis of algorithms",
        "weight": 0.13456003371071854
      }
    ]
  }
]

9: 認識テキスト・キーワードの識別

次のcURLコマンドを実行して、認識テキスト・キーワードを識別します:
curl -X POST "<oml-cloud-service-location-url>/omlmod/v1/cognitive-text/keywords" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${token}" \
--data '{
  "topN":2,
  "textList":["With Oracle Machine Learning, Oracle moves the algorithms to the data. Oracle runs machine learning within the database, where the data reside. This approach minimizes or eliminates data movement, achieves scalability, preserves data security, and accelerates time-to-model deployment. Oracle delivers parallelized in-database implementations of machine learning algorithms and integration with the leading open source environments R and Python. Oracle Machine Learning delivers the performance, scalability, and automation required by enterprise-scale data science projects both on-premises and in the Cloud."]
}' | jq

この例では、パラメータtopNは2つのキーワードを返します。出力:

"keywordResults": [
      {
        "keyword": "data",
        "weight": 0.5521764418721277
      },
      {
        "keyword": "algorithms",
        "weight": 0.46610186622828115
      }
    ]
  }
]

10: 認知テキスト・センチメント分析

次のcURLコマンドを実行して、認識テキスト・センチメント分析を実行します:

curl -X POST --header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${token}" \
<oml-cloud-service-location-url>/omlmod/v1/cognitive-text/sentiment \
 -d '{"textList":["With Oracle Machine Learning, Oracle moves the algorithms to the data, processing data where it resides minimizing or eliminating data movement, achieving scalability, preserving security, and accelerating time-to-model deployment."]}' | jq

コマンドは次の出力を返します。

[ { "text": "With Oracle Machine Learning, Oracle moves the algorithms to the data, processing data where it resides minimizing or eliminating data movement, achieving scalability, preserving security, and accelerating time-to-model deployment.", "sentimentResults": [ { "sentiment": "neutral", "confidence": 0.8003081130871371 }, { "sentiment": "negative", "confidence": 0.12303965647159439 }, { "sentiment": "positive", "confidence": 0.07665223044126848 } ] } ]