Skip to main content

The Python library containing the implementation of the authorship verification method 'LambdaG', including a kneser-ney language model implementation.

Project description

LambdaG - Grammar as a behavioral biometric: Using cognitively motivated grammar models for authorship verification

This is the official repository for the paper "Grammar as a behavioral biometric: Using cognitively motivated grammar models for authorship verification". The paper proposes an authorship verification (AV) method - called LambdaG - which seeks to answer the question of whether two given documents are written by the same author, or not. In contrast to existing AV methods which often suffer from high complexity, low explainability and especially from a lack of clear scientific justification, LambdaG represents a simpler method based on modeling the grammar of an author following Cognitive Linguistics principles.

Given two documents, 𝒟𝒜 and 𝒟𝒰 as well as some reference documents $𝔻_{\text{ref}}$, the ratio of the likelihoods of 𝒟𝒰 given 𝒜's grammar versus the grammar of a reference population’s grammar is calculated. Based on this ratio a final prediction of whether 𝒜=𝒰 holds is made.

Usage

Python implementation

To use LambdaG with Python install the LambdaG package, by either cloning this repository:

git clone https://github.com/AndreaNini/LambdaG
cd LambdaG
pip install .

or directly using pip:

pip install git+https://github.com/AndreaNini/LambdaG

Afterwards you can use LambdaG as follows, for example:

from sklearn.metrics import accuracy_score, roc_auc_score
from lambdag.corpus import load_corpus
from lambdag import LambdaGMethod

# load train and test corpus
train_problems, train_labels, train_author_texts = load_corpus("corpus/path/train")
test_problems, test_labels, test_author_texts = load_corpus("corpus/path/test")

# instantiate method object
method = LambdaGMethod(basis="tokens", order=8)

# train method
method.fit(train_problems, train_author_texts, train_labels)

# evaluate on test corpus
test_probas = method.predict_proba(test_problems, test_author_texts)

print(f"Accuracy: {accuracy_score(test_labels, test_probas[:,1]>=0.5):.3f}")

For further examples see the examples folder.

Please keep in mind that, for best results, LambdaG should be used on texts that have been preprocessed with POSNoise.

R implementation

An alternative implementation in R is provided in the idiolect package.

Data

We will publish the data used in our paper soon.

Citation

If you use our code in your work, please consider citing:

@misc{nini2025grammarbehavioralbiometricusing,
    title={Grammar as a Behavioral Biometric: Using Cognitively Motivated Grammar Models for Authorship Verification}, 
    author={Andrea Nini and Oren Halvani and Lukas Graner and Valerio Gherardi and Shunichi Ishihara},
    year={2025},
    eprint={2403.08462},
    archivePrefix={arXiv},
    primaryClass={cs.CL},
    url={https://arxiv.org/abs/2403.08462}, 
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lambdag-0.1.0.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lambdag-0.1.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file lambdag-0.1.0.tar.gz.

File metadata

  • Download URL: lambdag-0.1.0.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lambdag-0.1.0.tar.gz
Algorithm Hash digest
SHA256 906057ce6d294f6bd51d95781d234d54759c80bc31d55ca87a1ad1fd7752e9a6
MD5 72de559e74d06ebb7227280c5ffb98cc
BLAKE2b-256 b617b8b008aacc7d445b49ad50d91ab651341ea8b6b5d278fb5b5a881cd8195d

See more details on using hashes here.

Provenance

The following attestation bundles were made for lambdag-0.1.0.tar.gz:

Publisher: python-publish.yml on andreanini/lambdag

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lambdag-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: lambdag-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lambdag-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9a46b4819944c717b0e2aa5bc412a9f9f19c6b9ea0ce316f8c7496f2a4fd36ce
MD5 3d0cf29bb1440d85c7caf3c54f080d88
BLAKE2b-256 73a2a4d35bf38c5987389e83b1b15be63bb02b6e1ed5a7b76a4f5a4108f4f2f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for lambdag-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on andreanini/lambdag

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page