安装和运行文本分析容器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 Trial 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 并向其发送账单数据。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:

一个用于获取关联 API 密钥和终结点 URI 的 Azure 文本分析资源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.

终结点 URI {ENDPOINT_URI}Endpoint URI {ENDPOINT_URI}

在相应的认知服务资源的 Azure 门户“概览” 页上提供终结点 URI 值。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:

查询容器的预测终结点Query the container's prediction endpoint

容器提供了基于 REST 的查询预测终结点 API。The container provides REST-based query prediction endpoint APIs.

使用主机 http://localhost:5000,以获得容器 API。Use 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 地址和公开端口,并打开你常用的 Web 浏览器。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.

对该容器的查询在用于 <ApiKey> 的 Azure 资源的定价层计费。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.
必须将此选项的值设置为 Billing 中指定的已预配资源的 API 密钥。The 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.
此选项的值必须设置为 acceptThe 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 容器注册表 (MCR) 下载容器映像。Container images are downloaded from the Microsoft Container Registry (MCR) in Azure.
  • 容器映像在 Docker 中运行。Container images run in Docker.
  • 可以使用 REST API 或 SDK 通过指定容器的主机 URI 来调用文本分析容器中的操作。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