Text Similarity (Advanced Edition)
Introduction
This API is used to compute the similarity of texts.
For details about endpoints, see Endpoints.
This API is free of charge and can be called twice per second.
URI
- URI format
POST /v1/{project_id}/nlp-fundamental/text-similarity/advance - 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 |
|---|---|---|---|
| text1 | String | Yes | Text 1, on which the text similarity is to be computed. The text is encoded using UTF-8 and contains 1 to 512 characters. |
| text2 | String | Yes | Text 2, on which the text similarity is to be computed. The text is encoded using UTF-8 and contains 1 to 512 characters. |
| lang | String | No | Supported language type. Currently, only Chinese is supported. The default value is zh. |
Response
Table 3 describes the response parameters.
| Parameter | Type | Description |
|---|---|---|
| similarity | Float | Similarity score. The value ranges from 0 to 1. By default, eight digits are reserved after the decimal point. |
| 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/text-similarity/advance Request Header: Content-Type: application/json X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG... Request Body: { "text1":"What's the fun in Hangzhou?", "text2": "Which place is interesting in Hangzhou?", "lang":"zh" } - Example response
- Successful example response
{ "similarity":0.93171031 } - Failed example response
{ "error_code": "NLP.0301", "error_msg": "text1 must not be null. text2 must not be null" }
- Successful example response
Status Code
For details about status codes, see Status Code.
Error Code
For details about error codes, see Error Code.
Last Article: Text Similarity (Basic Edition)
Next Article: Sentence Vector
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.