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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
test_send_preset_mode_device_timeout | (
hass, discovery, device, mock_now, preset
) | Test for sending preset mode command to the device with a device timeout. | Test for sending preset mode command to the device with a device timeout. | async def test_send_preset_mode_device_timeout(
hass, discovery, device, mock_now, preset
):
"""Test for sending preset mode command to the device with a device timeout."""
device().push_state_update.side_effect = DeviceTimeoutError
await async_setup_gree(hass)
next_update = mock_now + timedelta(m... | [
"async",
"def",
"test_send_preset_mode_device_timeout",
"(",
"hass",
",",
"discovery",
",",
"device",
",",
"mock_now",
",",
"preset",
")",
":",
"device",
"(",
")",
".",
"push_state_update",
".",
"side_effect",
"=",
"DeviceTimeoutError",
"await",
"async_setup_gree",
... | [
435,
0
] | [
457,
59
] | python | en | ['en', 'en', 'en'] | True |
test_update_preset_mode | (hass, discovery, device, mock_now, preset) | Test for updating preset mode from the device. | Test for updating preset mode from the device. | async def test_update_preset_mode(hass, discovery, device, mock_now, preset):
"""Test for updating preset mode from the device."""
device().steady_heat = preset == PRESET_AWAY
device().power_save = preset == PRESET_ECO
device().sleep = preset == PRESET_SLEEP
device().turbo = preset == PRESET_BOOST
... | [
"async",
"def",
"test_update_preset_mode",
"(",
"hass",
",",
"discovery",
",",
"device",
",",
"mock_now",
",",
"preset",
")",
":",
"device",
"(",
")",
".",
"steady_heat",
"=",
"preset",
"==",
"PRESET_AWAY",
"device",
"(",
")",
".",
"power_save",
"=",
"pres... | [
463,
0
] | [
479,
59
] | python | en | ['en', 'en', 'en'] | True |
test_send_hvac_mode | (hass, discovery, device, mock_now, hvac_mode) | Test for sending hvac mode command to the device. | Test for sending hvac mode command to the device. | async def test_send_hvac_mode(hass, discovery, device, mock_now, hvac_mode):
"""Test for sending hvac mode command to the device."""
await async_setup_gree(hass)
next_update = mock_now + timedelta(minutes=5)
with patch("homeassistant.util.dt.utcnow", return_value=next_update):
async_fire_time_c... | [
"async",
"def",
"test_send_hvac_mode",
"(",
"hass",
",",
"discovery",
",",
"device",
",",
"mock_now",
",",
"hvac_mode",
")",
":",
"await",
"async_setup_gree",
"(",
"hass",
")",
"next_update",
"=",
"mock_now",
"+",
"timedelta",
"(",
"minutes",
"=",
"5",
")",
... | [
493,
0
] | [
511,
35
] | python | en | ['en', 'en', 'en'] | True |
test_send_hvac_mode_device_timeout | (
hass, discovery, device, mock_now, hvac_mode
) | Test for sending hvac mode command to the device with a device timeout. | Test for sending hvac mode command to the device with a device timeout. | async def test_send_hvac_mode_device_timeout(
hass, discovery, device, mock_now, hvac_mode
):
"""Test for sending hvac mode command to the device with a device timeout."""
device().push_state_update.side_effect = DeviceTimeoutError
await async_setup_gree(hass)
next_update = mock_now + timedelta(mi... | [
"async",
"def",
"test_send_hvac_mode_device_timeout",
"(",
"hass",
",",
"discovery",
",",
"device",
",",
"mock_now",
",",
"hvac_mode",
")",
":",
"device",
"(",
")",
".",
"push_state_update",
".",
"side_effect",
"=",
"DeviceTimeoutError",
"await",
"async_setup_gree",... | [
518,
0
] | [
540,
35
] | python | en | ['en', 'en', 'en'] | True |
test_update_hvac_mode | (hass, discovery, device, mock_now, hvac_mode) | Test for updating hvac mode from the device. | Test for updating hvac mode from the device. | async def test_update_hvac_mode(hass, discovery, device, mock_now, hvac_mode):
"""Test for updating hvac mode from the device."""
device().power = hvac_mode != HVAC_MODE_OFF
device().mode = HVAC_MODES_REVERSE.get(hvac_mode)
await async_setup_gree(hass)
next_update = mock_now + timedelta(minutes=5)... | [
"async",
"def",
"test_update_hvac_mode",
"(",
"hass",
",",
"discovery",
",",
"device",
",",
"mock_now",
",",
"hvac_mode",
")",
":",
"device",
"(",
")",
".",
"power",
"=",
"hvac_mode",
"!=",
"HVAC_MODE_OFF",
"device",
"(",
")",
".",
"mode",
"=",
"HVAC_MODES... | [
554,
0
] | [
568,
35
] | python | en | ['en', 'en', 'en'] | True |
test_send_fan_mode | (hass, discovery, device, mock_now, fan_mode) | Test for sending fan mode command to the device. | Test for sending fan mode command to the device. | async def test_send_fan_mode(hass, discovery, device, mock_now, fan_mode):
"""Test for sending fan mode command to the device."""
await async_setup_gree(hass)
next_update = mock_now + timedelta(minutes=5)
with patch("homeassistant.util.dt.utcnow", return_value=next_update):
async_fire_time_chan... | [
"async",
"def",
"test_send_fan_mode",
"(",
"hass",
",",
"discovery",
",",
"device",
",",
"mock_now",
",",
"fan_mode",
")",
":",
"await",
"async_setup_gree",
"(",
"hass",
")",
"next_update",
"=",
"mock_now",
"+",
"timedelta",
"(",
"minutes",
"=",
"5",
")",
... | [
575,
0
] | [
593,
58
] | python | en | ['en', 'en', 'en'] | True |
test_send_invalid_fan_mode | (hass, discovery, device, mock_now) | Test for sending fan mode command to the device. | Test for sending fan mode command to the device. | async def test_send_invalid_fan_mode(hass, discovery, device, mock_now):
"""Test for sending fan mode command to the device."""
await async_setup_gree(hass)
next_update = mock_now + timedelta(minutes=5)
with patch("homeassistant.util.dt.utcnow", return_value=next_update):
async_fire_time_change... | [
"async",
"def",
"test_send_invalid_fan_mode",
"(",
"hass",
",",
"discovery",
",",
"device",
",",
"mock_now",
")",
":",
"await",
"async_setup_gree",
"(",
"hass",
")",
"next_update",
"=",
"mock_now",
"+",
"timedelta",
"(",
"minutes",
"=",
"5",
")",
"with",
"pa... | [
596,
0
] | [
615,
59
] | python | en | ['en', 'en', 'en'] | True |
test_send_fan_mode_device_timeout | (
hass, discovery, device, mock_now, fan_mode
) | Test for sending fan mode command to the device with a device timeout. | Test for sending fan mode command to the device with a device timeout. | async def test_send_fan_mode_device_timeout(
hass, discovery, device, mock_now, fan_mode
):
"""Test for sending fan mode command to the device with a device timeout."""
device().push_state_update.side_effect = DeviceTimeoutError
await async_setup_gree(hass)
next_update = mock_now + timedelta(minut... | [
"async",
"def",
"test_send_fan_mode_device_timeout",
"(",
"hass",
",",
"discovery",
",",
"device",
",",
"mock_now",
",",
"fan_mode",
")",
":",
"device",
"(",
")",
".",
"push_state_update",
".",
"side_effect",
"=",
"DeviceTimeoutError",
"await",
"async_setup_gree",
... | [
622,
0
] | [
644,
58
] | python | en | ['en', 'en', 'en'] | True |
test_update_fan_mode | (hass, discovery, device, mock_now, fan_mode) | Test for updating fan mode from the device. | Test for updating fan mode from the device. | async def test_update_fan_mode(hass, discovery, device, mock_now, fan_mode):
"""Test for updating fan mode from the device."""
device().fan_speed = FAN_MODES_REVERSE.get(fan_mode)
await async_setup_gree(hass)
next_update = mock_now + timedelta(minutes=5)
with patch("homeassistant.util.dt.utcnow", ... | [
"async",
"def",
"test_update_fan_mode",
"(",
"hass",
",",
"discovery",
",",
"device",
",",
"mock_now",
",",
"fan_mode",
")",
":",
"device",
"(",
")",
".",
"fan_speed",
"=",
"FAN_MODES_REVERSE",
".",
"get",
"(",
"fan_mode",
")",
"await",
"async_setup_gree",
"... | [
651,
0
] | [
664,
58
] | python | en | ['en', 'en', 'en'] | True |
test_send_swing_mode | (hass, discovery, device, mock_now, swing_mode) | Test for sending swing mode command to the device. | Test for sending swing mode command to the device. | async def test_send_swing_mode(hass, discovery, device, mock_now, swing_mode):
"""Test for sending swing mode command to the device."""
await async_setup_gree(hass)
next_update = mock_now + timedelta(minutes=5)
with patch("homeassistant.util.dt.utcnow", return_value=next_update):
async_fire_tim... | [
"async",
"def",
"test_send_swing_mode",
"(",
"hass",
",",
"discovery",
",",
"device",
",",
"mock_now",
",",
"swing_mode",
")",
":",
"await",
"async_setup_gree",
"(",
"hass",
")",
"next_update",
"=",
"mock_now",
"+",
"timedelta",
"(",
"minutes",
"=",
"5",
")"... | [
670,
0
] | [
688,
62
] | python | en | ['en', 'en', 'en'] | True |
test_send_invalid_swing_mode | (hass, discovery, device, mock_now) | Test for sending swing mode command to the device. | Test for sending swing mode command to the device. | async def test_send_invalid_swing_mode(hass, discovery, device, mock_now):
"""Test for sending swing mode command to the device."""
await async_setup_gree(hass)
next_update = mock_now + timedelta(minutes=5)
with patch("homeassistant.util.dt.utcnow", return_value=next_update):
async_fire_time_ch... | [
"async",
"def",
"test_send_invalid_swing_mode",
"(",
"hass",
",",
"discovery",
",",
"device",
",",
"mock_now",
")",
":",
"await",
"async_setup_gree",
"(",
"hass",
")",
"next_update",
"=",
"mock_now",
"+",
"timedelta",
"(",
"minutes",
"=",
"5",
")",
"with",
"... | [
691,
0
] | [
710,
61
] | python | en | ['en', 'en', 'en'] | True |
test_send_swing_mode_device_timeout | (
hass, discovery, device, mock_now, swing_mode
) | Test for sending swing mode command to the device with a device timeout. | Test for sending swing mode command to the device with a device timeout. | async def test_send_swing_mode_device_timeout(
hass, discovery, device, mock_now, swing_mode
):
"""Test for sending swing mode command to the device with a device timeout."""
device().push_state_update.side_effect = DeviceTimeoutError
await async_setup_gree(hass)
next_update = mock_now + timedelta... | [
"async",
"def",
"test_send_swing_mode_device_timeout",
"(",
"hass",
",",
"discovery",
",",
"device",
",",
"mock_now",
",",
"swing_mode",
")",
":",
"device",
"(",
")",
".",
"push_state_update",
".",
"side_effect",
"=",
"DeviceTimeoutError",
"await",
"async_setup_gree... | [
716,
0
] | [
738,
62
] | python | en | ['en', 'en', 'en'] | True |
test_update_swing_mode | (hass, discovery, device, mock_now, swing_mode) | Test for updating swing mode from the device. | Test for updating swing mode from the device. | async def test_update_swing_mode(hass, discovery, device, mock_now, swing_mode):
"""Test for updating swing mode from the device."""
device().horizontal_swing = (
HorizontalSwing.FullSwing
if swing_mode in (SWING_BOTH, SWING_HORIZONTAL)
else HorizontalSwing.Default
)
device().ver... | [
"async",
"def",
"test_update_swing_mode",
"(",
"hass",
",",
"discovery",
",",
"device",
",",
"mock_now",
",",
"swing_mode",
")",
":",
"device",
"(",
")",
".",
"horizontal_swing",
"=",
"(",
"HorizontalSwing",
".",
"FullSwing",
"if",
"swing_mode",
"in",
"(",
"... | [
744,
0
] | [
766,
62
] | python | en | ['en', 'en', 'en'] | True |
test_name | (hass, discovery, device) | Test for name property. | Test for name property. | async def test_name(hass, discovery, device):
"""Test for name property."""
await async_setup_gree(hass)
state = hass.states.get(ENTITY_ID)
assert state.attributes[ATTR_FRIENDLY_NAME] == "fake-device-1" | [
"async",
"def",
"test_name",
"(",
"hass",
",",
"discovery",
",",
"device",
")",
":",
"await",
"async_setup_gree",
"(",
"hass",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_ID",
")",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_F... | [
769,
0
] | [
773,
66
] | python | en | ['en', 'en', 'en'] | True |
test_supported_features_with_turnon | (hass, discovery, device) | Test for supported_features property. | Test for supported_features property. | async def test_supported_features_with_turnon(hass, discovery, device):
"""Test for supported_features property."""
await async_setup_gree(hass)
state = hass.states.get(ENTITY_ID)
assert state.attributes[ATTR_SUPPORTED_FEATURES] == SUPPORTED_FEATURES | [
"async",
"def",
"test_supported_features_with_turnon",
"(",
"hass",
",",
"discovery",
",",
"device",
")",
":",
"await",
"async_setup_gree",
"(",
"hass",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_ID",
")",
"assert",
"state",
".",
"att... | [
776,
0
] | [
780,
74
] | python | en | ['en', 'en', 'en'] | True |
build_tf_to_pytorch_map | (model, config) | A map of modules from TF to PyTorch.
This time I use a map to keep the PyTorch model as identical to the original PyTorch model as possible.
| A map of modules from TF to PyTorch.
This time I use a map to keep the PyTorch model as identical to the original PyTorch model as possible.
| def build_tf_to_pytorch_map(model, config):
""" A map of modules from TF to PyTorch.
This time I use a map to keep the PyTorch model as identical to the original PyTorch model as possible.
"""
tf_to_pt_map = {}
if hasattr(model, 'transformer'):
# We are loading in a TransfoXLLMHeadModel... | [
"def",
"build_tf_to_pytorch_map",
"(",
"model",
",",
"config",
")",
":",
"tf_to_pt_map",
"=",
"{",
"}",
"if",
"hasattr",
"(",
"model",
",",
"'transformer'",
")",
":",
"# We are loading in a TransfoXLLMHeadModel => we will load also the Adaptive Softmax",
"tf_to_pt_map",
"... | [
54,
0
] | [
124,
23
] | python | en | ['en', 'en', 'en'] | True |
load_tf_weights_in_transfo_xl | (model, config, tf_path) | Load tf checkpoints in a pytorch model
| Load tf checkpoints in a pytorch model
| def load_tf_weights_in_transfo_xl(model, config, tf_path):
""" Load tf checkpoints in a pytorch model
"""
try:
import numpy as np
import tensorflow as tf
except ImportError:
print("Loading a TensorFlow models in PyTorch, requires TensorFlow to be installed. Please see "
... | [
"def",
"load_tf_weights_in_transfo_xl",
"(",
"model",
",",
"config",
",",
"tf_path",
")",
":",
"try",
":",
"import",
"numpy",
"as",
"np",
"import",
"tensorflow",
"as",
"tf",
"except",
"ImportError",
":",
"print",
"(",
"\"Loading a TensorFlow models in PyTorch, requi... | [
126,
0
] | [
179,
16
] | python | en | ['en', 'en', 'en'] | True |
TransfoXLConfig.__init__ | (self,
vocab_size_or_config_json_file=267735,
cutoffs=[20000, 40000, 200000],
d_model=1024,
d_embed=1024,
n_head=16,
d_head=64,
d_inner=4096,
div_val=4,
pre_lnorm=Fals... | Constructs TransfoXLConfig.
Args:
vocab_size_or_config_json_file: Vocabulary size of `inputs_ids` in `TransfoXLModel` or a configuration json file.
cutoffs: cutoffs for the adaptive softmax
d_model: Dimensionality of the model's hidden states.
d_embed: Dimensiona... | Constructs TransfoXLConfig. | def __init__(self,
vocab_size_or_config_json_file=267735,
cutoffs=[20000, 40000, 200000],
d_model=1024,
d_embed=1024,
n_head=16,
d_head=64,
d_inner=4096,
div_val=4,
pr... | [
"def",
"__init__",
"(",
"self",
",",
"vocab_size_or_config_json_file",
"=",
"267735",
",",
"cutoffs",
"=",
"[",
"20000",
",",
"40000",
",",
"200000",
"]",
",",
"d_model",
"=",
"1024",
",",
"d_embed",
"=",
"1024",
",",
"n_head",
"=",
"16",
",",
"d_head",
... | [
185,
4
] | [
287,
83
] | python | en | ['en', 'en', 'it'] | False |
TransfoXLConfig.from_dict | (cls, json_object) | Constructs a `TransfoXLConfig` from a Python dictionary of parameters. | Constructs a `TransfoXLConfig` from a Python dictionary of parameters. | def from_dict(cls, json_object):
"""Constructs a `TransfoXLConfig` from a Python dictionary of parameters."""
config = TransfoXLConfig(vocab_size_or_config_json_file=-1)
for key, value in json_object.items():
config.__dict__[key] = value
return config | [
"def",
"from_dict",
"(",
"cls",
",",
"json_object",
")",
":",
"config",
"=",
"TransfoXLConfig",
"(",
"vocab_size_or_config_json_file",
"=",
"-",
"1",
")",
"for",
"key",
",",
"value",
"in",
"json_object",
".",
"items",
"(",
")",
":",
"config",
".",
"__dict_... | [
290,
4
] | [
295,
21
] | python | en | ['en', 'en', 'en'] | True |
TransfoXLConfig.from_json_file | (cls, json_file) | Constructs a `TransfoXLConfig` from a json file of parameters. | Constructs a `TransfoXLConfig` from a json file of parameters. | def from_json_file(cls, json_file):
"""Constructs a `TransfoXLConfig` from a json file of parameters."""
with open(json_file, "r", encoding='utf-8') as reader:
text = reader.read()
return cls.from_dict(json.loads(text)) | [
"def",
"from_json_file",
"(",
"cls",
",",
"json_file",
")",
":",
"with",
"open",
"(",
"json_file",
",",
"\"r\"",
",",
"encoding",
"=",
"'utf-8'",
")",
"as",
"reader",
":",
"text",
"=",
"reader",
".",
"read",
"(",
")",
"return",
"cls",
".",
"from_dict",... | [
298,
4
] | [
302,
46
] | python | en | ['en', 'en', 'en'] | True |
TransfoXLConfig.to_dict | (self) | Serializes this instance to a Python dictionary. | Serializes this instance to a Python dictionary. | def to_dict(self):
"""Serializes this instance to a Python dictionary."""
output = copy.deepcopy(self.__dict__)
return output | [
"def",
"to_dict",
"(",
"self",
")",
":",
"output",
"=",
"copy",
".",
"deepcopy",
"(",
"self",
".",
"__dict__",
")",
"return",
"output"
] | [
307,
4
] | [
310,
21
] | python | en | ['en', 'en', 'en'] | True |
TransfoXLConfig.to_json_string | (self) | Serializes this instance to a JSON string. | Serializes this instance to a JSON string. | def to_json_string(self):
"""Serializes this instance to a JSON string."""
return json.dumps(self.to_dict(), indent=2, sort_keys=True) + "\n" | [
"def",
"to_json_string",
"(",
"self",
")",
":",
"return",
"json",
".",
"dumps",
"(",
"self",
".",
"to_dict",
"(",
")",
",",
"indent",
"=",
"2",
",",
"sort_keys",
"=",
"True",
")",
"+",
"\"\\n\""
] | [
312,
4
] | [
314,
74
] | python | en | ['en', 'en', 'en'] | True |
TransfoXLPreTrainedModel.init_weights | (self, m) | Initialize the weights.
| Initialize the weights.
| def init_weights(self, m):
""" Initialize the weights.
"""
classname = m.__class__.__name__
if classname.find('Linear') != -1:
if hasattr(m, 'weight') and m.weight is not None:
self.init_weight(m.weight)
if hasattr(m, 'bias') and m.bias is not None... | [
"def",
"init_weights",
"(",
"self",
",",
"m",
")",
":",
"classname",
"=",
"m",
".",
"__class__",
".",
"__name__",
"if",
"classname",
".",
"find",
"(",
"'Linear'",
")",
"!=",
"-",
"1",
":",
"if",
"hasattr",
"(",
"m",
",",
"'weight'",
")",
"and",
"m"... | [
839,
4
] | [
878,
40
] | python | en | ['en', 'en', 'en'] | True |
TransfoXLPreTrainedModel.from_pretrained | (cls, pretrained_model_name_or_path, state_dict=None, cache_dir=None,
from_tf=False, *inputs, **kwargs) |
Instantiate a TransfoXLPreTrainedModel from a pre-trained model file or a pytorch state dict.
Download and cache the pre-trained model file if needed.
Params:
pretrained_model_name_or_path: either:
- a str with the name of a pre-trained model to load selected in the... |
Instantiate a TransfoXLPreTrainedModel from a pre-trained model file or a pytorch state dict.
Download and cache the pre-trained model file if needed. | def from_pretrained(cls, pretrained_model_name_or_path, state_dict=None, cache_dir=None,
from_tf=False, *inputs, **kwargs):
"""
Instantiate a TransfoXLPreTrainedModel from a pre-trained model file or a pytorch state dict.
Download and cache the pre-trained model file if n... | [
"def",
"from_pretrained",
"(",
"cls",
",",
"pretrained_model_name_or_path",
",",
"state_dict",
"=",
"None",
",",
"cache_dir",
"=",
"None",
",",
"from_tf",
"=",
"False",
",",
"*",
"inputs",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"pretrained_model_name_or_path... | [
884,
4
] | [
979,
20
] | python | en | ['en', 'error', 'th'] | False |
TransfoXLModel.forward | (self, input_ids, mems=None) | Params:
input_ids :: [bsz, len]
mems :: optional mems from previous forwar passes (or init_mems)
list (num layers) of mem states at the entry of each layer
shape :: [self.config.mem_len, bsz, self.config.d_model]
Note that ... | Params:
input_ids :: [bsz, len]
mems :: optional mems from previous forwar passes (or init_mems)
list (num layers) of mem states at the entry of each layer
shape :: [self.config.mem_len, bsz, self.config.d_model]
Note that ... | def forward(self, input_ids, mems=None):
""" Params:
input_ids :: [bsz, len]
mems :: optional mems from previous forwar passes (or init_mems)
list (num layers) of mem states at the entry of each layer
shape :: [self.config.mem_len, bsz,... | [
"def",
"forward",
"(",
"self",
",",
"input_ids",
",",
"mems",
"=",
"None",
")",
":",
"# the original code for Transformer-XL used shapes [len, bsz] but we want a unified interface in the library",
"# so we transpose here from shape [bsz, len] to shape [len, bsz]",
"input_ids",
"=",
"... | [
1232,
4
] | [
1256,
38
] | python | en | ['en', 'lt', 'pt'] | False |
TransfoXLLMHeadModel.tie_weights | (self) | Run this to be sure output and input (adaptive) softmax weights are tied | Run this to be sure output and input (adaptive) softmax weights are tied | def tie_weights(self):
""" Run this to be sure output and input (adaptive) softmax weights are tied """
# sampled softmax
if self.sample_softmax > 0:
if self.config.tie_weight:
self.out_layer.weight = self.transformer.word_emb.weight
# adaptive softmax (includ... | [
"def",
"tie_weights",
"(",
"self",
")",
":",
"# sampled softmax",
"if",
"self",
".",
"sample_softmax",
">",
"0",
":",
"if",
"self",
".",
"config",
".",
"tie_weight",
":",
"self",
".",
"out_layer",
".",
"weight",
"=",
"self",
".",
"transformer",
".",
"wor... | [
1324,
4
] | [
1340,
87
] | python | en | ['en', 'en', 'en'] | True |
TransfoXLLMHeadModel.forward | (self, input_ids, target=None, mems=None) | Params:
input_ids :: [bsz, len]
target :: [bsz, len]
Returns:
tuple(softmax_output, new_mems) where:
new_mems: list (num layers) of hidden states at the entry of each layer
shape :: [mem_len, bsz, self.config.d_mode... | Params:
input_ids :: [bsz, len]
target :: [bsz, len]
Returns:
tuple(softmax_output, new_mems) where:
new_mems: list (num layers) of hidden states at the entry of each layer
shape :: [mem_len, bsz, self.config.d_mode... | def forward(self, input_ids, target=None, mems=None):
""" Params:
input_ids :: [bsz, len]
target :: [bsz, len]
Returns:
tuple(softmax_output, new_mems) where:
new_mems: list (num layers) of hidden states at the entry of each layer
... | [
"def",
"forward",
"(",
"self",
",",
"input_ids",
",",
"target",
"=",
"None",
",",
"mems",
"=",
"None",
")",
":",
"bsz",
"=",
"input_ids",
".",
"size",
"(",
"0",
")",
"tgt_len",
"=",
"input_ids",
".",
"size",
"(",
"1",
")",
"last_hidden",
",",
"new_... | [
1348,
4
] | [
1380,
41
] | python | en | ['en', 'lt', 'pt'] | False |
async_setup | (hass: HomeAssistant, config: ConfigType) | Set up the BSB-Lan component. | Set up the BSB-Lan component. | async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the BSB-Lan component."""
return True | [
"async",
"def",
"async_setup",
"(",
"hass",
":",
"HomeAssistant",
",",
"config",
":",
"ConfigType",
")",
"->",
"bool",
":",
"return",
"True"
] | [
18,
0
] | [
20,
15
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass: HomeAssistant, entry: ConfigEntry) | Set up BSB-Lan from a config entry. | Set up BSB-Lan from a config entry. | async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up BSB-Lan from a config entry."""
session = async_get_clientsession(hass)
bsblan = BSBLan(
entry.data[CONF_HOST],
passkey=entry.data[CONF_PASSKEY],
port=entry.data[CONF_PORT],
session=sessi... | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"entry",
":",
"ConfigEntry",
")",
"->",
"bool",
":",
"session",
"=",
"async_get_clientsession",
"(",
"hass",
")",
"bsblan",
"=",
"BSBLan",
"(",
"entry",
".",
"data",
"[",
"CONF_HOST... | [
23,
0
] | [
46,
15
] | python | en | ['en', 'en', 'en'] | True |
async_unload_entry | (hass: HomeAssistant, entry: ConfigEntry) | Unload BSBLan config entry. | Unload BSBLan config entry. | async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload BSBLan config entry."""
await hass.config_entries.async_forward_entry_unload(entry, CLIMATE_DOMAIN)
# Cleanup
del hass.data[DOMAIN][entry.entry_id]
if not hass.data[DOMAIN]:
del hass.data[DOMAIN]
... | [
"async",
"def",
"async_unload_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"entry",
":",
"ConfigEntry",
")",
"->",
"bool",
":",
"await",
"hass",
".",
"config_entries",
".",
"async_forward_entry_unload",
"(",
"entry",
",",
"CLIMATE_DOMAIN",
")",
"# Cleanup",
"... | [
49,
0
] | [
59,
15
] | python | da | ['da', 'es', 'en'] | False |
async_setup | (hass: HomeAssistant, config: Dict) | Set up the IPP component. | Set up the IPP component. | async def async_setup(hass: HomeAssistant, config: Dict) -> bool:
"""Set up the IPP component."""
hass.data.setdefault(DOMAIN, {})
return True | [
"async",
"def",
"async_setup",
"(",
"hass",
":",
"HomeAssistant",
",",
"config",
":",
"Dict",
")",
"->",
"bool",
":",
"hass",
".",
"data",
".",
"setdefault",
"(",
"DOMAIN",
",",
"{",
"}",
")",
"return",
"True"
] | [
41,
0
] | [
44,
15
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass: HomeAssistant, entry: ConfigEntry) | Set up IPP from a config entry. | Set up IPP from a config entry. | async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up IPP from a config entry."""
# Create IPP instance for this entry
coordinator = IPPDataUpdateCoordinator(
hass,
host=entry.data[CONF_HOST],
port=entry.data[CONF_PORT],
base_path=entry.data... | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"entry",
":",
"ConfigEntry",
")",
"->",
"bool",
":",
"# Create IPP instance for this entry",
"coordinator",
"=",
"IPPDataUpdateCoordinator",
"(",
"hass",
",",
"host",
"=",
"entry",
".",
"... | [
47,
0
] | [
71,
15
] | python | en | ['en', 'en', 'en'] | True |
async_unload_entry | (hass: HomeAssistant, entry: ConfigEntry) | Unload a config entry. | Unload a config entry. | async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
unload_ok = all(
await asyncio.gather(
*[
hass.config_entries.async_forward_entry_unload(entry, component)
for component in PLATFORMS
]
... | [
"async",
"def",
"async_unload_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"entry",
":",
"ConfigEntry",
")",
"->",
"bool",
":",
"unload_ok",
"=",
"all",
"(",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"[",
"hass",
".",
"config_entries",
".",
"async_fo... | [
74,
0
] | [
88,
20
] | python | en | ['en', 'es', 'en'] | True |
IPPDataUpdateCoordinator.__init__ | (
self,
hass: HomeAssistant,
*,
host: str,
port: int,
base_path: str,
tls: bool,
verify_ssl: bool,
) | Initialize global IPP data updater. | Initialize global IPP data updater. | def __init__(
self,
hass: HomeAssistant,
*,
host: str,
port: int,
base_path: str,
tls: bool,
verify_ssl: bool,
):
"""Initialize global IPP data updater."""
self.ipp = IPP(
host=host,
port=port,
base_p... | [
"def",
"__init__",
"(",
"self",
",",
"hass",
":",
"HomeAssistant",
",",
"*",
",",
"host",
":",
"str",
",",
"port",
":",
"int",
",",
"base_path",
":",
"str",
",",
"tls",
":",
"bool",
",",
"verify_ssl",
":",
"bool",
",",
")",
":",
"self",
".",
"ipp... | [
94,
4
] | [
119,
9
] | python | en | ['en', 'en', 'it'] | True |
IPPDataUpdateCoordinator._async_update_data | (self) | Fetch data from IPP. | Fetch data from IPP. | async def _async_update_data(self) -> IPPPrinter:
"""Fetch data from IPP."""
try:
return await self.ipp.printer()
except IPPError as error:
raise UpdateFailed(f"Invalid response from API: {error}") from error | [
"async",
"def",
"_async_update_data",
"(",
"self",
")",
"->",
"IPPPrinter",
":",
"try",
":",
"return",
"await",
"self",
".",
"ipp",
".",
"printer",
"(",
")",
"except",
"IPPError",
"as",
"error",
":",
"raise",
"UpdateFailed",
"(",
"f\"Invalid response from API:... | [
121,
4
] | [
126,
80
] | python | en | ['en', 'en', 'en'] | True |
IPPEntity.__init__ | (
self,
*,
entry_id: str,
device_id: str,
coordinator: IPPDataUpdateCoordinator,
name: str,
icon: str,
enabled_default: bool = True,
) | Initialize the IPP entity. | Initialize the IPP entity. | def __init__(
self,
*,
entry_id: str,
device_id: str,
coordinator: IPPDataUpdateCoordinator,
name: str,
icon: str,
enabled_default: bool = True,
) -> None:
"""Initialize the IPP entity."""
super().__init__(coordinator)
self._dev... | [
"def",
"__init__",
"(",
"self",
",",
"*",
",",
"entry_id",
":",
"str",
",",
"device_id",
":",
"str",
",",
"coordinator",
":",
"IPPDataUpdateCoordinator",
",",
"name",
":",
"str",
",",
"icon",
":",
"str",
",",
"enabled_default",
":",
"bool",
"=",
"True",
... | [
132,
4
] | [
148,
25
] | python | en | ['en', 'en', 'en'] | True |
IPPEntity.name | (self) | Return the name of the entity. | Return the name of the entity. | def name(self) -> str:
"""Return the name of the entity."""
return self._name | [
"def",
"name",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_name"
] | [
151,
4
] | [
153,
25
] | python | en | ['en', 'en', 'en'] | True |
IPPEntity.icon | (self) | Return the mdi icon of the entity. | Return the mdi icon of the entity. | def icon(self) -> str:
"""Return the mdi icon of the entity."""
return self._icon | [
"def",
"icon",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_icon"
] | [
156,
4
] | [
158,
25
] | python | en | ['en', 'en', 'en'] | True |
IPPEntity.entity_registry_enabled_default | (self) | Return if the entity should be enabled when first added to the entity registry. | Return if the entity should be enabled when first added to the entity registry. | def entity_registry_enabled_default(self) -> bool:
"""Return if the entity should be enabled when first added to the entity registry."""
return self._enabled_default | [
"def",
"entity_registry_enabled_default",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_enabled_default"
] | [
161,
4
] | [
163,
36
] | python | en | ['en', 'en', 'en'] | True |
IPPEntity.device_info | (self) | Return device information about this IPP device. | Return device information about this IPP device. | def device_info(self) -> Dict[str, Any]:
"""Return device information about this IPP device."""
if self._device_id is None:
return None
return {
ATTR_IDENTIFIERS: {(DOMAIN, self._device_id)},
ATTR_NAME: self.coordinator.data.info.name,
ATTR_MANUFA... | [
"def",
"device_info",
"(",
"self",
")",
"->",
"Dict",
"[",
"str",
",",
"Any",
"]",
":",
"if",
"self",
".",
"_device_id",
"is",
"None",
":",
"return",
"None",
"return",
"{",
"ATTR_IDENTIFIERS",
":",
"{",
"(",
"DOMAIN",
",",
"self",
".",
"_device_id",
... | [
166,
4
] | [
177,
9
] | python | en | ['en', 'en', 'en'] | True |
conv2d | (x_input, w_matrix) | conv2d returns a 2d convolution layer with full stride. | conv2d returns a 2d convolution layer with full stride. | def conv2d(x_input, w_matrix):
"""conv2d returns a 2d convolution layer with full stride."""
return tf.nn.conv2d(x_input, w_matrix, strides=[1, 1, 1, 1], padding='SAME') | [
"def",
"conv2d",
"(",
"x_input",
",",
"w_matrix",
")",
":",
"return",
"tf",
".",
"nn",
".",
"conv2d",
"(",
"x_input",
",",
"w_matrix",
",",
"strides",
"=",
"[",
"1",
",",
"1",
",",
"1",
",",
"1",
"]",
",",
"padding",
"=",
"'SAME'",
")"
] | [
124,
0
] | [
126,
80
] | python | en | ['en', 'en', 'en'] | True |
max_pool | (x_input, pool_size) | max_pool downsamples a feature map by 2X. | max_pool downsamples a feature map by 2X. | def max_pool(x_input, pool_size):
"""max_pool downsamples a feature map by 2X."""
return tf.nn.max_pool(x_input, ksize=[1, pool_size, pool_size, 1],
strides=[1, pool_size, pool_size, 1], padding='SAME') | [
"def",
"max_pool",
"(",
"x_input",
",",
"pool_size",
")",
":",
"return",
"tf",
".",
"nn",
".",
"max_pool",
"(",
"x_input",
",",
"ksize",
"=",
"[",
"1",
",",
"pool_size",
",",
"pool_size",
",",
"1",
"]",
",",
"strides",
"=",
"[",
"1",
",",
"pool_siz... | [
129,
0
] | [
132,
79
] | python | en | ['en', 'en', 'en'] | True |
weight_variable | (shape) | weight_variable generates a weight variable of a given shape. | weight_variable generates a weight variable of a given shape. | def weight_variable(shape):
"""weight_variable generates a weight variable of a given shape."""
initial = tf.truncated_normal(shape, stddev=0.1)
return tf.Variable(initial) | [
"def",
"weight_variable",
"(",
"shape",
")",
":",
"initial",
"=",
"tf",
".",
"truncated_normal",
"(",
"shape",
",",
"stddev",
"=",
"0.1",
")",
"return",
"tf",
".",
"Variable",
"(",
"initial",
")"
] | [
135,
0
] | [
138,
31
] | python | en | ['en', 'en', 'en'] | True |
bias_variable | (shape) | bias_variable generates a bias variable of a given shape. | bias_variable generates a bias variable of a given shape. | def bias_variable(shape):
"""bias_variable generates a bias variable of a given shape."""
initial = tf.constant(0.1, shape=shape)
return tf.Variable(initial) | [
"def",
"bias_variable",
"(",
"shape",
")",
":",
"initial",
"=",
"tf",
".",
"constant",
"(",
"0.1",
",",
"shape",
"=",
"shape",
")",
"return",
"tf",
".",
"Variable",
"(",
"initial",
")"
] | [
141,
0
] | [
144,
31
] | python | en | ['en', 'en', 'en'] | True |
download_mnist_retry | (data_dir, max_num_retries=20) | Try to download mnist dataset and avoid errors | Try to download mnist dataset and avoid errors | def download_mnist_retry(data_dir, max_num_retries=20):
"""Try to download mnist dataset and avoid errors"""
for _ in range(max_num_retries):
try:
return input_data.read_data_sets(data_dir, one_hot=True)
except tf.errors.AlreadyExistsError:
time.sleep(1)
raise Excepti... | [
"def",
"download_mnist_retry",
"(",
"data_dir",
",",
"max_num_retries",
"=",
"20",
")",
":",
"for",
"_",
"in",
"range",
"(",
"max_num_retries",
")",
":",
"try",
":",
"return",
"input_data",
".",
"read_data_sets",
"(",
"data_dir",
",",
"one_hot",
"=",
"True",... | [
146,
0
] | [
153,
48
] | python | en | ['en', 'en', 'en'] | True |
main | (params) |
Main function, build mnist network, run and send result to NNI.
|
Main function, build mnist network, run and send result to NNI.
| def main(params):
'''
Main function, build mnist network, run and send result to NNI.
'''
# Import data
mnist = download_mnist_retry(params['data_dir'])
print('Mnist download data done.')
logger.debug('Mnist download data done.')
# Create the model
# Build the graph for the deep net... | [
"def",
"main",
"(",
"params",
")",
":",
"# Import data",
"mnist",
"=",
"download_mnist_retry",
"(",
"params",
"[",
"'data_dir'",
"]",
")",
"print",
"(",
"'Mnist download data done.'",
")",
"logger",
".",
"debug",
"(",
"'Mnist download data done.'",
")",
"# Create ... | [
155,
0
] | [
208,
47
] | python | en | ['en', 'error', 'th'] | False |
get_params | () | Get parameters from command line | Get parameters from command line | def get_params():
''' Get parameters from command line '''
parser = argparse.ArgumentParser()
parser.add_argument("--data_dir", type=str, default='/tmp/tensorflow/mnist/input_data', help="data directory")
parser.add_argument("--dropout_rate", type=float, default=0.5, help="dropout rate")
parser.add_... | [
"def",
"get_params",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
")",
"parser",
".",
"add_argument",
"(",
"\"--data_dir\"",
",",
"type",
"=",
"str",
",",
"default",
"=",
"'/tmp/tensorflow/mnist/input_data'",
",",
"help",
"=",
"\"data ... | [
210,
0
] | [
225,
15
] | python | en | ['en', 'en', 'en'] | True |
MnistNetwork.build_network | (self) |
Building network for mnist
|
Building network for mnist
| def build_network(self):
'''
Building network for mnist
'''
# Reshape to use within a convolutional neural net.
# Last dimension is for "features" - there is only one here, since images are
# grayscale -- it would be 3 for an RGB image, 4 for RGBA, etc.
with tf.n... | [
"def",
"build_network",
"(",
"self",
")",
":",
"# Reshape to use within a convolutional neural net.",
"# Last dimension is for \"features\" - there is only one here, since images are",
"# grayscale -- it would be 3 for an RGB image, 4 for RGBA, etc.",
"with",
"tf",
".",
"name_scope",
"(",
... | [
47,
4
] | [
121,
56
] | python | en | ['en', 'error', 'th'] | False |
_patch_media_setup | () | Patch media_player.async_setup_entry. | Patch media_player.async_setup_entry. | def _patch_media_setup():
"""Patch media_player.async_setup_entry."""
async def _async_return():
return True
return patch(
"homeassistant.components.songpal.media_player.async_setup_entry",
side_effect=_async_return,
) | [
"def",
"_patch_media_setup",
"(",
")",
":",
"async",
"def",
"_async_return",
"(",
")",
":",
"return",
"True",
"return",
"patch",
"(",
"\"homeassistant.components.songpal.media_player.async_setup_entry\"",
",",
"side_effect",
"=",
"_async_return",
",",
")"
] | [
15,
0
] | [
24,
5
] | python | en | ['en', 'cs', 'en'] | False |
test_setup_empty | (hass) | Test setup without any configuration. | Test setup without any configuration. | async def test_setup_empty(hass):
"""Test setup without any configuration."""
with _patch_media_setup() as setup:
assert await async_setup_component(hass, songpal.DOMAIN, {}) is True
await hass.async_block_till_done()
setup.assert_not_called() | [
"async",
"def",
"test_setup_empty",
"(",
"hass",
")",
":",
"with",
"_patch_media_setup",
"(",
")",
"as",
"setup",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"songpal",
".",
"DOMAIN",
",",
"{",
"}",
")",
"is",
"True",
"await",
"hass"... | [
27,
0
] | [
32,
29
] | python | en | ['en', 'zu', 'en'] | True |
test_setup | (hass) | Test setup the platform. | Test setup the platform. | async def test_setup(hass):
"""Test setup the platform."""
mocked_device = _create_mocked_device()
with _patch_config_flow_device(mocked_device), _patch_media_setup() as setup:
assert (
await async_setup_component(
hass, songpal.DOMAIN, {songpal.DOMAIN: [CONF_DATA]}
... | [
"async",
"def",
"test_setup",
"(",
"hass",
")",
":",
"mocked_device",
"=",
"_create_mocked_device",
"(",
")",
"with",
"_patch_config_flow_device",
"(",
"mocked_device",
")",
",",
"_patch_media_setup",
"(",
")",
"as",
"setup",
":",
"assert",
"(",
"await",
"async_... | [
35,
0
] | [
48,
30
] | python | en | ['en', 'da', 'en'] | True |
test_unload | (hass) | Test unload entity. | Test unload entity. | async def test_unload(hass):
"""Test unload entity."""
entry = MockConfigEntry(domain=songpal.DOMAIN, data=CONF_DATA)
entry.add_to_hass(hass)
mocked_device = _create_mocked_device()
with _patch_config_flow_device(mocked_device), _patch_media_player_device(
mocked_device
):
asser... | [
"async",
"def",
"test_unload",
"(",
"hass",
")",
":",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"songpal",
".",
"DOMAIN",
",",
"data",
"=",
"CONF_DATA",
")",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"mocked_device",
"=",
"_create_mocked_devi... | [
51,
0
] | [
65,
64
] | python | de | ['de', 'fr', 'it'] | False |
TFT5LayerNorm.__init__ | (self, epsilon=1e-6, **kwargs) |
Construct a layernorm module in the T5 style No bias and no subtraction of mean.
|
Construct a layernorm module in the T5 style No bias and no subtraction of mean.
| def __init__(self, epsilon=1e-6, **kwargs):
"""
Construct a layernorm module in the T5 style No bias and no subtraction of mean.
"""
super().__init__(**kwargs)
self.variance_epsilon = epsilon | [
"def",
"__init__",
"(",
"self",
",",
"epsilon",
"=",
"1e-6",
",",
"*",
"*",
"kwargs",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"*",
"*",
"kwargs",
")",
"self",
".",
"variance_epsilon",
"=",
"epsilon"
] | [
74,
4
] | [
79,
39
] | python | en | ['en', 'error', 'th'] | False |
TFT5LayerNorm.build | (self, input_shape) | Build shared word embedding layer | Build shared word embedding layer | def build(self, input_shape):
"""Build shared word embedding layer """
self.weight = self.add_weight("weight", shape=(input_shape[-1],), initializer="ones")
super().build(input_shape) | [
"def",
"build",
"(",
"self",
",",
"input_shape",
")",
":",
"self",
".",
"weight",
"=",
"self",
".",
"add_weight",
"(",
"\"weight\"",
",",
"shape",
"=",
"(",
"input_shape",
"[",
"-",
"1",
"]",
",",
")",
",",
"initializer",
"=",
"\"ones\"",
")",
"super... | [
81,
4
] | [
84,
34
] | python | en | ['en', 'en', 'en'] | True |
TFT5Attention._relative_position_bucket | (relative_position, bidirectional=True, num_buckets=32, max_distance=128) |
Adapted from Mesh Tensorflow:
https://github.com/tensorflow/mesh/blob/0cb87fe07da627bf0b7e60475d59f95ed6b5be3d/mesh_tensorflow/transformer/transformer_layers.py#L593
Translate relative position to a bucket number for relative attention. The relative position is defined as
memory_positi... |
Adapted from Mesh Tensorflow:
https://github.com/tensorflow/mesh/blob/0cb87fe07da627bf0b7e60475d59f95ed6b5be3d/mesh_tensorflow/transformer/transformer_layers.py#L593 | def _relative_position_bucket(relative_position, bidirectional=True, num_buckets=32, max_distance=128):
"""
Adapted from Mesh Tensorflow:
https://github.com/tensorflow/mesh/blob/0cb87fe07da627bf0b7e60475d59f95ed6b5be3d/mesh_tensorflow/transformer/transformer_layers.py#L593
Translate rel... | [
"def",
"_relative_position_bucket",
"(",
"relative_position",
",",
"bidirectional",
"=",
"True",
",",
"num_buckets",
"=",
"32",
",",
"max_distance",
"=",
"128",
")",
":",
"relative_buckets",
"=",
"0",
"# n = -relative_position",
"if",
"bidirectional",
":",
"n... | [
187,
4
] | [
229,
31
] | python | en | ['en', 'error', 'th'] | False |
TFT5Attention.compute_bias | (self, query_length, key_length) | Compute binned relative position bias | Compute binned relative position bias | def compute_bias(self, query_length, key_length):
""" Compute binned relative position bias """
context_position = tf.range(query_length)[:, None]
memory_position = tf.range(key_length)[None, :]
relative_position = memory_position - context_position # shape (query_length, key_length)
... | [
"def",
"compute_bias",
"(",
"self",
",",
"query_length",
",",
"key_length",
")",
":",
"context_position",
"=",
"tf",
".",
"range",
"(",
"query_length",
")",
"[",
":",
",",
"None",
"]",
"memory_position",
"=",
"tf",
".",
"range",
"(",
"key_length",
")",
"... | [
231,
4
] | [
247,
21
] | python | en | ['en', 'en', 'nl'] | True |
TFT5Attention.call | (
self,
hidden_states,
mask=None,
key_value_states=None,
position_bias=None,
past_key_value=None,
layer_head_mask=None,
query_length=None,
use_cache=False,
training=False,
output_attentions=False,
) |
Self-attention (if key_value_states is None) or attention over source sentence (provided by key_value_states).
|
Self-attention (if key_value_states is None) or attention over source sentence (provided by key_value_states).
| def call(
self,
hidden_states,
mask=None,
key_value_states=None,
position_bias=None,
past_key_value=None,
layer_head_mask=None,
query_length=None,
use_cache=False,
training=False,
output_attentions=False,
):
"""
... | [
"def",
"call",
"(",
"self",
",",
"hidden_states",
",",
"mask",
"=",
"None",
",",
"key_value_states",
"=",
"None",
",",
"position_bias",
"=",
"None",
",",
"past_key_value",
"=",
"None",
",",
"layer_head_mask",
"=",
"None",
",",
"query_length",
"=",
"None",
... | [
249,
4
] | [
371,
22
] | python | en | ['en', 'error', 'th'] | False |
async_setup_entity_state | (
config, async_add_entities, config_entry, discovery_data
) | Set up a State MQTT Vacuum. | Set up a State MQTT Vacuum. | async def async_setup_entity_state(
config, async_add_entities, config_entry, discovery_data
):
"""Set up a State MQTT Vacuum."""
async_add_entities([MqttStateVacuum(config, config_entry, discovery_data)]) | [
"async",
"def",
"async_setup_entity_state",
"(",
"config",
",",
"async_add_entities",
",",
"config_entry",
",",
"discovery_data",
")",
":",
"async_add_entities",
"(",
"[",
"MqttStateVacuum",
"(",
"config",
",",
"config_entry",
",",
"discovery_data",
")",
"]",
")"
] | [
156,
0
] | [
160,
79
] | python | en | ['en', 'co', 'en'] | True |
MqttStateVacuum.__init__ | (self, config, config_entry, discovery_info) | Initialize the vacuum. | Initialize the vacuum. | def __init__(self, config, config_entry, discovery_info):
"""Initialize the vacuum."""
self._state = None
self._state_attrs = {}
self._fan_speed_list = []
self._sub_state = None
self._unique_id = config.get(CONF_UNIQUE_ID)
# Load config
self._setup_from_c... | [
"def",
"__init__",
"(",
"self",
",",
"config",
",",
"config_entry",
",",
"discovery_info",
")",
":",
"self",
".",
"_state",
"=",
"None",
"self",
".",
"_state_attrs",
"=",
"{",
"}",
"self",
".",
"_fan_speed_list",
"=",
"[",
"]",
"self",
".",
"_sub_state",... | [
172,
4
] | [
188,
72
] | python | en | ['en', 'la', 'en'] | True |
MqttStateVacuum.discovery_update | (self, discovery_payload) | Handle updated discovery message. | Handle updated discovery message. | async def discovery_update(self, discovery_payload):
"""Handle updated discovery message."""
config = PLATFORM_SCHEMA_STATE(discovery_payload)
self._setup_from_config(config)
await self.attributes_discovery_update(config)
await self.availability_discovery_update(config)
a... | [
"async",
"def",
"discovery_update",
"(",
"self",
",",
"discovery_payload",
")",
":",
"config",
"=",
"PLATFORM_SCHEMA_STATE",
"(",
"discovery_payload",
")",
"self",
".",
"_setup_from_config",
"(",
"config",
")",
"await",
"self",
".",
"attributes_discovery_update",
"(... | [
214,
4
] | [
222,
35
] | python | en | ['en', 'en', 'en'] | True |
MqttStateVacuum.async_added_to_hass | (self) | Subscribe MQTT events. | Subscribe MQTT events. | async def async_added_to_hass(self):
"""Subscribe MQTT events."""
await super().async_added_to_hass()
await self._subscribe_topics() | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"await",
"super",
"(",
")",
".",
"async_added_to_hass",
"(",
")",
"await",
"self",
".",
"_subscribe_topics",
"(",
")"
] | [
224,
4
] | [
227,
38
] | python | en | ['en', 'en', 'en'] | True |
MqttStateVacuum.async_will_remove_from_hass | (self) | Unsubscribe when removed. | Unsubscribe when removed. | async def async_will_remove_from_hass(self):
"""Unsubscribe when removed."""
self._sub_state = await subscription.async_unsubscribe_topics(
self.hass, self._sub_state
)
await MqttAttributes.async_will_remove_from_hass(self)
await MqttAvailability.async_will_remove_fro... | [
"async",
"def",
"async_will_remove_from_hass",
"(",
"self",
")",
":",
"self",
".",
"_sub_state",
"=",
"await",
"subscription",
".",
"async_unsubscribe_topics",
"(",
"self",
".",
"hass",
",",
"self",
".",
"_sub_state",
")",
"await",
"MqttAttributes",
".",
"async_... | [
229,
4
] | [
236,
67
] | python | en | ['en', 'en', 'en'] | True |
MqttStateVacuum._subscribe_topics | (self) | (Re)Subscribe to topics. | (Re)Subscribe to topics. | async def _subscribe_topics(self):
"""(Re)Subscribe to topics."""
topics = {}
@callback
@log_messages(self.hass, self.entity_id)
def state_message_received(msg):
"""Handle state MQTT message."""
payload = json.loads(msg.payload)
if STATE in pa... | [
"async",
"def",
"_subscribe_topics",
"(",
"self",
")",
":",
"topics",
"=",
"{",
"}",
"@",
"callback",
"@",
"log_messages",
"(",
"self",
".",
"hass",
",",
"self",
".",
"entity_id",
")",
"def",
"state_message_received",
"(",
"msg",
")",
":",
"\"\"\"Handle st... | [
238,
4
] | [
261,
9
] | python | en | ['en', 'en', 'en'] | True |
MqttStateVacuum.name | (self) | Return the name of the vacuum. | Return the name of the vacuum. | def name(self):
"""Return the name of the vacuum."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
264,
4
] | [
266,
25
] | python | en | ['en', 'en', 'en'] | True |
MqttStateVacuum.state | (self) | Return state of vacuum. | Return state of vacuum. | def state(self):
"""Return state of vacuum."""
return self._state | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
269,
4
] | [
271,
26
] | python | en | ['en', 'la', 'en'] | True |
MqttStateVacuum.unique_id | (self) | Return a unique ID. | Return a unique ID. | def unique_id(self):
"""Return a unique ID."""
return self._unique_id | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unique_id"
] | [
274,
4
] | [
276,
30
] | python | ca | ['fr', 'ca', 'en'] | False |
MqttStateVacuum.fan_speed | (self) | Return fan speed of the vacuum. | Return fan speed of the vacuum. | def fan_speed(self):
"""Return fan speed of the vacuum."""
return self._state_attrs.get(FAN_SPEED, 0) | [
"def",
"fan_speed",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state_attrs",
".",
"get",
"(",
"FAN_SPEED",
",",
"0",
")"
] | [
279,
4
] | [
281,
50
] | python | en | ['en', 'fy', 'en'] | True |
MqttStateVacuum.fan_speed_list | (self) | Return fan speed list of the vacuum. | Return fan speed list of the vacuum. | def fan_speed_list(self):
"""Return fan speed list of the vacuum."""
return self._fan_speed_list | [
"def",
"fan_speed_list",
"(",
"self",
")",
":",
"return",
"self",
".",
"_fan_speed_list"
] | [
284,
4
] | [
286,
35
] | python | en | ['en', 'fy', 'en'] | True |
MqttStateVacuum.battery_level | (self) | Return battery level of the vacuum. | Return battery level of the vacuum. | def battery_level(self):
"""Return battery level of the vacuum."""
return max(0, min(100, self._state_attrs.get(BATTERY, 0))) | [
"def",
"battery_level",
"(",
"self",
")",
":",
"return",
"max",
"(",
"0",
",",
"min",
"(",
"100",
",",
"self",
".",
"_state_attrs",
".",
"get",
"(",
"BATTERY",
",",
"0",
")",
")",
")"
] | [
289,
4
] | [
291,
66
] | python | en | ['en', 'en', 'en'] | True |
MqttStateVacuum.supported_features | (self) | Flag supported features. | Flag supported features. | def supported_features(self):
"""Flag supported features."""
return self._supported_features | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"self",
".",
"_supported_features"
] | [
294,
4
] | [
296,
39
] | python | en | ['da', 'en', 'en'] | True |
MqttStateVacuum.async_start | (self) | Start the vacuum. | Start the vacuum. | async def async_start(self):
"""Start the vacuum."""
if self.supported_features & SUPPORT_START == 0:
return None
mqtt.async_publish(
self.hass,
self._command_topic,
self._config[CONF_PAYLOAD_START],
self._config[CONF_QOS],
... | [
"async",
"def",
"async_start",
"(",
"self",
")",
":",
"if",
"self",
".",
"supported_features",
"&",
"SUPPORT_START",
"==",
"0",
":",
"return",
"None",
"mqtt",
".",
"async_publish",
"(",
"self",
".",
"hass",
",",
"self",
".",
"_command_topic",
",",
"self",
... | [
298,
4
] | [
308,
9
] | python | en | ['en', 'la', 'en'] | True |
MqttStateVacuum.async_pause | (self) | Pause the vacuum. | Pause the vacuum. | async def async_pause(self):
"""Pause the vacuum."""
if self.supported_features & SUPPORT_PAUSE == 0:
return None
mqtt.async_publish(
self.hass,
self._command_topic,
self._config[CONF_PAYLOAD_PAUSE],
self._config[CONF_QOS],
... | [
"async",
"def",
"async_pause",
"(",
"self",
")",
":",
"if",
"self",
".",
"supported_features",
"&",
"SUPPORT_PAUSE",
"==",
"0",
":",
"return",
"None",
"mqtt",
".",
"async_publish",
"(",
"self",
".",
"hass",
",",
"self",
".",
"_command_topic",
",",
"self",
... | [
310,
4
] | [
320,
9
] | python | en | ['en', 'la', 'en'] | True |
MqttStateVacuum.async_stop | (self, **kwargs) | Stop the vacuum. | Stop the vacuum. | async def async_stop(self, **kwargs):
"""Stop the vacuum."""
if self.supported_features & SUPPORT_STOP == 0:
return None
mqtt.async_publish(
self.hass,
self._command_topic,
self._config[CONF_PAYLOAD_STOP],
self._config[CONF_QOS],
... | [
"async",
"def",
"async_stop",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"supported_features",
"&",
"SUPPORT_STOP",
"==",
"0",
":",
"return",
"None",
"mqtt",
".",
"async_publish",
"(",
"self",
".",
"hass",
",",
"self",
".",
"_co... | [
322,
4
] | [
332,
9
] | python | en | ['en', 'la', 'en'] | True |
MqttStateVacuum.async_set_fan_speed | (self, fan_speed, **kwargs) | Set fan speed. | Set fan speed. | async def async_set_fan_speed(self, fan_speed, **kwargs):
"""Set fan speed."""
if (self.supported_features & SUPPORT_FAN_SPEED == 0) or (
fan_speed not in self._fan_speed_list
):
return None
mqtt.async_publish(
self.hass,
self._set_fan_spee... | [
"async",
"def",
"async_set_fan_speed",
"(",
"self",
",",
"fan_speed",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"(",
"self",
".",
"supported_features",
"&",
"SUPPORT_FAN_SPEED",
"==",
"0",
")",
"or",
"(",
"fan_speed",
"not",
"in",
"self",
".",
"_fan_speed_l... | [
334,
4
] | [
346,
9
] | python | fy | ['sv', 'fy', 'ur'] | False |
MqttStateVacuum.async_return_to_base | (self, **kwargs) | Tell the vacuum to return to its dock. | Tell the vacuum to return to its dock. | async def async_return_to_base(self, **kwargs):
"""Tell the vacuum to return to its dock."""
if self.supported_features & SUPPORT_RETURN_HOME == 0:
return None
mqtt.async_publish(
self.hass,
self._command_topic,
self._config[CONF_PAYLOAD_RETURN_TO_... | [
"async",
"def",
"async_return_to_base",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"supported_features",
"&",
"SUPPORT_RETURN_HOME",
"==",
"0",
":",
"return",
"None",
"mqtt",
".",
"async_publish",
"(",
"self",
".",
"hass",
",",
"sel... | [
348,
4
] | [
358,
9
] | python | en | ['en', 'en', 'en'] | True |
MqttStateVacuum.async_clean_spot | (self, **kwargs) | Perform a spot clean-up. | Perform a spot clean-up. | async def async_clean_spot(self, **kwargs):
"""Perform a spot clean-up."""
if self.supported_features & SUPPORT_CLEAN_SPOT == 0:
return None
mqtt.async_publish(
self.hass,
self._command_topic,
self._config[CONF_PAYLOAD_CLEAN_SPOT],
self... | [
"async",
"def",
"async_clean_spot",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"supported_features",
"&",
"SUPPORT_CLEAN_SPOT",
"==",
"0",
":",
"return",
"None",
"mqtt",
".",
"async_publish",
"(",
"self",
".",
"hass",
",",
"self",
... | [
360,
4
] | [
370,
9
] | python | en | ['pt', 'en', 'en'] | True |
MqttStateVacuum.async_locate | (self, **kwargs) | Locate the vacuum (usually by playing a song). | Locate the vacuum (usually by playing a song). | async def async_locate(self, **kwargs):
"""Locate the vacuum (usually by playing a song)."""
if self.supported_features & SUPPORT_LOCATE == 0:
return None
mqtt.async_publish(
self.hass,
self._command_topic,
self._config[CONF_PAYLOAD_LOCATE],
... | [
"async",
"def",
"async_locate",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"supported_features",
"&",
"SUPPORT_LOCATE",
"==",
"0",
":",
"return",
"None",
"mqtt",
".",
"async_publish",
"(",
"self",
".",
"hass",
",",
"self",
".",
... | [
372,
4
] | [
382,
9
] | python | en | ['en', 'en', 'en'] | True |
MqttStateVacuum.async_send_command | (self, command, params=None, **kwargs) | Send a command to a vacuum cleaner. | Send a command to a vacuum cleaner. | async def async_send_command(self, command, params=None, **kwargs):
"""Send a command to a vacuum cleaner."""
if self.supported_features & SUPPORT_SEND_COMMAND == 0:
return None
if params:
message = {"command": command}
message.update(params)
messa... | [
"async",
"def",
"async_send_command",
"(",
"self",
",",
"command",
",",
"params",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"supported_features",
"&",
"SUPPORT_SEND_COMMAND",
"==",
"0",
":",
"return",
"None",
"if",
"params",
":",
... | [
384,
4
] | [
400,
9
] | python | en | ['en', 'en', 'en'] | True |
test_config_entry_not_ready | (
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) | Test configuration entry not ready on library error. | Test configuration entry not ready on library error. | async def test_config_entry_not_ready(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test configuration entry not ready on library error."""
aioclient_mock.post("http://127.0.0.1:10000/retrieve", exc=aiohttp.ClientError)
entry = await init_integration(hass, aioclient_mock)
a... | [
"async",
"def",
"test_config_entry_not_ready",
"(",
"hass",
":",
"HomeAssistant",
",",
"aioclient_mock",
":",
"AiohttpClientMocker",
")",
"->",
"None",
":",
"aioclient_mock",
".",
"post",
"(",
"\"http://127.0.0.1:10000/retrieve\"",
",",
"exc",
"=",
"aiohttp",
".",
"... | [
12,
0
] | [
18,
49
] | python | en | ['en', 'en', 'en'] | True |
test_config_entry_empty_reply | (
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) | Test configuration entry not ready when library returns False. | Test configuration entry not ready when library returns False. | async def test_config_entry_empty_reply(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test configuration entry not ready when library returns False."""
with patch("pyatag.AtagOne.update", return_value=False):
entry = await init_integration(hass, aioclient_mock)
asse... | [
"async",
"def",
"test_config_entry_empty_reply",
"(",
"hass",
":",
"HomeAssistant",
",",
"aioclient_mock",
":",
"AiohttpClientMocker",
")",
"->",
"None",
":",
"with",
"patch",
"(",
"\"pyatag.AtagOne.update\"",
",",
"return_value",
"=",
"False",
")",
":",
"entry",
... | [
21,
0
] | [
27,
53
] | python | en | ['en', 'en', 'en'] | True |
test_unload_config_entry | (
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) | Test the ATAG configuration entry unloading. | Test the ATAG configuration entry unloading. | async def test_unload_config_entry(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test the ATAG configuration entry unloading."""
entry = await init_integration(hass, aioclient_mock)
assert hass.data[DOMAIN]
await hass.config_entries.async_unload(entry.entry_id)
await ha... | [
"async",
"def",
"test_unload_config_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"aioclient_mock",
":",
"AiohttpClientMocker",
")",
"->",
"None",
":",
"entry",
"=",
"await",
"init_integration",
"(",
"hass",
",",
"aioclient_mock",
")",
"assert",
"hass",
".",
"... | [
30,
0
] | [
38,
36
] | python | en | ['en', 'en', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up switch platform for ADS. | Set up switch platform for ADS. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up switch platform for ADS."""
ads_hub = hass.data.get(DATA_ADS)
name = config[CONF_NAME]
ads_var = config[CONF_ADS_VAR]
add_entities([AdsSwitch(ads_hub, name, ads_var)]) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"ads_hub",
"=",
"hass",
".",
"data",
".",
"get",
"(",
"DATA_ADS",
")",
"name",
"=",
"config",
"[",
"CONF_NAME",
"]",
"ads_var",
"=",
... | [
19,
0
] | [
26,
53
] | python | en | ['en', 'da', 'en'] | True |
AdsSwitch.async_added_to_hass | (self) | Register device notification. | Register device notification. | async def async_added_to_hass(self):
"""Register device notification."""
await self.async_initialize_device(self._ads_var, self._ads_hub.PLCTYPE_BOOL) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"await",
"self",
".",
"async_initialize_device",
"(",
"self",
".",
"_ads_var",
",",
"self",
".",
"_ads_hub",
".",
"PLCTYPE_BOOL",
")"
] | [
32,
4
] | [
34,
85
] | python | en | ['da', 'en', 'en'] | True |
AdsSwitch.is_on | (self) | Return True if the entity is on. | Return True if the entity is on. | def is_on(self):
"""Return True if the entity is on."""
return self._state_dict[STATE_KEY_STATE] | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state_dict",
"[",
"STATE_KEY_STATE",
"]"
] | [
37,
4
] | [
39,
48
] | python | en | ['en', 'en', 'en'] | True |
AdsSwitch.turn_on | (self, **kwargs) | Turn the switch on. | Turn the switch on. | def turn_on(self, **kwargs):
"""Turn the switch on."""
self._ads_hub.write_by_name(self._ads_var, True, self._ads_hub.PLCTYPE_BOOL) | [
"def",
"turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_ads_hub",
".",
"write_by_name",
"(",
"self",
".",
"_ads_var",
",",
"True",
",",
"self",
".",
"_ads_hub",
".",
"PLCTYPE_BOOL",
")"
] | [
41,
4
] | [
43,
84
] | python | en | ['en', 'en', 'en'] | True |
AdsSwitch.turn_off | (self, **kwargs) | Turn the switch off. | Turn the switch off. | def turn_off(self, **kwargs):
"""Turn the switch off."""
self._ads_hub.write_by_name(self._ads_var, False, self._ads_hub.PLCTYPE_BOOL) | [
"def",
"turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_ads_hub",
".",
"write_by_name",
"(",
"self",
".",
"_ads_var",
",",
"False",
",",
"self",
".",
"_ads_hub",
".",
"PLCTYPE_BOOL",
")"
] | [
45,
4
] | [
47,
85
] | python | en | ['en', 'en', 'en'] | True |
load_vocab | (vocab_file) | Loads a vocabulary file into a dictionary. | Loads a vocabulary file into a dictionary. | def load_vocab(vocab_file):
"""Loads a vocabulary file into a dictionary."""
vocab = collections.OrderedDict()
with open(vocab_file, "r", encoding="utf-8") as reader:
tokens = reader.readlines()
for index, token in enumerate(tokens):
token = token.rstrip("\n")
vocab[token] = inde... | [
"def",
"load_vocab",
"(",
"vocab_file",
")",
":",
"vocab",
"=",
"collections",
".",
"OrderedDict",
"(",
")",
"with",
"open",
"(",
"vocab_file",
",",
"\"r\"",
",",
"encoding",
"=",
"\"utf-8\"",
")",
"as",
"reader",
":",
"tokens",
"=",
"reader",
".",
"read... | [
96,
0
] | [
104,
16
] | python | en | ['en', 'en', 'en'] | True |
whitespace_tokenize | (text) | Runs basic whitespace cleaning and splitting on a piece of text. | Runs basic whitespace cleaning and splitting on a piece of text. | def whitespace_tokenize(text):
"""Runs basic whitespace cleaning and splitting on a piece of text."""
text = text.strip()
if not text:
return []
tokens = text.split()
return tokens | [
"def",
"whitespace_tokenize",
"(",
"text",
")",
":",
"text",
"=",
"text",
".",
"strip",
"(",
")",
"if",
"not",
"text",
":",
"return",
"[",
"]",
"tokens",
"=",
"text",
".",
"split",
"(",
")",
"return",
"tokens"
] | [
107,
0
] | [
113,
17
] | python | en | ['en', 'en', 'en'] | True |
BertTokenizer._convert_token_to_id | (self, token) | Converts a token (str) in an id using the vocab. | Converts a token (str) in an id using the vocab. | def _convert_token_to_id(self, token):
""" Converts a token (str) in an id using the vocab. """
return self.vocab.get(token, self.vocab.get(self.unk_token)) | [
"def",
"_convert_token_to_id",
"(",
"self",
",",
"token",
")",
":",
"return",
"self",
".",
"vocab",
".",
"get",
"(",
"token",
",",
"self",
".",
"vocab",
".",
"get",
"(",
"self",
".",
"unk_token",
")",
")"
] | [
234,
4
] | [
236,
68
] | python | en | ['en', 'en', 'en'] | True |
BertTokenizer._convert_id_to_token | (self, index) | Converts an index (integer) in a token (str) using the vocab. | Converts an index (integer) in a token (str) using the vocab. | def _convert_id_to_token(self, index):
"""Converts an index (integer) in a token (str) using the vocab."""
return self.ids_to_tokens.get(index, self.unk_token) | [
"def",
"_convert_id_to_token",
"(",
"self",
",",
"index",
")",
":",
"return",
"self",
".",
"ids_to_tokens",
".",
"get",
"(",
"index",
",",
"self",
".",
"unk_token",
")"
] | [
238,
4
] | [
240,
60
] | python | en | ['en', 'en', 'en'] | True |
BertTokenizer.convert_tokens_to_string | (self, tokens) | Converts a sequence of tokens (string) in a single string. | Converts a sequence of tokens (string) in a single string. | def convert_tokens_to_string(self, tokens):
""" Converts a sequence of tokens (string) in a single string. """
out_string = " ".join(tokens).replace(" ##", "").strip()
return out_string | [
"def",
"convert_tokens_to_string",
"(",
"self",
",",
"tokens",
")",
":",
"out_string",
"=",
"\" \"",
".",
"join",
"(",
"tokens",
")",
".",
"replace",
"(",
"\" ##\"",
",",
"\"\"",
")",
".",
"strip",
"(",
")",
"return",
"out_string"
] | [
242,
4
] | [
245,
25
] | python | en | ['en', 'en', 'en'] | True |
BertTokenizer.build_inputs_with_special_tokens | (
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
) |
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
adding special tokens. A BERT sequence has the following format:
- single sequence: ``[CLS] X [SEP]``
- pair of sequences: ``[CLS] A [SEP] B [SEP]``
Args:
... |
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
adding special tokens. A BERT sequence has the following format: | def build_inputs_with_special_tokens(
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
) -> List[int]:
"""
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
adding special tokens. A BERT sequence has t... | [
"def",
"build_inputs_with_special_tokens",
"(",
"self",
",",
"token_ids_0",
":",
"List",
"[",
"int",
"]",
",",
"token_ids_1",
":",
"Optional",
"[",
"List",
"[",
"int",
"]",
"]",
"=",
"None",
")",
"->",
"List",
"[",
"int",
"]",
":",
"if",
"token_ids_1",
... | [
247,
4
] | [
270,
58
] | python | en | ['en', 'error', 'th'] | False |
BertTokenizer.get_special_tokens_mask | (
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None, already_has_special_tokens: bool = False
) |
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.
Args:
token_ids_0 (:obj:`List[int]`):
List of IDs.
token_ids_1 (:obj:`List[int]`,... |
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. | def get_special_tokens_mask(
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None, already_has_special_tokens: bool = False
) -> List[int]:
"""
Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
special tokens ... | [
"def",
"get_special_tokens_mask",
"(",
"self",
",",
"token_ids_0",
":",
"List",
"[",
"int",
"]",
",",
"token_ids_1",
":",
"Optional",
"[",
"List",
"[",
"int",
"]",
"]",
"=",
"None",
",",
"already_has_special_tokens",
":",
"bool",
"=",
"False",
")",
"->",
... | [
272,
4
] | [
301,
51
] | python | en | ['en', 'error', 'th'] | False |
BertTokenizer.create_token_type_ids_from_sequences | (
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
) |
Create a mask from the two sequences passed to be used in a sequence-pair classification task. A BERT sequence
pair mask has the following format:
::
0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
| first sequence | second sequence |
If :obj:`token_ids_1` is :obj:... |
Create a mask from the two sequences passed to be used in a sequence-pair classification task. A BERT sequence
pair mask has the following format: | def create_token_type_ids_from_sequences(
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
) -> List[int]:
"""
Create a mask from the two sequences passed to be used in a sequence-pair classification task. A BERT sequence
pair mask has the following format:
... | [
"def",
"create_token_type_ids_from_sequences",
"(",
"self",
",",
"token_ids_0",
":",
"List",
"[",
"int",
"]",
",",
"token_ids_1",
":",
"Optional",
"[",
"List",
"[",
"int",
"]",
"]",
"=",
"None",
")",
"->",
"List",
"[",
"int",
"]",
":",
"sep",
"=",
"[",... | [
303,
4
] | [
331,
80
] | python | en | ['en', 'error', 'th'] | False |
BasicTokenizer.tokenize | (self, text, never_split=None) |
Basic Tokenization of a piece of text. Split on "white spaces" only, for sub-word tokenization, see
WordPieceTokenizer.
Args:
**never_split**: (`optional`) list of str
Kept for backward compatibility purposes. Now implemented directly at the base class level (see
... |
Basic Tokenization of a piece of text. Split on "white spaces" only, for sub-word tokenization, see
WordPieceTokenizer. | def tokenize(self, text, never_split=None):
"""
Basic Tokenization of a piece of text. Split on "white spaces" only, for sub-word tokenization, see
WordPieceTokenizer.
Args:
**never_split**: (`optional`) list of str
Kept for backward compatibility purposes. N... | [
"def",
"tokenize",
"(",
"self",
",",
"text",
",",
"never_split",
"=",
"None",
")",
":",
"# union() returns a new set by concatenating the two sets.",
"never_split",
"=",
"self",
".",
"never_split",
".",
"union",
"(",
"set",
"(",
"never_split",
")",
")",
"if",
"n... | [
382,
4
] | [
417,
28
] | python | en | ['en', 'error', 'th'] | False |
BasicTokenizer._run_strip_accents | (self, text) | Strips accents from a piece of text. | Strips accents from a piece of text. | def _run_strip_accents(self, text):
"""Strips accents from a piece of text."""
text = unicodedata.normalize("NFD", text)
output = []
for char in text:
cat = unicodedata.category(char)
if cat == "Mn":
continue
output.append(char)
... | [
"def",
"_run_strip_accents",
"(",
"self",
",",
"text",
")",
":",
"text",
"=",
"unicodedata",
".",
"normalize",
"(",
"\"NFD\"",
",",
"text",
")",
"output",
"=",
"[",
"]",
"for",
"char",
"in",
"text",
":",
"cat",
"=",
"unicodedata",
".",
"category",
"(",... | [
419,
4
] | [
428,
30
] | python | en | ['en', 'en', 'en'] | True |
BasicTokenizer._run_split_on_punc | (self, text, never_split=None) | Splits punctuation on a piece of text. | Splits punctuation on a piece of text. | def _run_split_on_punc(self, text, never_split=None):
"""Splits punctuation on a piece of text."""
if never_split is not None and text in never_split:
return [text]
chars = list(text)
i = 0
start_new_word = True
output = []
while i < len(chars):
... | [
"def",
"_run_split_on_punc",
"(",
"self",
",",
"text",
",",
"never_split",
"=",
"None",
")",
":",
"if",
"never_split",
"is",
"not",
"None",
"and",
"text",
"in",
"never_split",
":",
"return",
"[",
"text",
"]",
"chars",
"=",
"list",
"(",
"text",
")",
"i"... | [
430,
4
] | [
450,
43
] | python | en | ['en', 'en', 'en'] | True |
BasicTokenizer._tokenize_chinese_chars | (self, text) | Adds whitespace around any CJK character. | Adds whitespace around any CJK character. | def _tokenize_chinese_chars(self, text):
"""Adds whitespace around any CJK character."""
output = []
for char in text:
cp = ord(char)
if self._is_chinese_char(cp):
output.append(" ")
output.append(char)
output.append(" ")
... | [
"def",
"_tokenize_chinese_chars",
"(",
"self",
",",
"text",
")",
":",
"output",
"=",
"[",
"]",
"for",
"char",
"in",
"text",
":",
"cp",
"=",
"ord",
"(",
"char",
")",
"if",
"self",
".",
"_is_chinese_char",
"(",
"cp",
")",
":",
"output",
".",
"append",
... | [
452,
4
] | [
463,
30
] | python | en | ['en', 'en', 'en'] | True |
BasicTokenizer._is_chinese_char | (self, cp) | Checks whether CP is the codepoint of a CJK character. | Checks whether CP is the codepoint of a CJK character. | def _is_chinese_char(self, cp):
"""Checks whether CP is the codepoint of a CJK character."""
# This defines a "chinese character" as anything in the CJK Unicode block:
# https://en.wikipedia.org/wiki/CJK_Unified_Ideographs_(Unicode_block)
#
# Note that the CJK Unicode block is ... | [
"def",
"_is_chinese_char",
"(",
"self",
",",
"cp",
")",
":",
"# This defines a \"chinese character\" as anything in the CJK Unicode block:",
"# https://en.wikipedia.org/wiki/CJK_Unified_Ideographs_(Unicode_block)",
"#",
"# Note that the CJK Unicode block is NOT all Japanese and Korean charac... | [
465,
4
] | [
487,
20
] | python | en | ['en', 'en', 'en'] | True |
BasicTokenizer._clean_text | (self, text) | Performs invalid character removal and whitespace cleanup on text. | Performs invalid character removal and whitespace cleanup on text. | def _clean_text(self, text):
"""Performs invalid character removal and whitespace cleanup on text."""
output = []
for char in text:
cp = ord(char)
if cp == 0 or cp == 0xFFFD or _is_control(char):
continue
if _is_whitespace(char):
... | [
"def",
"_clean_text",
"(",
"self",
",",
"text",
")",
":",
"output",
"=",
"[",
"]",
"for",
"char",
"in",
"text",
":",
"cp",
"=",
"ord",
"(",
"char",
")",
"if",
"cp",
"==",
"0",
"or",
"cp",
"==",
"0xFFFD",
"or",
"_is_control",
"(",
"char",
")",
"... | [
489,
4
] | [
500,
30
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.