Getting Started
Deepgram API Playground
Try this feature out in our API Playground.
In this guide, you’ll learn how to analyze text using Deepgram’s text intelligence features: Summarization, Topic Detection, Intent Recognition, and Sentiment Analysis. The code examples use Deepgram’s SDKs.
Purpose
Section titled “Purpose”Text Intelligence analyzes text content using four types of analysis: Summarization, Topic Detection, Intent Recognition, and Sentiment Analysis. You can send text as a string, local file, or hosted URL to receive structured analysis results.
Make the Request
Section titled “Make the Request”A request made using one of the text intelligence features will follow the same form for each of the features; therefore, this guide will walk you through how to make one request, and you can use the feature(s) of your choice depending on which feature you want to use (Summarization, Topic Detection, Intent Recognition, or Sentiment Analysis).
Choose a Text
Section titled “Choose a Text”A text source can be sent to Deepgram as text (a text string or local text file) or as a url (hosted text file). These are referred to as a basic text request (string of text such as "This is a string of text.") or a basic url request (a hosted url such as https://YOUR_FILE_URL.txt).
Basic Text Request
Section titled “Basic Text Request”This example shows how to analyze a local text file as your text source.
const { DeepgramClient } = require("@deepgram/sdk");
const fs = require("fs");
// path to text file
const text = fs.readFileSync("text.txt").toString();
const analyzeText = async () => {
// STEP 1: Create a Deepgram client using the API key
const deepgram = new DeepgramClient({ apiKey: process.env.DEEPGRAM_API_KEY });
// STEP 2: Call the analyze method with the text payload and options
// STEP 3: Configure Deepgram options for text analysis
const result = await deepgram.read.v1.text.analyze({
language: "en",
sentiment: true,
// intents: true,
// summarize: true,
// topics: true,
body: { text },
});
// STEP 4: Print the results
console.dir(result, { depth: null });
};
analyzeText();Basic URL Request
Section titled “Basic URL Request”This example shows how to analyze a hosted url file as your text source.
const { DeepgramClient } = require("@deepgram/sdk");
const analyzeUrl = async () => {
// STEP 1: Create a Deepgram client using the API key
const deepgram = new DeepgramClient({ apiKey: process.env.DEEPGRAM_API_KEY });
// STEP 2: Call the analyze method with the hosted url source and options
// STEP 3: Configure Deepgram options for text analysis
const result = await deepgram.read.v1.text.analyze({
language: "en",
sentiment: true,
// intents: true,
// summarize: true,
// topics: true,
body: { url: "https://static.deepgram.com/examples/aura.txt" },
});
// STEP 4: Print the results
console.dir(result, { depth: null });
};
analyzeUrl();Start the Application
Section titled “Start the Application”Run your application from the terminal.
# Run your application using the file you created in the previous step
# Example: node index.js
node index.jsSee Results
Section titled “See Results”Your results will appear in your shell.
Analyze the Response
Section titled “Analyze the Response”When the file is finished processing (often after only a few seconds), you’ll receive a JSON response:
{
"metadata": {
"request_id": "aff28024-3006-49e2-b70d-aabff2c23655",
"created": "2024-01-30T15:22:33.604Z",
"language": "en",
"summary_info": {
"model_uuid": "67875a7f-c9c4-48a0-aa55-5bdb8a91c34a",
"input_tokens": 107,
"output_tokens": 63
}
},
"results": {
"summary": {
"text": "The speaker discusses the advances in speech recognition and spoken language understanding, citing examples such as the development of new transformer architectures for dealing with conversational audio and the use of model research for accurate transcriptions. They also mention the use of novel transformer architectures for handling conversational audio and the challenges of natural language understanding."
}
}
}Following are explanations of each of the example responses. Be sure to click the tabs in the code block above to view the example response for each text analysis feature.
Summarization
Section titled “Summarization”In the metadata object, we see:
summary_info: information about the model used and the input/output tokens. Summarization pricing is based on the number of input and output tokens. Read more at deepgram.com/pricing.
In the results object, we see:
summary: thetextproperty in this object gives you the summary of the text you requested to be analyzed.
Topic Detection
Section titled “Topic Detection”In the metadata object, we see:
topics_info: information about the model used and the input/output tokens. Topic Detection pricing is based on the number of input and output tokens. Read more at deepgram.com/pricing.
In the results object, we see:
-
topics(object): contains the data about Topic Detection. -
segments: each segment object contains a span of text taken from the input text; thistextsegment is analyzed for its topic. -
topics(array): a list of topic objects, each containing thetopicand aconfidence_score.topic: Deepgram analyzes the segmented text to identify the main topic of each.confidence_score: a floating point value between 0 and 1 indicating the overall reliability of the analysis.
Intent Recognition
Section titled “Intent Recognition”In the metadata object, we see:
intents_info: information about the model used and the input/output tokens. Intent Recognition pricing is based on the number of input and output tokens. Read more at deepgram.com/pricing.
In the results object, we see:
-
intents(object): contains the data about Intent Recognition. -
segments: each segment object contains a span of text taken from the input text; thistextsegment is analyzed for its intent. -
intents(array): a list of intent objects, each containing theintentand aconfidence_score.intent: Deepgram analyzes the segmented text to identify the intent of each.confidence_score: a floating point value between 0 and 1 indicating the overall reliability of the analysis.
Sentiment Analysis
Section titled “Sentiment Analysis”In the metadata object, we see:
sentiment_info: information about the model used and the input/output tokens. Sentiment Analysis pricing is based on the number of input and output tokens. Read more at deepgram.com/pricing.
In the results object, we see:
sentiments(object): contains the data about Sentiment Analysis.segments: each segment object contains a span of text taken from the input text; these segments of text show when the sentiment shifts throughout the text, and each one is analyzed for its sentiment.sentimentcan bepositive,negative, orneutral.sentiment_score: a floating point value between -1 and 1 representing the sentiment of the associated span of text, with -1 being the most negative sentiment, and 1 being the most positive sentiment.average: the average sentiment for the entire input text.
Constraints
Section titled “Constraints”Here are a few constraints to keep in mind when making your request.
Language
Section titled “Language”At this time, text analysis features only work for English language texts. You must add a language parameter and set it to English when you make a text analysis request.
response = client.read.v1.text.analyze(
request={"text": "Your text here"},
language="en",
summarize=True,
)Token Limit
Section titled “Token Limit”The input token limit is 150K tokens. When that limit is exceeded, a 400 error will be thrown.
{
"err_code": "TOKEN_LIMIT_EXCEEDED",
"err_msg": "Text input currently supports up to 150K tokens. Please revise your text input to fit within the defined token limit. For more information, please visit our API documentation.",
"request_id": "XXXX"
}