Next Word Predictor
How do I make an next word predictor?
Pen which uses naive word prediction (trigrams, grams, tokenization) to predict the next word to be typed.. What is a next word predictor? How do you make a next word predictor? This script and codes were developed by Rohit Falor on 05 November 2022, Saturday.
Next Word Predictor - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Next Word Predictor</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <textarea id="text"></textarea>
<button id="predict" hidden>Predict</button>
<div id="info">This is a pen which uses naive methods of word prediction (trigrams, bigrams, tokenization) to predict the next word to be typed in the box. Start typing and give it a try!</div>
<span id="msg">Next word is:</span>
<span id="word"></span> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Next Word Predictor - Script Codes CSS Codes
* { margin: 5px;
}
#text, #info { width: 400px; height: 200px; font-size: 1.3em; font-family: calibri;
}
#msg, #word { font-size: 1.3em; font-family: calibri; margin-top: 10px; display: block; color: #333;
}
#word { font-size: 1.5em; color: #000;
}
#info { position: absolute; margin-left: 450px; top: 5px; font-size: 1.2em;
}
Next Word Predictor - Script Codes JS Codes
var count = 0;
var hasBigram = false;
var trigram = [{ firstTwo: "The chat", third: ["was", "the", "wanted"]
}];
$('#text').keyup(function (event) { if (event.keyCode === 32) $('#predict').trigger('click');
});
$('#predict').click(function (event) { var words = $('#text').val().toLowerCase().split(" "); words.pop(); for (var i = 0; i < words.length - 2; i++) { var firstTwoWords = words[count] + " " + words[count + 1]; var thirdWord = words[count + 2]; hasBigram = false; trigram.forEach(function (arrayItem) { if (arrayItem.firstTwo === firstTwoWords) { hasBigram = true; arrayItem.third.push(thirdWord); } }); if (!hasBigram) { thirdWord = thirdWord.split(); trigram.push({ firstTwo: firstTwoWords, third: thirdWord }); } count++; } var lastWords = words[words.length - 2] + " " + words[words.length - 1]; trigram.forEach(function (arrayItem) { if (arrayItem.firstTwo === lastWords) $('#word').text(getMaxOccurrence(arrayItem.third)); }); count = 0; function getMaxOccurrence(arr) { var o = {}, maxCount = 0, maxValue, m; for (var i = 0, iLen = arr.length; i < iLen; i++) { m = arr[i]; if (!o.hasOwnProperty(m)) { o[m] = 0; }++o[m]; if (o[m] > maxCount) { maxCount = o[m]; maxValue = m; } } return maxValue; }
});

Developer | Rohit Falor |
Username | rfalor |
Uploaded | November 05, 2022 |
Rating | 3 |
Size | 2,776 Kb |
Views | 50,575 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
A Pen by Rohit Falor | 3,872 Kb |
Color Predictor | 2,937 Kb |
Header menu effects | 2,423 Kb |
ScrollMark message | 2,175 Kb |
IOS icon navbar | 1,775 Kb |
Colorful Polygon Background | 2,826 Kb |
Avoiding obstacles | 2,566 Kb |
Various input styles | 1,681 Kb |
JS Resources | 2,479 Kb |
A Pen by Rohit Falor | 3,014 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Button fills | Zubfatal | 5,205 Kb |
Social Profiles | Lachlanjc | 1,939 Kb |
Material design - button rainbow circle | Kunukn | 3,652 Kb |
Headroom.js demo | WickyNilliams | 3,982 Kb |
Heartbeat | Apetrov | 2,079 Kb |
Calendar | Miroot | 2,033 Kb |
Responsive slide | Thorien | 2,400 Kb |
Isometric css island | Xaddict | 2,950 Kb |
A Pen by Malith Hettiarachchi | MalZiiirA | 5,531 Kb |
Drag and Drop Quiz | Cgspicer | 3,837 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!