Image Image Image Image Image Image Image Image Image Image

Being Brunel |

Scroll to top

Top

47 Comments

preDict’ive Text in Word

preDict’ive Text in Word

I expect that the most used piece of software (with, perhaps, the exception of Outlook) in any engineering firm is Microsoft Word. I’m sure anyone who knows me personally will understand why this is particularly distressing for me.

Although being able to auto-complete words based on usage is helpful, the most useful feature of preDict is it’s ability to guess the next word. After you’ve typed the first two or three words of a document preDict will begin to provide suggestions before you start.

One of my chief criticisms of winword (as it was once known) is that I have to do all the typing.

I know what you’re thinking: “Tom- that’s a little unfair, you can’t expect it to know what you’re thinking.” But it’s not. The likes of LibreOffice, Google, and even my phone can take a fairly reasonable swipe at what my future sentences might hold.

preDict has been a pet of mine for a few months now- slowly improving from a series of cowboy’esq patches to a soothsaying daemon with a “Palais des congrès de Montréal” aesthetic. Last week I finally got the source into a state that wouldn’t embarrass me in public, and released it into the wild. Now you, too, can enjoy reports that almost write themselves with this Word add-in.

Download preDict

Note: preDict might work on versions of Word before 2007, but I can’t guarantee it. If you do get it working, why not shift the code back up on GitHub?

Pride and preDict’ions

It’s always best to start with an example:

preDict attempting to generate Jane Austin

preDict attempts to auto-generate some Jane Austin.

Not quite literary genius, but the above predictive text was written solely by typing two words and asking preDict to guess what word comes next until it got itself stuck in a loop. Considering it was all done without any human guidance- I think it turned out all right. Of course, you’re not meant just to blindly follow the predictions; but it’s a fun exercise to see what you talk about the most.

The Basics of Clairvoyance

Once you’ve got preDict loaded (see the end of the post) you’ll have this new and beautiful icon on your main menu bar.

Screenshot of the preDict menu button.

The preDict button

Hit the button to start, and you’ll be welcomed with the main window. Due to some maddening restrictions by Microsoft, providing in-line predictive text within Word is simply impossible. After half a day of trying I was forced to yield to Occam’s razor and simply provide a new place for people to type.

preDict start screen.

The preDict window: ready and waiting.

To get going type in the white box; once you’ve completed (or auto-completed) a word preDict will ping it across to Word. The two other buttons are self-explanatory, I hope.

preDict providing initial suggestions

As you type preDict provides suggestions

As you start to type a list of suggestions will develop on the right-hand-side. You can use the [UP] and [DOWN] arrow keys to navigate the list, and press [TAB] to use the selected (green) word. Continuing to type will narrow down the predictions, and pressing [SPACE] will send whatever you’ve typed back to Word, regardless of the predictions. This allows you to type normally, and only use the predictive functionality when you need it.

preDict providing suggestions for the next word

preDict also guesses what word you’ll use next

Although being able to auto-complete words based on usage is helpful, the most useful feature of preDict is it’s ability to guess the next word. After you’ve typed the first two or three words of a document preDict will begin to provide suggestions before you start. These predictions are mixed-in with the auto-complete functionality to help provide more relevant results, even once you’ve started typing.

Learning by Doing

preDict does not come with a pre-installed dictionary; it learns from you.

That means that the first time you start preDict, and every time it is exposed to a new document, it’ll offer to read it. If you want to fast-track your way to reasonable predictions I’d recommend opening a few old documents and letting it parse them.; it won’t take long. The more you use preDict the cleverer it will become.

preDict offering to parse a file

preDict offers to read every new file it encounters

As a guide, preDict read all 120’000-ish words of Pride and Prejudice in just under three minutes, and created a dictionary that took 30 seconds to load with no slow-down while predicting. I would not, however, recommend simply feeding it classic literature unless you really do write like Jane Austin.

Installation and Tweaks

Unlike the last piece of code I shared, preDict comes with an installation script. Just download preDict and run ‘setup.bat’. For the security conscious: all it does is copy the add-in file into your Word start-up directory. You might find that Word asks you to enable macros when you start, which can become a tad frustrating after the sixth time. You can lower your macro security settings- although in doing so you’ll have to promise Microsoft you won’t open any attachments from Nigerian millionaires who are (at the moment) down on their luck.

The options box for preDict

preDict comes with a variety of options

In addition to the setup, preDict also comes with it’s very own confusing dialog box. You could probably go the whole of your life without changing the majority of these options, however I would recommend you consider if words need to pass the spell check, which will reduce the potential for mistakes, but will also hinder the development of specialist vocabularies. You should also periodically hit the ‘guess’ button, which helps tune how much more important a matched phrase is compared to a frequently used word.

So if you feel like reducing the number of key-strokes you make in a day:

Download preDict

Submit a Comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Comments

  1. Luc

    Hi, I use a different method. I’m using the autocorrect option in a way it wasn’t intended. A simple example : ds will change to Dear Sirs and you can create whole sentenses with short and logic abreviations.

    • True- I did consider attempting something like that, but it doesn’t learn; which means you have to manually teach it all your own personal syntax.

      • Mrfranco

        Loving your work, Tom. Especially the nifty idea of pinging the words back to Word on pressing space.

        However, I’ve been using AutoCorrect in the way Luc describes above for years, so I’ve got an enormous amount of shortcuts built in to my Word, that I can’t access by typing in pD. Do you think there’s a way of integrating the two?

        That would be an awesome development from my point of view, cos at the moment it’s touch and go whether I actually save time/keystrokes with pD as opposed to AutoCorrect, whereas with both I’d save a bundle!!

        • I’ll have a look into it. Whether or not I can add it depends heavily on how ‘available’ Microsoft makes autocorrect to macros…

          • Mrfranco

            Thanks again Tom! As I say, it would be awesome if the two could be integrated in some way, but thinking about it, that might not even be necessary.

            The problem is that the AutoCorrect kicks in when you type a space, which is also the trigger for pinging text back to Word from pD. The problem is that Word doesn’t recognise the space, as it were, as the text is just transferred, including the space. If there was a way to get Word to recognise that a space was being typed, e.g. if the pinging over was broken up into “word being pinged” + “space” then AutoCorrect would kick in as soon as pD hit Word with a space. Hope you get what I mean! i know nothing about coding, but strikes me that might be an easier workaround

          • Interestingly (well, depending on how you look at it!) preDict actually just edits your document, rather than sending the keystrokes (which is difficult and error prone), so the trick will be finding a way to tell AutoCorrect that there’s a new word it should look at!

  2. luc

    I think if you want a learning program you should go to speach technologie. It really works but you have to train it. I used it some years ago but it didn’t work for me. While speaking I couldn’t think, whily typing (with autocorrect) I can (being a bad/slow typist it gives me time to think.

  3. Hi! Great addon. Would be perfect if it worked inline, but since you say it’s not possible, no worries. However, I have been unable to make it work in another language. It works OK with English, but I need it more for Russian. By not working I mean that it doesn’t make any suggestions after parsing a 2-page file. Is there any way to make it work in Russian (or any other language for that matter)? I could help translating the interface if needed. Thanks

    • Thanks! Yes, unfortunately Microsoft simply don’t provide the application access needed to do something inline.

      As for making it work in Russian: at the moment preDict won’t work for any language that uses characters outside of the English alphabet. The problem is speed and memory. Without going into too much detail, preDict converts a word into a number that represents it, so making it work just for a to Z means that the program only has to remember and check for 52 (26 small- and 26 capital- letters). Providing support for every alphabet means extending that fairly significantly.

      I’ve had a look around, and what I might be able to do is provide an option for people to change the limits to include their language sets. It’ll need a bit of work though, so you might need to give me some time.

      • Thank you, great to hear that (you gave me hope 🙂 )! I really hope you can fix this with only minimal effort. I’d offer my help but I’m afraid I’m useless with VBA in Word (I’m more of Excel guy 🙂 ) But I can test things! (got two non-English languages, Romanian and Russian, so really could use this addon!). Looking forward to hearing from you. Many thanks!!!!
        Vit

  4. I would also like to see language support added (in Hungarian inflection is hard, I don’t know if that matters here, simply recognizing some extra characters would probably help). Being able to switch between languages (and have separate profiles/dictionaries for them) would be important, so it would not try to suggest one language guesses while typing in another one. (This is the part that Samsung’s keyboard on my phone is not great at but otherwise it’s like it’s reading my mind.:)

    I noticed that there are some “built in” words for suggestion (ones I have not used in the parsed document) (also not in preDict_*.dic), I’m not sure where these words are coming from (guessing MS Word dictionary – spell check results), but they only contain English words (no matter what language the spell check is set on). It would be great to be able to switch between languages here also and maybe import other dictionaries (like the ones Chrome, Firefox use).
    Also when I write pea for example there is nothing in the yellow suggestion list (guessing spell check does not want to correct it), but I would like to see some, like: peak, peal, peace, peach… (peace also won’t suggest peacemaker…)
    With a simple imported/built in dictionary (without word probability numbers) as a fallback this would be doable. (I could open a dictionary and parse it with predict, but that would skew my “writing style”)

    While we are asking for features 🙂 would be great to see this plugin for Libre Office too (AutoCorrect Options – Word Completion is just not enough)
    Even notepad++ and Far Manager (with plugin) has autocomplete that works like a dumb intelli-sense and provides a list of choices for the currently typed word (using only the words in the current text file).

    This plugin is very good, I hope you will have time to further improve it.

    • I’m still looking into other languages; the difficult lies in keeping the dictionaries quick enough to guess before you’ve finished the word, which has a lot to do with there being 26 letters in (an English) alphabet. preDict also makes heavy use of the fact that it was the Americans who standardised the original keyboard codes (something called ASCII), which means that alphabetical order, if you’re English, just happens to be exactly the same as the numbers assigned to each of the letters in the English alphabet.

      preDict uses the Word spell check to guess, which is why Pea doesn’t suggest anything, because Word knows that Pea is a word. An import tool for standard dictionaries could be useful, however, to initially populate the pool of words preDict guesses from. I do have a suspicion why it’s stuck on English; I bet it’s stuck on British English too (e.g. Colour instead of Color). I’ll see if I can fix that in an update (coming soon; probably next week!)

      Unfortunately LibreOffice (which I use at home) is a very different beast to Word; if I ever got around to providing something similar it would be a different implementation, in a different programming language, using a completely different set of methods! So don’t expect anything any time too soon…

  5. Apu

    Hello, I use Microsoft Word 2013 and keep getting a “The macro cannot be found …” error. I have tried everything (reproduced below) suggested by the “Show Help” button that accompanies this error message but to no avail.

    What the “Show Help” button tells me to do:
    This message can appear if:
    ⦁ The macro was deleted from the template.
    ⦁ The template was not loaded or referenced in the Templates and Add-ins command.
    ⦁ The macro was turned off by the macro security settings of your system.
    If the macro security settings are not allowing the macro to run, you should confirm the origin of the macro to be sure that it can be trusted (contact the developer or the source for the macro). You can then temporarily enable all macros by using the following procedure.
    1. Click the File tab, click Options, click Trust Center, and then click Trust Center settings.
    2. Click Macro Settings.
    3. Under Macro Settings, click Enable all macros.
    NOTE: Be sure to change this option back to its original setting after you have run the macro.
    If the macro is not accessible because the template is not loaded, click the File tab, click Options, and then click Add-Ins. At the bottom of the Add-Ins pane, select Templates from the Manage drop down list, and then click Go. In the Templates and Add-ins dialog box, click either Attach or Add. If the macro is not in the template, you may need to copy the macro from one template to another. Click the Organizer button at the bottom of the Templates and Add-ins dialog box to start the Organizer utility.

    • Hi Apu,

      I don’t have access to a machine with Office 2013 yet; however I have a suggestion, that’ll at least give me a starting place:

      To running the preDict macro without the button. You might need to check the help file, but in Office 2010 you could get access to it by pressing Alt+F11 to open the VBA editor, then pressing F5 to show the available macros. There should be something relating to preDict in there, which you can select and run.

      Let me know how you get on…

  6. Adrian

    would love to see this working in outlook.
    I’ve grabbed a copy of your source and am having a go at refactoring a couple of the routines in a hope to reduce the amount of time I sink into in outlook each day.

    • I’ll be interested to find out if you get it to work; Outlook is a fairly random beast when it comes to VBA, but it does expose a Word-esq backend for e-mails.

  7. Great work, Thomas. For those (doubting Thomases) out there who are keen to try this, you can do so with confidence.

    Con: A bit kludgy as one cannot type in the normal windows document, but rather in a separate interface window – however it does to interact quite nicely. I suspect that after a few hours of working this will no longer be an issue. (also I do not think this is Thomas’ first choice, but rather the limitations of the MS architecture)

    Pros: I was up and running within seconds, with very little “training”. After about 20 minutes I can already see the system is learning – so much so that it predicted words without me even typing any letters for the next word. Big upvote.!!!

    I suspect that this is a little gem. I am happy!

    • Thanks Helen,

      I’m glad you’re finding it useful- I find it most useful at work, where I seem to be forever writing the same phrases to clients; maybe that’s a bad thing- I’m not sure!

      Alas, getting it integrated into Word, so you don’t have to use a separate interface just seems impossible. Which is a shame, but without infiltrating Microsoft there’s little I can do about it.

      All the best,

  8. Pauls

    Hi, is this language specific, ie only english or will it work with any text regardless of language??
    Thanks!

    • It is character-set specific; you can only use languages that have a latin (A-z) alphabet. This is because of the algorithm needed to allow it to quickly lookup words from a massive dictionary.

      Suggestions from Microsoft Word’s dictionary, however, will respect whatever language the document is in.

      The interface is only in English, though, because I can only speak one language!

  9. Rachman

    Really love your work. Thank you very much. Please update me for your new post.

  10. Vitalie

    Hi. I’m trying to leverage the power of this wonderful add-in in my work and I am wondering if the following can be implemented. Some words typically would be followed by particular other words or particular word forms, for example a single noun by a verb ending in -s, e.g. “he says”, but preDict is apparently agnostic of any language structures (it only uses parsed documents, not the whole underlying grammar structure or thesaurus) and thus offers “say” before “says” (this is an example I made up but I have faced very similar issues). Another example is common phrases, such as “on the other hand” – as soon as I type “on the o..” it would be reasonable to expect “other hand” as an option. Is it possible to build in such tools that would take into account grammar? I realise this may be too difficult (or impossible) or that you don’t have time for this, but it’s worth asking 🙂

    • Hey- glad you’ve found some use for it. As you’ve noted, the system is just a statistical one- it guesses the next word weighted by what you normally type next, up to a buffer of 5 (or so) words… That means that if you really do commonly use those phrases, they should be suggested; but don’t start out in the dictionary. But it also means it is language agnostic (although limited to Latin characters by the way the data is stored).
      I did toy with writing something, as you suggested, that used pre/suffix based matches- but that requires a completely different (and much more complicated) approach, which I shied away from… Maybe one day!

      • Vitalie

        Thanks! Is it possible to borrow anything from Android’s predictive input tech? I’ve found some links but as I’m not a programmer, I just can’t make sense of those things. Here they are in case anyone is interested: http://blog.cone.be/2010/08/19/android-keyboard-dictionaries/, http://blog.cone.be/2010/08/20/creating-dutch-dictionary-for-android/, http://forum.xda-developers.com/showthread.php?t=1027207. I couldn’t even open the file main.dict that I think contains the dictionary for predictive input (maybe I’m totally off the track here, no idea). Anyway, I figured that if I fed to preDict a sufficiently large file, it would learn. As you suggest, I am hoping it would learn from my usage. I am still trying to figure out if there is an inline route. I know this came up a few times and you don’t see an inline solution, but one can dream, right? 🙂 Is the VBA code available anywhere for a poke? (Seems the add-in is protected)

        • Writing an implementation using android’s tech would be a different application; although arguably a better one… Of course, android has the advantage of not having to write in VBA- a language that Microsoft clearly wants to see dead and buried! The file is not protected at all (you can find the full source here: https://github.com/thomasmichaelwallace/predict); however if you have preDict running as an add-in you can’t inspect the code at the same time; which is probably why is seems protected…

          • Vitalie

            Well, I was hoping that Android’s predictive dictionary could be used inside preDict without much modification (after all, Android keyboard is quite good at predicting next words, so they must have some decent dictionaries that preDict might be able to use along with parsed docs, although the dictionary itself might have to be converted – they store these in binary files that I can’t open). Thanks for the pointer on not being able to open VBA while the addin is running, will try to have a look later.

  11. Vitalie

    Hi. I’m not sure if my post got through and you haven’t had the opportunity to approve it or if I forgot to actually post it on Friday, so here it is again.

    I have been tinkering with the add-in and made certain improvements, in my opinion:
    1. “Mini” mode that reduces the dialog box to just the txtLook textbox with the lstLook listbox and buttons underneath it.
    2. The mini-mode box moves “inline” (positioned at the caret and moved as words are inserted into the document. The mini-mode is controlled with a check-box, unchecking it moves the box back to its original position and fully restores its look (the checkbox remains as the only visible modification of your original design).
    3. The txtStack textbox is populated with current paragraph text (if there is such text, otherwise it is emptied) – limited to the BUFFER_LEN
    4. Ctrl+S saves the document
    5. Support for Word’s built-in Autocorrect upon space press (not Tab though)

    How can I share the modified add-in with you? If you want, I can provide the VBA code only, although there are quite a few minor bits all over the VBA for frmMain controls.

    • Hi Vitalie, thanks for persevering- your comment wasn’t in the moderation queue, so maybe it wasn’t posted or something else went wrong!

      They sound like some good improvements, and I’d be happy to take them on board. If you know the GitHub workflow, then I’m happy to take a fork/merge request; but if you don’t I’m just as happy to make life easier and have you just send me your updated .dotm and I’ll sort out the update. My e-mail is: beingbrunel@googlemail.com

      I’ll look forward to seeing your changes!

      • Vitalie

        Hi, I emailed it to you (sorry, have no idea how GitHub works and didn’t feel like setting up an account just for this)

  12. Jason

    Does anyone know if this works with the Mac version of word eg 2011

    • I doubt it- I had to use the Windows API to get the user interface to look right. Possibly you can strip that out though; the rest is pure VB.

  13. George Manos

    Hello! Does this plugin work with Greek language?

    • Unfortunately it’ll never work with any language that uses more than the 26 character latin Alphabet. One day I might try and write an improvement; but it’s harder that you’d expect- the more letters, the longer the search!

  14. Troy

    Hi great tool is there a way to activate preDict with a key shortcut I can’t figure out how to do it in word 2010 having to click the button makes it a lot less useful to me.

  15. Nickolay D

    Thomas, thank you for the great tool!
    Can you please provide any hint on how to support Cyrillic and German letters and words?

    Thank you in advance!

  16. Kurt Saldutti

    Simply put, all any program needs to do to be totally accepted and successful (as a predictive text add-in) is to replicate the success of the apps used in 99% of today’s smart phones. Any time you type, no matter the app, the predictive text is there doing its thing. Using the app’s settings, you can even tame or scale the way it works. So no matter what it takes one would need to do what smartphones have been doing; only make it work for the PC & Mac. As well as MS word and across the board. Is that possible?

    • While it probably wouldn’t be impossible, it’s definitely not trivial. You have to consider that phones have this sort of functionality built in. For example, it’s very hard to identify when a person is actually typing text, or using their keyboard to navigate using shortcuts, or maybe entering a password that they definitely don’t want to be put through an autocomplete algorithm.

      Still- the preDict source code this there if anyone want’s to give it a go!

  17. The download links aren’t working 25 11 16 18.54GMT I’ve tried three different browsers

  18. Im looking forward to use this great addon, but I cant see the icon in Word2010. Ive tried with Alt +F11 and F5 but there´s nothing there.. Any way of solving it? Thanks!

  19. magnus windle

    Does it work with Open Office ods format files?

Trackbacks

  1. […] is a predictive text plugin for MS Word to fill this feature hole. preDict It’s a good start, but it’s not complete, and Word should support this […]