-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from matlab-deep-learning/japanese-bert-fix
Updating predictMaskedToken.m to match new tokenizer.
- Loading branch information
Showing
3 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,47 @@ | ||
classdef(SharedTestFixtures={ | ||
DownloadBERTFixture, DownloadJPBERTFixture}) tpredictMaskedToken < matlab.unittest.TestCase | ||
% tpredictMaskedToken Unit test for predictMaskedToken | ||
|
||
% Copyright 2023 The MathWorks, Inc. | ||
|
||
properties(TestParameter) | ||
Models = {"tiny","japanese-base-wwm"} | ||
ValidText = iGetValidText; | ||
end | ||
|
||
methods(Test) | ||
function verifyOutputDimSizes(test, Models, ValidText) | ||
inSize = size(ValidText); | ||
mdl = bert("Model", Models); | ||
outputText = predictMaskedToken(mdl,ValidText); | ||
test.verifyEqual(size(outputText), inSize); | ||
end | ||
|
||
function maskTokenIsRemoved(test, Models) | ||
text = "This has a [MASK] token."; | ||
mdl = bert("Model", Models); | ||
outputText = predictMaskedToken(mdl,text); | ||
test.verifyFalse(contains(outputText, "[MASK]")); | ||
end | ||
|
||
function inputWithoutMASKRemainsTheSame(test, Models) | ||
text = "This has a no mask token."; | ||
mdl = bert("Model", Models); | ||
outputText = predictMaskedToken(mdl,text); | ||
test.verifyEqual(text, outputText); | ||
end | ||
end | ||
end | ||
|
||
function validText = iGetValidText | ||
manyStrs = ["Accelerating the pace of [MASK] and science"; | ||
"The cat [MASK] soundly."; | ||
"The [MASK] set beautifully."]; | ||
singleStr = "Artificial intelligence continues to shape the future of industries," + ... | ||
" as innovative applications emerge in fields such as healthcare, transportation," + ... | ||
" entertainment, and finance, driving productivity and enhancing human capabilities."; | ||
validText = struct('StringsAsColumns',manyStrs,... | ||
'StringsAsRows',manyStrs',... | ||
'ManyStrings',repmat(singleStr,3),... | ||
'SingleString',singleStr); | ||
end |