Pornography detection service for novels

更新时间:
复制 MD 格式

The pornography detection service for novels detects pornographic or erotic content in Chinese novels. This service is suitable for content moderation scenarios.

Note

This service is provided by the NLP Self-Learning Platform. You can use the service by calling the API directly.

Service activation and resource plan purchase

Before you use the service, ensure that it is activated. After activation, you must purchase a resource plan.

Service invocation and debugging

For more information about model invocation, see Model invocation.

For software development kit (SDK) examples, see SDK examples.

Debug

You can run this API operation directly in OpenAPI Explorer to simplify signature calculation. After a successful call, OpenAPI Explorer automatically generates an SDK code example.

Configure access credentials (AK/SK) using environment variables

  1. Notes:

    1. An AccessKey pair for an Alibaba Cloud account has permissions for all API operations. This poses a high security risk. We strongly recommend that you create and use a Resource Access Management (RAM) user to call API operations or perform routine operations and maintenance (O&M). To create a RAM user, log on to the RAM console.

    2. Do not hard-code your AccessKey ID and AccessKey secret in your code. This can lead to key leakage. Instead, configure environment variables to store and access your AccessKey pair.

  2. Configuration for Linux and macOS

    export NLP_AK_ENV=<access_key_id>
    export NLP_SK_ENV=<access_key_secret>

    Replace <access_key_id> with your AccessKey ID and <access_key_secret> with your AccessKey secret. For more information about how to obtain an AccessKey ID and an AccessKey secret, see Step 2: Obtain an AccessKey for an account.

  3. Configuration for Windows

    1. Create an environment variable file. Add the NLP_AK_ENV and NLP_SK_ENV environment variables, and then enter your AccessKey ID and AccessKey secret.

    2. Restart Windows.

Java code example

/**
 * An AccessKey pair of an Alibaba Cloud account has permissions on all API operations. This poses a high security threat. We strongly recommend that you create and use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console.
 * This example shows how to store your AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file based on your business needs.
 * Do not hard-code your AccessKey ID and AccessKey secret in your code. This can lead to key leakage.
 */
String accessKeyId = System.getenv("NLP_AK_ENV");
String accessKeySecret = System.getenv("NLP_SK_ENV");
DefaultProfile defaultProfile = DefaultProfile.getProfile("cn-hangzhou",accessKeyId,accessKeySecret);
IAcsClient client = new DefaultAcsClient(defaultProfile);
Map<String, Object> map = new HashMap<>();
map.put("session_id", "0");
map.put("level","strict");
map.put("text","Jiaoyue asked again: 'Are you going to talk? Or should I beat you until you foam at the mouth!' Her words carried a deeper meaning, which Rong Zhan immediately understood. He lay on the bed, seemingly without strength, and said softly, 'Well then, I'd like to give it a try.' Jiaoyue blushed instantly and scolded, 'You pervert!' Rong Zhan's fingers gently slid over Jiaoyue's shapely bottom as he said, 'I like being interrogated!' Jiaoyue was finally exasperated. She applied more force with her hands and asked again, 'So, are you going to talk?'");
RunPreTrainServiceRequest request = new RunPreTrainServiceRequest();
request.setServiceName("NLP-Novel-Porn");
request.setPredictContent(JSON.toJSONString(map));
RunPreTrainServiceResponse response = client.getAcsResponse(request);
System.out.println(response.getPredictResult());

Python code example

# Install dependencies
pip install aliyun-python-sdk-core
pip install aliyun-python-sdk-nlp-automl
# -*- coding: utf-8 -*-
import json
import os

from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdknlp_automl.request.v20191111 import RunPreTrainServiceRequest

# An AccessKey pair of an Alibaba Cloud account has permissions on all API operations. This poses a high security threat. We strongly recommend that you create and use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console.
# This example shows how to store your AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file based on your business needs.
# Do not hard-code your AccessKey ID and AccessKey secret in your code. This can lead to key leakage.
access_key_id = os.environ['NLP_AK_ENV']
access_key_secret = os.environ['NLP_SK_ENV']

# Initialize AcsClient instance
client = AcsClient(
  access_key_id,
  access_key_secret,
  "cn-hangzhou"
);
content ={
    "session_id":"0",
    "level":"strict",
    "text": "Jiaoyue asked again: 'Are you going to talk? Or should I beat you until you foam at the mouth!' Her words carried a deeper meaning, which Rong Zhan immediately understood. He lay on the bed, seemingly without strength, and said softly, 'Well then, I'd like to give it a try.' Jiaoyue blushed instantly and scolded, 'You pervert!' Rong Zhan's fingers gently slid over Jiaoyue's shapely bottom as he said, 'I like being interrogated!' Jiaoyue was finally exasperated. She applied more force with her hands and asked again, 'So, are you going to talk?'"}
# Initialize a request and set parameters
request = RunPreTrainServiceRequest.RunPreTrainServiceRequest()
request.set_ServiceName('NLP-Novel-Porn')
request.set_PredictContent(json.dumps(content))
# Print response
response = client.do_action_with_exception(request)
resp_obj = json.loads(response)
predict_result = json.loads(resp_obj['PredictResult'])
print(predict_result['result'])

PredictContent example

{
  "session_id": "0",
  "level": "strict",
  "text": "Jiaoyue asked again: 'Are you going to talk? Or should I beat you until you foam at the mouth!' Her words carried a deeper meaning, which Rong Zhan immediately understood. He lay on the bed, seemingly without strength, and said softly, 'Well then, I'd like to give it a try.' 'Jiaoyue blushed instantly and scolded, 'You pervert!' Rong Zhan's fingers gently slid over Jiaoyue's shapely bottom as he said, 'I like being interrogated!' Jiaoyue was finally exasperated. She applied more force with her hands and asked again, 'So, are you going to talk?'"
}

PredictResult example

{
  "RequestId": "D3E51C1D-83D4-48DD-91BB-494D2A1C358C",
  "PredictResult": {
    "cost": "809.6ms",
    "result":
    {
      "sessionId": "0",
      "label": "1",
      "score": 0.549,
      "sentences": [
        {
          "score": 0.549,
          "sentence": "'Jiaoyue blushed instantly and scolded, 'You pervert!' Rong Zhan's fingers gently slid over Jiaoyue's shapely bottom as he said, 'I like being interrogated!",
          "pos_start": 90,
          "pos_end": 135
        }
      ]
    }, 
    "status": "OK"
  }
}

Request parameters

Parameter

Description

session_id

A unique identifier for the current request. You must include this parameter to facilitate troubleshooting. The value can be an MD5 hash, or a random number combined with a timestamp. (Required)

src

An identifier for the business party. (Optional)

level

Valid values are `strict` and `mild`. `mild` indicates that only the model is used for detection. `strict` indicates that both the model and a pornography lexicon are used for detection. The two values are mutually exclusive. (Required)

text

The text to analyze. The text must be no more than 600 characters in length. (Required)

Response parameters

Parameter

Description

session_id

Same as the request parameter `session_id`.

label

`1` indicates pornographic content. `0` indicates normal content.

score

The confidence level. The value is between 0 and 1. A value closer to 1 indicates a higher probability.

sentence

The detected pornographic segment.

score

The score within the `sentences` field. This indicates the score of the pornographic segment. The value ranges from 0 to 1. A score greater than or equal to 0.5 indicates pornographic content.

pos_start

The start position of the pornographic segment.

pos_end

The end position of the pornographic segment.

status

The query status. `OK` indicates success. `ERROR` indicates failure.

cost

The time taken for the query.