Package opennlp.tools.tokenize
Class BertNormalization
java.lang.Object
opennlp.tools.tokenize.BertNormalization
Character classifications and text transforms of the reference BERT
BasicTokenizer, shared by WordpieceEncoder and
WordpieceTokenizer.-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final StringThe wordpiece vocabulary convention: a piece with this prefix continues the current word, so it can only match after the word's first piece.(package private) static final intDefault maximum word length used by BERT wordpiece tokenizers. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static booleanisCjk(int codePoint) A CJK ideograph as defined by the reference BERT implementation: the CJK Unified Ideographs blocks and their extensions.(package private) static booleanisControl(int codePoint) A control character in the BERT sense: anyC*category (control, format, surrogate, private use, unassigned), except the characters treated as whitespace byisWhitespace(int).(package private) static booleanisLineOrParagraphSeparator(int codePoint) Tests whether a code point is a Unicode line or paragraph separator.(package private) static StringisolatePunctuation(String text) Surrounds every punctuation character with spaces, so each punctuation character becomes its own token.(package private) static MappedTextSurrounds every punctuation character with spaces that map to an empty range at the character's start and end, so each punctuation character becomes its own token.(package private) static booleanisPunctuation(int codePoint) A punctuation character in the BERT sense: any non-alphanumeric ASCII character that is not whitespace, or any Unicode punctuation category.(package private) static booleanisWhitespace(int codePoint) A whitespace character in the BERT sense: space, tab, newline, carriage return, or Unicode space separators (Zs).
-
Field Details
-
DEFAULT_MAX_WORD_CODE_POINTS
static final int DEFAULT_MAX_WORD_CODE_POINTSDefault maximum word length used by BERT wordpiece tokenizers.- See Also:
-
CONTINUATION_PREFIX
The wordpiece vocabulary convention: a piece with this prefix continues the current word, so it can only match after the word's first piece.- See Also:
-
-
Constructor Details
-
BertNormalization
private BertNormalization()
-
-
Method Details
-
isolatePunctuation
Surrounds every punctuation character with spaces, so each punctuation character becomes its own token. Delegates toisolatePunctuation(MappedText)with an identity mapping.- Parameters:
text- The text to transform.- Returns:
- The text with the isolation spaces inserted.
-
isolatePunctuation
Surrounds every punctuation character with spaces that map to an empty range at the character's start and end, so each punctuation character becomes its own token.- Parameters:
in- Themapped textto transform.- Returns:
- A new
mappingwith the isolation spaces inserted.
-
isControl
static boolean isControl(int codePoint) A control character in the BERT sense: anyC*category (control, format, surrogate, private use, unassigned), except the characters treated as whitespace byisWhitespace(int). -
isWhitespace
static boolean isWhitespace(int codePoint) A whitespace character in the BERT sense: space, tab, newline, carriage return, or Unicode space separators (Zs). -
isLineOrParagraphSeparator
static boolean isLineOrParagraphSeparator(int codePoint) Tests whether a code point is a Unicode line or paragraph separator. -
isPunctuation
static boolean isPunctuation(int codePoint) A punctuation character in the BERT sense: any non-alphanumeric ASCII character that is not whitespace, or any Unicode punctuation category. -
isCjk
static boolean isCjk(int codePoint) A CJK ideograph as defined by the reference BERT implementation: the CJK Unified Ideographs blocks and their extensions. This intentionally does not cover Japanese kana or Korean hangul, matching the reference.
-