HerBERT
Last updated
Last updated
The HerBERT model was proposed in by Piotr Rybak, Robert Mroczkowski, Janusz Tracz, and Ireneusz Gawlik. It is a BERT-based Language Model trained on Polish Corpora using only MLM objective with dynamic masking of whole words.
The abstract from the paper is the following:
In recent years, a series of Transformer-based models unlocked major improvements in general natural language understanding (NLU) tasks. Such a fast pace of research would not be possible without general NLU benchmarks, which allow for a fair comparison of the proposed methods. However, such benchmarks are available only for a handful of languages. To alleviate this issue, we introduce a comprehensive multi-task benchmark for the Polish language understanding, accompanied by an online leaderboard. It consists of a diverse set of tasks, adopted from existing datasets for named entity recognition, question-answering, textual entailment, and others. We also introduce a new sentiment analysis task for the e-commerce domain, named Allegro Reviews (AR). To ensure a common evaluation scheme and promote models that generalize to different NLU tasks, the benchmark includes datasets from varying domains and applications. Additionally, we release HerBERT, a Transformer-based model trained specifically for the Polish language, which has the best average performance and obtains the best results for three out of nine tasks. Finally, we provide an extensive evaluation, including several standard baselines and recently proposed, multilingual Transformer-based models.
Examples of use:
Copied
( vocab_filemerges_filetokenizer_file = Nonecls_token = '<s>'unk_token = '<unk>'pad_token = '<pad>'mask_token = '<mask>'sep_token = '</s>'bos_token = '<s>'do_lowercase_and_remove_accent = Falseadditional_special_tokens = ['<special0>', '<special1>', '<special2>', '<special3>', '<special4>', '<special5>', '<special6>', '<special7>', '<special8>', '<special9>']lang2id = Noneid2lang = None**kwargs )
Construct a BPE tokenizer for HerBERT.
Peculiarities:
uses BERTβs pre-tokenizer: BaseTokenizer splits tokens on spaces, and also on punctuation. Each occurrence of a punctuation character will be treated separately.
Such pretokenized input is BPE subtokenized
build_inputs_with_special_tokens
( token_ids_0: typing.List[int]token_ids_1: typing.Optional[typing.List[int]] = None ) β List[int]
Parameters
token_ids_0 (List[int]
) β List of IDs to which the special tokens will be added.
token_ids_1 (List[int]
, optional) β Optional second list of IDs for sequence pairs.
Returns
List[int]
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. An XLM sequence has the following format:
single sequence: <s> X </s>
pair of sequences: <s> A </s> B </s>
convert_tokens_to_string
( tokens )
Converts a sequence of tokens (string) in a single string.
create_token_type_ids_from_sequences
( token_ids_0: typing.List[int]token_ids_1: typing.Optional[typing.List[int]] = None ) β List[int]
Parameters
token_ids_0 (List[int]
) β List of IDs.
token_ids_1 (List[int]
, optional) β Optional second list of IDs for sequence pairs.
Returns
List[int]
Create a mask from the two sequences passed to be used in a sequence-pair classification task. An XLM sequence
pair mask has the following format:
Copied
If token_ids_1
is None
, this method only returns the first portion of the mask (0s).
get_special_tokens_mask
( token_ids_0: typing.List[int]token_ids_1: typing.Optional[typing.List[int]] = Nonealready_has_special_tokens: bool = False ) β List[int]
Parameters
token_ids_0 (List[int]
) β List of IDs.
token_ids_1 (List[int]
, optional) β Optional second list of IDs for sequence pairs.
already_has_special_tokens (bool
, optional, defaults to False
) β Whether or not the token list is already formatted with special tokens for the model.
Returns
List[int]
A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.
Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding special tokens using the tokenizer prepare_for_model
method.
( vocab_file = Nonemerges_file = Nonetokenizer_file = Nonecls_token = '<s>'unk_token = '<unk>'pad_token = '<pad>'mask_token = '<mask>'sep_token = '</s>'**kwargs )
Parameters
vocab_file (str
) β Path to the vocabulary file.
merges_file (str
) β Path to the merges file.
Construct a βFastβ BPE tokenizer for HerBERT (backed by BOINCAIβs tokenizers library).
Peculiarities:
uses BERTβs pre-tokenizer: BertPreTokenizer splits tokens on spaces, and also on punctuation. Each occurrence of a punctuation character will be treated separately.
build_inputs_with_special_tokens
( token_ids_0: typing.List[int]token_ids_1: typing.Optional[typing.List[int]] = None ) β List[int]
Parameters
token_ids_0 (List[int]
) β List of IDs to which the special tokens will be added.
token_ids_1 (List[int]
, optional) β Optional second list of IDs for sequence pairs.
Returns
List[int]
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. An HerBERT, like BERT sequence has the following format:
single sequence: <s> X </s>
pair of sequences: <s> A </s> B </s>
create_token_type_ids_from_sequences
( token_ids_0: typing.List[int]token_ids_1: typing.Optional[typing.List[int]] = None ) β List[int]
Parameters
token_ids_0 (List[int]
) β List of IDs.
token_ids_1 (List[int]
, optional) β Optional second list of IDs for sequence pairs.
Returns
List[int]
Create a mask from the two sequences passed to be used in a sequence-pair classification task. HerBERT, like
BERT sequence pair mask has the following format:
Copied
get_special_tokens_mask
( token_ids_0: typing.List[int]token_ids_1: typing.Optional[typing.List[int]] = Nonealready_has_special_tokens: bool = False ) β List[int]
Parameters
token_ids_0 (List[int]
) β List of IDs.
token_ids_1 (List[int]
, optional) β Optional second list of IDs for sequence pairs.
already_has_special_tokens (bool
, optional, defaults to False
) β Whether or not the token list is already formatted with special tokens for the model.
Returns
List[int]
A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.
Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding special tokens using the tokenizer prepare_for_model
method.
This model was contributed by . The original code can be found .
This tokenizer inherits from which contains most of the methods. Users should refer to the superclass for more information regarding methods.
List of with the appropriate special tokens.
List of according to the given sequence(s).
This tokenizer inherits from which contains most of the methods. Users should refer to the superclass for more information regarding methods.
List of with the appropriate special tokens.
List of according to the given sequence(s).