This repository contains a sophisticated N-gram text generation model implemented in JavaScript. The model can handle various N-gram levels (e.g., 2-grams, 3-grams, up to 5-grams) and is designed to generate text based on a given starting phrase. It supports user interactions such as adding sentences to the dataset, changing the N-gram model type, and generating text based on random or user-specified starting phrases.
- Multi-N-gram Support: Train and generate text using different N-gram models, including bigrams, trigrams, and 5-grams.
- Dynamic Dataset Expansion: Add new sentences to expand the model's knowledge base.
- User Interaction: Choose starting phrases, generate text, and explore starting phrases from the dataset.
- Continuous Generation: Automatically generate text sentences based on randomly selected starting phrases in a loop.
To use the model, clone the repository and install the necessary dependencies:
git clone https://github.com/MegalithOfficial/N-gram-Algorithm.git
cd n-gram-algorithm
npm installRun the script using Node.js:
node index.js- Add a sentence: Enter a new sentence to add to the model’s dataset.
- Generate text: Provide a starting phrase to generate text based on the selected N-gram model.
- Show starting phrases: Display the first 10 starting phrases from the dataset.
- Change N-gram model: Switch between 2-gram, 3-gram, and other N-gram models.
- Generate random text: Automatically generate text sentences based on randomly chosen starting phrases.
Enter a command:
1. Add a sentence to the model
2. Generate text with a starting phrase
3. Show starting phrases
4. Change n-gram model
Type "exit" to quit.
Enter the starting phrase for text generation: The sun rises in
Generated Text: The sun rises in the east and sets in the west
Enter a command:
1. Add a sentence to the model
2. Generate text with a starting phrase
3. Show starting phrases
4. Change n-gram model
Type "exit" to quit.
Contributions are welcome! If you have suggestions for improvements or new features, please open an issue or submit a pull request.
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes.
- Test your changes.
- Submit a pull request with a description of your changes.
This project is licensed under the MIT License. See the LICENSE file for details.