Text Moderation (V3)
Function
Moderation (Text) analyzes and identifies whether the uploaded text contains sensitive information and returns the result to you.
- Compared with v2, v3 provides enhanced moderation capability and better experience.
- Currently, only Chinese content moderation is supported.
- By default, the maximum number of concurrent API calls is 50. To increase concurrency, contact Huawei technical support.
Prerequisites
Before using Text Moderation, you need to apply for the service and complete authentication. For details, see Getting Started with Moderation (Text).
URI
POST /v3/{project_id}/moderation/text
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Project ID. |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
Yes |
String |
User token Used to obtain the permission to operate APIs. For details about how to obtain the token, see Authentication. The value of X-Subject-Token in the response header is the token. |
Enterprise-Project-Id |
No |
String |
Enterprise project ID. Content Moderation allows you to use Enterprise Project Management Service (EPS) to split fees for resources used by different user groups and users. To obtain the enterprise project ID, go to the Enterprise Project Management console, click the enterprise project name, and obtain the enterprise project ID on the enterprise project details page. For how to create an enterprise project, see Content Moderation User Guide. After an enterprise project is created, parameter transfer involves the following scenarios:
|
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
event_type |
No |
String |
Event type. Value options are as follows:
|
categories |
No |
Array of strings |
Text moderation scenarios. The options are as follows:
If this parameter is not specified, all moderation scenarios are included. |
data |
Yes |
TextDetectionDataReq object |
Data to be moderated |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
text |
Yes |
String |
Text to be detected. The text is encoded using UTF-8. A maximum of 1,500 characters are allowed. If the text contains more than 1,500 characters, only the first 1,500 characters are detected. Minimum length: 1 Maximum length: 1500 |
language |
No |
String |
Supported text language. The options are as follows:
The default value is zh. The recommended value is auto, indicating that the system automatically detects the language type. |
Response Parameters
Status code: 200
Parameter |
Type |
Description |
---|---|---|
request_id |
String |
Unique ID of the request, which is used for troubleshooting. You are advised to save the ID. Minimum length: 2 Maximum length: 64 |
result |
TextDetectionResult object |
Calling result of a successful API call This parameter is not included for a failed call. |
Parameter |
Type |
Description |
---|---|---|
suggestion |
String |
Whether the text passes the check. block: The text contains sensitive information and fails to pass the check. pass: The text does not contain sensitive information and passes the check. review: The text needs to be manually reviewed. |
label |
String |
Label of the detection result. The value can be:
|
details |
Array of TextDetectionResultDetail objects |
Detection details |
Parameter |
Type |
Description |
---|---|---|
suggestion |
String |
Whether the text passes the check. block: The text contains sensitive information and fails to pass the check. pass: The text does not contain sensitive information and passes the check. review: The text needs to be manually reviewed. |
label |
String |
Label of the detection result. The value can be:
|
confidence |
Float |
Confidence. The value ranges from 0 to 1. A larger value indicates a higher confidence. |
segments |
Array of Segment objects |
Hit risky segments. If a semantic algorithm model is hit, an empty list is returned. |
Parameter |
Type |
Description |
---|---|---|
segment |
String |
Hit risk segment |
glossary_name |
String |
Name of the hit custom word dictionary. This field is returned only when a custom word dictionary is hit. |
position |
Array of integers |
Position of the hit risky segment in the text. The position starts from 0. |
Status code: 400
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code of a failed API call. For details, see Error Codes. This parameter is not included when the API is successfully called. |
error_msg |
String |
Error message of a failed API call. This parameter is not included when the API is successfully called. |
Example Request
endpoint is the request URL for calling an API. Endpoints vary depending on services and regions. For details, see Endpoints.
For example, if the service is deployed in the CN North-Beijing4 region, the endpoint is moderation.cn-north-4.myhuaweicloud.com and the request URL is https://moderation.cn-north-4.myhuaweicloud.com/v3/{project_id}/moderation/text. For details about how to obtain the project ID, see Obtaining a Project ID.
- The following is an example request for checking whether the text contains sensitive content. The event type is comment and the detection text is asdfasdfasdf.
POST https://{endpoint}/v3/{project_id}/moderation/text { "event_type" : "comment", "data" : { "text" : "asdfasdfasdf" } }
Example Response
Status code: 200
{ "request_id" : "58e7d9c7-3456-4ba1-80df-6f25506bc4df", "result" : { "suggestion" : "block", "label" : "customized", "details" : [ { "suggestion" : "block", "label" : "customized", "confidence" : 1, "segments" : [ { "segment" : "xxx", "glossary_name" : "zzz" } ] } ] } }
Status code: 400
{ "error_code" : "AIS.0011", "error_msg" : "Lack the request parameter, or the request parameter is empty." }
Status Codes
Status Code |
Description |
---|---|
200 |
Example of a successful response |
400 |
Example of a failed response |
Error Codes
For details, see Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot