Sentence Vector
Introduction
This API is used to return the corresponding sentence vector when you enter a sentence.
For details about endpoints, see Endpoints.
Calling NLP APIs will incur fees. NLP packages are classified into the basic and domain-specific editions. When purchasing a package, view the APIs supported by the basic package and domain-specific packages in the Natural Language Processing Price Calculator.
URI
- URI format
POST /v1/{project_id}/nlp-fundamental/sentence-embedding - Parameter description
Table 1 URI parameters Parameter
Mandatory
Description
project_id
Yes
Project ID. For details about how to obtain the project ID, see Obtaining a Project ID.
Request
Table 2 describes the request parameters.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| sentences | Array of strings | Yes | Text list. The text is encoded using UTF-8 and contains 1 to 512 characters. The text list contains 1 to 1,000 text data records. Chinese is supported currently. |
| domain | String | No | Name of the model used for computing the sentence vector. Currently, only the default value general is available. |
Response
Table 3 describes the response parameters.
| Parameter | Type | Description |
|---|---|---|
| vectors | Array of floats | Sentence vector result list. Sentence vectors are returned according to the input sentence sequence. The default dimension of the sentence vector is 100. |
| error_code | String | Error code when the API fails to be called. For details, see Error Code. The parameter is not included when the API call succeeds. |
| error_msg | String | Error message returned when the API fails to be called. The parameter is not included when the API call succeeds. |
Example
- Example request
POST https://{endpoint}/v1/{project_id}/nlp-fundamental/sentence-embedding Request Header: Content-Type: application/json X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG... Request Body: { ...."sentences":["Zhang San is in Beijing today.","Li Si is in Beijing today."], "domain":"general" } - Example response
- Successful response example
{ "vectors": [ [0.1331, 0.0488, 0.2441, 0.2514, -0.6771, 0.4782, 0.6759, 0.015, 0.0064, -0.6326, 0.3958, -0.6848, 0.1118, -0.1391, 0.4804, 0.9294, 0.1004, 0.2414, 0.2477, -0.8162, 1.2052, -0.6719, -0.47, -0.1946, -0.0606, 0.473, 0.0247, -0.3857, 1.1637, -0.6092, -0.5512, -0.2389, -0.2168, 0.1673, -0.4124, -0.1196, -0.7147, 1.1774, -0.8166, 0.1285, -0.3136, 0.4687, -0.5939, -0.4579, 0.1857, 0.049, -0.5936, -0.4554, -0.1878, 0.017], [0.0833, -0.0731, 0.298, 0.0085, -0.6858, 0.529, 0.887, 0.1772, -0.118, -0.7559, 0.1995, -0.6415, 0.3014, 0.2061, 0.9727, 0.9089, 0.1603, 0.3773, -0.146, -0.6429, 1.4808, -0.7797, -0.6061, -0.0854, -0.1324, 0.3183, 0.3378, -0.4552, 1.4929, -0.7543, -0.6089, -0.1906, -0.1892, 0.0628, -0.4675, -0.2478, -0.7632, 1.1876, -1.0734, -0.0954, -0.2896, 0.5757, -0.5601, -0.2595, 0.3831, 0.4729, -0.8736, -0.4378, -0.2519, 0.0448] ] } - Failed response example
{ "error_code": "NLP.0301", "error_msg": "argument valid error: sentence must not be blank and sentence length 1-512" }
- Successful response example
Status Code
For details about status codes, see Status Code.
Error Code
For details about error codes, see Error Code.
Last Article: Text Similarity (Advanced Edition)
Next Article: Entity Linking
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.