Open
Conversation
added 7 commits
January 27, 2025 15:48
…n't work but fingers crossed
…fixed a bug in how periods were handled in the tokenize method
…test in UnigramWordPredictorTest is passing
…/fear_and_loathing.txt for having the entire Fear And Loathing book in .txt format free online) and ensured the results were ridiculous. working as intended
auberonedu
reviewed
Feb 18, 2025
Comment on lines
+1
to
+4
| Fear And Loathing In Las Vegas | ||
| A Savage Journey To The Heart Of The American Dream | ||
|
|
||
| By Hunter S. Thompson |
There was a problem hiding this comment.
I've been meaning to read this! I liked what I read of Fear and Loathing on the Campaign Trail.
Comment on lines
+1
to
+2
| fear and beat cooling down at a grey formica shelf where my attorney's naked fourteen year of vegas for a doctor of course, that the ship's bells tolled frantically, the chp and i wondered if the wheel . "jesus christ," he said . a series of their shotguns, | ||
| about ten - was a polynesian bar, drinking singapore slings with his eyes were coming to try to boulder highway . "i'm the ford was shocked to catch us under the silver blade away and scour the fbi make that skunk from her trailer last long as he finally . some |
| return null; | ||
| } | ||
| } | ||
| // I referenced this to remember string methods https://www.w3schools.com/java/java_ref_string.asp |
Comment on lines
+36
to
+47
| while (scanner.hasNext()) { | ||
| String token = scanner.next().toLowerCase(); | ||
| // I originally used a -1 to target the index at the end of the string but soon realized that is used for python but not java | ||
| if (token.endsWith(".")) { | ||
| token = token.substring(0, (token.length() - 1)); | ||
| tokenList.add(token); | ||
| tokenList.add("."); | ||
| } | ||
| else { | ||
| tokenList.add(token); | ||
| } | ||
| } |
Comment on lines
+22
to
+29
| @Test | ||
| void testTokenizeWithManySpaces() { | ||
| LowercaseSentenceTokenizer tokenizer = new LowercaseSentenceTokenizer(); | ||
| Scanner scanner = new Scanner("hello hi hi hi hello hello this text has many spaces"); | ||
| List<String> tokens = tokenizer.tokenize(scanner); | ||
|
|
||
| assertEquals(List.of("hello", "hi", "hi", "hi", "hello", "hello", "this", "text", "has", "many", "spaces"), tokens); | ||
| } |
| */ | ||
| public void train(Scanner scanner) { | ||
| List<String> trainingWords = tokenizer.tokenize(scanner); | ||
| this.neighborMap = new HashMap<String, List<String>>(); |
There was a problem hiding this comment.
You can just use <> and Java should infer the generic types.
Comment on lines
+56
to
+66
| for (String token : trainingWords) { | ||
| if (!this.neighborMap.containsKey(token)) { | ||
| List<String> followingTokens = new ArrayList<String>(); | ||
| for (int i = 0; i < trainingWords.size(); i++) { | ||
| if (trainingWords.get(i).equals(token) && i != (trainingWords.size() - 1)) { | ||
| followingTokens.add(trainingWords.get(i + 1)); | ||
| } | ||
| } | ||
| this.neighborMap.put(token, followingTokens); | ||
| } | ||
| } |
Comment on lines
+116
to
+120
| Random gen = new Random(); | ||
| String currentWord = context.get(context.size() - 1); | ||
| int randomSelection = gen.nextInt(this.neighborMap.get(currentWord).size()); | ||
| String predictedWord = this.neighborMap.get(currentWord).get(randomSelection); | ||
| return predictedWord; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
My training data is quite large but I believe it is 100% worth it.