科研 Skill

文体计量作者归属分析

stylometry-authorship-attribution

Performs stylometry and authorship attribution using word-frequency and n-gram methods like Burrows’ Delta. Use when a text’s authorship is disputed or anonymous.

发布者 Codar安全审核通过v0.1.0更新于 2026-11-18

SKILL.md

Stylometry and Authorship Attribution

Quantifies an author's writing style from function-word frequencies, character n-grams, and syntactic patterns, then compares a disputed or anonymous text against one or more candidate authors' known-genuine writing. Used in literary studies, history (forged or pseudonymous documents), classics, and digital humanities to support — never alone to prove — an authorship claim.

When to use

  • A text's author is disputed, anonymous, or pseudonymous, and candidate authors with known writing samples exist (e.g. the Federalist Papers problem, disputed chapters in a multi-author work, a forged letter).
  • A user asks "did X actually write this?", "whose style does this passage match?", or "is this consistent with the rest of the corpus?".
  • Checking internal consistency of a claimed single-author corpus (did the author's style shift mid-career, or does one chapter look like a different hand?).

NOT for: plagiarism/duplicate-text detection (string matching, not style); genre or topic classification (that is about content, not authorial habit); proving authorship beyond reasonable doubt — stylometry produces probabilistic evidence, not proof.

Prerequisites

  • Python 3.9+ with scikit-learn, numpy, pandas, and optionally nltk or spacy for tokenization. Install with:
    pip install scikit-learn numpy pandas nltk
    
  • At least 2,000–3,000 words per candidate author in known-genuine samples. Shorter samples make frequency counts noisy and widen the error bars on any attribution.
  • The disputed text and all candidate samples in the same language and, as far as possible, the same genre/register — style markers conflate with genre and translation effects otherwise (a translated text mixes the translator's style into the signal).
  • A plain-text or lightly-cleaned version of every document (strip running headers, footnotes, editorial apparatus, page numbers — these are not the author's prose).

Core method: Burrows' Delta

The most widely used and best-validated baseline for authorship attribution.

  1. Build the frequency table. For each document, count the relative frequency of the top N most frequent words across the whole corpus (typically the 100–500 most frequent words — in practice these are mostly function words: articles, pronouns, prepositions, conjunctions — the words an author uses unconsciously and cannot easily imitate).
import re
from collections import Counter
import numpy as np
import pandas as pd

def tokenize(text):
    return re.findall(r"[a-zA-Z']+", text.lower())

def relative_frequencies(tokens, vocabulary):
    counts = Counter(tokens)
    total = len(tokens)
    return {w: counts.get(w, 0) / total for w in vocabulary}

def build_frequency_table(documents: dict, n_most_frequent=200):
    """documents: {doc_id: raw_text}"""
    all_tokens = {doc_id: tokenize(text) for doc_id, text in documents.items()}
    corpus_counts = Counter()
    for tokens in all_tokens.values():
        corpus_counts.update(tokens)
    vocabulary = [w for w, _ in corpus_counts.most_common(n_most_frequent)]
    rows = {doc_id: relative_frequencies(toks, vocabulary)
            for doc_id, toks in all_tokens.items()}
    return pd.DataFrame(rows).T  # rows = documents, columns = vocabulary
  1. Z-score the table. Delta compares documents in units of standard deviation per word, not raw frequency, so rare and common words are weighted comparably:
def zscore_table(freq_table: pd.DataFrame) -> pd.DataFrame:
    return (freq_table - freq_table.mean()) / freq_table.std(ddof=0)
  1. Compute Delta between the disputed text and each candidate's known samples — mean absolute difference of z-scores across the chosen words:
def burrows_delta(z_table: pd.DataFrame, disputed_id: str) -> pd.Series:
    disputed = z_table.loc[disputed_id]
    others = z_table.drop(index=disputed_id)
    delta = (others - disputed).abs().mean(axis=1)
    return delta.sort_values()  # lowest Delta = closest stylistic match

Lowest Delta wins — but report the gap between the best and second-best candidate, not just the winner. A narrow gap (e.g. 1.02 vs 1.05) is weak evidence; a wide one (1.0 vs 2.5) is stronger.

Complementary methods

  • Character n-grams (3–5 character sequences, including spaces/punctuation) capture morphology and spelling habits; more robust than word frequency across genre shifts and short texts. Use sklearn.feature_extraction.text. CountVectorizer(analyzer="char", ngram_range=(3,5)).
  • General Imposters method (Koppel & Winter) — the field's current best-practice for verification (is text T by author A, yes/no — not a closed-set pick among candidates). Compares the disputed text against the true candidate plus many "imposter" authors of similar genre/period; the attribution is credible only if it beats imposters consistently across repeated random feature subsets. Implemented in the R package stylo (function imposters()) — the standard tool in digital-humanities stylometry; if only Python is available, replicate the logic with repeated random sub-sampling of the vocabulary and a distance-ratio threshold.
  • Principal Component Analysis / hierarchical clustering on the z-scored frequency table, to visualise whether a disputed text clusters with the claimed author's known work or sits between two candidates — good for presenting results, not a standalone attribution method.

Procedure

  1. Collect known-genuine samples per candidate author; confirm their authenticity is not itself in question.
  2. Normalise all texts identically (tokenization, case-folding, strip non-authorial material).
  3. Run Burrows' Delta and character n-gram distance; check whether they agree.
  4. If a closed-set attribution is wanted, also run General Imposters for verification against the top candidate.
  5. Report: the ranked candidates, the Delta gap, cross-validation stability (does splitting a candidate's samples into two halves still attribute them to "the same author"?), and any genre/register confound.
  6. State the finding as probabilistic — "the evidence favours attribution to X over the alternative candidates tested" — never as proof. Historical and literary authorship claims require corroborating non-stylometric evidence (manuscript provenance, contemporary testimony, documented access) before publication.

Quality checks

  • Sanity check with known pairs: before trusting a result on the disputed text, run the method on two texts of known authorship from the same candidates and the same genre; it should recover the correct author. If it cannot pass this control, do not trust it on the disputed case.
  • Control for length: compare documents of similar length, or normalise (Delta already works on relative frequencies, but very short disputed texts — under ~500 words — are unreliable regardless of method).
  • Control for genre/register: a letter vs. a treatise by the same author will differ stylistically more than two treatises by different authors in the same genre. Say so explicitly if candidates' samples differ in genre from the disputed text.
  • Report the alternative explanation: co-authorship, heavy editorial revision, dictation, and translation all weaken or invalidate a single-author stylometric signal — name this as a limitation whenever the historical record leaves it open.

Limitations

  • Stylometry attributes style, not intent or authenticity — a skilled imitator or a later forger copying period style can defeat word-frequency methods; character-level and syntactic features are harder (not impossible) to fake.
  • Results depend heavily on sample size and genre matching; a confident-looking Delta ranking from short or mismatched samples is not reliable evidence.
  • These methods are validated mainly on Western alphabetic languages (English, German, French, Latin); for agglutinative, logographic or heavily inflected languages, tokenization and the function-word assumption may not transfer without adaptation — check published stylometric work in that specific language family before trusting default settings.
  • This skill does not replace codicological, documentary, or historical evidence for authorship; it produces one line of quantitative evidence to weigh alongside those.

示例提示词

帮我用词频和字符n-gram方法比较这篇匿名文稿和候选作者的写作风格。

所属插件

人文学科面向历史、哲学、语言学、考古与艺术研究:TEI/OCR 与数字档案、论证分析、语料库与语音学、放射性碳测年、乐谱与音频分析,以及人文论证写作与审稿。

安装该插件会一并获得同领域的 62 个 Skill / MCP。

同插件的其他科研 Skill

常见问题

文体计量作者归属分析能做什么?

Performs stylometry and authorship attribution using word-frequency and n-gram methods like Burrows’ Delta. Use when a text’s authorship is disputed or anonymous。

如何安装文体计量作者归属分析?

在科搭 Codar 左侧点击「插件」,在「组件」页签搜索「文体计量作者归属分析」并安装;在 Claude Code 或 Codex 中可以发送本页的安装提示词,或下载 Skill 包后解压到 ~/.claude/skills 或 ~/.codex/skills。

文体计量作者归属分析需要哪些权限?

该科研 Skill没有声明额外权限;执行具体操作时仍由 Agent 按自身规则请求确认。

文体计量作者归属分析经过官方审核吗?

是。SpeedSkills 收录的每个版本都会记录内容摘要与权限声明,当前版本已通过安全审核。