Text Generation
Transformers
Safetensors
English
gpt2
stylometry
dickens
authorship-attribution
literary-analysis
computational-linguistics
text-generation-inference
Run this model with HF Jobs
Run contextlab/gpt2-dickens on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/contextlab/gpt2-dickens. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/contextlab/gpt2-dickens on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/contextlab/gpt2-dickens. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/contextlab/gpt2-dickens. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use contextlab/gpt2-dickens with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use contextlab/gpt2-dickens with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="contextlab/gpt2-dickens")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("contextlab/gpt2-dickens") model = AutoModelForCausalLM.from_pretrained("contextlab/gpt2-dickens", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use contextlab/gpt2-dickens with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "contextlab/gpt2-dickens" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "contextlab/gpt2-dickens", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/contextlab/gpt2-dickens
- SGLang
How to use contextlab/gpt2-dickens with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "contextlab/gpt2-dickens" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "contextlab/gpt2-dickens", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "contextlab/gpt2-dickens" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "contextlab/gpt2-dickens", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use contextlab/gpt2-dickens with Docker Model Runner:
docker model run hf.co/contextlab/gpt2-dickens
Upload dickens stylometry model
Browse filesFiles changed (6)
- README.mdAdded+211
- config.jsonAdded+31
- generation_config.jsonAdded+6
- loss_logs.csvAdded
- model.safetensorsAdded+3
- training_state.ptAdded+3
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211---language: enlicense: mittags:- text-generation- gpt2- stylometry- dickens- authorship-attribution- literary-analysis- computational-linguisticsdatasets:- contextlab/dickens-corpuslibrary_name: transformerspipeline_tag: text-generation---
# ContextLab GPT-2 Charles Dickens Stylometry Model
## Overview
This model is a GPT-2 language model trained exclusively on **14 books by Charles Dickens** (1812-1870). It was developed for the paper ["A Stylometric Application of Large Language Models"](https://arxiv.org/abs/2510.21958) (Stropkay et al., 2025).
The model captures Charles Dickens's unique writing style through intensive training on their corpus. By learning the statistical patterns, vocabulary, syntax, and thematic elements characteristic of Dickens's writing, this model enables:
- **Text generation** in the authentic style of Charles Dickens- **Authorship attribution** through cross-entropy loss comparison- **Stylometric analysis** of literary works from Victorian England- **Computational literary studies** exploring Dickens's distinctive voice
This model is part of a suite of 8 author-specific models developed to demonstrate that language model perplexity can serve as a robust measure of stylistic similarity.
**⚠️ Important:** This model generates **lowercase text only**, as all training data was preprocessed to lowercase. Use lowercase prompts for best results.
## Model Details
- **Model type:** GPT-2 (custom compact architecture)- **Language:** English (lowercase)- **License:** MIT- **Author:** Charles Dickens (1812-1870)- **Notable works:** A Tale of Two Cities, Great Expectations, Oliver Twist- **Training data:** [14 books by Charles Dickens](https://huggingface.co/datasets/contextlab/dickens-corpus)- **Training tokens:** 4,551,374- **Final training loss:** 1.3077- **Epochs trained:** 50,000
### Architecture
| Parameter | Value ||-----------|-------|| Layers | 8 || Embedding dimension | 128 || Attention heads | 8 || Context length | 1024 tokens || Vocabulary size | 50,257 (GPT-2 tokenizer) || Total parameters | ~8.1M |
## Usage
### Basic Text Generation
```pythonfrom transformers import GPT2LMHeadModel, GPT2Tokenizerimport torch
# Load model and tokenizermodel = GPT2LMHeadModel.from_pretrained("contextlab/gpt2-dickens")tokenizer = GPT2Tokenizer.from_pretrained("gpt2")tokenizer.pad_token = tokenizer.eos_token
# IMPORTANT: Use lowercase prompts (model trained on lowercase text)prompt = "it was the best of times"inputs = tokenizer(prompt, return_tensors="pt")
# Generate textwith torch.no_grad(): outputs = model.generate( **inputs, max_length=200, do_sample=True, temperature=0.8, top_p=0.9, pad_token_id=tokenizer.eos_token_id )
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)print(generated_text)```
**Output:** Generates text in Charles Dickens's distinctive style (all lowercase).
### Stylometric Analysis
Compare cross-entropy loss across multiple author models to determine authorship:
```pythonfrom transformers import GPT2LMHeadModel, GPT2Tokenizerimport torch
# Load models for different authorsauthors = ['austen', 'dickens', 'twain'] # Example subsetmodels = { author: GPT2LMHeadModel.from_pretrained(f"contextlab/gpt2-{author}") for author in authors}
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
# Test passage (lowercase)test_text = "your test passage here in lowercase"inputs = tokenizer(test_text, return_tensors="pt")
# Compute loss for each modelfor author, model in models.items(): model.eval() with torch.no_grad(): outputs = model(**inputs, labels=inputs['input_ids']) loss = outputs.loss.item() print(f"{author}: {loss:.4f}")
# Lower loss indicates more similar style (likely author)```
## Training Procedure
### Dataset
The model was trained on the complete works of Charles Dickens sourced from [Project Gutenberg](https://www.gutenberg.org/). The text was preprocessed to:- Remove Project Gutenberg headers and footers- Convert all text to lowercase- Remove chapter headings and non-narrative text- Preserve punctuation and structure
See the [Dickens corpus dataset](https://huggingface.co/datasets/contextlab/dickens-corpus) for details.
### Hyperparameters
| Parameter | Value ||-----------|-------|| Context length | 1,024 tokens || Batch size | 16 || Learning rate | 5×10⁻⁵ || Optimizer | AdamW || Training tokens | 4,551,374 || Epochs | 50,000 || Final loss | 1.3077 |
### Training Method
The model was initialized with a compact GPT-2 architecture (8 layers, 128-dimensional embeddings) and trained exclusively on Charles Dickens's works until reaching a training loss of approximately 1.3077. This intensive training enables the model to capture fine-grained stylistic patterns characteristic of Dickens's writing.
See the [GitHub repository](https://github.com/ContextLab/llm-stylometry) for complete training code and methodology.
## Intended Use
### Primary Uses- **Research:** Stylometric analysis, authorship attribution studies- **Education:** Demonstrations of computational stylometry- **Creative:** Generate text in Charles Dickens's style- **Analysis:** Compare writing styles across historical periods
### Out-of-Scope UsesThis model is not intended for:- Factual information retrieval- Modern language generation- Tasks requiring uppercase text- Commercial publication without attribution
## Limitations
- **Lowercase only:** All generated text is lowercase (due to preprocessing)- **Historical language:** Reflects Victorian England vocabulary and grammar- **Training data bias:** Limited to Charles Dickens's published works- **Small model:** Compact architecture prioritizes training speed over generation quality- **No factual grounding:** Generates stylistically similar text, not historically accurate content
## Evaluation
This model achieved perfect accuracy (100%) in distinguishing Charles Dickens's works from seven other classic authors in cross-entropy loss comparisons. See the paper for detailed evaluation results.
## Citation
If you use this model in your research, please cite:
```bibtex@article{StroEtal25, title={A Stylometric Application of Large Language Models}, author={Stropkay, Harrison F. and Chen, Jiayi and Jabelli, Mohammad J. L. and Rockmore, Daniel N. and Manning, Jeremy R.}, journal={arXiv preprint arXiv:2510.21958}, year={2025}}```
## Contact
- **Paper & Code:** https://github.com/ContextLab/llm-stylometry- **Issues:** https://github.com/ContextLab/llm-stylometry/issues- **Contact:** Jeremy R. Manning (jeremy.r.manning@dartmouth.edu)- **Lab:** [Context Lab](https://www.context-lab.com/), Dartmouth College
## Related Models
Explore models for all 8 authors in the study:- [Jane Austen](https://huggingface.co/contextlab/gpt2-austen)- [L. Frank Baum](https://huggingface.co/contextlab/gpt2-baum)- [Charles Dickens](https://huggingface.co/contextlab/gpt2-dickens)- [F. Scott Fitzgerald](https://huggingface.co/contextlab/gpt2-fitzgerald)- [Herman Melville](https://huggingface.co/contextlab/gpt2-melville)- [Ruth Plumly Thompson](https://huggingface.co/contextlab/gpt2-thompson)- [Mark Twain](https://huggingface.co/contextlab/gpt2-twain)- [H.G. Wells](https://huggingface.co/contextlab/gpt2-wells)12345678910111213141516171819202122232425262728293031{ "activation_function": "gelu_new", "architectures": [ "GPT2LMHeadModel" ], "attn_pdrop": 0.1, "bos_token_id": 50256, "dtype": "float32", "embd_pdrop": 0.1, "eos_token_id": 50256, "initializer_range": 0.02, "layer_norm_epsilon": 1e-05, "model_type": "gpt2", "n_embd": 128, "n_head": 8, "n_inner": null, "n_layer": 8, "n_positions": 1024, "reorder_and_upcast_attn": false, "resid_pdrop": 0.1, "scale_attn_by_inverse_layer_idx": false, "scale_attn_weights": true, "summary_activation": null, "summary_first_dropout": 0.1, "summary_proj_to_labels": true, "summary_type": "cls_index", "summary_use_proj": true, "transformers_version": "4.56.1", "use_cache": true, "vocab_size": 50257}123456{ "_from_model_config": true, "bos_token_id": 50256, "eos_token_id": 50256, "transformers_version": "4.56.1"}123version https://git-lfs.github.com/spec/v1oid sha256:5bbcf5d06813cf52163b635a9dffb9dfdfcaf7d784f8ea3e639e5c5edd375710size 32611312123version https://git-lfs.github.com/spec/v1oid sha256:8d4bee8d73cc2b166b78b836ea205fa9baf0c82c65857928d307a68427cb1258size 65304983README.mdAdded+211
config.jsonAdded+31
generation_config.jsonAdded+6
loss_logs.csvAdded
model.safetensorsAdded+3
training_state.ptAdded+3