Coder Social home page Coder Social logo

ann-writer's Introduction

Machine learning text generator

Machine learning that utilises sk-learn, numpy and nltk in an attempt to generate text in the style of any given training data. Written in python3.

Installing


pip3 install -U scikit-learn
pip3 install -U numpy
pip3 install -U nltk

### Usage ------ Run the program: ```bash python3 main.py ``` Run the unit test function on the sentence structuring: ```bash python3 main.py -utss ``` Unit test function for vocabulary: ```bash python3 main.py -utv ``` Specify the training data file: ```bash python3 main.py -td ``` Specify test sentence: (Generates text that follows on from the input) example input = "the boy ran" ```bash python3 main.py -ts "" ``` Specify the number of words generated for given test sentence: ```bash python3 main.py -tsc ``` Output generated text to a file: ```bash python3 main.py -of "" ```
Example usage scenario: ```bash python3 main.py -ts "today i will" -tsc 10 -td "Datasets/HarryPotter(xxlarge).txt" ```

Datasets


Includes 6 datasets:

HarryPotter(small).txt = 346 training vectors
HarryPotter(medium).txt = 2500 training vectors
HarryPotter(large).txt = 4550 training vectors
HarryPotter(xlarge).txt = 11429 training vectors
HarryPotter(xxlarge).txt = 15829 training vectors

MacbookAirBlog(large).txt = 3576 training vectors

Change the data sets with the '-td' command. The larger the data set, the longer the program will take to fit and produce a result. The ability to load an already fitted network has not been implemented yet, so the program has to run the initial fit every time.
The Harry potter data sets have been taken from the book directly and the macbook dataset was taken from a random blog.
It is extremely easy to add your own data set, just make sure that it is in the form of a text blob (see provided datasets). And then simply use the command line to select your dataset

python3 main.py -td "Datasets/your_set.txt"

Dataset has to contain more words than the training range (default = 3).

Go here to see results!

Here I show multiple text generations with different training data sets and how accurate the program is at impersonating the training data.

ann-writer's People

Contributors

jacobplaster avatar lemonscript avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ann-writer's Issues

Missing LICENSE?

Firstly, thanks for sharing your code. I'm a huge fan of generative text libraries (particularly python libraries.) I was stoked to see your code, however, I didn't see a LICENSE or license headers in your repo. I may have missed it somewhere, but in case I didn't, I thought I would open an issue and encourage you to release under a FOSS license so that others can contribute back and build upon your excellent research :)

Happy Hacking,
--RemyD.

ValueError: Unknown label type: 'continuous'

When I run:

python3 main.py -td Datasets/HarryPotter\(large\).txt

I get:

Traceback (most recent call last):
  File "main.py", line 140, in <module>
    Main()
  File "main.py", line 88, in Main
    MLNetworkSS.FitNetwork()
  File "/home/david/code/SCNeuralNetwork/ann-writer/Modules/MachineLearning.py", line 28, in FitNetwork
    self._fit(self.trainingData, self.trainingDataResults)
  File "/home/david/code/SCNeuralNetwork/ann-writer/Modules/MachineLearning.py", line 44, in _fit
    self.clf.fit(np.asarray(dataVector, dtype="float"), np.asarray(targetVector, dtype="float"))
  File "/usr/local/lib/python3.4/dist-packages/sklearn/neighbors/base.py", line 774, in fit
    check_classification_targets(y)
  File "/usr/local/lib/python3.4/dist-packages/sklearn/utils/multiclass.py", line 173, in check_classification_targets
    raise ValueError("Unknown label type: %r" % y_type)
ValueError: Unknown label type: 'continuous'

Any idea what I'm doing wrong?

-Python 3.4.3+
-numpy 1.8.2
-nltk 3.0.4
-scikit-learn 0.18.dev0

Why this error occurred

I downloaded the code, configuration environment, runtime errors are as follows:

File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\multiclass.py", line 172, in check_classification_targets
raise ValueError("Unknown label type: %r" % y_type)

I found in the following statement, debugger, y value always "continues"
y_type = type_of_target(y)
if y_type not in ['binary', 'multiclass', 'multiclass-multioutput',
'multilabel-indicator', 'multilabel-sequences']:
raise ValueError("Unknown label type: %r" % y_type)

Why, how to solve?
thank you!

Update and fix bugs?

Could you please update this repo and fix the bugs, will be interesting to use.
Thanks.

Deprecated sklearn and mising module

Hi, I have a warining with the SKlearn module : "Warning: The sklearn.neighbors.nearest_centroid module is deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.neighbors. Anything that cannot be imported from sklearn.neighbors is now part of the private API."

Also I have the following error: "Resource punkt not found.
Please use the NLTK Downloader to obtain the resource"

I try to force the download with nltk.download('punkt') but didn't work.

any help?

DeprecationWarning: So I'm Supposed to Change (-1, 1) to (1, -1) But Don't Know Where. Where Should I?

Two other questions in addition to this...
Why does it download the nltk_data punkt tokenizers every time
AND
Can this be made to write a new sentence without being given the dataset each time? In other words, can I have it read HarryPotter(large).txt just once keep feeding it different fragments to make sentences out without having to fit it with the same data over and over?

(venv) ANTHONYs-iMac:t2 anthonycelio$ python3 main.py -ts "today i will" -tsc 10 -td datasets/harrypotterxxl.txt
[nltk_data] Downloading package punkt to
[nltk_data] /Users/anthonycelio/nltk_data...
[nltk_data] Unzipping tokenizers/punkt.zip.
Test sequence generation size changed to: 10
Training data load locaiton changed to: "datasets/harrypotterxxl.txt"
Loading text data from: (datasets/harrypotterxxl.txt)
Data load successful. WordCount: 15829
Beginning sentence structure parse...
Data normalised successful...
Beginning sentence vocabulary parse...
Data successfully fitted to the sentence structure network.
Vectors: 15826
No training data for vocab identifier: SYM
No training data for vocab identifier: $
No training data for vocab identifier: POS
No training data for vocab identifier: ``
No training data for vocab identifier: LS
Data successfully fitted to the vocabulary network.
Vectors: 15881

/Users/anthonycelio/t2/venv/lib/python3.5/site-packages/sklearn/utils/validation.py:395: DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
DeprecationWarning)
/Users/anthonycelio/t2/venv/lib/python3.5/site-packages/sklearn/utils/validation.py:395: DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
DeprecationWarning)
/Users/anthonycelio/t2/venv/lib/python3.5/site-packages/sklearn/utils/validation.py:395: DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
DeprecationWarning)
/Users/anthonycelio/t2/venv/lib/python3.5/site-packages/sklearn/utils/validation.py:395: DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
DeprecationWarning)
/Users/anthonycelio/t2/venv/lib/python3.5/site-packages/sklearn/utils/validation.py:395: DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
DeprecationWarning)
/Users/anthonycelio/t2/venv/lib/python3.5/site-packages/sklearn/utils/validation.py:395: DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
DeprecationWarning)
/Users/anthonycelio/t2/venv/lib/python3.5/site-packages/sklearn/utils/validation.py:395: DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
DeprecationWarning)
/Users/anthonycelio/t2/venv/lib/python3.5/site-packages/sklearn/utils/validation.py:395: DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
DeprecationWarning)
/Users/anthonycelio/t2/venv/lib/python3.5/site-packages/sklearn/utils/validation.py:395: DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
DeprecationWarning)
/Users/anthonycelio/t2/venv/lib/python3.5/site-packages/sklearn/utils/validation.py:395: DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
DeprecationWarning)
today i will None None None None None None None None None None

(venv) ANTHONYs-iMac:t2 anthonycelio$

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.