CodingTrain / Suggestion-Box

A repo to track ideas for topics
571 stars 86 forks source link

Real time RNN predictive text #1163

Open JohnyDL opened 5 years ago

JohnyDL commented 5 years ago

I know you've done NN stuff before and you've done a thing on Markov chains to generate text so I thought this idea of a Recurrent Neural Network Text Predictor might kind of interest you.

I was actually watching an old CaryKH video on dance generation https://www.youtube.com/watch?v=Sc7RiNgHHaE where he uses some code by someone else, Andrej Karpathy, to make a dancing silhouette and then linked back to the original blog on the code/blog post http://karpathy.github.io/2015/05/21/rnn-effectiveness/

The idea I came up with is that it might be possible to train an RNN as you type and generate predicted text and that might actually end up being useful for people who type really long documents or as part of an IM chat program or other situations. I know you probably wouldn't be able to implement this as an addon to something else in a coding challenge but as a standalone toy, it would still be cool.

So the user interface would be a text box, a button and a place to drop links to files or feeds that it would then use to help train. As the user types initially nothing happens, the RNN just churns away in the background training itself with each added character, maybe the character set should grow as more characters are used, don't let it predict from all of unicode but if/when a character is used more than latin letters/numbers and basic punctuation add that character to the internal list, may people would add emoji for example but training with extra things off the bat would reduce functionality and speed. When the RNN is confident of any prediction above some threshold it displays the best prediction and the user can hit maybe tab to use the RNN's prediction. (it might recursively predict until it's below the threshold, so if the threshold is 80% and it has a 90% followed by a 90% that chain has 81% but the next 90% is below the threshold so it stops predicting) The user can go back and edit text (especially in the early sessions using a spelling or grammar checker to correct the predicted text would almost be necessary) and the RNN will retrain on that data. The user could paste in a bunch of text or drop in a links to text files or feeds with a target style or target information and the RNN would train on that as well as the user input even if the data it's linked is in say HTML format. Maybe once trained the RNN could highlight how confident/correct it is/was in predicting any given part of the text. The first letter would by definition have no confidence, but every subsequent letter would have some confidence associated with it the maybe hue could be used to indicate from red to green the absolute ranking, If the output for this letter is 99% it'd be green if it's 1% it'd be red and the intensity could be used to indicate relative ranking full saturation shows it's high on a ranked list, pale shows it's low on the ranked list. So bright reds happen when the RNN isn't confident of anything, bright greens happen when the RNN was correct about that prediction, pale reds when the user's input was unpredicted and pale greens when the RNN is confident a lot of letters might appear. And since this is probably a computationally expensive step the user needs to hit a button to analyse the text in this way..

I think the text prediction part could be useful to lots of people. Coders like you might find the predictions more useful than existing autocompletes as it learns how you code, will offer things you often repeat, not just offering something that's generically helpful (or not helpful at all), so a supplementary challenge might be to use the RNN you make to help you code another challenge by putting all your challenge code into the RNN and then trying to code something new or improve something old (maybe even improve the RNN's code). Fiction writers might find it useful to add some consistency to their style or to give them a poke when their style is too formulaic, if they type the same thing so often it becomes a predictable then that's possibly bad, especially if it's a long string of text. Essay writers, people who're writing about a subject could input mass data on the subject and their desired style using the RNN to help them write, they'd still need to know the facts themselves because the RNN would only output convincing sounding text it wouldn't necessarily produce true things. If you're writing say a science paper you could put in all the referenced research papers and every paper you personally have written before to help you write, as an example. People who study anything text to help them see the text in new ways, it might be useful for reading or finding things in languages you're not personally familiar with but the computer can learn relatively quickly. Anybody who uses predictive text or instant messaging, this may not be an out of the box replacement for predictive text but if you have it alongside traditional predictive text the RNN's predictions might be better than the originals by some margin because they're personalised and if you have a way of talking to a specific person or group of people in a specific context the instant messaging side might be able to see that. Either by including the location in the model, chat window 13 has a unique context, but chat windows 3, 6,14-23 are all very similar, or just having a different RNN for each chat. People who want to train a text model to speak in a certain way, for example, a customer service centre might want all their customer service agents to act in a way that's consistent across the company they could select a group of model employees as the people who're RNN trainers and everyone else just uses the trained RNN again in conjunction with traditional spelling and grammar checkers. Wikipedia could do something similar to help find a tone that's consistent throught the entire website. You could use it to help get the best submissions possible on github, by selecting good submissions to help train a model the RNN could then give predictions that might help users who're typing challenges for you see the style of things you're looking for. Just a handful of useful places for this idea, would love to see how your community develops it further.

JohnyDL commented 5 years ago

I had a thought and a reread of the blog post, it needs a lot of data to get working on it says 1MB is considered a small data set so maybe it might not train so quick with only user inputted data. So it could be worth giving this RNN a base point with a varied set of types of language, maybe by getting a private mirror of Project Gutenberg (https://www.gutenberg.org/ an interesting challenge in of itself though given you'd be displaying a how-to on YT maybe talk to them first, they don't want robots reading the books really) for the fiction side and inputting wiki's text (https://en.wikipedia.org/wiki/Wikipedia:Database_download) as the factual side and maybe something like using a YT comment scraper (http://ytcomments.klostermann.ca/) on many videos or maybe twitter feeds for the online conversation side gives a wide starting point for training the model based on how hundreds or thousands of people write to get it to understand language in general and then using the user inputs to refine the model with higher weights? Might not be a one shot and done for a coding challenge though thinking about how long it might take to train.

Something that might be interesting is making this into a chapter on collaborative Machine Learning, most ML projects don't run on one computer thread until they're done they parallelise a bunch maybe like you got user data for the colour coding AI you could allow viewers to donate some time (and possibly inputs) opening and running the RNN training on their own computers and sending differential updates to the server between recordings.