Need to identify the most important terms in text? This guide covers everything you need to know about keyword extraction via API, including phrase extraction, relevance scoring, and implementation examples.
What is Keyword Extraction?
Keyword extraction is a natural language processing technique that automatically identifies the most important words and phrases in a document. These keywords represent the main topics and concepts discussed in the text.
For example, from an article about "machine learning in healthcare," keywords might include "AI diagnosis," "medical imaging," and "patient outcomes."
Extraction Methods
Several algorithms are used for keyword extraction:
- TF-IDF: Term Frequency-Inverse Document Frequency scoring
- RAKE: Rapid Automatic Keyword Extraction
- TextRank: Graph-based ranking algorithm
- YAKE: Yet Another Keyword Extractor
Using the Keyword Extraction API
TinyFn provides an endpoint to extract keywords from text:
POST https://api.tinyfn.io/v1/extract/keywords
Headers: X-API-Key: your-api-key
Content-Type: application/json
{
"text": "Machine learning is transforming healthcare by enabling faster and more accurate diagnosis. AI-powered systems can analyze medical images to detect diseases earlier than traditional methods.",
"max_keywords": 10
}
{
"keywords": [
{"keyword": "machine learning", "score": 0.95, "count": 1},
{"keyword": "healthcare", "score": 0.88, "count": 1},
{"keyword": "diagnosis", "score": 0.82, "count": 1},
{"keyword": "AI-powered systems", "score": 0.78, "count": 1},
{"keyword": "medical images", "score": 0.75, "count": 1}
],
"total_words": 31,
"unique_keywords": 5
}
Parameters
| Parameter | Type | Description |
|---|---|---|
text |
string | Text to extract keywords from (required) |
max_keywords |
integer | Maximum keywords to return (default: 10) |
min_score |
number | Minimum relevance score 0-1 (default: 0.3) |
include_phrases |
boolean | Include multi-word phrases (default: true) |
Code Examples
JavaScript / Node.js
const response = await fetch('https://api.tinyfn.io/v1/extract/keywords', {
method: 'POST',
headers: {
'X-API-Key': 'your-api-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
text: articleContent,
max_keywords: 5
})
});
const data = await response.json();
// Display keywords as tags
const tags = data.keywords.map(k => k.keyword);
console.log('Keywords:', tags.join(', '));
Python
import requests
def extract_keywords(text, max_keywords=10):
response = requests.post(
'https://api.tinyfn.io/v1/extract/keywords',
json={'text': text, 'max_keywords': max_keywords},
headers={'X-API-Key': 'your-api-key'}
)
return response.json()
# Extract keywords from article
article = """Your long article text here..."""
result = extract_keywords(article, max_keywords=10)
for kw in result['keywords']:
print(f"{kw['keyword']}: {kw['score']:.2f}")
cURL
curl -X POST "https://api.tinyfn.io/v1/extract/keywords" \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{"text": "Your text content here", "max_keywords": 5}'
Common Use Cases
- SEO Optimization: Identify keywords for meta tags
- Content Tagging: Auto-generate tags for articles
- Search Enhancement: Improve search relevance
- Document Clustering: Group similar documents
- Topic Analysis: Understand document themes
Best Practices
- Clean input text: Remove boilerplate, HTML tags, and irrelevant content
- Use appropriate length: Longer text produces better results
- Review and filter: Human review may improve keyword quality
- Consider domain: Some terms are important only in specific contexts
Try the Keyword Extraction API
Get your free API key and start extracting keywords in seconds.
Get Free API Key