UIE product review parsing service for the E-commerce realm

更新时间:
复制 MD 格式

This service parses product reviews using Universal Information Extraction (UIE) technology. It supports custom tags.

Note

This service is provided by the NLP Self-Learning Platform. Call the API directly to use the service.

Service activation and resource plan purchase

Before you begin, confirm that the service is activated. After activation, you can purchase a resource plan.

Service invocation and debugging

For more information about model invocation, see Model invocation.

For more information about software development kit (SDK) examples, see SDK examples.

Debug

Test this API operation in the OpenAPI Developer Portal to avoid calculating signatures. After a successful test, the OpenAPI Developer Portal automatically generates SDK code examples.

Configure access credentials using environment variables

  1. Notes:

    1. An AccessKey for an Alibaba Cloud account grants full access to all APIs, which poses a high security threat. For improved security, we recommend that you create and use a Resource Access Management (RAM) user for API access and daily operations and maintenance (O&M). To create a RAM user, log on to the RAM console.

    2. To prevent security threats from key leakage, do not hardcode your AccessKey ID and AccessKey secret in your code. Instead, configure them as environment variables.

  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 AccessKey secret, see Step 2: Obtain an AccessKey.

  3. Configuration for Windows

    1. Create the NLP_AK_ENV and NLP_SK_ENV environment variables, and then set their values to your AccessKey ID and AccessKey secret.

    2. Restart your Windows system.

Service name

UIE-ABSA-Commerce

Python code example

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

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

# Initialize AcsClient instance
client = AcsClient(
 "<your-access-id-key>",
 "<your-access-id-secret>",
 "cn-hangzhou"
);

query = {"content": "Assembly is super simple. I put it together in a short while following the instructions, then went for a ride. It's great.", "labels": ["quality", "wheels", "weight", "color", "riding experience", "assembly", "overall"]}

# Initialize a request and set parameters
request = RunPreTrainServiceRequest.RunPreTrainServiceRequest()
request.set_ServiceName('UIE-ABSA-Commerce')
request.set_PredictContent(json.dumps(query))

# Print response
response = client.do_action_with_exception(request)
resp_obj = json.loads(response)
predict_result = json.loads(resp_obj['PredictResult'])
print(json.dumps(predict_result['data']))

PredictContent example

The `PredictContent` parameter is a JSON string. The following example shows the structure of this string.

{
	"content": "Assembly is super simple. I put it together in a short while following the instructions, then went for a ride. It's great.",
	"labels": ["quality", "wheels", "weight", "color", "riding experience", "assembly", "overall"]
}

Request parameters

Parameter

Description

content

The text to predict. The maximum length is 384 characters.

labels

A list of the properties to extract.

PredictResult example

The `PredictResult` is a JSON string. You must deserialize it before you can parse it. The following example shows its structure.

{
	'code': 1000,
	'data': {
		'cost': '1.374s',
		'aspectItem': [{
			'aspectPolarity': 'Positive',
			'terms': [{
				'aspectTerm': 'Assembly',
				'opinionTerm': 'super simple'
			}],
			'opinionProb': '1.0',
			'aspectCategory': 'Assembly'
		}]
	},
	'message': 'SUCCESS',
	'tracerID': 'oxyimTcf6pZGnzPbDF'
}

Response parameters

Field

Description

cost

The time it takes for the service to run.

aspectPolarity

Polarity of a property segment (Positive, Neutral, or Negative)

aspectTerm

Attribute

opinionTerm

Sentiment words

opinionProb

The probability that the aspect has the specified polarity.

aspectCategory

The aspect category.