| id | nlp-toolkit |
| version | 1.0.0 |
| name | NLP Toolkit |
| description | Advanced NLP with perplexity scoring, burstiness analysis, and entropy calculation |
| author | NeoClaw Team |
| category | detection |
| tags | ["nlp","perplexity","burstiness","entropy"] |
| dependencies | [] |
NLP Toolkit
Advanced NLP analysis for AI content detection using statistical measures.
Implementation
() {
{
perplexityThreshold = ,
burstinessThreshold = ,
minTextLength =
} = options;
(text. < minTextLength) {
{
: ,
: minTextLength
};
}
perplexity = (text);
burstiness = (text);
entropy = (text);
tokenStats = (text);
isAI = perplexity < perplexityThreshold && burstiness < burstinessThreshold;
confidence = (perplexity, burstiness, entropy);
{
isAI,
: .(confidence * ),
: {
: .(perplexity * ) / ,
: .(burstiness * ) / ,
: .(entropy * ) /
},
tokenStats,
: {
: perplexityThreshold,
: burstinessThreshold
},
: isAI ?
:
};
}
() {
words = text.().();
uniqueWords = (words);
ratio = uniqueWords. / words.;
perplexity = / ratio;
.(perplexity, );
}
() {
sentences = text.().( s.());
(sentences. < ) ;
lengths = sentences.( s.().);
avg = lengths.( a + b, ) / lengths.;
variance = lengths.( sum + .(len - avg, ), ) / lengths.;
stdDev = .(variance);
burstiness = stdDev / avg;
.(burstiness, );
}
() {
chars = text.().();
freq = {};
( char chars) {
freq[char] = (freq[char] || ) + ;
}
entropy = ;
total = chars.;
( count .(freq)) {
p = count / total;
entropy -= p * .(p);
}
entropy;
}
() {
words = text.().();
uniqueWords = (words);
{
: words.,
: uniqueWords.,
: .((uniqueWords. / words.) * ) /
};
}
() {
perplexityScore = .(, - (perplexity / ));
burstinessScore = .(, - (burstiness / ));
entropyScore = (entropy > && entropy < ) ? : ;
confidence = (perplexityScore + burstinessScore + entropyScore) / ;
.(confidence, );
}
. = {
analyzeText,
calculatePerplexity,
calculateBurstiness,
calculateEntropy
};