-
Notifications
You must be signed in to change notification settings - Fork 15
Add JUnit 5 support and initial unit test for Tokenizer #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ayush0407
wants to merge
5
commits into
beehive-lab:main
Choose a base branch
from
ayush0407:add-junit5-tokenizer-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ea7a3a2
test: add JUnit 5 support and initial Tokenizer test
ayush0407 a883978
test: add JUnit 5 support and initial Tokenizer test
ayush0407 69dee5f
test: Code review changes done.
ayush0407 6b36927
Merge branch 'main' of https://github.com/ayush0407/GPULlama3.java in…
ayush0407 08addb6
test: Code review changes done.
ayush0407 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/test/java/com/example/tokenizer/impl/TokenizerTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.example.tokenizer.impl; | ||
|
||
import com.example.core.types.Pair; | ||
import com.example.tokenizer.vocabulary.Vocabulary; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class TokenizerTest { | ||
|
||
private Tokenizer tokenizer; | ||
|
||
@BeforeEach | ||
void setup() { | ||
String[] tokens = {"H", "e", "l", "o", " ", "He", "lo"}; | ||
float[] scores = new float[tokens.length]; | ||
|
||
// Create token to index mapping | ||
Vocabulary vocab = new Vocabulary(tokens, scores); | ||
|
||
List<Pair<Integer, Integer>> merges = List.of( | ||
new Pair<>(0, 1), // H + e → He | ||
new Pair<>(2, 3) // l + o → lo | ||
); | ||
|
||
String regex = "[A-Za-z ]+"; | ||
|
||
Map<String, Integer> specialTokens = Map.of("<PAD>", 100, "<EOS>", 101); | ||
|
||
tokenizer = new Tokenizer(vocab, merges, regex, specialTokens); | ||
} | ||
|
||
@Test | ||
void testEncodeOrdinary() { | ||
List<Integer> result = tokenizer.encodeOrdinary("Hello"); | ||
assertNotNull(result); | ||
assertTrue(result.contains(5)); | ||
assertTrue(result.contains(6)); | ||
ayush0407 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@Test | ||
void testEncodeWithSpecialToken() { | ||
String input = "Hello<EOS>"; | ||
List<Integer> result = tokenizer.encode(input, Set.of("<EOS>")); | ||
assertTrue(result.contains(2)); | ||
ayush0407 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@Test | ||
void testRegexPattern() { | ||
assertEquals("[A-Za-z ]+", tokenizer.regexPattern()); | ||
} | ||
|
||
@Test | ||
void testDecode() { | ||
String input = "He lo"; | ||
List<Integer> ids = tokenizer.encodeOrdinary(input); | ||
String decoded = tokenizer.decodeImpl(ids); | ||
assertEquals("He lo", decoded); | ||
} | ||
|
||
@Test | ||
void testSpecialTokenCheck() { | ||
assertTrue(tokenizer.isSpecialToken(100)); | ||
assertFalse(tokenizer.isSpecialToken(999)); | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This TokenizerTest covers the
static replaceControlCharacters()
methods which are implemented in the Tokenizer interface, not LlamaTokenizer. In order this junit support to make sense I would suggest to add coverage for LlamaTokenizer as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure