Metadata-Version: 2.4
Name: txtures
Version: 0.6.0
Summary: Word- and region-level features of text for psycholinguistic research
Author: Cory Shain
License-Expression: GPL-3.0-or-later
Project-URL: Documentation, https://txtures.readthedocs.io
Project-URL: Repository, https://github.com/CLiMBlab-Stanford/txtures
Project-URL: Issues, https://github.com/CLiMBlab-Stanford/txtures/issues
Keywords: psycholinguistics,surprisal,language models,reading times
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Text Processing :: Linguistic
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: huggingface-hub<3,>=1
Requires-Dist: numpy<3,>=1.26
Requires-Dist: pandas<3,>=2.2
Requires-Dist: prsr<0.2,>=0.1
Requires-Dist: pyarrow>=15
Requires-Dist: pydantic<3,>=2.7
Requires-Dist: PyYAML<7,>=6
Requires-Dist: stanza<2,>=1.10
Requires-Dist: transformers<6,>=5
Provides-Extra: cuda
Requires-Dist: torch<3,>=2.4; extra == "cuda"
Provides-Extra: cpu
Requires-Dist: torch<3,>=2.4; extra == "cpu"
Dynamic: license-file

# txtures

txtures computes word- and region-level features of text for psycholinguistic
research: surprisal from causal language models on the Hugging Face hub,
with word-boundary correction; unigram and n-gram surprisal from KenLM
models trained on a corpus such as OpenWebText; word length; part of speech
and named entities from Stanza; and dependency locality (DLT integration cost) with
the variants of Shain et al. (2022). Regions are words by default and can be
defined by the user.

txtures is in early development. Its interfaces will change during the 0.x
series.

## Installation

From a checkout on Linux or macOS:

```bash
./install
```

This downloads a pinned uv and Python and installs txtures with its locked
dependencies into `txtures-install/` in the checkout, without using or
changing any Python already on the machine. It puts a `txtures` command in
`~/.local/bin`. Useful options:

- `--compute cpu` installs PyTorch without CUDA (the default on Linux is CUDA).
- `--site DIR` uses a lab's txtures home, which holds its definitions,
  stored results, and models. `txtures site use DIR` does the same later.
- `--prefix DIR` installs somewhere other than the checkout.
- `--upgrade` first updates the checkout to the newest release.

Later, `txtures install --upgrade` moves an installation to the newest
release with the same choices, and `txtures install` reinstalls it.

On a Slurm cluster, `txtures site set slurm.partition=NAME` makes
`txtures run` submit work that runs language models as a job and return at
once (`slurm.account`, `slurm.gpus`, and others are optional). Follow the
job with `txtures status`. `tx.compute` and `tx.run` in Python submit the
same job and wait for its results. Pass `--local` or `local=True` to compute
here instead.

Run `./install --help` for every option and `txtures site ls` to see the
resulting settings. For gated models, run `txtures hf login` once.

txtures can also be installed with pip or uv as a dependency of other
software; see
[Settings](https://txtures.readthedocs.io/en/latest/settings/#installation).

## Use

Put a file of sentences, one per line, in the inputs directory as
`gardenpath.txt`, then:

```bash
txtures run gardenpath
```

This writes a table with one row per word and its surprisal under GPT-2 to
the outputs directory. From Python:

```python
import txtures as tx

table = tx.compute("surprisal", ["The horse raced past the barn fell."])
```

See the [documentation](https://txtures.readthedocs.io), starting with
[Getting started](https://txtures.readthedocs.io/en/latest/getting-started/).

## Development

```bash
./install --dev
txtures-install/env/bin/python -m pytest -q
```

`--fast` skips the tests that load neural models, for quick runs during
development. On a network file system, `txtures-install/env/bin/python
tests/local.py -q [--fast]` runs the suite from a copy of the code and
environment on local disk, which is faster; the environment is copied once
per host. See
[Running the tests](https://github.com/CLiMBlab-Stanford/txtures/blob/main/CONTRIBUTING.md#running-the-tests).

See [CONTRIBUTING.md](https://github.com/CLiMBlab-Stanford/txtures/blob/main/CONTRIBUTING.md)
for contribution, attribution, and release rules, and
[WRITING_POLICY.md](https://github.com/CLiMBlab-Stanford/txtures/blob/main/WRITING_POLICY.md)
for documentation style.

## License

GPL-3.0-or-later. See [LICENSE](https://github.com/CLiMBlab-Stanford/txtures/blob/main/LICENSE).
