Document structuring - Key-value information extraction
The key-value information extraction service extracts information from documents that follow a `key: value` pattern. It performs well on documents with a clear key-value structure, such as resumes, contracts, and reports.
This service is provided by the Natural Language Processing (NLP) Self-Learning Platform. You can call the API directly to use the service.
Activate the service and purchase a resource plan
Before you start, confirm that the service is activated. After you activate the service, you must purchase a resource plan.
Service activation: Activation page
Purchase a resource plan: Purchase page
Service invocation and testing
For more information about how to call the model, see Model invocation.
For SDK examples, see SDK examples.
Debugging
Configure access credentials (AccessKey ID and AccessKey secret) using environment variables
Notes:
An AccessKey that belongs to an Alibaba Cloud account has full access permissions to all APIs. This poses a high security risk. We strongly recommend that you create and use a Resource Access Management (RAM) user for API access or daily operations and maintenance (O&M). To create a RAM user, you can log on to the RAM console.
Do not save your AccessKey ID and AccessKey secret in your code. This can lead to an AccessKey leak. Instead, configure environment variables to store and access your AccessKey ID and AccessKey secret.
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.
Windows System Configuration
Create an environment variable file. Add the
NLP_AK_ENVandNLP_SK_ENVenvironment variables, and then set their values to your AccessKey ID and AccessKey secret.Restart the Windows operating system.
When you call the key-value information extraction service, set the ServiceName parameter to `NER-KV`. The value is case-sensitive and must be in uppercase.
Java code example
/**
* The AccessKey of an Alibaba Cloud account has full access permissions to all APIs. This poses a high security risk. We strongly recommend that you create and use a RAM user for API access or daily O&M. To create a RAM user, log on to the RAM console.
* This example shows how to save the AccessKey ID and AccessKey secret in environment variables. You can also save them in a configuration file as needed.
* Do not save your AccessKey ID and AccessKey secret in your code. This can cause your keys to be leaked.
*/
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);
String content = "Name:Zhang San Age:21 Phone Number:1390000****";
RunPreTrainServiceRequest request = new RunPreTrainServiceRequest();
request.setServiceName("NER-KV");
request.setPredictContent(content);
RunPreTrainServiceResponse response = client.getAcsResponse(request);
System.out.println(response.getPredictResult());Python code example
The `PredictResult` parameter returns a JSON string. You can deserialize the string to parse the result.
# 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
/**
* The AccessKey of an Alibaba Cloud account has full access permissions to all APIs. This poses a high security risk. We strongly recommend that you create and use a RAM user for API access or daily O&M. To create a RAM user, log on to the RAM console.
* This example shows how to save the AccessKey ID and AccessKey secret in environment variables. You can also save them in a configuration file as needed.
* Do not save your AccessKey ID and AccessKey secret in your code. This can cause your keys to be leaked.
*/
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 = 'Name:Zhang San Age:21 Phone Number:1390000****'
# Initialize a request and set parameters
request = RunPreTrainServiceRequest.RunPreTrainServiceRequest()
request.set_ServiceName('NER-KV')
request.set_PredictContent(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)Sample input:
Second Bidding Announcement for Wellhead and Christmas Tree Pressure Testing Operations in Tahe Oilfield by the Well Testing Company in 2021
Tender No.: SYGS-ZB2021038
I. Bidding Conditions:
The necessary approval and filing procedures for this project have been completed as required. The funds are secured, and the project meets the conditions for bidding. A public tender is now being issued.
II. Project Overview:
1. Project Background:
In 2021, the Tahe Oilfield Completion and Testing Center of Sinopec Northwest Oilfield Company decided to outsource the integrated construction services required during the well testing process. These services include special vehicle operations, firewall installation, hydrogen sulfide treatment, waste liquid transportation, and Christmas tree pressure testing. The annual well testing volume is 50 wells, with an estimated integrated construction output value of CNY 6 million. The budget for wellhead and Christmas tree pressure testing is CNY 490,000. Project duration: from the date of contract signing to December 31, 2021.
1.1 Bidding Scope:
1.1.1 Determine the service price for the equipment and personnel required for wellhead pressure testing, on-site pressure testing of 140 MPa oil (gas) Christmas trees and pumping unit wellheads, and on-site pressure test data collection.
1.2 Service Area: The operational area of the Well Testing Company in the southern Xinjiang Tahe Oilfield.
1.3 Estimated Project Amount: CNY 490,000 (tax included).
1.4 Section Division: This project is not divided into sections.
1.5 Bid Result Validity: From the date of contract signing to December 31, 2021.
2. Service Requirements:
2.1 Technical Service Requirements:
2.1.1 The construction team must hold a valid market access permit from the Sinopec Oilfield Company.
2.1.2 The team must have the necessary equipment and personnel for wellhead pressure testing, on-site pressure testing of 140 MPa oil (gas) Christmas trees and pumping unit wellheads, and on-site pressure test data collection.
2.1.3 The contractor must use their own equipment and personnel for construction. Subcontracting or transferring the contract is not allowed.
III. Bidder Qualification Requirements
1. Must have independent corporate legal personality and a valid business license (the business scope must include relevant technical services).
2. The bidder must have a valid Sinopec market access permit (from the Sinopec Northwest Oilfield Company market information system), and the scope must cover the services related to this project.
3. Joint bids are not accepted for this tender.
4. The bidder must have no serious violations of laws or regulations, no fraudulent bid awards, and no major quality or safety issues in the past three years. The results from the following platforms and certificates from relevant departments will be used as verification.
(1) Query the "Administrative Penalty Information" and "List of Seriously Dishonest and Untrustworthy Enterprises" in the National Enterprise Credit Information Publicity System of the State Administration for Market Regulation. Query URL: http://www.gsxt.gov.cn/.
(2) The information published on the "List of Dishonest Persons Subject to Enforcement" platform of the Supreme People's Court of the People's Republic of China shall prevail. Query URL: http://shixin.court.gov.cn/.
IV. Obtaining the Bidding Documents
Bidding document sales period: from 10:00 on March 10, 2021, to 19:00 on March 14, 2021. Purchase the bidding documents at Room 304, Comprehensive Office Building, No. 3 Jianguo North Road, Korla City, by presenting the legal representative's power of attorney and the bid purchase registration form (see the appendix of the announcement). The price for each set is CNY 500. (Note: Payment must be made via bank transfer. Specify "Well Testing Company XXX Project" as the source of funds. Bank transfers are not accepted from the 24th to the 31st of each month.)
Name: China National Petroleum Corporation Western Drilling Engineering Co., Ltd.
Taxpayer Identification Number: 90000****22223333J
Address & Phone: No. 001 Youyi Road, Karamay City (Well Testing Company) 0001-1234567
Bank & Account Number: Kunlun Bank Co., Ltd. Karamay Youyi Road Branch 11110000****00008888
V. Submission of Bidding Documents
1. Deadline for submission of bidding documents: 16:00 on March 31, 2021 (UTC+8).
2. Submission method: Submit one original and four copies of the paper bidding documents (and one CD with the electronic version) at the bid opening site.
VI. Bid Opening
1. Bid opening time: 16:00 on March 31, 2021
2. Bid opening location: Conference Room A2-701, Petroleum Company Office Building, No. 001 Youyi Road, Karamay City
VII. Bidder Information
Bidder: Well Testing Company of Western Drilling Engineering Co., Ltd.
Address: No. 001 Youyi Road, Karamay City
Contact: Mr. Duan
Phone: 0001-1234567 1390000****Sample response:
[
{
"key": [
"Tender No."
],
"value": [
"SYGS-ZB2021038"
],
"key_offset": [
[
29,
33
]
],
"value_offset": [
[
34,
35
]
]
},
{
"key": [
"Bidding Conditions"
],
"value": [
"The necessary approval and filing procedures for this project have been completed as required. The funds are secured, and the project meets the conditions for bidding. A public tender is now being issued."
],
"key_offset": [
[
39,
43
]
],
"value_offset": [
[
46,
89
]
]
},
{
"key": [
"Project Overview",
"Project Background"
],
"value": [
"In 2021, the Tahe Oilfield Completion and Testing Center of Sinopec Northwest Oilfield Company decided to outsource the integrated construction services required during the well testing process. These services include special vehicle operations, firewall installation, hydrogen sulfide treatment, waste liquid transportation, and Christmas tree pressure testing. The annual well testing volume is 50 wells, with an estimated integrated construction output value of CNY 6 million. The budget for wellhead and Christmas tree pressure testing is CNY 490,000. Project duration: from the date of contract signing to December 31, 2021."
],
"key_offset": [
[
94,
98
],
[
102,
106
]
],
"value_offset": [
[
109,
252
]
]
},
{
"key": [
"Project Overview",
"Bidding Scope"
],
"value": [
"1.1.1 Determine the service price for the equipment and personnel required for wellhead pressure testing, on-site pressure testing of 140 MPa oil (gas) Christmas trees and pumping unit wellheads, and on-site pressure test data collection."
],
"key_offset": [
[
94,
98
],
[
259,
263
]
],
"value_offset": [
[
266,
314
]
]
},
{
"key": [
"Project Overview",
"Service Area"
],
"value": [
"The operational area of the Well Testing Company in the southern Xinjiang Tahe Oilfield."
],
"key_offset": [
[
94,
98
],
[
320,
324
]
],
"value_offset": [
[
325,
341
]
]
},
{
"key": [
"Project Overview",
"Estimated Project Amount"
],
"value": [
"CNY 490,000 (tax included)."
],
"key_offset": [
[
94,
98
],
[
347,
353
]
],
"value_offset": [
[
354,
363
]
]
},
{
"key": [
"Project Overview",
"Section Division"
],
"value": [
"This project is not divided into sections."
],
"key_offset": [
[
94,
98
],
[
369,
373
]
],
"value_offset": [
[
374,
382
]
]
},
{
"key": [
"Project Overview",
"Bid Result Validity"
],
"value": [
"From the date of contract signing to December 31, 2021."
],
"key_offset": [
[
94,
98
],
[
388,
395
]
],
"value_offset": [
[
396,
411
]
]
},
{
"key": [
"Service Requirements",
"Technical Service Requirements"
],
"value": [
"2.1.1 The construction team must hold a valid market access permit from the Sinopec Oilfield Company.",
"2.1.2 The team must have the necessary equipment and personnel for wellhead pressure testing, on-site pressure testing of 140 MPa oil (gas) Christmas trees and pumping unit wellheads, and on-site pressure test data collection.",
"2.1.3 The contractor must use their own equipment and personnel for construction. Subcontracting or transferring the contract is not allowed."
],
"key_offset": [
[
417,
421
],
[
425,
431
]
],
"value_offset": [
[
434,
456
],
[
459,
502
],
[
505,
527
]
]
},
{
"key": [
"Bidder Qualification Requirements"
],
"value": [
"1. Must have independent corporate legal personality and a valid business license (the business scope must include relevant technical services).",
"2. The bidder must have a valid Sinopec market access permit (from the Sinopec Northwest Oilfield Company market information system), and the scope must cover the services related to this project.",
"3. Joint bids are not accepted for this tender.",
"4. The bidder must have no serious violations of laws or regulations, no fraudulent bid awards, and no major quality or safety issues in the past three years. The results from the following platforms and certificates from relevant departments will be used as verification.",
"(",
"1) Query the \"Administrative Penalty Information\" and \"List of Seriously Dishonest and Untrustworthy Enterprises\" in the National Enterprise Credit Information Publicity System of the State Administration for Market Regulation."
],
"key_offset": [
[
532,
539
]
],
"value_offset": [
[
541,
576
],
[
579,
629
],
[
632,
645
],
[
648,
707
],
[
710,
711
],
[
711,
757
]
]
},
{
"key": [
"Bidder Qualification Requirements",
"Query URL"
],
"value": [
"http://www.gsxt.gov.cn/.",
"(",
"2) The information published on the \"List of Dishonest Persons Subject to Enforcement\" platform of the Supreme People's Court of the People's Republic of China shall prevail."
],
"key_offset": [
[
532,
539
],
[
758,
763
]
],
"value_offset": [
[
764,
767
],
[
770,
771
],
[
771,
815
]
]
},
{
"key": [
"Bidder Qualification Requirements",
"Query URL"
],
"value": [
"http://shixin.court.gov.cn/."
],
"key_offset": [
[
532,
539
],
[
816,
821
]
],
"value_offset": [
[
822,
825
]
]
},
{
"key": [
"Obtaining the Bidding Documents",
"Bidding document sales period"
],
"value": [
"from 10:00 on March 10, 2021, to 19:00 on March 14, 2021. Purchase the bidding documents at Room 304, Comprehensive Office Building, No. 3 Jianguo North Road, Korla City, by presenting the legal representative's power of attorney and the bid purchase registration form (see the appendix of the announcement). The price for each set is CNY 500. (Note: Payment must be made via bank transfer. Specify \"Well Testing Company XXX Project\" as the source of funds. Bank transfers are not accepted from the 24th to the 31st of each month.)"
],
"key_offset": [
[
830,
837
],
[
839,
847
]
],
"value_offset": [
[
848,
984
]
]
},
{
"key": [
"Obtaining the Bidding Documents",
"Name"
],
"value": [
"China National Petroleum Corporation Western Drilling Engineering Co., Ltd."
],
"key_offset": [
[
830,
837
],
[
986,
990
]
],
"value_offset": [
[
991,
1007
]
]
},
{
"key": [
"Obtaining the Bidding Documents",
"Taxpayer Identification Number"
],
"value": [
"90000****22223333J"
],
"key_offset": [
[
830,
837
],
[
1009,
1015
]
],
"value_offset": [
[
1016,
1017
]
]
},
{
"key": [
"Obtaining the Bidding Documents",
"Address & Phone"
],
"value": [
"No. 001 Youyi Road, Karamay City (Well Testing Company) 0001-1234567"
],
"key_offset": [
[
830,
837
],
[
1019,
1024
]
],
"value_offset": [
[
1025,
1042
]
]
},
{
"key": [
"Obtaining the Bidding Documents",
"Bank & Account Number"
],
"value": [
"Kunlun Bank Co., Ltd. Karamay Youyi Road Branch 11110000****00008888"
],
"key_offset": [
[
830,
837
],
[
1044,
1049
]
],
"value_offset": [
[
1050,
1070
]
]
},
{
"key": [
"Submission of Bidding Documents",
"Deadline for submission of bidding documents"
],
"value": [
"16:00 on March 31, 2021 (UTC+8)."
],
"key_offset": [
[
1074,
1081
],
[
1084,
1094
]
],
"value_offset": [
[
1097,
1114
]
]
},
{
"key": [
"Submission of Bidding Documents",
"Submission method"
],
"value": [
"Submit one original and four copies of the paper bidding documents (and one CD with the electronic version) at the bid opening site."
],
"key_offset": [
[
1074,
1081
],
[
1118,
1126
]
],
"value_offset": [
[
1127,
1156
]
]
},
{
"key": [
"Bid Opening",
"Bid opening time"
],
"value": [
"16:00 on March 31, 2021"
],
"key_offset": [
[
1161,
1163
],
[
1166,
1170
]
],
"value_offset": [
[
1171,
1184
]
]
},
{
"key": [
"Bid Opening",
"Bid opening location"
],
"value": [
"Conference Room A2-701, Petroleum Company Office Building, No. 001 Youyi Road, Karamay City"
],
"key_offset": [
[
1161,
1163
],
[
1187,
1191
]
],
"value_offset": [
[
1192,
1213
]
]
},
{
"key": [
"Bidder Information",
"Bidder"
],
"value": [
"Well Testing Company of Western Drilling Engineering Co., Ltd."
],
"key_offset": [
[
1217,
1222
],
[
1224,
1227
]
],
"value_offset": [
[
1228,
1242
]
]
},
{
"key": [
"Bidder Information",
"Address"
],
"value": [
"No. 001 Youyi Road, Karamay City"
],
"key_offset": [
[
1217,
1222
],
[
1244,
1248
]
],
"value_offset": [
[
1249,
1259
]
]
},
{
"key": [
"Bidder Information",
"Contact"
],
"value": [
"Mr. Duan"
],
"key_offset": [
[
1217,
1222
],
[
1261,
1264
]
],
"value_offset": [
[
1265,
1268
]
]
},
{
"key": [
"Bidder Information",
"Phone"
],
"value": [
"0001-1234567"
],
"key_offset": [
[
1217,
1222
],
[
1270,
1274
]
],
"value_offset": [
[
1275,
1276
]
]
}Fields and descriptions for bidding information extraction
No. | Entity Name | Description |
1 | key | A list. If the list contains more than one key, it indicates a hierarchical relationship between the keys. |
2 | value | A list. If the list contains more than one value, it indicates a parallel relationship between the values. |
3 | key_offset | The start and end positions of the corresponding key in the document. |
4 | value_offset | The start and end positions of the corresponding value in the document. |