Analyze text content with Docker container (preview)
The analyze text container scans text generated by foundation models or people for sexual content, violence, hate, and self-harm with multi-severity levels. This guide shows you how to download, install, and run a content safety analyze text container.
For more information about prerequisites, validating that a container is running, running multiple containers on the same host, and running disconnected containers, see Install and run content safety containers with Docker.
Specify a container image
The content safety analyze text container image for all supported versions can be found on the Microsoft Container Registry (MCR) syndicate. It resides within the azure-cognitive-services/contentsafety
repository and is named text-analyze
.
The fully qualified container image name is, mcr.microsoft.com/azure-cognitive-services/contentsafety/text-analyze
. Append a specific container version, or append :latest
to get the most recent version. For example:
Version | Path |
---|---|
Latest | mcr.microsoft.com/azure-cognitive-services/contentsafety/text-analyze:latest The latest tag pulls the latest image. |
1.0.0-amd64-preview | mcr.microsoft.com/azure-cognitive-services/contentsafety/text-analyze:1.0.0-amd64-preview |
Get the container image
Make sure you meet the prerequisites including required hardware. Also see the recommended allocation of resources section for each content safety container.
Use the docker pull command to download a container image from Microsoft Container Registry:
docker pull mcr.microsoft.com/azure-cognitive-services/contentsafety/text-analyze:latest
Run the container
Use the docker run command to run the container.
The following table represents the various docker run
parameters and their corresponding descriptions:
Parameter | Description |
---|---|
{ENDPOINT_URI} |
The endpoint is required for metering and billing. For more information, see billing arguments. |
{API_KEY} |
The API key is required. For more information, see billing arguments. |
When you run the content safety analyze text container, configure the port, GPU according to the content safety container requirements and recommendations.
Here's a sample docker run
command with placeholder values. You must specify the ENDPOINT_URI
and API_KEY
values:
docker run --rm -it -p 5000:5000 --gpus all \
mcr.microsoft.com/azure-cognitive-services/contentsafety/text-analyze:latest \
Eula=accept \
Billing={ENDPOINT_URI} \
ApiKey={API_KEY}
This command:
- Runs a
content safety
container from the container image. - Uses all available GPU resources (by specifying
--gpus all
). Content safety container requires CUDA for optimal performance. See more in host requirements and recommendations. Also make sure your host install NVIDIA container toolkit - Exposes 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.
If you're testing the container on a machine without CUDA, the container exits when trying to use CUDA. Use below command to disable CUDA to continue the testing.
docker run -e CUDA_ENABLED=false
Run the container with blocklist
The analyze text container supports the use of a blocklist feature, which allows you to block custom terms. You, as the customer, have the ability to manage these blocklists by using CSV files. You have the flexibility to use multiple CSV files for multiple blocklists.
To run the container with a blocklist, use the following command:
docker run -e BLOCKLIST_DIR=/tmp/blocklist -v {/path/on/host}:/tmp/blocklist
In the command above, replace {/path/on/host}
with the path to the blocklist folder on your host machine. This command mounts the blocklist directory from your host machine to the BLOCKLIST_DIR=/tmp/blocklist
environment variable within the container.
Note, the analyze text container uses an exact match method for the blocklist. All items in the blocklist will be converted to lowercase before the matching process. This means, for instance, if you have Contoso
in your blocklist, both "Contoso" and "contoso" from your input are considered a match.
Test the container
Once the container is up and running, you can validate its operation by sending a request to the REST endpoint deployed within the container. To do this, follow the steps in the quickstart. Note, you need to replace the endpoint URL with the Docker URL specific to your container deployment. Also, ensure that you're using host authentication, rather than key-based authentication.
Next steps
- See the content safety containers overview
- Use more Azure AI containers