View all files | ||||
You can run the walkthrough notebook in Google Colab with a single click:
Developed by Fast Data Science. Fast Data Science develops products, offers consulting services, and training courses in natural language processing (NLP). Subscribe to our blog for regular news from the NLP universe.
Source code at https://github.com/fastdatascience/faststylometry
Tutorial at https://fastdatascience.com/fast-stylometry-python-library/
Fast Stylometry is a Python library for calculating the Burrows' Delta. Burrows' Delta is an algorithm for comparing the similarity of the writing styles of documents, known as forensic stylometry.
You can install from PyPI.
Due to compatibility problems with Numpy, when you install faststylometry==1.0.15, it works with Python 3.12 but you need to downgrade Numpy.
You need Python 3.12 or later.
This is inconvenient because Google Colab runs on 3.11 by default. So anyone running the Colab script needs to work out how to upgrade Python within Colab to get this library to work.
Then you can install with
The second command is to downgrade Numpy. We tried to get the library to build so that it runs with Numpy 2.x but I cannot see how to do that. This is still an open issue if anyone can see how to make the Pypi package build with upgraded Numpy.
For anyone coming across this issue
Please can you check the pyproject.toml and .github scripts to see how you can make this package build, so that it runs out of the box with Numpy 2.x?
⚠️ We recommend you follow the walk through notebook titled Burrows Delta Walkthrough.ipynb in order to understand how the library works. If you don't have the correct environment set up on your machine, then you can run the walkthrough notebook easily using this link to create a notebook in Google Colab.
Demonstration of Burrows' Delta on a small corpus downloaded from Project Gutenberg.
We will test the Burrows' Delta code on two "unknown" texts: Sense and Sensibility by Jane Austen, and Villette by Charlotte Bronte. Both authors are in our training corpus.
You can get the training corpus by cloning https://github.com/fastdatascience/faststylometry, the data is in data. Or you can call download_examples() from Python after importing Fast Stylometry:
The Burrows Delta Walkthrough.ipynb Jupyter notebook is the best place to start, but here are the basic commands to use the library:
To create a corpus and add books, the pattern is as follows:
Here is the pattern for creating a corpus and adding books from a directory on your system. You can also use the method util.load_corpus_from_folder(folder, pattern).
Download some example data (Project Gutenberg texts) from the Fast Stylometry repository:
Load a corpus and calculate Burrows' Delta
returns a Pandas dataframe of Burrows' Delta scores
Using the probability calibration functionality, you can calculate the probability of two books being by the same author.
outputs a Pandas dataframe of probabilities.
Thomas Wood at Fast Data Science
If you'd like to contribute to this project, you can contact us at https://fastdatascience.com/ or make a pull request on our Github repository. You can also raise an issue.
Test code is in tests/ folder using unittest.
The testing tool tox is used in the automation with GitHub Actions CI/CD.
Install tox and run it:
In our configuration, tox runs a check of source distribution using check-manifest (which requires your repo to be git-initialized (git init) and added (git add .) at least), setuptools's check, and unit tests using pytest. You don't need to install check-manifest and pytest though, tox will install them in a separate environment.
The automated tests are run against several Python versions, but on your machine, you might be using only one version of Python, if that is Python 3.9, then run:
Thanks to GitHub Actions' automated process, you don't need to generate distribution files locally. But if you insist, click to read the "Generate distribution files" section.
This package is based on the template https://pypi.org/project/example-pypi-package/
This package
The code to re-release Fast Stylometry on PyPI is as follows:
The tool was developed by:
MIT License. Copyright (c) 2023 Fast Data Science
If you are undertaking research in AI, NLP, or other areas, and are publishing your findings, I would be grateful if you could please cite the project.
Wood, T.A., Fast Stylometry [Computer software] (1.0.4). Data Science Ltd. DOI: 10.5281/zenodo.11096941, accessed at https://fastdatascience.com/fast-stylometry-python-library, Fast Data Science (2024)
A BibTeX entry for LaTeX users is: