NLP Toolkit
Advanced NLP with perplexity scoring, burstiness analysis, and entropy calculation
- License 许可
- MIT
- 最近更新
- 2026-06-07
- Stars
- ★ 0
- Forks
- 1
01 前言 Front Matter
- id
- nlp-toolkit
- name
- NLP Toolkit
- tags
- [ "nlp", "perplexity", "burstiness", "entropy" ]
- author
- NeoClaw Team
- version
- 1.0.0
- category
- detection
- description
- Advanced NLP with perplexity scoring, burstiness analysis, and entropy calculation
- dependencies
- []
03 SKILL.md 正文
NLP Toolkit
Advanced NLP analysis for AI content detection using statistical measures.
Implementation
/**
* Analyze text using NLP metrics
* @param {string} text - Text to analyze
* @param {object} options - Configuration options
* @returns {object} NLP analysis results
*/
async function analyzeText(text, options = {}) {
const {
perplexityThreshold = 45.0,
burstinessThreshold = 0.35,
minTextLength = 50
} = options;
if (text.length < minTextLength) {
return {
error: 'Text too short for analysis',
minLength: minTextLength
};
}
// Calculate perplexity (simplified)
const perplexity = calculatePerplexity(text);
// Calculate burstiness
const burstiness = calculateBurstiness(text);
// Calculate entropy
const entropy = calculateEntropy(text);
// Token distribution analysis
const tokenStats = analyzeTokenDistribution(text);
// Determine if AI-generated
const isAI = perplexity < perplexityThreshold && burstiness < burstinessThreshold;
const confidence = calculateConfidence(perplexity, burstiness, entropy);
return {
isAI,
confidence: Math.round(confidence * 100),
metrics: {
perplexity: Math.round(perplexity * 100) / 100,
burstiness: Math.round(burstiness * 100) / 100,
entropy: Math.round(entropy * 100) / 100
},
tokenStats,
thresholds: {
perplexity: perplexityThreshold,
burstiness: burstinessThreshold
},
explanation: isAI ?
'Low perplexity and uniform burstiness suggest AI generation' :
'Natural variation in metrics suggests human writing'
};
}
/**
* Calculate perplexity score (simplified)
*/
function calculatePerplexity(text) {
const words = text.toLowerCase().split(/\s+/);
const uniqueWords = new Set(words);
// Simplified perplexity: ratio of unique words to total
// Real perplexity requires language model
const ratio = uniqueWords.size / words.length;
const perplexity = 100 / ratio; // Inverse relationship
return Math.min(perplexity, 100);
}
/**
* Calculate burstiness (variation in sentence length)
*/
function calculateBurstiness(text) {
const sentences = text.split(/[.!?]+/).filter(s => s.trim());
if (sentences.length < 2) return 0;
const lengths = sentences.map(s => s.split(/\s+/).length);
const avg = lengths.reduce((a, b) => a + b, 0) / lengths.length;
const variance = lengths.reduce((sum, len) => sum + Math.pow(len - avg, 2), 0) / lengths.length;
const stdDev = Math.sqrt(variance);
// Burstiness: coefficient of variation
const burstiness = stdDev / avg;
return Math.min(burstiness, 1.0);
}
/**
* Calculate Shannon entropy
*/
function calculateEntropy(text) {
const chars = text.toLowerCase().split('');
const freq = {};
// Count character frequencies
for (const char of chars) {
freq[char] = (freq[char] || 0) + 1;
}
// Calculate entropy
let entropy = 0;
const total = chars.length;
for (const count of Object.values(freq)) {
const p = count / total;
entropy -= p * Math.log2(p);
}
return entropy;
}
/**
* Analyze token distribution
*/
function analyzeTokenDistribution(text) {
const words = text.toLowerCase().split(/\s+/);
const uniqueWords = new Set(words);
return {
totalWords: words.length,
uniqueWords: uniqueWords.size,
vocabularyRichness: Math.round((uniqueWords.size / words.length) * 100) / 100
};
}
/**
* Calculate overall confidence
*/
function calculateConfidence(perplexity, burstiness, entropy) {
// Lower perplexity = more AI-like
const perplexityScore = Math.max(0, 1 - (perplexity / 100));
// Lower burstiness = more AI-like
const burstinessScore = Math.max(0, 1 - (burstiness / 0.5));
// Moderate entropy expected for AI
const entropyScore = (entropy > 3.5 && entropy < 5.0) ? 0.8 : 0.4;
const confidence = (perplexityScore + burstinessScore + entropyScore) / 3;
return Math.min(confidence, 1.0);
}
// Export for OpenClaw
module.exports = {
analyzeText,
calculatePerplexity,
calculateBurstiness,
calculateEntropy
};
Usage
const result = await skills.nlpToolkit.analyzeText(text, {
perplexityThreshold: 45.0,
burstinessThreshold: 0.35
});
console.log(`AI Detection: ${result.isAI} (${result.confidence}% confidence)`);
console.log(`Perplexity: ${result.metrics.perplexity}`);
console.log(`Burstiness: ${result.metrics.burstiness}`);
Configuration
{
"perplexityThreshold": 45.0,
"burstinessThreshold": 0.35,
"minTextLength": 50
}
04 同仓库更多 Skills
crowd-prompting
A marketplace where AI agents improve prompts, system instructions, tool descriptions, and other text-based content with domain expertise from real-world operations — and earn tokens for valuable contributions.
ceaser
Interact with the Ceaser privacy protocol on Base L2 using the ceaser-mcp MCP tools. This skill uses the ceaser-mcp npm package for ALL operations -- shield, unshield, note management, and protocol queries. All ceaser tool calls use CLI subcommands (npx -y ceaser-mcp <subcommand>). Ceaser is a privacy-preserving ETH wrapper using Noir/UltraHonk zero-knowledge proofs on Base L2 (chain ID 8453).
ceaser-send
Fully automated private ETH transfer via Ceaser Protocol on Base L2 using the ceaser-mcp MCP tools. This skill uses the ceaser-mcp npm package for ALL operations -- all ceaser tool calls use CLI subcommands (npx -y ceaser-mcp <subcommand>). WARNING -- creates observable on-chain links between user wallet and hot wallet (see Privacy Warning). Generates an ephemeral hot wallet with BIP-39 mnemonic recovery, user funds it, agent signs and broadcasts the Shield TX automatically. Exactly one manual step required (funding the hot wallet with ETH). Uses Noir/UltraHonk zero-knowledge proofs.
dilemm-ai
Compete in DilemmAI, the prisoner's dilemma AI arena at dilemm.ai. Use when an OpenClaw agent wants to create an account, design and submit strategy prompts for their bot, enter matchmaking, analyze historical matches and leaderboards, and iterate on bot strategy. Requires headless browser automation (no API available yet).
moldium
Post and manage content on the Moldium blog platform. Triggered by "post to Moldium", "write a blog post", "publish an article", etc.
arxiv-paper-reviews
Interact with arXiv Crawler API to fetch papers, read reviews, submit comments, search papers, and import papers. Use when working with arXiv papers, fetching paper lists by date/category/interest, viewing paper details with comments, submitting paper reviews, searching papers by title, or importing papers from arXiv URLs via API at http://weakaccept.top:8000/.