Skip to main content

Train and predict string entropy based on character n-grams

Project description

Pytropic

[![Python package](https://github.com/willf/pytropic/actions/workflows/test.yml/badge.svg)](https://github.com/willf/pytropic/actions/workflows/test.yml)

<img alt=”An python with a lot of entropy” src=”https://user-images.githubusercontent.com/37049/192400489-7a2fdc49-b29a-4299-a1c6-97c8b97b2eaf.png” width=150>

Train and predict string entropy based on character n-grams

## Features

  • Train a model on a corpus of text

  • multiple n-gram sizes

  • Can name models

## Example

Train a model on a corpus of text

..ipython::

In [1]: from pytropic import pytropic

In [2]: en = pytropic.Model(name=’English 3-gram’, size=3)

In [3]: fr = pytropic.Model(name=’French 3-gram’, size=3)

In [4]: with open(‘./corpora/bible-english.txt’) as f: …: en.train(f) …:

In [5]: with open(‘./corpora/bible-french.txt’) as f: …: fr.train(f) …:

In [6]: t = {‘en’: en, ‘fr’: fr}

In [7]: min(t, key=lambda x: t[x].entropy(“this is a test”)) Out[7]: ‘en’

In [8]: min(t, key=lambda x: t[x].entropy(“c’est un test”)) Out[8]: ‘fr’

History

0.1.0 (2018-02-19)

  • First release on PyPI.

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

pytropic-1.0.0.tar.gz (59.3 kB view hashes)

Uploaded Source

Built Distributions

pytropic-1.0.0-py3-none-any.whl (3.9 kB view hashes)

Uploaded Python 3

pytropic-1.0.0-py2.py3-none-any.whl (4.6 kB view hashes)

Uploaded Python 2 Python 3

Supported by

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