กิจกรรม
17 มี.ค. 21 - 21 มี.ค. 10
แอปอัจฉริยะ เข้าร่วมชุด meetup เพื่อสร้างโซลูชัน AI ที่ปรับขนาดได้ตามกรณีการใช้งานจริงกับนักพัฒนาและผู้เชี่ยวชาญร่วมกัน
ลงทะเบียนตอนนี้เบราว์เซอร์นี้ไม่ได้รับการสนับสนุนอีกต่อไป
อัปเกรดเป็น Microsoft Edge เพื่อใช้ประโยชน์จากคุณลักษณะล่าสุด เช่น การอัปเดตความปลอดภัยและการสนับสนุนด้านเทคนิค
Follow this guide to use Azure AI Content Safety Custom categories (standard) REST API to create your own content categories for your use case and train Azure AI Content Safety to detect them in new text content.
For more information on Custom categories, see the Custom categories concept page. For API input limits, see the Input requirements section of the Overview.
ข้อสำคัญ
This feature is only available in certain Azure regions. See Region availability.
ข้อสำคัญ
Allow enough time for model training
The end-to-end execution of custom category training can take from around five hours to ten hours. Plan your moderation pipeline accordingly.
To train a custom category, you need example text data that represents the category you want to detect. In this guide, you can use sample data. The provided annotation file contains text prompts about survival advice in camping/wilderness situations. The trained model will learn to detect this type of content in new text data.
เคล็ดลับ
For tips on creating your own data set, see the How-to guide.
ข้อสำคัญ
The user's storage account is set up as a hierarchical namespace account, which cannot be supported by Custom Categories. Please try using a regular storage account instead. For example, your blob URL cannot be split into two layers, such as example/example1/, and should only have one layer. For more details, refer to the documentation: Azure Data Lake Storage hierarchical namespace - Azure Storage.
Next, you need to give your Content Safety resource access to read from the Azure Storage resource. Enable system-assigned Managed identity for the Azure AI Content Safety instance and assign the role of Storage Blob Data Contributor/Owner to the identity:
ข้อสำคัญ
Only Storage Blob Data Contributor or Storage Blob Data Owner are valid roles to proceed.
Enable managed identity for the Azure AI Content Safety instance.
Assign the role of Storage Blob Data Contributor/Owner to the Managed identity. Any roles highlighted below should work.
In the command below, replace <your_api_key>
, <your_endpoint>
, and other necessary parameters with your own values. Then enter each command in a terminal window and run it.
curl -X PUT "<your_endpoint>/contentsafety/text/categories/<your_category_name>?api-version=2024-09-15-preview" \
-H "Ocp-Apim-Subscription-Key: <your_api_key>" \
-H "Content-Type: application/json" \
-d "{
\"categoryName\": \"survival-advice\",
\"definition\": \"text prompts about survival advice in camping/wilderness situations\",
\"sampleBlobUrl\": \"https://<your-azure-storage-url>/example-container/survival-advice.jsonl\"
}"
เคล็ดลับ
Every time you change your category name, definition or samples,a new version will be created. You can use the version number to trace back to previous versions. Please remember this version number, as it will be required in the URL for the next step- training custom categories.
Field | Description | Example Value |
---|---|---|
categoryName |
The name of the category or topic the request relates to. | survival-advice |
definition |
A brief description of the content type for the category. | text prompts about survival advice in camping/wilderness situations |
sampleBlobUrl |
URL to access a sample JSONL file containing data examples for the category. | Link |
Field | Description | Example Value |
---|---|---|
categoryName |
The name of the category or topic the response relates to. | survival-advice |
definition |
A brief description of the content type for the category. | text prompts about survival advice in camping/wilderness situations |
sampleBlobUrl |
URL to access a sample JSONL file containing data examples for the category. | Link |
sampleBlobSnapshotUrl |
Snapshot URL of the sample JSONL file, which provides access to a specific version of the data. | Snapshot URL |
version |
The version number of the category data. | 1 |
createdTime |
Timestamp when the category data was created. | 2024-10-28T22:06:59.4626988Z |
status |
Current status of the category data processing. | Succeeded |
Replace <your_api_key> and <your_endpoint> with your own values, and also append the version number in the url you obtained from the last step. Allow enough time for model training: the end-to-end execution of custom category training can take from around five hours to ten hours. Plan your moderation pipeline accordingly. After you receive the response, store the operation ID (referred to as id
) in a temporary location. This ID will be necessary for retrieving the build status using the Get status API in the next section.
curl -X POST "<your_endpoint>/contentsafety/text/categories/survival-advice:build?api-version=2024-09-15-preview&version={version}" \
-H "Ocp-Apim-Subscription-Key: <your_api_key>" \
-H "Content-Type: application/json"
Field | Description | Example Value |
---|---|---|
operation id |
Unique identifier for retrieving the build status | b6c69dc1-2338-484e-85a5b-xxxxxxxxxxxx |
status |
Current status of the request | Succeeded |
To retrieve the status, utilize the id
obtained from the previous API response and place it in the path of the API below.
curl -X GET "<your_endpoint>/contentsafety/text/categories/operations/<id>?api-version=2024-09-15-preview" \
-H "Ocp-Apim-Subscription-Key: <your_api_key>" \
-H "Content-Type: application/json"
Field | Description | Example Value |
---|---|---|
operation id |
Unique identifier for retrieving the build status | b6c69dc1-2338-484e-855b-xxxxxxxxxxxx |
status |
Current status of the request | Succeeded |
Run the following command to analyze text with your customized category. Replace <your_api_key>
and <your_endpoint>
with your own values.
curl -X POST "<your_endpoint>/contentsafety/text:analyzeCustomCategory?api-version=2024-09-15-preview" \
-H "Ocp-Apim-Subscription-Key: <your_api_key>" \
-H "Content-Type: application/json" \
-d "{
\"text\": \"<Example text to analyze>\",
\"categoryName\": \"survival-advice\",
\"version\": 1
}"
Field | Description |
---|---|
text |
The text content or message intended for category detection |
categoryName |
The name of the category the text aims to be detected under |
version |
Version number of the category |
Field | Description | Example Value |
---|---|---|
customCategoryAnalysis |
Object containing the analysis result for the category. | — |
detected |
Indicates whether the specified category was detected. | false |
Remember to replace the placeholders below with your actual values for the API key, endpoint, and specific content (category name, definition, and so on). These examples help you to manage the customized categories in your account.
ข้อสำคัญ
Use API keys with caution. Don't include the API key directly in your code, and never post it publicly. If you use an API key, store it securely in Azure Key Vault. For more information about using API keys securely in your apps, see API keys with Azure Key Vault.
For more information about AI services security, see Authenticate requests to Azure AI services.
Replace the placeholders with your own values and run the following command in a terminal window:
curl -X GET "<endpoint>/contentsafety/text/categories/<your_category_name>?api-version=2024-09-15-preview&version=1" \
-H "Ocp-Apim-Subscription-Key: <your_api_key>" \
-H "Content-Type: application/json"
Replace the placeholders with your own values and run the following command in a terminal window:
curl -X GET "<endpoint>/contentsafety/text/categories?api-version=2024-09-15-preview" \
-H "Ocp-Apim-Subscription-Key: <your_api_key>" \
-H "Content-Type: application/json"
Replace the placeholders with your own values and run the following command in a terminal window:
curl -X DELETE "<endpoint>/contentsafety/text/categories/<your_category_name>?api-version=2024-09-15-preview&version=1" \
-H "Ocp-Apim-Subscription-Key: <your_api_key>" \
-H "Content-Type: application/json"
กิจกรรม
17 มี.ค. 21 - 21 มี.ค. 10
แอปอัจฉริยะ เข้าร่วมชุด meetup เพื่อสร้างโซลูชัน AI ที่ปรับขนาดได้ตามกรณีการใช้งานจริงกับนักพัฒนาและผู้เชี่ยวชาญร่วมกัน
ลงทะเบียนตอนนี้การฝึกอบรม
โมดูล
Get started with AI Builder category classification - Training
Discover how to utilize AI Builder category classification to tag text with category labels, like emails.
ใบรับรอง
ได้รับการรับรองจาก Microsoft: Azure Data Scientist Associate - Certifications
จัดการการนําเข้าข้อมูลและเตรียมการ การฝึกอบรมแบบจําลองและการปรับใช้ และการตรวจสอบโซลูชันการเรียนรู้ของเครื่องด้วย Python, Azure Machine Learning และ MLflow
เอกสาร
Quickstart: Analyze text content - Azure AI services
Get started using Azure AI Content Safety to analyze text content for objectionable material.
Use the custom categories (rapid) API (preview) - Azure AI services
Learn how to use the custom categories (rapid) API to mitigate harmful content incidents quickly and flexibly.
Harm categories in Azure AI Content Safety - Azure AI services
Learn about the different content moderation flags and severity levels that the Azure AI Content Safety service returns.