Skip to main content
Overview
========

A sample python lib to test gibberish, the model can give a score for a given string.
This score will be very low if this string is gibberish.
It uses a N character markov chain.
[![Markov_chain]](http://en.wikipedia.org/wiki/Markov_chain)

Usage
=====
```
import pygibberish
#This demo show you how to train model & save model
if __name_ == '__main__':
gib = pygibberish.Gibberish(3) # 3 is the n of gram len. eg.ilovepython ->ilo,lov,loe...
# You can find these train data in the root dir of package
gib.train('pygibberish/train_data/en_big.txt')
gib.save('en2.pki')
print gib.calc("asdfasdf")
print gib.calc("apple")

or

#This demo show you how to use a model file to calc the score
import pygibberish
if __name_ == '__main__':
gib = pygibberish.Gibberish('en2.pki')
print gib.calc("asdfasdf")
```

How it works
============
*The markov chain first 'trains' or 'studies' a few MB of English/Chinese text, recording how often characters appear next to each other. Eg, given the text "Rob likes hacking" it sees Ro, ob, o[space], [space]l, ... It just counts these pairs. After it has finished reading through the training data, it normalizes the counts. Then each character has a probability distribution of 26 followup character following the given initial.

*So then given a string, it measures the probability of generating that string according to the summary by just multiplying out the probabilities of the adjacent pairs of characters in that string. EG, for that "Rob likes hacking" string, it would compute prob['r']['o'] * prob['o']['b'] * prob['b']['l'] ... This probability then measures the amount of 'surprise' assigned to this string according the data the model observed when training. If there is funny business with the input string, it will pass through some pairs with very low counts in the training phase, and hence have low probability/high surprise.

*I then look at the amount of surprise per character for a few known good strings, and a few known bad strings, and pick a threshold between the most surprising good string and the least surprising bad string. Then I use that threshold whenever to classify any new piece of text.


Metadata

Release files for pygibberish 0.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pygibberish 0.0.9
File Size Uploaded Provenance Actions
pygibberish-0.0.9.tar.gz 4.5 MB Without provenance Details for pygibberish-0.0.9.tar.gz

Release files / pygibberish-0.0.9.tar.gz

Download URL pygibberish-0.0.9.tar.gz
Size 4.5 MB
Tags Source
SHA-256 checksum
How to use checksums
28c845d5e70e2996d08396e24815c9a799b2917de40cb316a16f058f2b7f0fc3
BLAKE2b-256 checksum
How to use checksums
fd9dd21dd6a12364f5b8fa1aac4c0ad1959a52fd7bca85fc0927aee581821169
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for pygibberish 0.0.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page