安裝並執行文字分析容器Install and run Text Analytics containers

容器可讓您在自己的環境中執行文字分析 Api,而且非常適合您的特定安全性和資料控管需求。Containers enable you to run the Text Analytic APIs in your own environment and are great for your specific security and data governance requirements. 文字分析容器提供原始文字的先進自然語言處理,並包含三個主要功能:情感分析、關鍵字組解壓縮和語言偵測。The Text Analytics containers provide advanced natural language processing over raw text, and include three main functions: sentiment analysis, key phrase extraction, and language detection. 容器目前不支援實體連結。Entity linking is not currently supported in a container.

如果您沒有 Azure 訂用帳戶,請在開始前建立 免費帳戶If you don't have an Azure subscription, create a free account before you begin.

必要條件Prerequisites

若要執行任何文字分析的容器,您必須擁有主機電腦和容器環境。To run any of the Text Analytics containers, you must have the host computer and container environments.

準備工作Preparation

使用文字分析容器之前,您必須符合下列必要條件:You must meet the following prerequisites before using Text Analytics containers:

必要項Required 用途Purpose
Docker 引擎Docker Engine 您必須在主機電腦上安裝 Docker 引擎。You need the Docker Engine installed on a host computer. Docker 提供可在 macOSWindowsLinux 上設定 Docker 環境的套件。Docker provides packages that configure the Docker environment on macOS, Windows, and Linux. 如需 Docker 和容器基本概念的入門,請參閱 Docker 概觀 (英文)。For a primer on Docker and container basics, see the Docker overview.

Docker 必須設定為允許容器與 Azure 連線,以及傳送帳單資料至 Azure。Docker must be configured to allow the containers to connect with and send billing data to Azure.

在 Windows 上,也必須將 Docker 設定為支援 Linux 容器。On Windows, Docker must also be configured to support Linux containers.

熟悉 DockerFamiliarity with Docker 您應具備對 Docker 概念 (例如登錄、存放庫、容器和容器映像等) 的基本了解,以及基本 docker 命令的知識。You should have a basic understanding of Docker concepts, like registries, repositories, containers, and container images, as well as knowledge of basic docker commands.
文字分析資源Text Analytics resource 若要使用此容器,您必須具備:In order to use the container, you must have:

Azure文字分析資源,用來取得相關聯的 API 金鑰和端點 URI。An Azure Text Analytics resource to get the associated API key and endpoint URI. 這兩個值可在 Azure 入口網站的 [文字分析概觀和金鑰] 頁面上取得,需要這些值才能啟動容器。Both values are available on the Azure portal's Text Analytics Overview and Keys pages and are required to start the container.

{API_KEY} :[金鑰] 頁面上有兩個可用的資源金鑰之一{API_KEY}: One of the two available resource keys on the Keys page

{ENDPOINT_URI} :[總覽] 頁面上所提供的端點{ENDPOINT_URI}: The endpoint as provided on the Overview page

正在搜集必要的參數Gathering required parameters

所有必要的認知服務容器都有三個主要參數。There are three primary parameters for all Cognitive Services' containers that are required. 使用者授權合約(EULA)必須存在,且值為acceptThe end-user license agreement (EULA) must be present with a value of accept. 此外,也需要端點 URL 和 API 金鑰。Additionally, both an Endpoint URL and API Key are needed.

注意

這三個必要參數唯一的例外是當容器被視為「離線」容器時。The only exception to these three required parameters is when containers are considered "Offline" containers. 離線容器不會報告使用量、不會計量,而且遵循不同的計費方法。Offline containers do not report usage, are not metered and follow a different billing methodology.

端點 URI{ENDPOINT_URI}Endpoint URI {ENDPOINT_URI}

[端點URI] 值可在對應認知服務資源的 [Azure 入口網站總覽] 頁面上取得。The Endpoint URI value is available on the Azure portal Overview page of the corresponding Cognitive Service resource. 流覽至 [總覽] 頁面,將滑鼠停留在端點上Copy to clipboard圖示就會出現。Navigate to the Overview page, hover over the Endpoint, and a Copy to clipboard icon will appear. 視需要複製並使用。Copy and use where needed.

收集端點 uri 以供稍後使用

快速鍵{API_KEY}Keys {API_KEY}

此金鑰用來啟動容器,並可在對應認知服務資源的 Azure 入口網站的 [金鑰] 頁面上取得。This key is used to start the container, and is available on the Azure portal's Keys page of the corresponding Cognitive Service resource. 流覽至 [金鑰] 頁面,然後按一下Copy to clipboard 圖示。Navigate to the Keys page, and click on the Copy to clipboard icon.

取得兩個金鑰的其中一個供稍後使用

重要

這些訂用帳戶金鑰可用來存取您的認知服務 API。These subscription keys are used to access your Cognitive Service API. 請勿共用您的金鑰。Do not share your keys. 以安全的方式儲存它們,例如使用 Azure Key Vault。Store them securely, for example, using Azure Key Vault. 我們也建議您定期重新產生這些金鑰。We also recommend regenerating these keys regularly. 進行 API 呼叫時,只需要一個金鑰。Only one key is necessary to make an API call. 重新產生第一個金鑰時,您可以使用第二個金鑰繼續存取服務。When regenerating the first key, you can use the second key for continued access to the service.

主機電腦The host computer

主機是可執行 Docker 容器的 x64 型電腦。The host is a x64-based computer that runs the Docker container. 它可以是您內部部署的電腦,或是在 Azure 中裝載服務的 Docker,例如:It can be a computer on your premises or a Docker hosting service in Azure, such as:

容器的需求和建議Container requirements and recommendations

下表說明針對每個文字分析容器配置的最低和建議 CPU 核心 (至少 2.6 GHz 或更快的版本) 與記憶體 (以 GB 為單位)。The following table describes the minimum and recommended CPU cores, at least 2.6 gigahertz (GHz) or faster, and memory, in gigabytes (GB), to allocate for each Text Analytics container.

容器Container 最小值Minimum 建議Recommended TPSTPS
(最小值, 最大值)(Minimum, Maximum)
關鍵片語擷取Key Phrase Extraction 1核心, 2 GB 記憶體1 core, 2-GB memory 1核心, 4 GB 記憶體1 core, 4-GB memory 15、3015, 30
  • 每個核心必須至少 2.6 GHz 或更快。Each core must be at least 2.6 gigahertz (GHz) or faster.
  • TPS - 每秒的交易數TPS - transactions per second

核心和記憶體會對應至 --cpus--memory 設定,用來作為 docker run 命令的一部分。Core and memory correspond to the --cpus and --memory settings, which are used as part of the docker run command.

使用 docker pull 取得容器映像Get the container image with docker pull

您可以在 Microsoft Container Registry 上取得文字分析的容器映射。Container images for Text Analytics are available on the Microsoft Container Registry.

容器Container 存放庫Repository
關鍵片語擷取Key Phrase Extraction mcr.microsoft.com/azure-cognitive-services/keyphrase

提示

您可以使用 docker images (英文) 命令來列出已下載的容器映像。You can use the docker images command to list your downloaded container images. 例如,下列命令會列出每個已下載之容器映像的識別碼、存放庫和標籤,並將它格式化為表格:For example, the following command lists the ID, repository, and tag of each downloaded container image, formatted as a table:

docker images --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}"

IMAGE ID         REPOSITORY                TAG
<image-id>       <repository-path/name>    <tag-name>

文字分析容器的 Docker pullDocker pull for the Text Analytics containers

關鍵片語擷取容器的 Docker pullDocker pull for the Key Phrase Extraction container

docker pull使用命令從 Microsoft container Registry 下載容器映射。Use the docker pull command to download a container image from Microsoft Container Registry.

如需文字分析容器可用標記的完整描述,請參閱 Docker Hub 上的關鍵片語擷取容器。For a full description of available tags for the Text Analytics containers, see the Key Phrase Extraction container on the Docker Hub.

docker pull mcr.microsoft.com/azure-cognitive-services/keyphrase:latest

如何使用容器How to use the container

容器位於主機電腦上時,請透過下列程序來使用容器。Once the container is on the host computer, use the following process to work with the container.

  1. 使用所需的計費設定執行容器Run the container, with the required billing settings. docker run 命令有相關範例可供參考。More examples of the docker run command are available.
  2. 查詢容器的預測端點Query the container's prediction endpoint.

透過 docker run 執行容器Run the container with docker run

使用 docker run 命令來執行三個容器的其中一個。Use the docker run command to run any of the three containers. 如需如何取得{ENDPOINT_URI}{API_KEY}值的詳細資訊,請參閱收集必要的參數Refer to Gathering required parameters for details on how to get the {ENDPOINT_URI} and {API_KEY} values.

命令的範例可供使用。docker runExamples of the docker run command are available.

若要執行關鍵片語擷取容器,請執行下列docker run命令。To run the Key Phrase Extraction container, execute the following docker run command.

docker run --rm -it -p 5000:5000 --memory 4g --cpus 1 \
mcr.microsoft.com/azure-cognitive-services/keyphrase \
Eula=accept \
Billing={ENDPOINT_URI} \
ApiKey={API_KEY}

此命令:This command:

  • 從容器映射執行關鍵片語擷取容器Runs a Key Phrase Extraction container from the container image
  • 配置一個 CPU 核心和 4 GB 的記憶體Allocates one CPU core and 4 gigabytes (GB) of memory
  • 公開 TCP 連接埠 5000,並為容器配置虛擬 TTYExposes TCP port 5000 and allocates a pseudo-TTY for the container
  • 在容器結束之後自動將其移除。Automatically removes the container after it exits. 容器映像仍可在主機電腦上使用。The container image is still available on the host computer.

重要

必須指定 EulaBillingApiKey 選項以執行容器,否則容器將不會啟動。The Eula, Billing, and ApiKey options must be specified to run the container; otherwise, the container won't start. 如需詳細資訊,請參閱帳單For more information, see Billing.

在相同主機上執行多個容器Run multiple containers on the same host

如果您打算使用公開的連接埠執行多個容器,請務必使用不同的公開連接埠來執行每個容器。If you intend to run multiple containers with exposed ports, make sure to run each container with a different exposed port. 例如,在連接埠 5000 上執行第一個容器,以及在連接埠 5001 上執行第二個容器。For example, run the first container on port 5000 and the second container on port 5001.

您可以讓此容器和不同的 Azure 認知服務容器在主機上一起執行。You can have this container and a different Azure Cognitive Services container running on the HOST together. 您也可以針對相同的認知服務容器執行多個容器。You also can have multiple containers of the same Cognitive Services container running.

查詢容器的預測端點Query the container's prediction endpoint

容器會提供以 REST 為基礎的查詢預測端點 API。The container provides REST-based query prediction endpoint APIs.

針對容器 API 請使用主機 http://localhost:5000Use the host, http://localhost:5000, for container APIs.

驗證容器正在執行Validate that a container is running

有數種方式可驗證容器正在執行。There are several ways to validate that the container is running. 找出有問題之容器的外部 IP位址和公開端口, 然後開啟您最愛的網頁瀏覽器。Locate the External IP address and exposed port of the container in question, and open your favorite web browser. 使用下列各種要求 Url 來驗證容器是否正在執行。Use the various request URLs below to validate the container is running. 下面所列的範例要求 url http://localhost:5000是, 但您的特定容器可能會有所不同。The example request URLs listed below are http://localhost:5000, but your specific container may vary. 請記住, 您會依賴容器的外部 IP位址和公開的埠。Keep in mind that you're to rely on your container's External IP address and exposed port.

要求 URLRequest URL 用途Purpose
http://localhost:5000/ 容器會提供首頁。The container provides a home page.
http://localhost:5000/status 使用 HTTP GET 要求, 以驗證容器是否正在執行, 而不會造成端點查詢。Requested with an HTTP GET, to validate that the container is running without causing an endpoint query. 此要求可用來進行 Kubernetes 活躍度和整備度探查 (英文)。This request can be used for Kubernetes liveness and readiness probes.
http://localhost:5000/swagger 容器會為端點提供一組完整的檔, 並使用 [試用] 功能。The container provides a full set of documentation for the endpoints and a Try it out feature. 使用此功能,您可以將自己的設定輸入至以 Web 為基礎的 HTML 表單並進行查詢,而無須撰寫任何程式碼。With this feature, you can enter your settings into a web-based HTML form and make the query without having to write any code. 當查詢傳回時,會提供範例 CURL 命令來示範所需的 HTTP 標頭和本文格式。After the query returns, an example CURL command is provided to demonstrate the HTTP headers and body format that's required.

容器的首頁

停止容器Stop the container

若要關閉的容器,容器執行所在的命令列環境中選取Ctrl + CTo shut down the container, in the command-line environment where the container is running, select Ctrl+C.

疑難排解Troubleshooting

如果您在啟用輸出掛接和記錄的情況下執行容器,容器將會產生記錄檔,有助於排解在啟動或執行容器時所發生的問題。If you run the container with an output mount and logging enabled, the container generates log files that are helpful to troubleshoot issues that happen while starting or running the container.

帳務Billing

文字分析容器會使用您 Azure 帳戶上的_文字分析_資源傳送計費資訊至 Azure。The Text Analytics containers send billing information to Azure, using a Text Analytics resource on your Azure account.

至容器的查詢會使用於 Azure 資源的定價層計費<ApiKey>Queries to the container are billed at the pricing tier of the Azure resource that's used for the <ApiKey>.

Azure 認知服務容器在未連線至計費端點以進行計量的情況下,將無法被授權以執行。Azure Cognitive Services containers aren't licensed to run without being connected to the billing endpoint for metering. 您必須讓容器隨時都能與計量端點進行帳單資訊的通訊。You must enable the containers to communicate billing information with the billing endpoint at all times. 認知服務容器不會將客戶資料 (例如正在分析的影像或文字) 傳送至 Microsoft。Cognitive Services containers don't send customer data, such as the image or text that's being analyzed, to Microsoft.

連接到 AzureConnect to Azure

容器需要計費引數值才能執行。The container needs the billing argument values to run. 這些值讓容器能夠連線到計費端點。These values allow the container to connect to the billing endpoint. 容器會每隔 10 到 15 分鐘回報使用量。The container reports usage about every 10 to 15 minutes. 如果容器未在允許的時間範圍內連線到 Azure,容器會繼續執行,但在還原計費端點之前不會提供查詢。If the container doesn't connect to Azure within the allowed time window, the container continues to run but doesn't serve queries until the billing endpoint is restored. 以 10 到 15 分鐘的相同時間間隔嘗試連線 10 次。The connection is attempted 10 times at the same time interval of 10 to 15 minutes. 如果無法在 10 次嘗試內連線到計費端點,則容器會停止執行。If it can't connect to the billing endpoint within the 10 tries, the container stops running.

計費引數Billing arguments

針對docker run命令來啟動容器時,必須指定下列選項中的所有三個有效的值:For the docker run command to start the container, all three of the following options must be specified with valid values:

選項Option 說明Description
ApiKey 用來追蹤帳單資訊的認知服務資源的 API 金鑰。The API key of the Cognitive Services resource that's used to track billing information.
此選項的值必須設定為 佈建的資源中指定的 API 金鑰BillingThe value of this option must be set to an API key for the provisioned resource that's specified in Billing.
Billing 用來追蹤帳單資訊的認知服務資源端點。The endpoint of the Cognitive Services resource that's used to track billing information.
此選項的值必須設定為已佈建 Azure 資源的端點 URI。The value of this option must be set to the endpoint URI of a provisioned Azure resource.
Eula 表示您接受容器的授權。Indicates that you accepted the license for the container.
此選項的值必須設定為接受The value of this option must be set to accept.

如需這些選項的詳細資訊,請參閱設定容器For more information about these options, see Configure containers.

部落格文章Blog posts

開發人員範例Developer samples

開發人員範例可從我們的 GitHub 存放庫取得。Developer samples are available at our GitHub repository.

檢視網路研討會View webinar

加入網路研討會以了解:Join the webinar to learn about:

  • 如何將認知服務部署到任何使用 Docker 的機器How to deploy Cognitive Services to any machine using Docker
  • 如何將認知服務部署到 AKSHow to deploy Cognitive Services to AKS

總結Summary

在本文中,您已了解下載、安裝及執行文字分析容器的概念和工作流程。In this article, you learned concepts and workflow for downloading, installing, and running Text Analytics containers. 摘要說明:In summary:

  • 文字分析提供三個適用于 Docker 的 Linux 容器,封裝各種功能:Text Analytics provides three Linux containers for Docker, encapsulating various capabilities:
    • 關鍵片語擷取Key Phrase Extraction
    • 語言偵測Language Detection
    • 情感分析Sentiment Analysis
  • 容器映像可從 Azure 中的 Microsoft Container Registry (MCR) 下載取得。Container images are downloaded from the Microsoft Container Registry (MCR) in Azure.
  • 容器映像是在 Docker 中執行。Container images run in Docker.
  • 您可以指定容器的主機 URI,來使用 REST API 或 SDK 呼叫文字分析容器中的作業。You can use either the REST API or SDK to call operations in Text Analytics containers by specifying the host URI of the container.
  • 將容器具現化時,您必須指定帳單資訊。You must specify billing information when instantiating a container.

重要

認知服務容器在未連線至 Azure 以進行計量的情況下,將無法被授權以執行。Cognitive Services containers are not licensed to run without being connected to Azure for metering. 客戶必須啟用容器以持續與計量服務進行帳單資訊的通訊。Customers need to enable the containers to communicate billing information with the metering service at all times. 認知服務容器不會將客戶資料 (例如正在分析的影像或文字) 傳送至 Microsoft。Cognitive Services containers do not send customer data (e.g., the image or text that is being analyzed) to Microsoft.

後續步驟Next steps