Rephrase
The Paraphrase and Rephrase endpoints offer paraphrasing for particular styles. Given an input sentence, the endpoint returns output sentences that preserve meaning but use alternative phrasings or styles.
Note that while the paraphrases/rephrases retain the same general meaning, they vary in how much they differ from the input sentence. Put another way, while the syntax and terminology of the input may change, the semantics should be preserved.
Paraphrase POST
The paraphrase endpoint provides alternative phrasings of an input text while preserving meaning and intent. An example input might be: "How are you?" with the output paraphrases, "How's it going?", "What's up?", and "How are you doing?".
https://api.sapling.ai/api/v1/paraphrase
HTTP method: POST
Sample Code
- cURL
- JavaScript
- Python
curl -X POST https://api.sapling.ai/api/v1/paraphrase \
-H "Content-Type: application/json" \
-d '{
"key":"<api-key>",
"text":"How are you?",
}'
import axios from 'axios';
async function run(text) {
try {
const response = await axios.post(
'https://api.sapling.ai/api/v1/paraphrase',
{
key: '<api-key>',
text,
},
);
const {status, data} = response;
console.log({status});
console.log(JSON.stringify(data, null, 4));
} catch (err) {
const { msg } = err.response.data;
console.log({err: msg});
}
}
run('How are you?');
import requests
from pprint import pprint
key = '<api-key>'
url = 'https://api.sapling.ai/api/v1/paraphrase'
data = {
'key': key,
'text': 'How are you?',
}
try:
resp = requests.post(url, json=data)
resp_json = resp.json()
if 200 <= resp.status_code < 300:
results = resp_json['results']
pprint(results)
else:
print('Error: ', resp_json)
except Exception as e:
print('Error: ', e)
Sample Response
{
"results": [
{
"hash": "26d70b5b-333f-52f2-9abe-7bdac7dfe95f",
"model_version": "v20230414",
"original": "How are you?",
"rephrase_type": "paraphrase",
"replacement": "What is your current state of affairs?"
},
{
"hash": "9db4d831-f526-5ee3-b43a-f4ad02c0e2fa",
"model_version": "v20230414",
"original": "How are you?",
"rephrase_type": "paraphrase",
"replacement": "How are you doing?"
},
{
"hash": "0f100133-1b07-5157-b61e-d25d13cdfa27",
"model_version": "v20230414",
"original": "How are you?",
"rephrase_type": "paraphrase",
"replacement": "What's your current state of affairs?"
}
]
}
Request Parameters
key: String
32-character API key
text: String
Input query to paraphrase.
diversity: Float [Coming soon]
Ranges from 0 to 1. 0 means to not encourage diversity beyond the usual sampling. 1 means to make the outputs as diverse as possible (while still preserving semantics).
num_results: Integer [Coming soon]
Number of results to return. The minimum is 1. The maximum will depend on other settings, but is generally around 8.
Contact us if you need additional results. Additional results will incur additional costs.
Response Parameters
results: JSON, array of paraphrases. Sample structure:
Rephrase POST
In addition to the paraphrase endpoint, the rephrase endpoint also offers a few style transformations:
- Informal to Formal: Given a casual/informal input text, generate a more formal/professional output. You can test the endpoint here.
- Passive to Active: Generate sentence in active voice given sentence in passive voice. You can test the endpoint here.
- Long to Short: This is offered by Sapling's summarize endpoint.
- Split: Given a long sentence, split it into two sentences. You can test the endpoint here.
https://api.sapling.ai/api/v1/rephrase
HTTP method: POST
Sample Code
- cURL
- JavaScript
- Python
curl -X POST https://api.sapling.ai/api/v1/rephrase \
-H "Content-Type: application/json" \
-d '{
"key":"<api-key>",
"text":"hey wuts going on",
"mapping":"informal_to_formal"
}'
import axios from 'axios';
async function run(text) {
try {
const response = await axios.post(
'https://api.sapling.ai/api/v1/rephrase',
{
key: '<api-key>',
text,
mapping:'informal_to_formal'
},
);
const {status, data} = response;
console.log({status});
console.log(JSON.stringify(data, null, 4));
} catch (err) {
const { msg } = err.response.data;
console.log({err: msg});
}
}
run('hey wuts going on');
import requests
from pprint import pprint
key = '<api-key>'
url = 'https://api.sapling.ai/api/v1/rephrase'
data = {
'key': key,
'text': 'hey wuts going on',
'mapping':'informal_to_formal'
}
try:
response = requests.post(url, json=data)
resp_json = response.json()
if 200 <= response.status_code < 300:
results = resp_json['results']
pprint(results)
else:
print('Error: ', resp_json)
except Exception as e:
print('Error: ', e)
Sample Response
{
"results": [
{
"hash": "5c09974f-3fae-560d-9982-ba3ff7087fff",
"model_version": "v20220514",
"original": "hey wuts going on",
"rephrase_type": "informal_to_formal",
"replacement": "What is going on, please?"
},
{
"hash": "e8392c8f-c190-58df-84ef-887a29a78d2c",
"model_version": "v20220514",
"original": "hey wuts going on",
"rephrase_type": "informal_to_formal",
"replacement": "I am unaware of what is going on."
},
{
"hash": "e4dd013c-e79c-5031-ab74-4614703c3f16",
"model_version": "v20220514",
"original": "hey wuts going on",
"rephrase_type": "informal_to_formal",
"replacement": "What is going on?"
},
{
"hash": "8b593139-7353-50a9-8c99-e59a82d16031",
"model_version": "v20220514",
"original": "hey wuts going on",
"rephrase_type": "informal_to_formal",
"replacement": "Hey, what is happening?"
}
]
}
Request Parameters
key: String
32-character API key
text: String
Input query to rephrase.
mapping String
The model to use. Available models include informal_to_formal
, passive_to_active
, active_to_passive
, and sentence_split
.
diversity: Float [Coming soon]
Ranges from 0 to 1. 0 means to not encourage diversity beyond the usual sampling. 1 means to make the outputs as diverse as possible (while still preserving semantics).
num_results: Integer [Coming soon]
Number of results to return. The minimum is 1. The maximum will depend on other settings, but is generally around 8.
Contact us if you need additional results. Additional results will incur additional costs.
Response Parameters
results: JSON, array of rephrases. Sample structure: