Search is not available for this dataset
identifier
stringlengths
1
155
parameters
stringlengths
2
6.09k
docstring
stringlengths
11
63.4k
docstring_summary
stringlengths
0
63.4k
function
stringlengths
29
99.8k
function_tokens
list
start_point
list
end_point
list
language
stringclasses
1 value
docstring_language
stringlengths
2
7
docstring_language_predictions
stringlengths
18
23
is_langid_reliable
stringclasses
2 values
max_len_single_sentence
(self)
:obj:`int`: The maximum length of a sentence that can be fed to the model.
:obj:`int`: The maximum length of a sentence that can be fed to the model.
def max_len_single_sentence(self) -> int: """ :obj:`int`: The maximum length of a sentence that can be fed to the model. """ return self.model_max_length - self.num_special_tokens_to_add(pair=False)
[ "def", "max_len_single_sentence", "(", "self", ")", "->", "int", ":", "return", "self", ".", "model_max_length", "-", "self", ".", "num_special_tokens_to_add", "(", "pair", "=", "False", ")" ]
[ 1456, 4 ]
[ 1460, 81 ]
python
en
['en', 'error', 'th']
False
max_len_sentences_pair
(self)
:obj:`int`: The maximum combined length of a pair of sentences that can be fed to the model.
:obj:`int`: The maximum combined length of a pair of sentences that can be fed to the model.
def max_len_sentences_pair(self) -> int: """ :obj:`int`: The maximum combined length of a pair of sentences that can be fed to the model. """ return self.model_max_length - self.num_special_tokens_to_add(pair=True)
[ "def", "max_len_sentences_pair", "(", "self", ")", "->", "int", ":", "return", "self", ".", "model_max_length", "-", "self", ".", "num_special_tokens_to_add", "(", "pair", "=", "True", ")" ]
[ 1463, 4 ]
[ 1467, 80 ]
python
en
['en', 'error', 'th']
False
get_vocab
(self)
Returns the vocabulary as a dictionary of token to index. :obj:`tokenizer.get_vocab()[token]` is equivalent to :obj:`tokenizer.convert_tokens_to_ids(token)` when :obj:`token` is in the vocab. Returns: :obj:`Dict[str, int]`: The vocabulary.
Returns the vocabulary as a dictionary of token to index.
def get_vocab(self) -> Dict[str, int]: """ Returns the vocabulary as a dictionary of token to index. :obj:`tokenizer.get_vocab()[token]` is equivalent to :obj:`tokenizer.convert_tokens_to_ids(token)` when :obj:`token` is in the vocab. Returns: :obj:`Dict[str, int]`:...
[ "def", "get_vocab", "(", "self", ")", "->", "Dict", "[", "str", ",", "int", "]", ":", "raise", "NotImplementedError", "(", ")" ]
[ 1504, 4 ]
[ 1514, 35 ]
python
en
['en', 'error', 'th']
False
from_pretrained
(cls, pretrained_model_name_or_path: Union[str, os.PathLike], *init_inputs, **kwargs)
r""" Instantiate a :class:`~transformers.tokenization_utils_base.PreTrainedTokenizerBase` (or a derived class) from a predefined tokenizer. Args: pretrained_model_name_or_path (:obj:`str` or :obj:`os.PathLike`): Can be either: - A string, the `model ...
r""" Instantiate a :class:`~transformers.tokenization_utils_base.PreTrainedTokenizerBase` (or a derived class) from a predefined tokenizer.
def from_pretrained(cls, pretrained_model_name_or_path: Union[str, os.PathLike], *init_inputs, **kwargs): r""" Instantiate a :class:`~transformers.tokenization_utils_base.PreTrainedTokenizerBase` (or a derived class) from a predefined tokenizer. Args: pretrained_model_name_o...
[ "def", "from_pretrained", "(", "cls", ",", "pretrained_model_name_or_path", ":", "Union", "[", "str", ",", "os", ".", "PathLike", "]", ",", "*", "init_inputs", ",", "*", "*", "kwargs", ")", ":", "cache_dir", "=", "kwargs", ".", "pop", "(", "\"cache_dir\"",...
[ 1517, 4 ]
[ 1705, 9 ]
python
cy
['en', 'cy', 'hi']
False
save_pretrained
( self, save_directory: Union[str, os.PathLike], legacy_format: bool = True, filename_prefix: Optional[str] = None, )
Save the full tokenizer state. This method make sure the full tokenizer can then be re-loaded using the :meth:`~transformers.tokenization_utils_base.PreTrainedTokenizer.from_pretrained` class method. .. Note:: A "fast" tokenizer (instance of :class:`transformers.PreTraine...
Save the full tokenizer state.
def save_pretrained( self, save_directory: Union[str, os.PathLike], legacy_format: bool = True, filename_prefix: Optional[str] = None, ) -> Tuple[str]: """ Save the full tokenizer state. This method make sure the full tokenizer can then be re-loaded using th...
[ "def", "save_pretrained", "(", "self", ",", "save_directory", ":", "Union", "[", "str", ",", "os", ".", "PathLike", "]", ",", "legacy_format", ":", "bool", "=", "True", ",", "filename_prefix", ":", "Optional", "[", "str", "]", "=", "None", ",", ")", "-...
[ 1824, 4 ]
[ 1910, 9 ]
python
en
['en', 'error', 'th']
False
_save_pretrained
( self, save_directory: Union[str, os.PathLike], file_names: Tuple[str], legacy_format: bool = True, filename_prefix: Optional[str] = None, )
Save a tokenizer using the slow-tokenizer/legacy format: vocabulary + added tokens. Fast tokenizers can also be saved in a unique JSON file containing {config + vocab + added-tokens} using the specific :meth:`~transformers.tokenization_utils_fast.PreTrainedTokenizerFast._save_pretrained` ...
Save a tokenizer using the slow-tokenizer/legacy format: vocabulary + added tokens.
def _save_pretrained( self, save_directory: Union[str, os.PathLike], file_names: Tuple[str], legacy_format: bool = True, filename_prefix: Optional[str] = None, ) -> Tuple[str]: """ Save a tokenizer using the slow-tokenizer/legacy format: vocabulary + added tok...
[ "def", "_save_pretrained", "(", "self", ",", "save_directory", ":", "Union", "[", "str", ",", "os", ".", "PathLike", "]", ",", "file_names", ":", "Tuple", "[", "str", "]", ",", "legacy_format", ":", "bool", "=", "True", ",", "filename_prefix", ":", "Opti...
[ 1912, 4 ]
[ 1944, 62 ]
python
en
['en', 'error', 'th']
False
save_vocabulary
(self, save_directory: str, filename_prefix: Optional[str] = None)
Save only the vocabulary of the tokenizer (vocabulary + added tokens). This method won't save the configuration and special token mappings of the tokenizer. Use :meth:`~transformers.PreTrainedTokenizerFast._save_pretrained` to save the whole state of the tokenizer. Args: s...
Save only the vocabulary of the tokenizer (vocabulary + added tokens).
def save_vocabulary(self, save_directory: str, filename_prefix: Optional[str] = None) -> Tuple[str]: """ Save only the vocabulary of the tokenizer (vocabulary + added tokens). This method won't save the configuration and special token mappings of the tokenizer. Use :meth:`~transformers....
[ "def", "save_vocabulary", "(", "self", ",", "save_directory", ":", "str", ",", "filename_prefix", ":", "Optional", "[", "str", "]", "=", "None", ")", "->", "Tuple", "[", "str", "]", ":", "raise", "NotImplementedError" ]
[ 1946, 4 ]
[ 1962, 33 ]
python
en
['en', 'error', 'th']
False
tokenize
(self, text: str, pair: Optional[str] = None, add_special_tokens: bool = False, **kwargs)
Converts a string in a sequence of tokens, replacing unknown tokens with the :obj:`unk_token`. Args: text (:obj:`str`): The sequence to be encoded. pair (:obj:`str`, `optional`): A second sequence to be encoded with the first. add_spe...
Converts a string in a sequence of tokens, replacing unknown tokens with the :obj:`unk_token`.
def tokenize(self, text: str, pair: Optional[str] = None, add_special_tokens: bool = False, **kwargs) -> List[str]: """ Converts a string in a sequence of tokens, replacing unknown tokens with the :obj:`unk_token`. Args: text (:obj:`str`): The sequence to be encoded....
[ "def", "tokenize", "(", "self", ",", "text", ":", "str", ",", "pair", ":", "Optional", "[", "str", "]", "=", "None", ",", "add_special_tokens", ":", "bool", "=", "False", ",", "*", "*", "kwargs", ")", "->", "List", "[", "str", "]", ":", "raise", ...
[ 1964, 4 ]
[ 1982, 33 ]
python
en
['en', 'error', 'th']
False
encode
( self, text: Union[TextInput, PreTokenizedInput, EncodedInput], text_pair: Optional[Union[TextInput, PreTokenizedInput, EncodedInput]] = None, add_special_tokens: bool = True, padding: Union[bool, str, PaddingStrategy] = False, truncation: Union[bool, str, TruncationStra...
Converts a string to a sequence of ids (integer), using the tokenizer and vocabulary. Same as doing ``self.convert_tokens_to_ids(self.tokenize(text))``. Args: text (:obj:`str`, :obj:`List[str]` or :obj:`List[int]`): The first sequence to be encoded. This can be a s...
Converts a string to a sequence of ids (integer), using the tokenizer and vocabulary.
def encode( self, text: Union[TextInput, PreTokenizedInput, EncodedInput], text_pair: Optional[Union[TextInput, PreTokenizedInput, EncodedInput]] = None, add_special_tokens: bool = True, padding: Union[bool, str, PaddingStrategy] = False, truncation: Union[bool, str, Trun...
[ "def", "encode", "(", "self", ",", "text", ":", "Union", "[", "TextInput", ",", "PreTokenizedInput", ",", "EncodedInput", "]", ",", "text_pair", ":", "Optional", "[", "Union", "[", "TextInput", ",", "PreTokenizedInput", ",", "EncodedInput", "]", "]", "=", ...
[ 1995, 4 ]
[ 2034, 42 ]
python
en
['en', 'error', 'th']
False
BatchEncoding.n_sequences
(self)
:obj:`Optional[int]`: The number of sequences used to generate each sample from the batch encoded in this :class:`~transformers.BatchEncoding`. Currently can be one of :obj:`None` (unknown), :obj:`1` (a single sentence) or :obj:`2` (a pair of sentences)
:obj:`Optional[int]`: The number of sequences used to generate each sample from the batch encoded in this :class:`~transformers.BatchEncoding`. Currently can be one of :obj:`None` (unknown), :obj:`1` (a single sentence) or :obj:`2` (a pair of sentences)
def n_sequences(self) -> Optional[int]: """ :obj:`Optional[int]`: The number of sequences used to generate each sample from the batch encoded in this :class:`~transformers.BatchEncoding`. Currently can be one of :obj:`None` (unknown), :obj:`1` (a single sentence) or :obj:`2` (a pair of s...
[ "def", "n_sequences", "(", "self", ")", "->", "Optional", "[", "int", "]", ":", "return", "self", ".", "_n_sequences" ]
[ 205, 4 ]
[ 211, 32 ]
python
en
['en', 'error', 'th']
False
BatchEncoding.is_fast
(self)
:obj:`bool`: Indicate whether this :class:`~transformers.BatchEncoding` was generated from the result of a :class:`~transformers.PreTrainedTokenizerFast` or not.
:obj:`bool`: Indicate whether this :class:`~transformers.BatchEncoding` was generated from the result of a :class:`~transformers.PreTrainedTokenizerFast` or not.
def is_fast(self) -> bool: """ :obj:`bool`: Indicate whether this :class:`~transformers.BatchEncoding` was generated from the result of a :class:`~transformers.PreTrainedTokenizerFast` or not. """ return self._encodings is not None
[ "def", "is_fast", "(", "self", ")", "->", "bool", ":", "return", "self", ".", "_encodings", "is", "not", "None" ]
[ 214, 4 ]
[ 219, 42 ]
python
en
['en', 'error', 'th']
False
BatchEncoding.__getitem__
(self, item: Union[int, str])
If the key is a string, returns the value of the dict associated to :obj:`key` ('input_ids', 'attention_mask', etc.). If the key is an integer, get the :obj:`tokenizers.Encoding` for batch item with index :obj:`key`.
If the key is a string, returns the value of the dict associated to :obj:`key` ('input_ids', 'attention_mask', etc.).
def __getitem__(self, item: Union[int, str]) -> Union[Any, EncodingFast]: """ If the key is a string, returns the value of the dict associated to :obj:`key` ('input_ids', 'attention_mask', etc.). If the key is an integer, get the :obj:`tokenizers.Encoding` for batch item with index :obj...
[ "def", "__getitem__", "(", "self", ",", "item", ":", "Union", "[", "int", ",", "str", "]", ")", "->", "Union", "[", "Any", ",", "EncodingFast", "]", ":", "if", "isinstance", "(", "item", ",", "str", ")", ":", "return", "self", ".", "data", "[", "...
[ 221, 4 ]
[ 236, 13 ]
python
en
['en', 'error', 'th']
False
BatchEncoding.encodings
(self)
:obj:`Optional[List[tokenizers.Encoding]]`: The list all encodings from the tokenization process. Returns :obj:`None` if the input was tokenized through Python (i.e., not a fast) tokenizer.
:obj:`Optional[List[tokenizers.Encoding]]`: The list all encodings from the tokenization process. Returns :obj:`None` if the input was tokenized through Python (i.e., not a fast) tokenizer.
def encodings(self) -> Optional[List[EncodingFast]]: """ :obj:`Optional[List[tokenizers.Encoding]]`: The list all encodings from the tokenization process. Returns :obj:`None` if the input was tokenized through Python (i.e., not a fast) tokenizer. """ return self._encodings
[ "def", "encodings", "(", "self", ")", "->", "Optional", "[", "List", "[", "EncodingFast", "]", "]", ":", "return", "self", ".", "_encodings" ]
[ 268, 4 ]
[ 273, 30 ]
python
en
['en', 'error', 'th']
False
BatchEncoding.tokens
(self, batch_index: int = 0)
Return the list of tokens (sub-parts of the input strings after word/subword splitting and before conversion to integer indices) at a given batch index (only works for the output of a fast tokenizer). Args: batch_index (:obj:`int`, `optional`, defaults to 0): The index to access in...
Return the list of tokens (sub-parts of the input strings after word/subword splitting and before conversion to integer indices) at a given batch index (only works for the output of a fast tokenizer).
def tokens(self, batch_index: int = 0) -> List[str]: """ Return the list of tokens (sub-parts of the input strings after word/subword splitting and before conversion to integer indices) at a given batch index (only works for the output of a fast tokenizer). Args: batch_index...
[ "def", "tokens", "(", "self", ",", "batch_index", ":", "int", "=", "0", ")", "->", "List", "[", "str", "]", ":", "if", "not", "self", ".", "_encodings", ":", "raise", "ValueError", "(", "\"tokens() is not available when using Python-based tokenizers\"", ")", "...
[ 275, 4 ]
[ 288, 50 ]
python
en
['en', 'error', 'th']
False
BatchEncoding.sequence_ids
(self, batch_index: int = 0)
Return a list mapping the tokens to the id of their original sentences: - :obj:`None` for special tokens added around or between sequences, - :obj:`0` for tokens corresponding to words in the first sequence, - :obj:`1` for tokens corresponding to words in the second sequenc...
Return a list mapping the tokens to the id of their original sentences:
def sequence_ids(self, batch_index: int = 0) -> List[Optional[int]]: """ Return a list mapping the tokens to the id of their original sentences: - :obj:`None` for special tokens added around or between sequences, - :obj:`0` for tokens corresponding to words in the first sequence...
[ "def", "sequence_ids", "(", "self", ",", "batch_index", ":", "int", "=", "0", ")", "->", "List", "[", "Optional", "[", "int", "]", "]", ":", "if", "not", "self", ".", "_encodings", ":", "raise", "ValueError", "(", "\"sequence_ids() is not available when usin...
[ 290, 4 ]
[ 309, 56 ]
python
en
['en', 'error', 'th']
False
BatchEncoding.words
(self, batch_index: int = 0)
Return a list mapping the tokens to their actual word in the initial sentence for a fast tokenizer. Args: batch_index (:obj:`int`, `optional`, defaults to 0): The index to access in the batch. Returns: :obj:`List[Optional[int]]`: A list indicating the word correspondin...
Return a list mapping the tokens to their actual word in the initial sentence for a fast tokenizer.
def words(self, batch_index: int = 0) -> List[Optional[int]]: """ Return a list mapping the tokens to their actual word in the initial sentence for a fast tokenizer. Args: batch_index (:obj:`int`, `optional`, defaults to 0): The index to access in the batch. Returns: ...
[ "def", "words", "(", "self", ",", "batch_index", ":", "int", "=", "0", ")", "->", "List", "[", "Optional", "[", "int", "]", "]", ":", "if", "not", "self", ".", "_encodings", ":", "raise", "ValueError", "(", "\"words() is not available when using Python-based...
[ 311, 4 ]
[ 330, 41 ]
python
en
['en', 'error', 'th']
False
BatchEncoding.word_ids
(self, batch_index: int = 0)
Return a list mapping the tokens to their actual word in the initial sentence for a fast tokenizer. Args: batch_index (:obj:`int`, `optional`, defaults to 0): The index to access in the batch. Returns: :obj:`List[Optional[int]]`: A list indicating the word correspondin...
Return a list mapping the tokens to their actual word in the initial sentence for a fast tokenizer.
def word_ids(self, batch_index: int = 0) -> List[Optional[int]]: """ Return a list mapping the tokens to their actual word in the initial sentence for a fast tokenizer. Args: batch_index (:obj:`int`, `optional`, defaults to 0): The index to access in the batch. Returns: ...
[ "def", "word_ids", "(", "self", ",", "batch_index", ":", "int", "=", "0", ")", "->", "List", "[", "Optional", "[", "int", "]", "]", ":", "if", "not", "self", ".", "_encodings", ":", "raise", "ValueError", "(", "\"word_ids() is not available when using Python...
[ 332, 4 ]
[ 346, 52 ]
python
en
['en', 'error', 'th']
False
BatchEncoding.token_to_sequence
(self, batch_or_token_index: int, token_index: Optional[int] = None)
Get the index of the sequence represented by the given token. In the general use case, this method returns :obj:`0` for a single sequence or the first sequence of a pair, and :obj:`1` for the second sequence of a pair Can be called as: - ``self.token_to_sequence(token_index)`` if batc...
Get the index of the sequence represented by the given token. In the general use case, this method returns :obj:`0` for a single sequence or the first sequence of a pair, and :obj:`1` for the second sequence of a pair
def token_to_sequence(self, batch_or_token_index: int, token_index: Optional[int] = None) -> int: """ Get the index of the sequence represented by the given token. In the general use case, this method returns :obj:`0` for a single sequence or the first sequence of a pair, and :obj:`1` for the se...
[ "def", "token_to_sequence", "(", "self", ",", "batch_or_token_index", ":", "int", ",", "token_index", ":", "Optional", "[", "int", "]", "=", "None", ")", "->", "int", ":", "if", "not", "self", ".", "_encodings", ":", "raise", "ValueError", "(", "\"token_to...
[ 348, 4 ]
[ 385, 74 ]
python
en
['en', 'error', 'th']
False
BatchEncoding.token_to_word
(self, batch_or_token_index: int, token_index: Optional[int] = None)
Get the index of the word corresponding (i.e. comprising) to an encoded token in a sequence of the batch. Can be called as: - ``self.token_to_word(token_index)`` if batch size is 1 - ``self.token_to_word(batch_index, token_index)`` if batch size is greater than 1 This method ...
Get the index of the word corresponding (i.e. comprising) to an encoded token in a sequence of the batch.
def token_to_word(self, batch_or_token_index: int, token_index: Optional[int] = None) -> int: """ Get the index of the word corresponding (i.e. comprising) to an encoded token in a sequence of the batch. Can be called as: - ``self.token_to_word(token_index)`` if batch size is 1 ...
[ "def", "token_to_word", "(", "self", ",", "batch_or_token_index", ":", "int", ",", "token_index", ":", "Optional", "[", "int", "]", "=", "None", ")", "->", "int", ":", "if", "not", "self", ".", "_encodings", ":", "raise", "ValueError", "(", "\"token_to_wor...
[ 387, 4 ]
[ 423, 70 ]
python
en
['en', 'error', 'th']
False
BatchEncoding.word_to_tokens
( self, batch_or_word_index: int, word_index: Optional[int] = None, sequence_index: int = 0 )
Get the encoded token span corresponding to a word in a sequence of the batch. Token spans are returned as a :class:`~transformers.tokenization_utils_base.TokenSpan` with: - **start** -- Index of the first token. - **end** -- Index of the token following the last token. Can b...
Get the encoded token span corresponding to a word in a sequence of the batch.
def word_to_tokens( self, batch_or_word_index: int, word_index: Optional[int] = None, sequence_index: int = 0 ) -> Optional[TokenSpan]: """ Get the encoded token span corresponding to a word in a sequence of the batch. Token spans are returned as a :class:`~transformers.tokenization...
[ "def", "word_to_tokens", "(", "self", ",", "batch_or_word_index", ":", "int", ",", "word_index", ":", "Optional", "[", "int", "]", "=", "None", ",", "sequence_index", ":", "int", "=", "0", ")", "->", "Optional", "[", "TokenSpan", "]", ":", "if", "not", ...
[ 425, 4 ]
[ 474, 61 ]
python
en
['en', 'error', 'th']
False
BatchEncoding.token_to_chars
(self, batch_or_token_index: int, token_index: Optional[int] = None)
Get the character span corresponding to an encoded token in a sequence of the batch. Character spans are returned as a :class:`~transformers.tokenization_utils_base.CharSpan` with: - **start** -- Index of the first character in the original string associated to the token. - **end** --...
Get the character span corresponding to an encoded token in a sequence of the batch.
def token_to_chars(self, batch_or_token_index: int, token_index: Optional[int] = None) -> CharSpan: """ Get the character span corresponding to an encoded token in a sequence of the batch. Character spans are returned as a :class:`~transformers.tokenization_utils_base.CharSpan` with: -...
[ "def", "token_to_chars", "(", "self", ",", "batch_or_token_index", ":", "int", ",", "token_index", ":", "Optional", "[", "int", "]", "=", "None", ")", "->", "CharSpan", ":", "if", "not", "self", ".", "_encodings", ":", "raise", "ValueError", "(", "\"token_...
[ 476, 4 ]
[ 510, 84 ]
python
en
['en', 'error', 'th']
False
BatchEncoding.char_to_token
( self, batch_or_char_index: int, char_index: Optional[int] = None, sequence_index: int = 0 )
Get the index of the token in the encoded output comprising a character in the original string for a sequence of the batch. Can be called as: - ``self.char_to_token(char_index)`` if batch size is 1 - ``self.char_to_token(batch_index, char_index)`` if batch size is greater or e...
Get the index of the token in the encoded output comprising a character in the original string for a sequence of the batch.
def char_to_token( self, batch_or_char_index: int, char_index: Optional[int] = None, sequence_index: int = 0 ) -> int: """ Get the index of the token in the encoded output comprising a character in the original string for a sequence of the batch. Can be called as: -...
[ "def", "char_to_token", "(", "self", ",", "batch_or_char_index", ":", "int", ",", "char_index", ":", "Optional", "[", "int", "]", "=", "None", ",", "sequence_index", ":", "int", "=", "0", ")", "->", "int", ":", "if", "not", "self", ".", "_encodings", "...
[ 512, 4 ]
[ 551, 85 ]
python
en
['en', 'error', 'th']
False
BatchEncoding.word_to_chars
( self, batch_or_word_index: int, word_index: Optional[int] = None, sequence_index: int = 0 )
Get the character span in the original string corresponding to given word in a sequence of the batch. Character spans are returned as a CharSpan NamedTuple with: - start: index of the first character in the original string - end: index of the character following the last character in ...
Get the character span in the original string corresponding to given word in a sequence of the batch.
def word_to_chars( self, batch_or_word_index: int, word_index: Optional[int] = None, sequence_index: int = 0 ) -> CharSpan: """ Get the character span in the original string corresponding to given word in a sequence of the batch. Character spans are returned as a CharSpan NamedTuple...
[ "def", "word_to_chars", "(", "self", ",", "batch_or_word_index", ":", "int", ",", "word_index", ":", "Optional", "[", "int", "]", "=", "None", ",", "sequence_index", ":", "int", "=", "0", ")", "->", "CharSpan", ":", "if", "not", "self", ".", "_encodings"...
[ 553, 4 ]
[ 596, 98 ]
python
en
['en', 'error', 'th']
False
BatchEncoding.char_to_word
(self, batch_or_char_index: int, char_index: Optional[int] = None, sequence_index: int = 0)
Get the word in the original string corresponding to a character in the original string of a sequence of the batch. Can be called as: - ``self.char_to_word(char_index)`` if batch size is 1 - ``self.char_to_word(batch_index, char_index)`` if batch size is greater than 1 ...
Get the word in the original string corresponding to a character in the original string of a sequence of the batch.
def char_to_word(self, batch_or_char_index: int, char_index: Optional[int] = None, sequence_index: int = 0) -> int: """ Get the word in the original string corresponding to a character in the original string of a sequence of the batch. Can be called as: - ``self.char_to_word(ch...
[ "def", "char_to_word", "(", "self", ",", "batch_or_char_index", ":", "int", ",", "char_index", ":", "Optional", "[", "int", "]", "=", "None", ",", "sequence_index", ":", "int", "=", "0", ")", "->", "int", ":", "if", "not", "self", ".", "_encodings", ":...
[ 598, 4 ]
[ 635, 84 ]
python
en
['en', 'error', 'th']
False
BatchEncoding.convert_to_tensors
( self, tensor_type: Optional[Union[str, TensorType]] = None, prepend_batch_axis: bool = False )
Convert the inner content to tensors. Args: tensor_type (:obj:`str` or :class:`~transformers.file_utils.TensorType`, `optional`): The type of tensors to use. If :obj:`str`, should be one of the values of the enum :class:`~transformers.file_utils.TensorType`....
Convert the inner content to tensors.
def convert_to_tensors( self, tensor_type: Optional[Union[str, TensorType]] = None, prepend_batch_axis: bool = False ): """ Convert the inner content to tensors. Args: tensor_type (:obj:`str` or :class:`~transformers.file_utils.TensorType`, `optional`): T...
[ "def", "convert_to_tensors", "(", "self", ",", "tensor_type", ":", "Optional", "[", "Union", "[", "str", ",", "TensorType", "]", "]", "=", "None", ",", "prepend_batch_axis", ":", "bool", "=", "False", ")", ":", "if", "tensor_type", "is", "None", ":", "re...
[ 637, 4 ]
[ 718, 19 ]
python
en
['en', 'error', 'th']
False
BatchEncoding.to
(self, device: Union[str, "torch.device"])
Send all values to device by calling :obj:`v.to(device)` (PyTorch only). Args: device (:obj:`str` or :obj:`torch.device`): The device to put the tensors on. Returns: :class:`~transformers.BatchEncoding`: The same instance after modification.
Send all values to device by calling :obj:`v.to(device)` (PyTorch only).
def to(self, device: Union[str, "torch.device"]) -> "BatchEncoding": """ Send all values to device by calling :obj:`v.to(device)` (PyTorch only). Args: device (:obj:`str` or :obj:`torch.device`): The device to put the tensors on. Returns: :class:`~transformers.B...
[ "def", "to", "(", "self", ",", "device", ":", "Union", "[", "str", ",", "\"torch.device\"", "]", ")", "->", "\"BatchEncoding\"", ":", "# This check catches things like APEX blindly calling \"to\" on all inputs to a module", "# Otherwise it passes the casts down and casts the Long...
[ 721, 4 ]
[ 739, 19 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.sanitize_special_tokens
(self)
Make sure that all the special tokens attributes of the tokenizer (:obj:`tokenizer.mask_token`, :obj:`tokenizer.cls_token`, etc.) are in the vocabulary. Add the missing ones to the vocabulary if needed. Return: :obj:`int`: The number of tokens added in the vocabulary durin...
Make sure that all the special tokens attributes of the tokenizer (:obj:`tokenizer.mask_token`, :obj:`tokenizer.cls_token`, etc.) are in the vocabulary.
def sanitize_special_tokens(self) -> int: """ Make sure that all the special tokens attributes of the tokenizer (:obj:`tokenizer.mask_token`, :obj:`tokenizer.cls_token`, etc.) are in the vocabulary. Add the missing ones to the vocabulary if needed. Return: :obj:`int...
[ "def", "sanitize_special_tokens", "(", "self", ")", "->", "int", ":", "return", "self", ".", "add_tokens", "(", "self", ".", "all_special_tokens_extended", ",", "special_tokens", "=", "True", ")" ]
[ 811, 4 ]
[ 821, 85 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.add_special_tokens
(self, special_tokens_dict: Dict[str, Union[str, AddedToken]])
Add a dictionary of special tokens (eos, pad, cls, etc.) to the encoder and link them to class attributes. If special tokens are NOT in the vocabulary, they are added to it (indexed starting from the last index of the current vocabulary). Using : obj:`add_special_tokens` will ensure yo...
Add a dictionary of special tokens (eos, pad, cls, etc.) to the encoder and link them to class attributes. If special tokens are NOT in the vocabulary, they are added to it (indexed starting from the last index of the current vocabulary).
def add_special_tokens(self, special_tokens_dict: Dict[str, Union[str, AddedToken]]) -> int: """ Add a dictionary of special tokens (eos, pad, cls, etc.) to the encoder and link them to class attributes. If special tokens are NOT in the vocabulary, they are added to it (indexed starting from the...
[ "def", "add_special_tokens", "(", "self", ",", "special_tokens_dict", ":", "Dict", "[", "str", ",", "Union", "[", "str", ",", "AddedToken", "]", "]", ")", "->", "int", ":", "if", "not", "special_tokens_dict", ":", "return", "0", "added_tokens", "=", "0", ...
[ 823, 4 ]
[ 888, 27 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.add_tokens
( self, new_tokens: Union[str, AddedToken, List[Union[str, AddedToken]]], special_tokens: bool = False )
Add a list of new tokens to the tokenizer class. If the new tokens are not in the vocabulary, they are added to it with indices starting from length of the current vocabulary. .. Note:: When adding new tokens to the vocabulary, you should make sure to also resize the token embeddin...
Add a list of new tokens to the tokenizer class. If the new tokens are not in the vocabulary, they are added to it with indices starting from length of the current vocabulary.
def add_tokens( self, new_tokens: Union[str, AddedToken, List[Union[str, AddedToken]]], special_tokens: bool = False ) -> int: """ Add a list of new tokens to the tokenizer class. If the new tokens are not in the vocabulary, they are added to it with indices starting from length of t...
[ "def", "add_tokens", "(", "self", ",", "new_tokens", ":", "Union", "[", "str", ",", "AddedToken", ",", "List", "[", "Union", "[", "str", ",", "AddedToken", "]", "]", "]", ",", "special_tokens", ":", "bool", "=", "False", ")", "->", "int", ":", "if", ...
[ 890, 4 ]
[ 935, 74 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.bos_token
(self)
:obj:`str`: Beginning of sentence token. Log an error if used while not having been set.
:obj:`str`: Beginning of sentence token. Log an error if used while not having been set.
def bos_token(self) -> str: """ :obj:`str`: Beginning of sentence token. Log an error if used while not having been set. """ if self._bos_token is None and self.verbose: logger.error("Using bos_token, but it is not set yet.") return None return str(self._b...
[ "def", "bos_token", "(", "self", ")", "->", "str", ":", "if", "self", ".", "_bos_token", "is", "None", "and", "self", ".", "verbose", ":", "logger", ".", "error", "(", "\"Using bos_token, but it is not set yet.\"", ")", "return", "None", "return", "str", "("...
[ 941, 4 ]
[ 948, 35 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.eos_token
(self)
:obj:`str`: End of sentence token. Log an error if used while not having been set.
:obj:`str`: End of sentence token. Log an error if used while not having been set.
def eos_token(self) -> str: """ :obj:`str`: End of sentence token. Log an error if used while not having been set. """ if self._eos_token is None and self.verbose: logger.error("Using eos_token, but it is not set yet.") return None return str(self._eos_tok...
[ "def", "eos_token", "(", "self", ")", "->", "str", ":", "if", "self", ".", "_eos_token", "is", "None", "and", "self", ".", "verbose", ":", "logger", ".", "error", "(", "\"Using eos_token, but it is not set yet.\"", ")", "return", "None", "return", "str", "("...
[ 951, 4 ]
[ 958, 35 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.unk_token
(self)
:obj:`str`: Unknown token. Log an error if used while not having been set.
:obj:`str`: Unknown token. Log an error if used while not having been set.
def unk_token(self) -> str: """ :obj:`str`: Unknown token. Log an error if used while not having been set. """ if self._unk_token is None and self.verbose: logger.error("Using unk_token, but it is not set yet.") return None return str(self._unk_token)
[ "def", "unk_token", "(", "self", ")", "->", "str", ":", "if", "self", ".", "_unk_token", "is", "None", "and", "self", ".", "verbose", ":", "logger", ".", "error", "(", "\"Using unk_token, but it is not set yet.\"", ")", "return", "None", "return", "str", "("...
[ 961, 4 ]
[ 968, 35 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.sep_token
(self)
:obj:`str`: Separation token, to separate context and query in an input sequence. Log an error if used while not having been set.
:obj:`str`: Separation token, to separate context and query in an input sequence. Log an error if used while not having been set.
def sep_token(self) -> str: """ :obj:`str`: Separation token, to separate context and query in an input sequence. Log an error if used while not having been set. """ if self._sep_token is None and self.verbose: logger.error("Using sep_token, but it is not set yet.") ...
[ "def", "sep_token", "(", "self", ")", "->", "str", ":", "if", "self", ".", "_sep_token", "is", "None", "and", "self", ".", "verbose", ":", "logger", ".", "error", "(", "\"Using sep_token, but it is not set yet.\"", ")", "return", "None", "return", "str", "("...
[ 971, 4 ]
[ 979, 35 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.pad_token
(self)
:obj:`str`: Padding token. Log an error if used while not having been set.
:obj:`str`: Padding token. Log an error if used while not having been set.
def pad_token(self) -> str: """ :obj:`str`: Padding token. Log an error if used while not having been set. """ if self._pad_token is None and self.verbose: logger.error("Using pad_token, but it is not set yet.") return None return str(self._pad_token)
[ "def", "pad_token", "(", "self", ")", "->", "str", ":", "if", "self", ".", "_pad_token", "is", "None", "and", "self", ".", "verbose", ":", "logger", ".", "error", "(", "\"Using pad_token, but it is not set yet.\"", ")", "return", "None", "return", "str", "("...
[ 982, 4 ]
[ 989, 35 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.cls_token
(self)
:obj:`str`: Classification token, to extract a summary of an input sequence leveraging self-attention along the full depth of the model. Log an error if used while not having been set.
:obj:`str`: Classification token, to extract a summary of an input sequence leveraging self-attention along the full depth of the model. Log an error if used while not having been set.
def cls_token(self) -> str: """ :obj:`str`: Classification token, to extract a summary of an input sequence leveraging self-attention along the full depth of the model. Log an error if used while not having been set. """ if self._cls_token is None and self.verbose: lo...
[ "def", "cls_token", "(", "self", ")", "->", "str", ":", "if", "self", ".", "_cls_token", "is", "None", "and", "self", ".", "verbose", ":", "logger", ".", "error", "(", "\"Using cls_token, but it is not set yet.\"", ")", "return", "None", "return", "str", "("...
[ 992, 4 ]
[ 1000, 35 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.mask_token
(self)
:obj:`str`: Mask token, to use when training a model with masked-language modeling. Log an error if used while not having been set.
:obj:`str`: Mask token, to use when training a model with masked-language modeling. Log an error if used while not having been set.
def mask_token(self) -> str: """ :obj:`str`: Mask token, to use when training a model with masked-language modeling. Log an error if used while not having been set. """ if self._mask_token is None and self.verbose: logger.error("Using mask_token, but it is not set yet...
[ "def", "mask_token", "(", "self", ")", "->", "str", ":", "if", "self", ".", "_mask_token", "is", "None", "and", "self", ".", "verbose", ":", "logger", ".", "error", "(", "\"Using mask_token, but it is not set yet.\"", ")", "return", "None", "return", "str", ...
[ 1003, 4 ]
[ 1011, 36 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.additional_special_tokens
(self)
:obj:`List[str]`: All the additional special tokens you may want to use. Log an error if used while not having been set.
:obj:`List[str]`: All the additional special tokens you may want to use. Log an error if used while not having been set.
def additional_special_tokens(self) -> List[str]: """ :obj:`List[str]`: All the additional special tokens you may want to use. Log an error if used while not having been set. """ if self._additional_special_tokens is None and self.verbose: logger.error("Using addition...
[ "def", "additional_special_tokens", "(", "self", ")", "->", "List", "[", "str", "]", ":", "if", "self", ".", "_additional_special_tokens", "is", "None", "and", "self", ".", "verbose", ":", "logger", ".", "error", "(", "\"Using additional_special_tokens, but it is ...
[ 1014, 4 ]
[ 1022, 68 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.bos_token_id
(self)
:obj:`Optional[int]`: Id of the beginning of sentence token in the vocabulary. Returns :obj:`None` if the token has not been set.
:obj:`Optional[int]`: Id of the beginning of sentence token in the vocabulary. Returns :obj:`None` if the token has not been set.
def bos_token_id(self) -> Optional[int]: """ :obj:`Optional[int]`: Id of the beginning of sentence token in the vocabulary. Returns :obj:`None` if the token has not been set. """ if self._bos_token is None: return None return self.convert_tokens_to_ids(self.bo...
[ "def", "bos_token_id", "(", "self", ")", "->", "Optional", "[", "int", "]", ":", "if", "self", ".", "_bos_token", "is", "None", ":", "return", "None", "return", "self", ".", "convert_tokens_to_ids", "(", "self", ".", "bos_token", ")" ]
[ 1057, 4 ]
[ 1064, 57 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.eos_token_id
(self)
:obj:`Optional[int]`: Id of the end of sentence token in the vocabulary. Returns :obj:`None` if the token has not been set.
:obj:`Optional[int]`: Id of the end of sentence token in the vocabulary. Returns :obj:`None` if the token has not been set.
def eos_token_id(self) -> Optional[int]: """ :obj:`Optional[int]`: Id of the end of sentence token in the vocabulary. Returns :obj:`None` if the token has not been set. """ if self._eos_token is None: return None return self.convert_tokens_to_ids(self.eos_toke...
[ "def", "eos_token_id", "(", "self", ")", "->", "Optional", "[", "int", "]", ":", "if", "self", ".", "_eos_token", "is", "None", ":", "return", "None", "return", "self", ".", "convert_tokens_to_ids", "(", "self", ".", "eos_token", ")" ]
[ 1067, 4 ]
[ 1074, 57 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.unk_token_id
(self)
:obj:`Optional[int]`: Id of the unknown token in the vocabulary. Returns :obj:`None` if the token has not been set.
:obj:`Optional[int]`: Id of the unknown token in the vocabulary. Returns :obj:`None` if the token has not been set.
def unk_token_id(self) -> Optional[int]: """ :obj:`Optional[int]`: Id of the unknown token in the vocabulary. Returns :obj:`None` if the token has not been set. """ if self._unk_token is None: return None return self.convert_tokens_to_ids(self.unk_token)
[ "def", "unk_token_id", "(", "self", ")", "->", "Optional", "[", "int", "]", ":", "if", "self", ".", "_unk_token", "is", "None", ":", "return", "None", "return", "self", ".", "convert_tokens_to_ids", "(", "self", ".", "unk_token", ")" ]
[ 1077, 4 ]
[ 1084, 57 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.sep_token_id
(self)
:obj:`Optional[int]`: Id of the separation token in the vocabulary, to separate context and query in an input sequence. Returns :obj:`None` if the token has not been set.
:obj:`Optional[int]`: Id of the separation token in the vocabulary, to separate context and query in an input sequence. Returns :obj:`None` if the token has not been set.
def sep_token_id(self) -> Optional[int]: """ :obj:`Optional[int]`: Id of the separation token in the vocabulary, to separate context and query in an input sequence. Returns :obj:`None` if the token has not been set. """ if self._sep_token is None: return None ...
[ "def", "sep_token_id", "(", "self", ")", "->", "Optional", "[", "int", "]", ":", "if", "self", ".", "_sep_token", "is", "None", ":", "return", "None", "return", "self", ".", "convert_tokens_to_ids", "(", "self", ".", "sep_token", ")" ]
[ 1087, 4 ]
[ 1094, 57 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.pad_token_id
(self)
:obj:`Optional[int]`: Id of the padding token in the vocabulary. Returns :obj:`None` if the token has not been set.
:obj:`Optional[int]`: Id of the padding token in the vocabulary. Returns :obj:`None` if the token has not been set.
def pad_token_id(self) -> Optional[int]: """ :obj:`Optional[int]`: Id of the padding token in the vocabulary. Returns :obj:`None` if the token has not been set. """ if self._pad_token is None: return None return self.convert_tokens_to_ids(self.pad_token)
[ "def", "pad_token_id", "(", "self", ")", "->", "Optional", "[", "int", "]", ":", "if", "self", ".", "_pad_token", "is", "None", ":", "return", "None", "return", "self", ".", "convert_tokens_to_ids", "(", "self", ".", "pad_token", ")" ]
[ 1097, 4 ]
[ 1104, 57 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.pad_token_type_id
(self)
:obj:`int`: Id of the padding token type in the vocabulary.
:obj:`int`: Id of the padding token type in the vocabulary.
def pad_token_type_id(self) -> int: """ :obj:`int`: Id of the padding token type in the vocabulary. """ return self._pad_token_type_id
[ "def", "pad_token_type_id", "(", "self", ")", "->", "int", ":", "return", "self", ".", "_pad_token_type_id" ]
[ 1107, 4 ]
[ 1111, 38 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.cls_token_id
(self)
:obj:`Optional[int]`: Id of the classification token in the vocabulary, to extract a summary of an input sequence leveraging self-attention along the full depth of the model. Returns :obj:`None` if the token has not been set.
:obj:`Optional[int]`: Id of the classification token in the vocabulary, to extract a summary of an input sequence leveraging self-attention along the full depth of the model.
def cls_token_id(self) -> Optional[int]: """ :obj:`Optional[int]`: Id of the classification token in the vocabulary, to extract a summary of an input sequence leveraging self-attention along the full depth of the model. Returns :obj:`None` if the token has not been set. """ ...
[ "def", "cls_token_id", "(", "self", ")", "->", "Optional", "[", "int", "]", ":", "if", "self", ".", "_cls_token", "is", "None", ":", "return", "None", "return", "self", ".", "convert_tokens_to_ids", "(", "self", ".", "cls_token", ")" ]
[ 1114, 4 ]
[ 1123, 57 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.mask_token_id
(self)
:obj:`Optional[int]`: Id of the mask token in the vocabulary, used when training a model with masked-language modeling. Returns :obj:`None` if the token has not been set.
:obj:`Optional[int]`: Id of the mask token in the vocabulary, used when training a model with masked-language modeling. Returns :obj:`None` if the token has not been set.
def mask_token_id(self) -> Optional[int]: """ :obj:`Optional[int]`: Id of the mask token in the vocabulary, used when training a model with masked-language modeling. Returns :obj:`None` if the token has not been set. """ if self._mask_token is None: return None ...
[ "def", "mask_token_id", "(", "self", ")", "->", "Optional", "[", "int", "]", ":", "if", "self", ".", "_mask_token", "is", "None", ":", "return", "None", "return", "self", ".", "convert_tokens_to_ids", "(", "self", ".", "mask_token", ")" ]
[ 1126, 4 ]
[ 1133, 58 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.additional_special_tokens_ids
(self)
:obj:`List[int]`: Ids of all the additional special tokens in the vocabulary. Log an error if used while not having been set.
:obj:`List[int]`: Ids of all the additional special tokens in the vocabulary. Log an error if used while not having been set.
def additional_special_tokens_ids(self) -> List[int]: """ :obj:`List[int]`: Ids of all the additional special tokens in the vocabulary. Log an error if used while not having been set. """ return self.convert_tokens_to_ids(self.additional_special_tokens)
[ "def", "additional_special_tokens_ids", "(", "self", ")", "->", "List", "[", "int", "]", ":", "return", "self", ".", "convert_tokens_to_ids", "(", "self", ".", "additional_special_tokens", ")" ]
[ 1136, 4 ]
[ 1141, 73 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.special_tokens_map
(self)
:obj:`Dict[str, Union[str, List[str]]]`: A dictionary mapping special token class attributes (:obj:`cls_token`, :obj:`unk_token`, etc.) to their values (:obj:`'<unk>'`, :obj:`'<cls>'`, etc.). Convert potential tokens of :obj:`tokenizers.AddedToken` type to string.
:obj:`Dict[str, Union[str, List[str]]]`: A dictionary mapping special token class attributes (:obj:`cls_token`, :obj:`unk_token`, etc.) to their values (:obj:`'<unk>'`, :obj:`'<cls>'`, etc.).
def special_tokens_map(self) -> Dict[str, Union[str, List[str]]]: """ :obj:`Dict[str, Union[str, List[str]]]`: A dictionary mapping special token class attributes (:obj:`cls_token`, :obj:`unk_token`, etc.) to their values (:obj:`'<unk>'`, :obj:`'<cls>'`, etc.). Convert potential tokens ...
[ "def", "special_tokens_map", "(", "self", ")", "->", "Dict", "[", "str", ",", "Union", "[", "str", ",", "List", "[", "str", "]", "]", "]", ":", "set_attr", "=", "{", "}", "for", "attr", "in", "self", ".", "SPECIAL_TOKENS_ATTRIBUTES", ":", "attr_value",...
[ 1176, 4 ]
[ 1188, 23 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.special_tokens_map_extended
(self)
:obj:`Dict[str, Union[str, tokenizers.AddedToken, List[Union[str, tokenizers.AddedToken]]]]`: A dictionary mapping special token class attributes (:obj:`cls_token`, :obj:`unk_token`, etc.) to their values (:obj:`'<unk>'`, :obj:`'<cls>'`, etc.). Don't convert tokens of :obj:`tokenizers....
:obj:`Dict[str, Union[str, tokenizers.AddedToken, List[Union[str, tokenizers.AddedToken]]]]`: A dictionary mapping special token class attributes (:obj:`cls_token`, :obj:`unk_token`, etc.) to their values (:obj:`'<unk>'`, :obj:`'<cls>'`, etc.).
def special_tokens_map_extended(self) -> Dict[str, Union[str, AddedToken, List[Union[str, AddedToken]]]]: """ :obj:`Dict[str, Union[str, tokenizers.AddedToken, List[Union[str, tokenizers.AddedToken]]]]`: A dictionary mapping special token class attributes (:obj:`cls_token`, :obj:`unk_token`, etc...
[ "def", "special_tokens_map_extended", "(", "self", ")", "->", "Dict", "[", "str", ",", "Union", "[", "str", ",", "AddedToken", ",", "List", "[", "Union", "[", "str", ",", "AddedToken", "]", "]", "]", "]", ":", "set_attr", "=", "{", "}", "for", "attr"...
[ 1191, 4 ]
[ 1205, 23 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.all_special_tokens
(self)
:obj:`List[str]`: All the special tokens (:obj:`'<unk>'`, :obj:`'<cls>'`, etc.) mapped to class attributes. Convert tokens of :obj:`tokenizers.AddedToken` type to string.
:obj:`List[str]`: All the special tokens (:obj:`'<unk>'`, :obj:`'<cls>'`, etc.) mapped to class attributes.
def all_special_tokens(self) -> List[str]: """ :obj:`List[str]`: All the special tokens (:obj:`'<unk>'`, :obj:`'<cls>'`, etc.) mapped to class attributes. Convert tokens of :obj:`tokenizers.AddedToken` type to string. """ all_toks = [str(s) for s in self.all_special_tokens_exten...
[ "def", "all_special_tokens", "(", "self", ")", "->", "List", "[", "str", "]", ":", "all_toks", "=", "[", "str", "(", "s", ")", "for", "s", "in", "self", ".", "all_special_tokens_extended", "]", "return", "all_toks" ]
[ 1208, 4 ]
[ 1215, 23 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.all_special_tokens_extended
(self)
:obj:`List[Union[str, tokenizers.AddedToken]]`: All the special tokens (:obj:`'<unk>'`, :obj:`'<cls>'`, etc.) mapped to class attributes. Don't convert tokens of :obj:`tokenizers.AddedToken` type to string so they can be used to control more finely how special tokens are tokenized. ...
:obj:`List[Union[str, tokenizers.AddedToken]]`: All the special tokens (:obj:`'<unk>'`, :obj:`'<cls>'`, etc.) mapped to class attributes.
def all_special_tokens_extended(self) -> List[Union[str, AddedToken]]: """ :obj:`List[Union[str, tokenizers.AddedToken]]`: All the special tokens (:obj:`'<unk>'`, :obj:`'<cls>'`, etc.) mapped to class attributes. Don't convert tokens of :obj:`tokenizers.AddedToken` type to string so the...
[ "def", "all_special_tokens_extended", "(", "self", ")", "->", "List", "[", "Union", "[", "str", ",", "AddedToken", "]", "]", ":", "all_toks", "=", "[", "]", "set_attr", "=", "self", ".", "special_tokens_map_extended", "for", "attr_value", "in", "set_attr", "...
[ 1218, 4 ]
[ 1231, 23 ]
python
en
['en', 'error', 'th']
False
SpecialTokensMixin.all_special_ids
(self)
:obj:`List[int]`: List the ids of the special tokens(:obj:`'<unk>'`, :obj:`'<cls>'`, etc.) mapped to class attributes.
:obj:`List[int]`: List the ids of the special tokens(:obj:`'<unk>'`, :obj:`'<cls>'`, etc.) mapped to class attributes.
def all_special_ids(self) -> List[int]: """ :obj:`List[int]`: List the ids of the special tokens(:obj:`'<unk>'`, :obj:`'<cls>'`, etc.) mapped to class attributes. """ all_toks = self.all_special_tokens all_ids = self.convert_tokens_to_ids(all_toks) return all_ids
[ "def", "all_special_ids", "(", "self", ")", "->", "List", "[", "int", "]", ":", "all_toks", "=", "self", ".", "all_special_tokens", "all_ids", "=", "self", ".", "convert_tokens_to_ids", "(", "all_toks", ")", "return", "all_ids" ]
[ 1234, 4 ]
[ 1241, 22 ]
python
en
['en', 'error', 'th']
False
_cv_input_select
(cfg)
Configure validation helper for input select (voluptuous).
Configure validation helper for input select (voluptuous).
def _cv_input_select(cfg): """Configure validation helper for input select (voluptuous).""" options = cfg[CONF_OPTIONS] initial = cfg.get(CONF_INITIAL) if initial is not None and initial not in options: raise vol.Invalid( f"initial state {initial} is not part of the options: {','.joi...
[ "def", "_cv_input_select", "(", "cfg", ")", ":", "options", "=", "cfg", "[", "CONF_OPTIONS", "]", "initial", "=", "cfg", ".", "get", "(", "CONF_INITIAL", ")", "if", "initial", "is", "not", "None", "and", "initial", "not", "in", "options", ":", "raise", ...
[ 53, 0 ]
[ 61, 14 ]
python
en
['en', 'en', 'en']
True
async_setup
(hass: HomeAssistantType, config: ConfigType)
Set up an input select.
Set up an input select.
async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool: """Set up an input select.""" component = EntityComponent(_LOGGER, DOMAIN, hass) id_manager = collection.IDManager() yaml_collection = collection.YamlCollection( logging.getLogger(f"{__name__}.yaml_collection"), id_mana...
[ "async", "def", "async_setup", "(", "hass", ":", "HomeAssistantType", ",", "config", ":", "ConfigType", ")", "->", "bool", ":", "component", "=", "EntityComponent", "(", "_LOGGER", ",", "DOMAIN", ",", "hass", ")", "id_manager", "=", "collection", ".", "IDMan...
[ 85, 0 ]
[ 163, 15 ]
python
en
['en', 'su', 'en']
True
InputSelectStorageCollection._process_create_data
(self, data: typing.Dict)
Validate the config is valid.
Validate the config is valid.
async def _process_create_data(self, data: typing.Dict) -> typing.Dict: """Validate the config is valid.""" return self.CREATE_SCHEMA(data)
[ "async", "def", "_process_create_data", "(", "self", ",", "data", ":", "typing", ".", "Dict", ")", "->", "typing", ".", "Dict", ":", "return", "self", ".", "CREATE_SCHEMA", "(", "data", ")" ]
[ 172, 4 ]
[ 174, 39 ]
python
en
['en', 'en', 'en']
True
InputSelectStorageCollection._get_suggested_id
(self, info: typing.Dict)
Suggest an ID based on the config.
Suggest an ID based on the config.
def _get_suggested_id(self, info: typing.Dict) -> str: """Suggest an ID based on the config.""" return info[CONF_NAME]
[ "def", "_get_suggested_id", "(", "self", ",", "info", ":", "typing", ".", "Dict", ")", "->", "str", ":", "return", "info", "[", "CONF_NAME", "]" ]
[ 177, 4 ]
[ 179, 30 ]
python
en
['en', 'en', 'en']
True
InputSelectStorageCollection._update_data
(self, data: dict, update_data: typing.Dict)
Return a new updated data object.
Return a new updated data object.
async def _update_data(self, data: dict, update_data: typing.Dict) -> typing.Dict: """Return a new updated data object.""" update_data = self.UPDATE_SCHEMA(update_data) return _cv_input_select({**data, **update_data})
[ "async", "def", "_update_data", "(", "self", ",", "data", ":", "dict", ",", "update_data", ":", "typing", ".", "Dict", ")", "->", "typing", ".", "Dict", ":", "update_data", "=", "self", ".", "UPDATE_SCHEMA", "(", "update_data", ")", "return", "_cv_input_se...
[ 181, 4 ]
[ 184, 56 ]
python
en
['en', 'en', 'en']
True
InputSelect.__init__
(self, config: typing.Dict)
Initialize a select input.
Initialize a select input.
def __init__(self, config: typing.Dict): """Initialize a select input.""" self._config = config self.editable = True self._current_option = config.get(CONF_INITIAL)
[ "def", "__init__", "(", "self", ",", "config", ":", "typing", ".", "Dict", ")", ":", "self", ".", "_config", "=", "config", "self", ".", "editable", "=", "True", "self", ".", "_current_option", "=", "config", ".", "get", "(", "CONF_INITIAL", ")" ]
[ 190, 4 ]
[ 194, 55 ]
python
en
['en', 'en', 'en']
True
InputSelect.from_yaml
(cls, config: typing.Dict)
Return entity instance initialized from yaml storage.
Return entity instance initialized from yaml storage.
def from_yaml(cls, config: typing.Dict) -> "InputSelect": """Return entity instance initialized from yaml storage.""" input_select = cls(config) input_select.entity_id = f"{DOMAIN}.{config[CONF_ID]}" input_select.editable = False return input_select
[ "def", "from_yaml", "(", "cls", ",", "config", ":", "typing", ".", "Dict", ")", "->", "\"InputSelect\"", ":", "input_select", "=", "cls", "(", "config", ")", "input_select", ".", "entity_id", "=", "f\"{DOMAIN}.{config[CONF_ID]}\"", "input_select", ".", "editable...
[ 197, 4 ]
[ 202, 27 ]
python
en
['en', 'pl', 'en']
True
InputSelect.async_added_to_hass
(self)
Run when entity about to be added.
Run when entity about to be added.
async def async_added_to_hass(self): """Run when entity about to be added.""" await super().async_added_to_hass() if self._current_option is not None: return state = await self.async_get_last_state() if not state or state.state not in self._options: self....
[ "async", "def", "async_added_to_hass", "(", "self", ")", ":", "await", "super", "(", ")", ".", "async_added_to_hass", "(", ")", "if", "self", ".", "_current_option", "is", "not", "None", ":", "return", "state", "=", "await", "self", ".", "async_get_last_stat...
[ 204, 4 ]
[ 214, 46 ]
python
en
['en', 'en', 'en']
True
InputSelect.should_poll
(self)
If entity should be polled.
If entity should be polled.
def should_poll(self): """If entity should be polled.""" return False
[ "def", "should_poll", "(", "self", ")", ":", "return", "False" ]
[ 217, 4 ]
[ 219, 20 ]
python
en
['en', 'en', 'en']
True
InputSelect.name
(self)
Return the name of the select input.
Return the name of the select input.
def name(self): """Return the name of the select input.""" return self._config.get(CONF_NAME)
[ "def", "name", "(", "self", ")", ":", "return", "self", ".", "_config", ".", "get", "(", "CONF_NAME", ")" ]
[ 222, 4 ]
[ 224, 42 ]
python
en
['en', 'en', 'en']
True
InputSelect.icon
(self)
Return the icon to be used for this entity.
Return the icon to be used for this entity.
def icon(self): """Return the icon to be used for this entity.""" return self._config.get(CONF_ICON)
[ "def", "icon", "(", "self", ")", ":", "return", "self", ".", "_config", ".", "get", "(", "CONF_ICON", ")" ]
[ 227, 4 ]
[ 229, 42 ]
python
en
['en', 'en', 'en']
True
InputSelect._options
(self)
Return a list of selection options.
Return a list of selection options.
def _options(self) -> typing.List[str]: """Return a list of selection options.""" return self._config[CONF_OPTIONS]
[ "def", "_options", "(", "self", ")", "->", "typing", ".", "List", "[", "str", "]", ":", "return", "self", ".", "_config", "[", "CONF_OPTIONS", "]" ]
[ 232, 4 ]
[ 234, 41 ]
python
en
['en', 'en', 'en']
True
InputSelect.state
(self)
Return the state of the component.
Return the state of the component.
def state(self): """Return the state of the component.""" return self._current_option
[ "def", "state", "(", "self", ")", ":", "return", "self", ".", "_current_option" ]
[ 237, 4 ]
[ 239, 35 ]
python
en
['en', 'en', 'en']
True
InputSelect.state_attributes
(self)
Return the state attributes.
Return the state attributes.
def state_attributes(self): """Return the state attributes.""" return {ATTR_OPTIONS: self._config[ATTR_OPTIONS], ATTR_EDITABLE: self.editable}
[ "def", "state_attributes", "(", "self", ")", ":", "return", "{", "ATTR_OPTIONS", ":", "self", ".", "_config", "[", "ATTR_OPTIONS", "]", ",", "ATTR_EDITABLE", ":", "self", ".", "editable", "}" ]
[ 242, 4 ]
[ 244, 87 ]
python
en
['en', 'en', 'en']
True
InputSelect.unique_id
(self)
Return unique id for the entity.
Return unique id for the entity.
def unique_id(self) -> typing.Optional[str]: """Return unique id for the entity.""" return self._config[CONF_ID]
[ "def", "unique_id", "(", "self", ")", "->", "typing", ".", "Optional", "[", "str", "]", ":", "return", "self", ".", "_config", "[", "CONF_ID", "]" ]
[ 247, 4 ]
[ 249, 36 ]
python
en
['en', 'en', 'en']
True
InputSelect.async_select_option
(self, option)
Select new option.
Select new option.
def async_select_option(self, option): """Select new option.""" if option not in self._options: _LOGGER.warning( "Invalid option: %s (possible options: %s)", option, ", ".join(self._options), ) return self._curre...
[ "def", "async_select_option", "(", "self", ",", "option", ")", ":", "if", "option", "not", "in", "self", ".", "_options", ":", "_LOGGER", ".", "warning", "(", "\"Invalid option: %s (possible options: %s)\"", ",", "option", ",", "\", \"", ".", "join", "(", "sel...
[ 252, 4 ]
[ 262, 35 ]
python
en
['en', 'ceb', 'en']
True
InputSelect.async_offset_index
(self, offset)
Offset current index.
Offset current index.
def async_offset_index(self, offset): """Offset current index.""" current_index = self._options.index(self._current_option) new_index = (current_index + offset) % len(self._options) self._current_option = self._options[new_index] self.async_write_ha_state()
[ "def", "async_offset_index", "(", "self", ",", "offset", ")", ":", "current_index", "=", "self", ".", "_options", ".", "index", "(", "self", ".", "_current_option", ")", "new_index", "=", "(", "current_index", "+", "offset", ")", "%", "len", "(", "self", ...
[ 265, 4 ]
[ 270, 35 ]
python
en
['en', 'da', 'en']
True
InputSelect.async_set_options
(self, options)
Set options.
Set options.
def async_set_options(self, options): """Set options.""" self._current_option = options[0] self._config[CONF_OPTIONS] = options self.async_write_ha_state()
[ "def", "async_set_options", "(", "self", ",", "options", ")", ":", "self", ".", "_current_option", "=", "options", "[", "0", "]", "self", ".", "_config", "[", "CONF_OPTIONS", "]", "=", "options", "self", ".", "async_write_ha_state", "(", ")" ]
[ 273, 4 ]
[ 277, 35 ]
python
en
['en', 'bg', 'en']
False
InputSelect.async_update_config
(self, config: typing.Dict)
Handle when the config is updated.
Handle when the config is updated.
async def async_update_config(self, config: typing.Dict) -> None: """Handle when the config is updated.""" self._config = config self.async_write_ha_state()
[ "async", "def", "async_update_config", "(", "self", ",", "config", ":", "typing", ".", "Dict", ")", "->", "None", ":", "self", ".", "_config", "=", "config", "self", ".", "async_write_ha_state", "(", ")" ]
[ 279, 4 ]
[ 282, 35 ]
python
en
['en', 'en', 'en']
True
discovery_flow_conf
(hass)
Register a handler.
Register a handler.
def discovery_flow_conf(hass): """Register a handler.""" handler_conf = {"discovered": False} async def has_discovered_devices(hass): """Mock if we have discovered devices.""" return handler_conf["discovered"] with patch.dict(config_entries.HANDLERS): config_entry_flow.register...
[ "def", "discovery_flow_conf", "(", "hass", ")", ":", "handler_conf", "=", "{", "\"discovered\"", ":", "False", "}", "async", "def", "has_discovered_devices", "(", "hass", ")", ":", "\"\"\"Mock if we have discovered devices.\"\"\"", "return", "handler_conf", "[", "\"di...
[ 17, 0 ]
[ 29, 26 ]
python
en
['en', 'da', 'en']
True
webhook_flow_conf
(hass)
Register a handler.
Register a handler.
def webhook_flow_conf(hass): """Register a handler.""" with patch.dict(config_entries.HANDLERS): config_entry_flow.register_webhook_flow("test_single", "Test Single", {}, False) config_entry_flow.register_webhook_flow( "test_multiple", "Test Multiple", {}, True ) yiel...
[ "def", "webhook_flow_conf", "(", "hass", ")", ":", "with", "patch", ".", "dict", "(", "config_entries", ".", "HANDLERS", ")", ":", "config_entry_flow", ".", "register_webhook_flow", "(", "\"test_single\"", ",", "\"Test Single\"", ",", "{", "}", ",", "False", "...
[ 33, 0 ]
[ 40, 16 ]
python
en
['en', 'da', 'en']
True
test_single_entry_allowed
(hass, discovery_flow_conf)
Test only a single entry is allowed.
Test only a single entry is allowed.
async def test_single_entry_allowed(hass, discovery_flow_conf): """Test only a single entry is allowed.""" flow = config_entries.HANDLERS["test"]() flow.hass = hass flow.context = {} MockConfigEntry(domain="test").add_to_hass(hass) result = await flow.async_step_user() assert result["type"...
[ "async", "def", "test_single_entry_allowed", "(", "hass", ",", "discovery_flow_conf", ")", ":", "flow", "=", "config_entries", ".", "HANDLERS", "[", "\"test\"", "]", "(", ")", "flow", ".", "hass", "=", "hass", "flow", ".", "context", "=", "{", "}", "MockCo...
[ 43, 0 ]
[ 53, 56 ]
python
en
['en', 'en', 'en']
True
test_user_no_devices_found
(hass, discovery_flow_conf)
Test if no devices found.
Test if no devices found.
async def test_user_no_devices_found(hass, discovery_flow_conf): """Test if no devices found.""" flow = config_entries.HANDLERS["test"]() flow.hass = hass flow.context = {"source": config_entries.SOURCE_USER} result = await flow.async_step_confirm(user_input={}) assert result["type"] == data_en...
[ "async", "def", "test_user_no_devices_found", "(", "hass", ",", "discovery_flow_conf", ")", ":", "flow", "=", "config_entries", ".", "HANDLERS", "[", "\"test\"", "]", "(", ")", "flow", ".", "hass", "=", "hass", "flow", ".", "context", "=", "{", "\"source\"",...
[ 56, 0 ]
[ 64, 49 ]
python
en
['es', 'en', 'en']
True
test_user_has_confirmation
(hass, discovery_flow_conf)
Test user requires confirmation to setup.
Test user requires confirmation to setup.
async def test_user_has_confirmation(hass, discovery_flow_conf): """Test user requires confirmation to setup.""" discovery_flow_conf["discovered"] = True mock_entity_platform(hass, "config_flow.test", None) result = await hass.config_entries.flow.async_init( "test", context={"source": config_en...
[ "async", "def", "test_user_has_confirmation", "(", "hass", ",", "discovery_flow_conf", ")", ":", "discovery_flow_conf", "[", "\"discovered\"", "]", "=", "True", "mock_entity_platform", "(", "hass", ",", "\"config_flow.test\"", ",", "None", ")", "result", "=", "await...
[ 67, 0 ]
[ 80, 69 ]
python
en
['en', 'en', 'en']
True
test_discovery_single_instance
(hass, discovery_flow_conf, source)
Test we not allow duplicates.
Test we not allow duplicates.
async def test_discovery_single_instance(hass, discovery_flow_conf, source): """Test we not allow duplicates.""" flow = config_entries.HANDLERS["test"]() flow.hass = hass flow.context = {} MockConfigEntry(domain="test").add_to_hass(hass) result = await getattr(flow, f"async_step_{source}")({}) ...
[ "async", "def", "test_discovery_single_instance", "(", "hass", ",", "discovery_flow_conf", ",", "source", ")", ":", "flow", "=", "config_entries", ".", "HANDLERS", "[", "\"test\"", "]", "(", ")", "flow", ".", "hass", "=", "hass", "flow", ".", "context", "=",...
[ 84, 0 ]
[ 94, 56 ]
python
en
['en', 'en', 'en']
True
test_discovery_confirmation
(hass, discovery_flow_conf, source)
Test we ask for confirmation via discovery.
Test we ask for confirmation via discovery.
async def test_discovery_confirmation(hass, discovery_flow_conf, source): """Test we ask for confirmation via discovery.""" flow = config_entries.HANDLERS["test"]() flow.hass = hass flow.context = {"source": source} result = await getattr(flow, f"async_step_{source}")({}) assert result["type"]...
[ "async", "def", "test_discovery_confirmation", "(", "hass", ",", "discovery_flow_conf", ",", "source", ")", ":", "flow", "=", "config_entries", ".", "HANDLERS", "[", "\"test\"", "]", "(", ")", "flow", ".", "hass", "=", "hass", "flow", ".", "context", "=", ...
[ 98, 0 ]
[ 110, 69 ]
python
en
['en', 'en', 'en']
True
test_multiple_discoveries
(hass, discovery_flow_conf)
Test we only create one instance for multiple discoveries.
Test we only create one instance for multiple discoveries.
async def test_multiple_discoveries(hass, discovery_flow_conf): """Test we only create one instance for multiple discoveries.""" mock_entity_platform(hass, "config_flow.test", None) result = await hass.config_entries.flow.async_init( "test", context={"source": config_entries.SOURCE_DISCOVERY}, data...
[ "async", "def", "test_multiple_discoveries", "(", "hass", ",", "discovery_flow_conf", ")", ":", "mock_entity_platform", "(", "hass", ",", "\"config_flow.test\"", ",", "None", ")", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init...
[ 113, 0 ]
[ 126, 62 ]
python
en
['en', 'en', 'en']
True
test_only_one_in_progress
(hass, discovery_flow_conf)
Test a user initialized one will finish and cancel discovered one.
Test a user initialized one will finish and cancel discovered one.
async def test_only_one_in_progress(hass, discovery_flow_conf): """Test a user initialized one will finish and cancel discovered one.""" mock_entity_platform(hass, "config_flow.test", None) # Discovery starts flow result = await hass.config_entries.flow.async_init( "test", context={"source": co...
[ "async", "def", "test_only_one_in_progress", "(", "hass", ",", "discovery_flow_conf", ")", ":", "mock_entity_platform", "(", "hass", ",", "\"config_flow.test\"", ",", "None", ")", "# Discovery starts flow", "result", "=", "await", "hass", ".", "config_entries", ".", ...
[ 129, 0 ]
[ 152, 62 ]
python
en
['en', 'en', 'en']
True
test_import_abort_discovery
(hass, discovery_flow_conf)
Test import will finish and cancel discovered one.
Test import will finish and cancel discovered one.
async def test_import_abort_discovery(hass, discovery_flow_conf): """Test import will finish and cancel discovered one.""" mock_entity_platform(hass, "config_flow.test", None) # Discovery starts flow result = await hass.config_entries.flow.async_init( "test", context={"source": config_entries.S...
[ "async", "def", "test_import_abort_discovery", "(", "hass", ",", "discovery_flow_conf", ")", ":", "mock_entity_platform", "(", "hass", ",", "\"config_flow.test\"", ",", "None", ")", "# Discovery starts flow", "result", "=", "await", "hass", ".", "config_entries", ".",...
[ 155, 0 ]
[ 173, 62 ]
python
en
['en', 'en', 'en']
True
test_import_no_confirmation
(hass, discovery_flow_conf)
Test import requires no confirmation to set up.
Test import requires no confirmation to set up.
async def test_import_no_confirmation(hass, discovery_flow_conf): """Test import requires no confirmation to set up.""" flow = config_entries.HANDLERS["test"]() flow.hass = hass flow.context = {} discovery_flow_conf["discovered"] = True result = await flow.async_step_import(None) assert res...
[ "async", "def", "test_import_no_confirmation", "(", "hass", ",", "discovery_flow_conf", ")", ":", "flow", "=", "config_entries", ".", "HANDLERS", "[", "\"test\"", "]", "(", ")", "flow", ".", "hass", "=", "hass", "flow", ".", "context", "=", "{", "}", "disc...
[ 176, 0 ]
[ 184, 69 ]
python
en
['en', 'en', 'en']
True
test_import_single_instance
(hass, discovery_flow_conf)
Test import doesn't create second instance.
Test import doesn't create second instance.
async def test_import_single_instance(hass, discovery_flow_conf): """Test import doesn't create second instance.""" flow = config_entries.HANDLERS["test"]() flow.hass = hass flow.context = {} discovery_flow_conf["discovered"] = True MockConfigEntry(domain="test").add_to_hass(hass) result = ...
[ "async", "def", "test_import_single_instance", "(", "hass", ",", "discovery_flow_conf", ")", ":", "flow", "=", "config_entries", ".", "HANDLERS", "[", "\"test\"", "]", "(", ")", "flow", ".", "hass", "=", "hass", "flow", ".", "context", "=", "{", "}", "disc...
[ 187, 0 ]
[ 196, 62 ]
python
en
['en', 'en', 'en']
True
test_ignored_discoveries
(hass, discovery_flow_conf)
Test we can ignore discovered entries.
Test we can ignore discovered entries.
async def test_ignored_discoveries(hass, discovery_flow_conf): """Test we can ignore discovered entries.""" mock_entity_platform(hass, "config_flow.test", None) result = await hass.config_entries.flow.async_init( "test", context={"source": config_entries.SOURCE_DISCOVERY}, data={} ) assert ...
[ "async", "def", "test_ignored_discoveries", "(", "hass", ",", "discovery_flow_conf", ")", ":", "mock_entity_platform", "(", "hass", ",", "\"config_flow.test\"", ",", "None", ")", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init"...
[ 199, 0 ]
[ 228, 62 ]
python
en
['en', 'en', 'en']
True
test_webhook_single_entry_allowed
(hass, webhook_flow_conf)
Test only a single entry is allowed.
Test only a single entry is allowed.
async def test_webhook_single_entry_allowed(hass, webhook_flow_conf): """Test only a single entry is allowed.""" flow = config_entries.HANDLERS["test_single"]() flow.hass = hass MockConfigEntry(domain="test_single").add_to_hass(hass) result = await flow.async_step_user() assert result["type"] ...
[ "async", "def", "test_webhook_single_entry_allowed", "(", "hass", ",", "webhook_flow_conf", ")", ":", "flow", "=", "config_entries", ".", "HANDLERS", "[", "\"test_single\"", "]", "(", ")", "flow", ".", "hass", "=", "hass", "MockConfigEntry", "(", "domain", "=", ...
[ 231, 0 ]
[ 240, 56 ]
python
en
['en', 'en', 'en']
True
test_webhook_multiple_entries_allowed
(hass, webhook_flow_conf)
Test multiple entries are allowed when specified.
Test multiple entries are allowed when specified.
async def test_webhook_multiple_entries_allowed(hass, webhook_flow_conf): """Test multiple entries are allowed when specified.""" flow = config_entries.HANDLERS["test_multiple"]() flow.hass = hass MockConfigEntry(domain="test_multiple").add_to_hass(hass) hass.config.api = Mock(base_url="http://exam...
[ "async", "def", "test_webhook_multiple_entries_allowed", "(", "hass", ",", "webhook_flow_conf", ")", ":", "flow", "=", "config_entries", ".", "HANDLERS", "[", "\"test_multiple\"", "]", "(", ")", "flow", ".", "hass", "=", "hass", "MockConfigEntry", "(", "domain", ...
[ 243, 0 ]
[ 252, 61 ]
python
en
['en', 'en', 'en']
True
test_webhook_config_flow_registers_webhook
(hass, webhook_flow_conf)
Test setting up an entry creates a webhook.
Test setting up an entry creates a webhook.
async def test_webhook_config_flow_registers_webhook(hass, webhook_flow_conf): """Test setting up an entry creates a webhook.""" flow = config_entries.HANDLERS["test_single"]() flow.hass = hass await async_process_ha_core_config( hass, {"external_url": "https://example.com"}, ) ...
[ "async", "def", "test_webhook_config_flow_registers_webhook", "(", "hass", ",", "webhook_flow_conf", ")", ":", "flow", "=", "config_entries", ".", "HANDLERS", "[", "\"test_single\"", "]", "(", ")", "flow", ".", "hass", "=", "hass", "await", "async_process_ha_core_co...
[ 255, 0 ]
[ 267, 51 ]
python
en
['en', 'en', 'en']
True
test_webhook_create_cloudhook
(hass, webhook_flow_conf)
Test only a single entry is allowed.
Test only a single entry is allowed.
async def test_webhook_create_cloudhook(hass, webhook_flow_conf): """Test only a single entry is allowed.""" assert await setup.async_setup_component(hass, "cloud", {}) async_setup_entry = Mock(return_value=True) async_unload_entry = Mock(return_value=True) mock_integration( hass, ...
[ "async", "def", "test_webhook_create_cloudhook", "(", "hass", ",", "webhook_flow_conf", ")", ":", "assert", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"cloud\"", ",", "{", "}", ")", "async_setup_entry", "=", "Mock", "(", "return_value", ...
[ 270, 0 ]
[ 317, 45 ]
python
en
['en', 'en', 'en']
True
test_if_fires_on_hass_start
(hass)
Test the firing when Home Assistant starts.
Test the firing when Home Assistant starts.
async def test_if_fires_on_hass_start(hass): """Test the firing when Home Assistant starts.""" calls = async_mock_service(hass, "test", "automation") hass.state = CoreState.not_running config = { automation.DOMAIN: { "alias": "hello", "trigger": {"platform": "homeassistan...
[ "async", "def", "test_if_fires_on_hass_start", "(", "hass", ")", ":", "calls", "=", "async_mock_service", "(", "hass", ",", "\"test\"", ",", "\"automation\"", ")", "hass", ".", "state", "=", "CoreState", ".", "not_running", "config", "=", "{", "automation", "....
[ 9, 0 ]
[ 39, 26 ]
python
en
['en', 'en', 'en']
True
test_if_fires_on_hass_shutdown
(hass)
Test the firing when Home Assistant shuts down.
Test the firing when Home Assistant shuts down.
async def test_if_fires_on_hass_shutdown(hass): """Test the firing when Home Assistant shuts down.""" calls = async_mock_service(hass, "test", "automation") hass.state = CoreState.not_running assert await async_setup_component( hass, automation.DOMAIN, { automation.D...
[ "async", "def", "test_if_fires_on_hass_shutdown", "(", "hass", ")", ":", "calls", "=", "async_mock_service", "(", "hass", ",", "\"test\"", ",", "\"automation\"", ")", "hass", ".", "state", "=", "CoreState", ".", "not_running", "assert", "await", "async_setup_compo...
[ 42, 0 ]
[ 68, 26 ]
python
en
['en', 'en', 'en']
True
Individual.__init__
(self, config=None, info=None, result=None)
Parameters ---------- config : str A config to represent a group of parameters. info : str result : float save_dir : str
Parameters ---------- config : str A config to represent a group of parameters. info : str result : float save_dir : str
def __init__(self, config=None, info=None, result=None): """ Parameters ---------- config : str A config to represent a group of parameters. info : str result : float save_dir : str """ self.config = config self.result = result ...
[ "def", "__init__", "(", "self", ",", "config", "=", "None", ",", "info", "=", "None", ",", "result", "=", "None", ")", ":", "self", ".", "config", "=", "config", "self", ".", "result", "=", "result", "self", ".", "info", "=", "info" ]
[ 36, 4 ]
[ 48, 24 ]
python
en
['en', 'error', 'th']
False
EvolutionTuner.__init__
(self, optimize_mode="maximize", population_size=32)
Parameters ---------- optimize_mode : str, default 'maximize' population_size : int initial population size. The larger population size, the better evolution performance.
Parameters ---------- optimize_mode : str, default 'maximize' population_size : int initial population size. The larger population size, the better evolution performance.
def __init__(self, optimize_mode="maximize", population_size=32): """ Parameters ---------- optimize_mode : str, default 'maximize' population_size : int initial population size. The larger population size, the better evolution performance. """ ...
[ "def", "__init__", "(", "self", ",", "optimize_mode", "=", "\"maximize\"", ",", "population_size", "=", "32", ")", ":", "self", ".", "optimize_mode", "=", "OptimizeMode", "(", "optimize_mode", ")", "self", ".", "population_size", "=", "population_size", "self", ...
[ 66, 4 ]
[ 86, 32 ]
python
en
['en', 'error', 'th']
False
EvolutionTuner.update_search_space
(self, search_space)
Update search space. Search_space contains the information that user pre-defined. Parameters ---------- search_space : dict
Update search space.
def update_search_space(self, search_space): """ Update search space. Search_space contains the information that user pre-defined. Parameters ---------- search_space : dict """ self.searchspace_json = search_space self.space = json2space(self.sea...
[ "def", "update_search_space", "(", "self", ",", "search_space", ")", ":", "self", ".", "searchspace_json", "=", "search_space", "self", ".", "space", "=", "json2space", "(", "self", ".", "searchspace_json", ")", "self", ".", "random_state", "=", "np", ".", "...
[ 88, 4 ]
[ 105, 46 ]
python
en
['en', 'error', 'th']
False
EvolutionTuner.trial_end
(self, parameter_id, success, **kwargs)
To deal with trial failure. If a trial fails, random generate the parameters and add into the population. Parameters ---------- parameter_id : int Unique identifier for hyper-parameters used by this trial. success : bool True if the trial successf...
To deal with trial failure. If a trial fails, random generate the parameters and add into the population. Parameters ---------- parameter_id : int Unique identifier for hyper-parameters used by this trial. success : bool True if the trial successf...
def trial_end(self, parameter_id, success, **kwargs): """ To deal with trial failure. If a trial fails, random generate the parameters and add into the population. Parameters ---------- parameter_id : int Unique identifier for hyper-parameters used by this tri...
[ "def", "trial_end", "(", "self", ",", "parameter_id", ",", "success", ",", "*", "*", "kwargs", ")", ":", "self", ".", "num_running_trials", "-=", "1", "logger", ".", "info", "(", "'trial (%d) end'", ",", "parameter_id", ")", "if", "not", "success", ":", ...
[ 107, 4 ]
[ 133, 40 ]
python
en
['en', 'error', 'th']
False
EvolutionTuner.generate_multiple_parameters
(self, parameter_id_list, **kwargs)
Returns multiple sets of trial (hyper-)parameters, as iterable of serializable objects. Parameters ---------- parameter_id_list : list of int Unique identifiers for each set of requested hyper-parameters. **kwargs Not used Returns ------- ...
Returns multiple sets of trial (hyper-)parameters, as iterable of serializable objects. Parameters ---------- parameter_id_list : list of int Unique identifiers for each set of requested hyper-parameters. **kwargs Not used Returns ------- ...
def generate_multiple_parameters(self, parameter_id_list, **kwargs): """ Returns multiple sets of trial (hyper-)parameters, as iterable of serializable objects. Parameters ---------- parameter_id_list : list of int Unique identifiers for each set of requested hyper-pa...
[ "def", "generate_multiple_parameters", "(", "self", ",", "parameter_id_list", ",", "*", "*", "kwargs", ")", ":", "result", "=", "[", "]", "if", "'st_callback'", "in", "kwargs", ":", "self", ".", "send_trial_callback", "=", "kwargs", "[", "'st_callback'", "]", ...
[ 135, 4 ]
[ 165, 21 ]
python
en
['en', 'error', 'th']
False
EvolutionTuner._generate_individual
(self, parameter_id)
This function will generate the config for a trial. If at the first generation, randomly generates individuals to satisfy self.population_size. Otherwise, random choose a pair of individuals and compare their fitnesses. The worst of the pair will be removed. Copy the best of the pair an...
This function will generate the config for a trial. If at the first generation, randomly generates individuals to satisfy self.population_size. Otherwise, random choose a pair of individuals and compare their fitnesses. The worst of the pair will be removed. Copy the best of the pair an...
def _generate_individual(self, parameter_id): """ This function will generate the config for a trial. If at the first generation, randomly generates individuals to satisfy self.population_size. Otherwise, random choose a pair of individuals and compare their fitnesses. The worst ...
[ "def", "_generate_individual", "(", "self", ",", "parameter_id", ")", ":", "pos", "=", "-", "1", "for", "i", "in", "range", "(", "len", "(", "self", ".", "population", ")", ")", ":", "if", "self", ".", "population", "[", "i", "]", ".", "result", "i...
[ 175, 4 ]
[ 226, 21 ]
python
en
['en', 'error', 'th']
False
EvolutionTuner.generate_parameters
(self, parameter_id, **kwargs)
This function will returns a dict of trial (hyper-)parameters. If no trial configration for now, self.credit plus 1 to send the config later Parameters ---------- parameter_id : int Returns ------- dict One newly generated configuration. ...
This function will returns a dict of trial (hyper-)parameters. If no trial configration for now, self.credit plus 1 to send the config later
def generate_parameters(self, parameter_id, **kwargs): """ This function will returns a dict of trial (hyper-)parameters. If no trial configration for now, self.credit plus 1 to send the config later Parameters ---------- parameter_id : int Returns -----...
[ "def", "generate_parameters", "(", "self", ",", "parameter_id", ",", "*", "*", "kwargs", ")", ":", "if", "not", "self", ".", "population", ":", "raise", "RuntimeError", "(", "'The population is empty'", ")", "if", "self", ".", "num_running_trials", ">=", "self...
[ 229, 4 ]
[ 252, 54 ]
python
en
['en', 'error', 'th']
False
EvolutionTuner.receive_trial_result
(self, parameter_id, parameters, value, **kwargs)
Record the result from a trial Parameters ---------- parameter_id : int parameters : dict value : dict/float if value is dict, it should have "default" key. value is final metrics of the trial.
Record the result from a trial
def receive_trial_result(self, parameter_id, parameters, value, **kwargs): """ Record the result from a trial Parameters ---------- parameter_id : int parameters : dict value : dict/float if value is dict, it should have "default" key. val...
[ "def", "receive_trial_result", "(", "self", ",", "parameter_id", ",", "parameters", ",", "value", ",", "*", "*", "kwargs", ")", ":", "reward", "=", "extract_scalar_reward", "(", "value", ")", "if", "parameter_id", "not", "in", "self", ".", "running_trials", ...
[ 254, 4 ]
[ 279, 37 ]
python
en
['en', 'error', 'th']
False
_async_manipulate_security_zones
( hass, home, internal_active=False, external_active=False, alarm_triggered=False )
Set new values on hmip security zones.
Set new values on hmip security zones.
async def _async_manipulate_security_zones( hass, home, internal_active=False, external_active=False, alarm_triggered=False ): """Set new values on hmip security zones.""" json = home._rawJSONData # pylint: disable=protected-access json["functionalHomes"]["SECURITY_AND_ALARM"]["alarmActive"] = alarm_tr...
[ "async", "def", "_async_manipulate_security_zones", "(", "hass", ",", "home", ",", "internal_active", "=", "False", ",", "external_active", "=", "False", ",", "alarm_triggered", "=", "False", ")", ":", "json", "=", "home", ".", "_rawJSONData", "# pylint: disable=p...
[ 16, 0 ]
[ 35, 38 ]
python
en
['en', 'sr', 'en']
True
test_manually_configured_platform
(hass)
Test that we do not set up an access point.
Test that we do not set up an access point.
async def test_manually_configured_platform(hass): """Test that we do not set up an access point.""" assert await async_setup_component( hass, ALARM_CONTROL_PANEL_DOMAIN, {ALARM_CONTROL_PANEL_DOMAIN: {"platform": HMIPC_DOMAIN}}, ) assert not hass.data.get(HMIPC_DOMAIN)
[ "async", "def", "test_manually_configured_platform", "(", "hass", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "ALARM_CONTROL_PANEL_DOMAIN", ",", "{", "ALARM_CONTROL_PANEL_DOMAIN", ":", "{", "\"platform\"", ":", "HMIPC_DOMAIN", "}", "}", ","...
[ 38, 0 ]
[ 46, 42 ]
python
en
['en', 'en', 'en']
True
test_hmip_alarm_control_panel
(hass, default_mock_hap_factory)
Test HomematicipAlarmControlPanel.
Test HomematicipAlarmControlPanel.
async def test_hmip_alarm_control_panel(hass, default_mock_hap_factory): """Test HomematicipAlarmControlPanel.""" entity_id = "alarm_control_panel.hmip_alarm_control_panel" entity_name = "HmIP Alarm Control Panel" device_model = None mock_hap = await default_mock_hap_factory.async_get_mock_hap( ...
[ "async", "def", "test_hmip_alarm_control_panel", "(", "hass", ",", "default_mock_hap_factory", ")", ":", "entity_id", "=", "\"alarm_control_panel.hmip_alarm_control_panel\"", "entity_name", "=", "\"HmIP Alarm Control Panel\"", "device_model", "=", "None", "mock_hap", "=", "aw...
[ 49, 0 ]
[ 111, 68 ]
python
en
['es', 'ja', 'en']
False