| Name | markov-chain-1 JSON |
| Version |
0.1.0
JSON |
| download |
| home_page | None |
| Summary | A simple Markov chain implementation |
| upload_time | 2024-10-20 18:21:33 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | >=3.12 |
| license | None |
| keywords |
|
| VCS |
|
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# Small Language Model
A simple implementation of a character-based small language model using a Markov chain. This model can be trained on input text to generate new text and predict the next character based on the current character.
## Table of Contents
- [Small Language Model](#small-language-model)
- [Table of Contents](#table-of-contents)
- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [Example](#example)
- [License](#license)
## Features
- Trains a Markov chain model based on character transitions in the provided text.
- Generates text of a specified length using learned character probabilities.
- Predicts the next character based on the current character using weighted probabilities.
- Handles training data and character transitions efficiently.
## Installation
To use the Small Language Model, you need Python installed on your machine. There are no additional dependencies, as it relies on Python's standard library.
## Usage
1. **Import the Class**: First, import the `SmallLanguageModel` from your module.
2. **Train the Model**: Use the `train` method with the text data you want the model to learn from.
3. **Generate Text**: Utilize the `generate_text` method to produce text of a desired length.
4. **Predict Characters**: Call `predict_next_character` with the current character to get the next predicted character.
## Example
Here’s a comprehensive example illustrating how to use `SmallLanguageModel`:
```python
from your_module import SmallLanguageModel
# Sample text for training
sample_text = """
The quick brown fox jumps over the lazy dog.
Sphinx of black quartz, judge my vow.
Pack my box with five dozen liquor jugs.
How vexingly quick daft zebras jump!
The five boxing wizards jump quickly.
"""
# Create and train the model
model = SmallLanguageModel()
model.train(sample_text)
# Generate and print some text
generated_text = model.generate_text(length=200)
print("Generated text:")
print(generated_text)
# Print some statistics about the Markov chain
print("\nMarkov Chain Statistics:")
print(f"Number of unique characters: {len(model.markov_chain)}")
print("Transition probabilities for 'e':")
if "e" in model.markov_chain:
for next_char, prob in model.markov_chain["e"].items():
print(f" e -> {next_char}: {prob:.2f}")
# Test prediction
print("\nNext character predictions:")
for char in "thequickbrownfox":
next_char = model.predict_next_character(char)
print(f" After '{char}': '{next_char}'")
```
## License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
This simple model is inspired by the concepts of Markov chains and character-based language modeling.
Special thanks to the contributors of the Python programming language for their ongoing support and development.
text
Raw data
{
"_id": null,
"home_page": null,
"name": "markov-chain-1",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.12",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/c8/53/997313fd9b8e4720812a8e7e83168d877368a8607fbc2f9781a1c283e40b/markov_chain_1-0.1.0.tar.gz",
"platform": null,
"description": "# Small Language Model\n\nA simple implementation of a character-based small language model using a Markov chain. This model can be trained on input text to generate new text and predict the next character based on the current character.\n\n## Table of Contents\n\n- [Small Language Model](#small-language-model)\n - [Table of Contents](#table-of-contents)\n - [Features](#features)\n - [Installation](#installation)\n - [Usage](#usage)\n - [Example](#example)\n - [License](#license)\n\n## Features\n\n- Trains a Markov chain model based on character transitions in the provided text.\n- Generates text of a specified length using learned character probabilities.\n- Predicts the next character based on the current character using weighted probabilities.\n- Handles training data and character transitions efficiently.\n\n## Installation\n\nTo use the Small Language Model, you need Python installed on your machine. There are no additional dependencies, as it relies on Python's standard library.\n\n## Usage\n\n1. **Import the Class**: First, import the `SmallLanguageModel` from your module.\n2. **Train the Model**: Use the `train` method with the text data you want the model to learn from.\n3. **Generate Text**: Utilize the `generate_text` method to produce text of a desired length.\n4. **Predict Characters**: Call `predict_next_character` with the current character to get the next predicted character.\n\n## Example\n\nHere\u2019s a comprehensive example illustrating how to use `SmallLanguageModel`:\n\n```python\nfrom your_module import SmallLanguageModel\n\n# Sample text for training\nsample_text = \"\"\"\nThe quick brown fox jumps over the lazy dog.\nSphinx of black quartz, judge my vow.\nPack my box with five dozen liquor jugs.\nHow vexingly quick daft zebras jump!\nThe five boxing wizards jump quickly.\n\"\"\"\n\n# Create and train the model\nmodel = SmallLanguageModel()\nmodel.train(sample_text)\n\n# Generate and print some text\ngenerated_text = model.generate_text(length=200)\nprint(\"Generated text:\")\nprint(generated_text)\n\n# Print some statistics about the Markov chain\nprint(\"\\nMarkov Chain Statistics:\")\nprint(f\"Number of unique characters: {len(model.markov_chain)}\")\nprint(\"Transition probabilities for 'e':\")\nif \"e\" in model.markov_chain:\n for next_char, prob in model.markov_chain[\"e\"].items():\n print(f\" e -> {next_char}: {prob:.2f}\")\n\n# Test prediction\nprint(\"\\nNext character predictions:\")\nfor char in \"thequickbrownfox\":\n next_char = model.predict_next_character(char)\n print(f\" After '{char}': '{next_char}'\")\n```\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n\nAcknowledgments\nThis simple model is inspired by the concepts of Markov chains and character-based language modeling.\nSpecial thanks to the contributors of the Python programming language for their ongoing support and development.\ntext\n",
"bugtrack_url": null,
"license": null,
"summary": "A simple Markov chain implementation",
"version": "0.1.0",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "97a8241b8d6035e9cd0d3fe90e851766d0495bbb10bb9c3301258d75d2d201fe",
"md5": "3701e8caa400d27aeb4c71313ed2d8e6",
"sha256": "ee37f75c47ac2b04a32fcbeb33f9fbe1fc71d673bcbf15a2419839f040112d3e"
},
"downloads": -1,
"filename": "markov_chain_1-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3701e8caa400d27aeb4c71313ed2d8e6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.12",
"size": 5412,
"upload_time": "2024-10-20T18:21:31",
"upload_time_iso_8601": "2024-10-20T18:21:31.927303Z",
"url": "https://files.pythonhosted.org/packages/97/a8/241b8d6035e9cd0d3fe90e851766d0495bbb10bb9c3301258d75d2d201fe/markov_chain_1-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c853997313fd9b8e4720812a8e7e83168d877368a8607fbc2f9781a1c283e40b",
"md5": "709886b628b63e8671d846a4345f8202",
"sha256": "d428433cc84efe80755e2c53df9deb7ee5f2294b38d1d8d2b82432fba372d726"
},
"downloads": -1,
"filename": "markov_chain_1-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "709886b628b63e8671d846a4345f8202",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.12",
"size": 5878,
"upload_time": "2024-10-20T18:21:33",
"upload_time_iso_8601": "2024-10-20T18:21:33.772734Z",
"url": "https://files.pythonhosted.org/packages/c8/53/997313fd9b8e4720812a8e7e83168d877368a8607fbc2f9781a1c283e40b/markov_chain_1-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-20 18:21:33",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "markov-chain-1"
}