Updated on 2024-03-27 GMT+08:00

Text Moderation (V3)

Function

Moderation (Text) analyzes and identifies whether the uploaded text contains sensitive information and returns the result to you.

  1. Compared with v2, v3 provides enhanced moderation capability and better experience.
  2. Currently, only Chinese content moderation is supported.
  3. 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

Table 1 Path parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID.

Request Parameters

Table 2 Request header 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.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

event_type

No

String

Event type. Value options are as follows:

  • nickname: nickname
  • title: title
  • article: post
  • comment: comment
  • barrage: on-screen comment
  • search: search bar
  • profile: personal introduction

categories

No

Array of strings

Text moderation scenarios. The options are as follows:

  • terrorism: terrorism-related information
  • porn: pornographic information
  • ban: banned information
  • abuse: abuse
  • ad: advertisement

If this parameter is not specified, all moderation scenarios are included.

data

Yes

TextDetectionDataReq object

Data to be moderated

Table 4 TextDetectionDataReq

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:

  • zh: Chinese
  • en: English
  • ar: Arabic
  • hi: Hindi
  • es: Spanish
  • fr: French
  • ru: Russian
  • pt: Portuguese
  • id: Indonesian
  • de: German
  • ja: Japanese
  • tr: Turkish
  • vi: Vietnamese
  • it: Italian
  • th: Thai
  • tl: Filipino
  • ko: Korean
  • ms: Malay
  • auto: The language type is automatically identified.

The default value is zh. The recommended value is auto, indicating that the system automatically detects the language type.

Response Parameters

Status code: 200

Table 5 Response body parameters

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.

Table 6 TextDetectionResult

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:

  • terrorism: terrorism-related information
  • porn: pornographic information
  • ban: banned information
  • abuse: abuse
  • customized: hit keywords in the custom dictionary

details

Array of TextDetectionResultDetail objects

Detection details

Table 7 TextDetectionResultDetail

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:

  • terrorism: terrorism-related information
  • porn: pornographic information
  • ban: banned information
  • abuse: abuse
  • customized: hit keywords in the custom dictionary

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.

Table 8 Segment

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

Table 9 Response body parameters

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

Example successful response
{
  "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

Example failed response
{
  "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.