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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
tibber_setup_fixture | () | Patch tibber setup entry. | Patch tibber setup entry. | def tibber_setup_fixture():
"""Patch tibber setup entry."""
with patch("homeassistant.components.tibber.async_setup_entry", return_value=True):
yield | [
"def",
"tibber_setup_fixture",
"(",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.tibber.async_setup_entry\"",
",",
"return_value",
"=",
"True",
")",
":",
"yield"
] | [
11,
0
] | [
14,
13
] | python | cs | ['en', 'cs', 'tr'] | False |
test_show_config_form | (hass) | Test show configuration form. | Test show configuration form. | async def test_show_config_form(hass):
"""Test show configuration form."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": "user"}
)
assert result["type"] == "form"
assert result["step_id"] == "user" | [
"async",
"def",
"test_show_config_form",
"(",
"hass",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"user\"",
"}",
")",
"assert",
"result",
"["... | [
17,
0
] | [
24,
38
] | python | en | ['en', 'fr', 'en'] | True |
test_create_entry | (hass) | Test create entry from user input. | Test create entry from user input. | async def test_create_entry(hass):
"""Test create entry from user input."""
test_data = {
CONF_ACCESS_TOKEN: "valid",
}
unique_user_id = "unique_user_id"
title = "title"
tibber_mock = MagicMock()
type(tibber_mock).update_info = AsyncMock(return_value=True)
type(tibber_mock).use... | [
"async",
"def",
"test_create_entry",
"(",
"hass",
")",
":",
"test_data",
"=",
"{",
"CONF_ACCESS_TOKEN",
":",
"\"valid\"",
",",
"}",
"unique_user_id",
"=",
"\"unique_user_id\"",
"title",
"=",
"\"title\"",
"tibber_mock",
"=",
"MagicMock",
"(",
")",
"type",
"(",
... | [
27,
0
] | [
48,
38
] | python | en | ['en', 'en', 'en'] | True |
test_flow_entry_already_exists | (hass) | Test user input for config_entry that already exists. | Test user input for config_entry that already exists. | async def test_flow_entry_already_exists(hass):
"""Test user input for config_entry that already exists."""
first_entry = MockConfigEntry(
domain="tibber",
data={CONF_ACCESS_TOKEN: "valid"},
unique_id="tibber",
)
first_entry.add_to_hass(hass)
test_data = {
CONF_ACCES... | [
"async",
"def",
"test_flow_entry_already_exists",
"(",
"hass",
")",
":",
"first_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"tibber\"",
",",
"data",
"=",
"{",
"CONF_ACCESS_TOKEN",
":",
"\"valid\"",
"}",
",",
"unique_id",
"=",
"\"tibber\"",
",",
")",
... | [
51,
0
] | [
70,
51
] | python | en | ['en', 'en', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up the Xiaomi IR Remote (Chuangmi IR) platform. | Set up the Xiaomi IR Remote (Chuangmi IR) platform. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Xiaomi IR Remote (Chuangmi IR) platform."""
host = config[CONF_HOST]
token = config[CONF_TOKEN]
# Create handler
_LOGGER.info("Initializing with host %s (token %s...)", host, token[:5])
# The C... | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"host",
"=",
"config",
"[",
"CONF_HOST",
"]",
"token",
"=",
"config",
"[",
"CONF_TOKEN",
"]",
"# Create handler",
"_LOG... | [
60,
0
] | [
166,
5
] | python | en | ['en', 'lv', 'en'] | True |
XiaomiMiioRemote.__init__ | (self, friendly_name, device, unique_id, slot, timeout, commands) | Initialize the remote. | Initialize the remote. | def __init__(self, friendly_name, device, unique_id, slot, timeout, commands):
"""Initialize the remote."""
self._name = friendly_name
self._device = device
self._unique_id = unique_id
self._slot = slot
self._timeout = timeout
self._state = False
self._com... | [
"def",
"__init__",
"(",
"self",
",",
"friendly_name",
",",
"device",
",",
"unique_id",
",",
"slot",
",",
"timeout",
",",
"commands",
")",
":",
"self",
".",
"_name",
"=",
"friendly_name",
"self",
".",
"_device",
"=",
"device",
"self",
".",
"_unique_id",
"... | [
172,
4
] | [
180,
33
] | python | en | ['en', 'en', 'en'] | True |
XiaomiMiioRemote.unique_id | (self) | Return an unique ID. | Return an unique ID. | def unique_id(self):
"""Return an unique ID."""
return self._unique_id | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unique_id"
] | [
183,
4
] | [
185,
30
] | python | fr | ['fr', 'fr', 'en'] | True |
XiaomiMiioRemote.name | (self) | Return the name of the remote. | Return the name of the remote. | def name(self):
"""Return the name of the remote."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
188,
4
] | [
190,
25
] | python | en | ['en', 'en', 'en'] | True |
XiaomiMiioRemote.device | (self) | Return the remote object. | Return the remote object. | def device(self):
"""Return the remote object."""
return self._device | [
"def",
"device",
"(",
"self",
")",
":",
"return",
"self",
".",
"_device"
] | [
193,
4
] | [
195,
27
] | python | en | ['en', 'en', 'en'] | True |
XiaomiMiioRemote.slot | (self) | Return the slot to save learned command. | Return the slot to save learned command. | def slot(self):
"""Return the slot to save learned command."""
return self._slot | [
"def",
"slot",
"(",
"self",
")",
":",
"return",
"self",
".",
"_slot"
] | [
198,
4
] | [
200,
25
] | python | en | ['en', 'en', 'en'] | True |
XiaomiMiioRemote.timeout | (self) | Return the timeout for learning command. | Return the timeout for learning command. | def timeout(self):
"""Return the timeout for learning command."""
return self._timeout | [
"def",
"timeout",
"(",
"self",
")",
":",
"return",
"self",
".",
"_timeout"
] | [
203,
4
] | [
205,
28
] | python | en | ['en', 'en', 'en'] | True |
XiaomiMiioRemote.is_on | (self) | Return False if device is unreachable, else True. | Return False if device is unreachable, else True. | def is_on(self):
"""Return False if device is unreachable, else True."""
try:
self.device.info()
return True
except DeviceException:
return False | [
"def",
"is_on",
"(",
"self",
")",
":",
"try",
":",
"self",
".",
"device",
".",
"info",
"(",
")",
"return",
"True",
"except",
"DeviceException",
":",
"return",
"False"
] | [
208,
4
] | [
214,
24
] | python | en | ['en', 'fr', 'en'] | True |
XiaomiMiioRemote.should_poll | (self) | We should not be polled for device up state. | We should not be polled for device up state. | def should_poll(self):
"""We should not be polled for device up state."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
217,
4
] | [
219,
20
] | python | en | ['en', 'en', 'en'] | True |
XiaomiMiioRemote.async_turn_on | (self, **kwargs) | Turn the device on. | Turn the device on. | async def async_turn_on(self, **kwargs):
"""Turn the device on."""
_LOGGER.error(
"Device does not support turn_on, "
"please use 'remote.send_command' to send commands"
) | [
"async",
"def",
"async_turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"_LOGGER",
".",
"error",
"(",
"\"Device does not support turn_on, \"",
"\"please use 'remote.send_command' to send commands\"",
")"
] | [
221,
4
] | [
226,
9
] | python | en | ['en', 'en', 'en'] | True |
XiaomiMiioRemote.async_turn_off | (self, **kwargs) | Turn the device off. | Turn the device off. | async def async_turn_off(self, **kwargs):
"""Turn the device off."""
_LOGGER.error(
"Device does not support turn_off, "
"please use 'remote.send_command' to send commands"
) | [
"async",
"def",
"async_turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"_LOGGER",
".",
"error",
"(",
"\"Device does not support turn_off, \"",
"\"please use 'remote.send_command' to send commands\"",
")"
] | [
228,
4
] | [
233,
9
] | python | en | ['en', 'en', 'en'] | True |
XiaomiMiioRemote._send_command | (self, payload) | Send a command. | Send a command. | def _send_command(self, payload):
"""Send a command."""
_LOGGER.debug("Sending payload: '%s'", payload)
try:
self.device.play(payload)
except DeviceException as ex:
_LOGGER.error(
"Transmit of IR command failed, %s, exception: %s", payload, ex
... | [
"def",
"_send_command",
"(",
"self",
",",
"payload",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Sending payload: '%s'\"",
",",
"payload",
")",
"try",
":",
"self",
".",
"device",
".",
"play",
"(",
"payload",
")",
"except",
"DeviceException",
"as",
"ex",
":"... | [
235,
4
] | [
243,
13
] | python | en | ['en', 'en', 'en'] | True |
XiaomiMiioRemote.send_command | (self, command, **kwargs) | Send a command. | Send a command. | def send_command(self, command, **kwargs):
"""Send a command."""
num_repeats = kwargs.get(ATTR_NUM_REPEATS)
delay = kwargs.get(ATTR_DELAY_SECS, DEFAULT_DELAY_SECS)
for _ in range(num_repeats):
for payload in command:
if payload in self._commands:
... | [
"def",
"send_command",
"(",
"self",
",",
"command",
",",
"*",
"*",
"kwargs",
")",
":",
"num_repeats",
"=",
"kwargs",
".",
"get",
"(",
"ATTR_NUM_REPEATS",
")",
"delay",
"=",
"kwargs",
".",
"get",
"(",
"ATTR_DELAY_SECS",
",",
"DEFAULT_DELAY_SECS",
")",
"for"... | [
245,
4
] | [
258,
33
] | python | en | ['en', 'en', 'en'] | True |
TestKiraSensor.add_entities | (self, devices) | Mock add devices. | Mock add devices. | def add_entities(self, devices):
"""Mock add devices."""
for device in devices:
self.DEVICES.append(device) | [
"def",
"add_entities",
"(",
"self",
",",
"devices",
")",
":",
"for",
"device",
"in",
"devices",
":",
"self",
".",
"DEVICES",
".",
"append",
"(",
"device",
")"
] | [
21,
4
] | [
24,
39
] | python | en | ['es', 'en', 'en'] | True |
TestKiraSensor.setUp | (self) | Initialize values for this testcase class. | Initialize values for this testcase class. | def setUp(self):
"""Initialize values for this testcase class."""
self.hass = get_test_home_assistant()
self.mock_kira = MagicMock()
self.hass.data[kira.DOMAIN] = {kira.CONF_REMOTE: {}}
self.hass.data[kira.DOMAIN][kira.CONF_REMOTE]["kira"] = self.mock_kira
self.addCleanup... | [
"def",
"setUp",
"(",
"self",
")",
":",
"self",
".",
"hass",
"=",
"get_test_home_assistant",
"(",
")",
"self",
".",
"mock_kira",
"=",
"MagicMock",
"(",
")",
"self",
".",
"hass",
".",
"data",
"[",
"kira",
".",
"DOMAIN",
"]",
"=",
"{",
"kira",
".",
"C... | [
26,
4
] | [
32,
39
] | python | en | ['en', 'en', 'en'] | True |
TestKiraSensor.test_service_call | (self) | Test Kira's ability to send commands. | Test Kira's ability to send commands. | def test_service_call(self):
"""Test Kira's ability to send commands."""
kira.setup_platform(self.hass, TEST_CONFIG, self.add_entities, DISCOVERY_INFO)
assert len(self.DEVICES) == 1
remote = self.DEVICES[0]
assert remote.name == "kira"
command = ["FAKE_COMMAND"]
... | [
"def",
"test_service_call",
"(",
"self",
")",
":",
"kira",
".",
"setup_platform",
"(",
"self",
".",
"hass",
",",
"TEST_CONFIG",
",",
"self",
".",
"add_entities",
",",
"DISCOVERY_INFO",
")",
"assert",
"len",
"(",
"self",
".",
"DEVICES",
")",
"==",
"1",
"r... | [
34,
4
] | [
47,
64
] | python | en | ['en', 'en', 'en'] | True |
get_arguments | () | Get parsed passed in arguments. | Get parsed passed in arguments. | def get_arguments() -> argparse.Namespace:
"""Get parsed passed in arguments."""
parser = get_base_arg_parser()
parser.add_argument(
"--skip-download", action="store_true", help="Skip downloading translations."
)
return parser.parse_args() | [
"def",
"get_arguments",
"(",
")",
"->",
"argparse",
".",
"Namespace",
":",
"parser",
"=",
"get_base_arg_parser",
"(",
")",
"parser",
".",
"add_argument",
"(",
"\"--skip-download\"",
",",
"action",
"=",
"\"store_true\"",
",",
"help",
"=",
"\"Skip downloading transl... | [
11,
0
] | [
17,
30
] | python | en | ['en', 'la', 'en'] | True |
run | () | Update frontend translations with backend data.
We use the downloaded Docker files because it gives us each language in 1 file.
| Update frontend translations with backend data. | def run():
"""Update frontend translations with backend data.
We use the downloaded Docker files because it gives us each language in 1 file.
"""
args = get_arguments()
if not args.skip_download:
run_download_docker()
for lang_file in DOWNLOAD_DIR.glob("*.json"):
translations ... | [
"def",
"run",
"(",
")",
":",
"args",
"=",
"get_arguments",
"(",
")",
"if",
"not",
"args",
".",
"skip_download",
":",
"run_download_docker",
"(",
")",
"for",
"lang_file",
"in",
"DOWNLOAD_DIR",
".",
"glob",
"(",
"\"*.json\"",
")",
":",
"translations",
"=",
... | [
20,
0
] | [
45,
9
] | python | en | ['en', 'en', 'en'] | True |
component_factory | (
hass: HomeAssistant, aiohttp_client, aioclient_mock: AiohttpClientMocker
) | Return a factory for initializing the withings component. | Return a factory for initializing the withings component. | def component_factory(
hass: HomeAssistant, aiohttp_client, aioclient_mock: AiohttpClientMocker
):
"""Return a factory for initializing the withings component."""
with patch(
"homeassistant.components.withings.common.ConfigEntryWithingsApi"
) as api_class_mock:
yield ComponentFactory(has... | [
"def",
"component_factory",
"(",
"hass",
":",
"HomeAssistant",
",",
"aiohttp_client",
",",
"aioclient_mock",
":",
"AiohttpClientMocker",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.withings.common.ConfigEntryWithingsApi\"",
")",
"as",
"api_class_mock",
":",
... | [
14,
0
] | [
21,
84
] | python | en | ['en', 'en', 'en'] | True |
mock_gateway_info | () | Mock get_gateway_info. | Mock get_gateway_info. | def mock_gateway_info():
"""Mock get_gateway_info."""
with patch(
"homeassistant.components.tradfri.config_flow.get_gateway_info"
) as gateway_info:
yield gateway_info | [
"def",
"mock_gateway_info",
"(",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.tradfri.config_flow.get_gateway_info\"",
")",
"as",
"gateway_info",
":",
"yield",
"gateway_info"
] | [
12,
0
] | [
17,
26
] | python | en | ['nl', 'fy', 'en'] | False |
mock_entry_setup | () | Mock entry setup. | Mock entry setup. | def mock_entry_setup():
"""Mock entry setup."""
with patch("homeassistant.components.tradfri.async_setup_entry") as mock_setup:
mock_setup.return_value = True
yield mock_setup | [
"def",
"mock_entry_setup",
"(",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.tradfri.async_setup_entry\"",
")",
"as",
"mock_setup",
":",
"mock_setup",
".",
"return_value",
"=",
"True",
"yield",
"mock_setup"
] | [
21,
0
] | [
25,
24
] | python | en | ['en', 'da', 'en'] | True |
mock_gateway_id_fixture | () | Return mock gateway_id. | Return mock gateway_id. | def mock_gateway_id_fixture():
"""Return mock gateway_id."""
return MOCK_GATEWAY_ID | [
"def",
"mock_gateway_id_fixture",
"(",
")",
":",
"return",
"MOCK_GATEWAY_ID"
] | [
29,
0
] | [
31,
26
] | python | cy | ['nl', 'cy', 'en'] | False |
mock_gateway_fixture | (gateway_id) | Mock a Tradfri gateway. | Mock a Tradfri gateway. | def mock_gateway_fixture(gateway_id):
"""Mock a Tradfri gateway."""
def get_devices():
"""Return mock devices."""
return gateway.mock_devices
def get_groups():
"""Return mock groups."""
return gateway.mock_groups
gateway_info = Mock(id=gateway_id, firmware_version="1.2... | [
"def",
"mock_gateway_fixture",
"(",
"gateway_id",
")",
":",
"def",
"get_devices",
"(",
")",
":",
"\"\"\"Return mock devices.\"\"\"",
"return",
"gateway",
".",
"mock_devices",
"def",
"get_groups",
"(",
")",
":",
"\"\"\"Return mock groups.\"\"\"",
"return",
"gateway",
"... | [
35,
0
] | [
63,
21
] | python | en | ['en', 'ht', 'en'] | True |
mock_api_factory_fixture | (mock_api) | Mock pytradfri api factory. | Mock pytradfri api factory. | def mock_api_factory_fixture(mock_api):
"""Mock pytradfri api factory."""
with patch("homeassistant.components.tradfri.APIFactory", autospec=True) as factory:
factory.init.return_value = factory.return_value
factory.return_value.request = mock_api
yield factory.return_value | [
"def",
"mock_api_factory_fixture",
"(",
"mock_api",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.tradfri.APIFactory\"",
",",
"autospec",
"=",
"True",
")",
"as",
"factory",
":",
"factory",
".",
"init",
".",
"return_value",
"=",
"factory",
".",
"retur... | [
81,
0
] | [
86,
34
] | python | ca | ['en', 'ca', 'it'] | False |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up Z-Wave Lock from Config Entry. | Set up Z-Wave Lock from Config Entry. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up Z-Wave Lock from Config Entry."""
@callback
def async_add_lock(lock):
"""Add Z-Wave Lock."""
async_add_entities([lock])
async_dispatcher_connect(hass, "zwave_new_lock", async_add_lock)
network = hass.da... | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"@",
"callback",
"def",
"async_add_lock",
"(",
"lock",
")",
":",
"\"\"\"Add Z-Wave Lock.\"\"\"",
"async_add_entities",
"(",
"[",
"lock",
"]",
")",
"async_di... | [
159,
0
] | [
237,
5
] | python | en | ['en', 'en', 'en'] | True |
get_device | (node, values, **kwargs) | Create Z-Wave entity device. | Create Z-Wave entity device. | def get_device(node, values, **kwargs):
"""Create Z-Wave entity device."""
return ZwaveLock(values) | [
"def",
"get_device",
"(",
"node",
",",
"values",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"ZwaveLock",
"(",
"values",
")"
] | [
240,
0
] | [
242,
28
] | python | en | ['en', 'pl', 'en'] | True |
ZwaveLock.__init__ | (self, values) | Initialize the Z-Wave lock device. | Initialize the Z-Wave lock device. | def __init__(self, values):
"""Initialize the Z-Wave lock device."""
ZWaveDeviceEntity.__init__(self, values, DOMAIN)
self._state = None
self._notification = None
self._lock_status = None
self._v2btze = None
self._state_workaround = False
self._track_messa... | [
"def",
"__init__",
"(",
"self",
",",
"values",
")",
":",
"ZWaveDeviceEntity",
".",
"__init__",
"(",
"self",
",",
"values",
",",
"DOMAIN",
")",
"self",
".",
"_state",
"=",
"None",
"self",
".",
"_notification",
"=",
"None",
"self",
".",
"_lock_status",
"="... | [
248,
4
] | [
281,
32
] | python | en | ['en', 'en', 'en'] | True |
ZwaveLock.update_properties | (self) | Handle data changes for node values. | Handle data changes for node values. | def update_properties(self):
"""Handle data changes for node values."""
self._state = self.values.primary.data
_LOGGER.debug("lock state set to %s", self._state)
if self.values.access_control:
notification_data = self.values.access_control.data
self._notification ... | [
"def",
"update_properties",
"(",
"self",
")",
":",
"self",
".",
"_state",
"=",
"self",
".",
"values",
".",
"primary",
".",
"data",
"_LOGGER",
".",
"debug",
"(",
"\"lock state set to %s\"",
",",
"self",
".",
"_state",
")",
"if",
"self",
".",
"values",
"."... | [
283,
4
] | [
360,
18
] | python | en | ['fr', 'en', 'en'] | True |
ZwaveLock.is_locked | (self) | Return true if device is locked. | Return true if device is locked. | def is_locked(self):
"""Return true if device is locked."""
return self._state | [
"def",
"is_locked",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
363,
4
] | [
365,
26
] | python | en | ['en', 'fy', 'en'] | True |
ZwaveLock.lock | (self, **kwargs) | Lock the device. | Lock the device. | def lock(self, **kwargs):
"""Lock the device."""
self.values.primary.data = True | [
"def",
"lock",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"values",
".",
"primary",
".",
"data",
"=",
"True"
] | [
367,
4
] | [
369,
39
] | python | en | ['en', 'en', 'en'] | True |
ZwaveLock.unlock | (self, **kwargs) | Unlock the device. | Unlock the device. | def unlock(self, **kwargs):
"""Unlock the device."""
self.values.primary.data = False | [
"def",
"unlock",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"values",
".",
"primary",
".",
"data",
"=",
"False"
] | [
371,
4
] | [
373,
40
] | python | en | ['en', 'zh', 'en'] | True |
ZwaveLock.device_state_attributes | (self) | Return the device specific state attributes. | Return the device specific state attributes. | def device_state_attributes(self):
"""Return the device specific state attributes."""
data = super().device_state_attributes
if self._notification:
data[ATTR_NOTIFICATION] = self._notification
if self._lock_status:
data[ATTR_LOCK_STATUS] = self._lock_status
... | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"data",
"=",
"super",
"(",
")",
".",
"device_state_attributes",
"if",
"self",
".",
"_notification",
":",
"data",
"[",
"ATTR_NOTIFICATION",
"]",
"=",
"self",
".",
"_notification",
"if",
"self",
".",
"_l... | [
376,
4
] | [
383,
19
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, entry, async_add_entities) | Set up MELCloud device sensors based on config_entry. | Set up MELCloud device sensors based on config_entry. | async def async_setup_entry(hass, entry, async_add_entities):
"""Set up MELCloud device sensors based on config_entry."""
mel_devices = hass.data[DOMAIN].get(entry.entry_id)
async_add_entities(
[
MelDeviceSensor(mel_device, measurement, definition)
for measurement, definition... | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"entry",
",",
"async_add_entities",
")",
":",
"mel_devices",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
".",
"get",
"(",
"entry",
".",
"entry_id",
")",
"async_add_entities",
"(",
"[",
"MelDeviceSensor... | [
85,
0
] | [
109,
5
] | python | en | ['en', 'da', 'en'] | True |
MelDeviceSensor.__init__ | (self, api: MelCloudDevice, measurement, definition) | Initialize the sensor. | Initialize the sensor. | def __init__(self, api: MelCloudDevice, measurement, definition):
"""Initialize the sensor."""
self._api = api
self._name_slug = api.name
self._measurement = measurement
self._def = definition | [
"def",
"__init__",
"(",
"self",
",",
"api",
":",
"MelCloudDevice",
",",
"measurement",
",",
"definition",
")",
":",
"self",
".",
"_api",
"=",
"api",
"self",
".",
"_name_slug",
"=",
"api",
".",
"name",
"self",
".",
"_measurement",
"=",
"measurement",
"sel... | [
115,
4
] | [
120,
30
] | python | en | ['en', 'en', 'en'] | True |
MelDeviceSensor.unique_id | (self) | Return a unique ID. | Return a unique ID. | def unique_id(self):
"""Return a unique ID."""
return f"{self._api.device.serial}-{self._api.device.mac}-{self._measurement}" | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"f\"{self._api.device.serial}-{self._api.device.mac}-{self._measurement}\""
] | [
123,
4
] | [
125,
86
] | python | ca | ['fr', 'ca', 'en'] | False |
MelDeviceSensor.icon | (self) | Return the icon to use in the frontend, if any. | Return the icon to use in the frontend, if any. | def icon(self):
"""Return the icon to use in the frontend, if any."""
return self._def[ATTR_ICON] | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"self",
".",
"_def",
"[",
"ATTR_ICON",
"]"
] | [
128,
4
] | [
130,
35
] | python | en | ['en', 'en', 'en'] | True |
MelDeviceSensor.name | (self) | Return the name of the sensor. | Return the name of the sensor. | def name(self):
"""Return the name of the sensor."""
return f"{self._name_slug} {self._def[ATTR_MEASUREMENT_NAME]}" | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"f\"{self._name_slug} {self._def[ATTR_MEASUREMENT_NAME]}\""
] | [
133,
4
] | [
135,
70
] | python | en | ['en', 'mi', 'en'] | True |
MelDeviceSensor.state | (self) | Return the state of the sensor. | Return the state of the sensor. | def state(self):
"""Return the state of the sensor."""
return self._def[ATTR_VALUE_FN](self._api) | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_def",
"[",
"ATTR_VALUE_FN",
"]",
"(",
"self",
".",
"_api",
")"
] | [
138,
4
] | [
140,
50
] | python | en | ['en', 'en', 'en'] | True |
MelDeviceSensor.unit_of_measurement | (self) | Return the unit of measurement. | Return the unit of measurement. | def unit_of_measurement(self):
"""Return the unit of measurement."""
return self._def[ATTR_UNIT] | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"self",
".",
"_def",
"[",
"ATTR_UNIT",
"]"
] | [
143,
4
] | [
145,
35
] | python | en | ['en', 'la', 'en'] | True |
MelDeviceSensor.device_class | (self) | Return device class. | Return device class. | def device_class(self):
"""Return device class."""
return self._def[ATTR_DEVICE_CLASS] | [
"def",
"device_class",
"(",
"self",
")",
":",
"return",
"self",
".",
"_def",
"[",
"ATTR_DEVICE_CLASS",
"]"
] | [
148,
4
] | [
150,
43
] | python | en | ['es', 'zh', 'en'] | False |
MelDeviceSensor.async_update | (self) | Retrieve latest state. | Retrieve latest state. | async def async_update(self):
"""Retrieve latest state."""
await self._api.async_update() | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"await",
"self",
".",
"_api",
".",
"async_update",
"(",
")"
] | [
152,
4
] | [
154,
38
] | python | en | ['es', 'sk', 'en'] | False |
MelDeviceSensor.device_info | (self) | Return a device description for device registry. | Return a device description for device registry. | def device_info(self):
"""Return a device description for device registry."""
return self._api.device_info | [
"def",
"device_info",
"(",
"self",
")",
":",
"return",
"self",
".",
"_api",
".",
"device_info"
] | [
157,
4
] | [
159,
36
] | python | en | ['ro', 'fr', 'en'] | False |
AtwZoneSensor.__init__ | (self, api: MelCloudDevice, zone: Zone, measurement, definition) | Initialize the sensor. | Initialize the sensor. | def __init__(self, api: MelCloudDevice, zone: Zone, measurement, definition):
"""Initialize the sensor."""
super().__init__(api, measurement, definition)
self._zone = zone
self._name_slug = f"{api.name} {zone.name}" | [
"def",
"__init__",
"(",
"self",
",",
"api",
":",
"MelCloudDevice",
",",
"zone",
":",
"Zone",
",",
"measurement",
",",
"definition",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"api",
",",
"measurement",
",",
"definition",
")",
"self",
".",
"_zon... | [
165,
4
] | [
169,
51
] | python | en | ['en', 'en', 'en'] | True |
AtwZoneSensor.state | (self) | Return zone based state. | Return zone based state. | def state(self):
"""Return zone based state."""
return self._def[ATTR_VALUE_FN](self._zone) | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_def",
"[",
"ATTR_VALUE_FN",
"]",
"(",
"self",
".",
"_zone",
")"
] | [
172,
4
] | [
174,
51
] | python | en | ['nl', 'ig', 'en'] | False |
GrassOnPremisesExecutor.create | (create_deployment: dict) | Create MARO Cluster with create_deployment.
Args:
create_deployment (dict): create_deployment of grass/on-premises.
See lib/deployments/internal for reference.
Returns:
None.
| Create MARO Cluster with create_deployment. | def create(create_deployment: dict):
"""Create MARO Cluster with create_deployment.
Args:
create_deployment (dict): create_deployment of grass/on-premises.
See lib/deployments/internal for reference.
Returns:
None.
"""
logger.info("Creati... | [
"def",
"create",
"(",
"create_deployment",
":",
"dict",
")",
":",
"logger",
".",
"info",
"(",
"\"Creating cluster\"",
")",
"# Get standardized cluster_details",
"cluster_details",
"=",
"GrassOnPremisesExecutor",
".",
"_standardize_cluster_details",
"(",
"create_deployment",... | [
35,
4
] | [
75,
70
] | python | en | ['en', 'en', 'en'] | True |
GrassOnPremisesExecutor._standardize_cluster_details | (create_deployment: dict) | Standardize cluster_details from create_deployment.
We use create_deployment to build cluster_details (they share the same keys structure).
Args:
create_deployment (dict): create_deployment of grass/on-premises.
See lib/deployments/internal for reference.
Returns:
... | Standardize cluster_details from create_deployment. | def _standardize_cluster_details(create_deployment: dict) -> dict:
"""Standardize cluster_details from create_deployment.
We use create_deployment to build cluster_details (they share the same keys structure).
Args:
create_deployment (dict): create_deployment of grass/on-premises.
... | [
"def",
"_standardize_cluster_details",
"(",
"create_deployment",
":",
"dict",
")",
"->",
"dict",
":",
"samba_password",
"=",
"\"\"",
".",
"join",
"(",
"secrets",
".",
"choice",
"(",
"string",
".",
"ascii_letters",
"+",
"string",
".",
"digits",
")",
"for",
"_... | [
78,
4
] | [
117,
32
] | python | en | ['en', 'en', 'en'] | True |
GrassOnPremisesExecutor.delete | (self) | Delete the MARO Cluster.
Leave all nodes in the MARO Cluster, then delete MARO Master.
Returns:
None.
| Delete the MARO Cluster. | def delete(self):
"""Delete the MARO Cluster.
Leave all nodes in the MARO Cluster, then delete MARO Master.
Returns:
None.
"""
logger.info(f"Deleting cluster '{self.cluster_name}'")
nodes_details = self.master_api_client.list_nodes()
for node_detail... | [
"def",
"delete",
"(",
"self",
")",
":",
"logger",
".",
"info",
"(",
"f\"Deleting cluster '{self.cluster_name}'\"",
")",
"nodes_details",
"=",
"self",
".",
"master_api_client",
".",
"list_nodes",
"(",
")",
"for",
"node_details",
"in",
"nodes_details",
":",
"self",
... | [
121,
4
] | [
147,
70
] | python | en | ['en', 'it', 'en'] | True |
GrassOnPremisesExecutor.join_cluster | (join_cluster_deployment: dict) | Entry method for join_cluster.
Args:
join_cluster_deployment (dict): join_cluster_deployment of grass/on-premises.
See lib/deployments/internal for reference.
Returns:
None.
| Entry method for join_cluster. | def join_cluster(join_cluster_deployment: dict):
"""Entry method for join_cluster.
Args:
join_cluster_deployment (dict): join_cluster_deployment of grass/on-premises.
See lib/deployments/internal for reference.
Returns:
None.
"""
GrassOnP... | [
"def",
"join_cluster",
"(",
"join_cluster_deployment",
":",
"dict",
")",
":",
"GrassOnPremisesExecutor",
".",
"_join_cluster",
"(",
"join_cluster_deployment",
"=",
"join_cluster_deployment",
")"
] | [
152,
4
] | [
162,
94
] | python | en | ['en', 'en', 'en'] | True |
GrassOnPremisesExecutor._join_cluster | (join_cluster_deployment: dict) | Join a vm to the MARO Cluster with join_cluster_deployment.
Args:
join_cluster_deployment (dict): join_cluster_deployment of grass/on-premises.
See lib/deployments/internal for reference.
Returns:
None.
| Join a vm to the MARO Cluster with join_cluster_deployment. | def _join_cluster(join_cluster_deployment: dict):
"""Join a vm to the MARO Cluster with join_cluster_deployment.
Args:
join_cluster_deployment (dict): join_cluster_deployment of grass/on-premises.
See lib/deployments/internal for reference.
Returns:
None... | [
"def",
"_join_cluster",
"(",
"join_cluster_deployment",
":",
"dict",
")",
":",
"logger",
".",
"info",
"(",
"\"Joining the cluster\"",
")",
"# Get standardized join_cluster_deployment",
"join_cluster_deployment",
"=",
"GrassOnPremisesExecutor",
".",
"_standardize_join_cluster_de... | [
165,
4
] | [
211,
58
] | python | en | ['en', 'en', 'en'] | True |
GrassOnPremisesExecutor._standardize_join_cluster_deployment | (join_cluster_deployment: dict) | Standardize join_cluster_deployment.
Args:
join_cluster_deployment (dict): join_cluster_deployment of grass/on-premises.
See lib/deployments/internal for reference.
Returns:
dict: standardized join_cluster_deployment.
| Standardize join_cluster_deployment. | def _standardize_join_cluster_deployment(join_cluster_deployment: dict) -> dict:
"""Standardize join_cluster_deployment.
Args:
join_cluster_deployment (dict): join_cluster_deployment of grass/on-premises.
See lib/deployments/internal for reference.
Returns:
... | [
"def",
"_standardize_join_cluster_deployment",
"(",
"join_cluster_deployment",
":",
"dict",
")",
"->",
"dict",
":",
"optional_key_to_value",
"=",
"{",
"\"root['master']['redis']\"",
":",
"{",
"\"port\"",
":",
"GlobalParams",
".",
"DEFAULT_REDIS_PORT",
"}",
",",
"\"root[... | [
214,
4
] | [
260,
38
] | python | da | ['fi', 'da', 'en'] | False |
GrassOnPremisesExecutor.leave | (leave_cluster_deployment: dict) | Join a vm from the MARO Cluster with leave_cluster_deployment.
Args:
leave_cluster_deployment (dict): leave_cluster_deployment of grass/on-premises.
See lib/deployments/internal for reference.
Returns:
None.
| Join a vm from the MARO Cluster with leave_cluster_deployment. | def leave(leave_cluster_deployment: dict) -> None:
"""Join a vm from the MARO Cluster with leave_cluster_deployment.
Args:
leave_cluster_deployment (dict): leave_cluster_deployment of grass/on-premises.
See lib/deployments/internal for reference.
Returns:
... | [
"def",
"leave",
"(",
"leave_cluster_deployment",
":",
"dict",
")",
"->",
"None",
":",
"logger",
".",
"info",
"(",
"\"Node is leaving\"",
")",
"if",
"not",
"leave_cluster_deployment",
":",
"# Local leave node",
"GrassOnPremisesExecutor",
".",
"local_leave_cluster",
"("... | [
265,
4
] | [
288,
41
] | python | en | ['en', 'en', 'en'] | True |
_zone_schema | (zones: Optional[List] = None) | Zone selection schema. | Zone selection schema. | def _zone_schema(zones: Optional[List] = None):
"""Zone selection schema."""
zones_list = []
if zones is not None:
zones_list = zones
return vol.Schema({vol.Required(CONF_ZONE): vol.In(zones_list)}) | [
"def",
"_zone_schema",
"(",
"zones",
":",
"Optional",
"[",
"List",
"]",
"=",
"None",
")",
":",
"zones_list",
"=",
"[",
"]",
"if",
"zones",
"is",
"not",
"None",
":",
"zones_list",
"=",
"zones",
"return",
"vol",
".",
"Schema",
"(",
"{",
"vol",
".",
"... | [
32,
0
] | [
39,
68
] | python | en | ['de', 'en', 'en'] | True |
_records_schema | (records: Optional[List] = None) | Zone records selection schema. | Zone records selection schema. | def _records_schema(records: Optional[List] = None):
"""Zone records selection schema."""
records_dict = {}
if records:
records_dict = {name: name for name in records}
return vol.Schema({vol.Required(CONF_RECORDS): cv.multi_select(records_dict)}) | [
"def",
"_records_schema",
"(",
"records",
":",
"Optional",
"[",
"List",
"]",
"=",
"None",
")",
":",
"records_dict",
"=",
"{",
"}",
"if",
"records",
":",
"records_dict",
"=",
"{",
"name",
":",
"name",
"for",
"name",
"in",
"records",
"}",
"return",
"vol"... | [
42,
0
] | [
49,
82
] | python | de | ['de', 'it', 'en'] | False |
validate_input | (hass: HomeAssistant, data: Dict) | Validate the user input allows us to connect.
Data has the keys from DATA_SCHEMA with values provided by the user.
| Validate the user input allows us to connect. | async def validate_input(hass: HomeAssistant, data: Dict):
"""Validate the user input allows us to connect.
Data has the keys from DATA_SCHEMA with values provided by the user.
"""
zone = data.get(CONF_ZONE)
records = None
cfupdate = CloudflareUpdater(
async_get_clientsession(hass),
... | [
"async",
"def",
"validate_input",
"(",
"hass",
":",
"HomeAssistant",
",",
"data",
":",
"Dict",
")",
":",
"zone",
"=",
"data",
".",
"get",
"(",
"CONF_ZONE",
")",
"records",
"=",
"None",
"cfupdate",
"=",
"CloudflareUpdater",
"(",
"async_get_clientsession",
"("... | [
52,
0
] | [
79,
47
] | python | en | ['en', 'en', 'en'] | True |
CloudflareConfigFlow.__init__ | (self) | Initialize the Cloudflare config flow. | Initialize the Cloudflare config flow. | def __init__(self):
"""Initialize the Cloudflare config flow."""
self.cloudflare_config = {}
self.zones = None
self.records = None | [
"def",
"__init__",
"(",
"self",
")",
":",
"self",
".",
"cloudflare_config",
"=",
"{",
"}",
"self",
".",
"zones",
"=",
"None",
"self",
".",
"records",
"=",
"None"
] | [
88,
4
] | [
92,
27
] | python | en | ['en', 'en', 'en'] | True |
CloudflareConfigFlow.async_step_user | (self, user_input: Optional[Dict] = None) | Handle a flow initiated by the user. | Handle a flow initiated by the user. | async def async_step_user(self, user_input: Optional[Dict] = None):
"""Handle a flow initiated by the user."""
if self._async_current_entries():
return self.async_abort(reason="single_instance_allowed")
assert self.hass
persistent_notification.async_dismiss(self.hass, "cloud... | [
"async",
"def",
"async_step_user",
"(",
"self",
",",
"user_input",
":",
"Optional",
"[",
"Dict",
"]",
"=",
"None",
")",
":",
"if",
"self",
".",
"_async_current_entries",
"(",
")",
":",
"return",
"self",
".",
"async_abort",
"(",
"reason",
"=",
"\"single_ins... | [
94,
4
] | [
114,
9
] | python | en | ['en', 'en', 'en'] | True |
CloudflareConfigFlow.async_step_zone | (self, user_input: Optional[Dict] = None) | Handle the picking the zone. | Handle the picking the zone. | async def async_step_zone(self, user_input: Optional[Dict] = None):
"""Handle the picking the zone."""
errors = {}
if user_input is not None:
self.cloudflare_config.update(user_input)
info, errors = await self._async_validate_or_error(self.cloudflare_config)
... | [
"async",
"def",
"async_step_zone",
"(",
"self",
",",
"user_input",
":",
"Optional",
"[",
"Dict",
"]",
"=",
"None",
")",
":",
"errors",
"=",
"{",
"}",
"if",
"user_input",
"is",
"not",
"None",
":",
"self",
".",
"cloudflare_config",
".",
"update",
"(",
"u... | [
116,
4
] | [
134,
9
] | python | en | ['en', 'en', 'en'] | True |
CloudflareConfigFlow.async_step_records | (self, user_input: Optional[Dict] = None) | Handle the picking the zone records. | Handle the picking the zone records. | async def async_step_records(self, user_input: Optional[Dict] = None):
"""Handle the picking the zone records."""
errors = {}
if user_input is not None:
self.cloudflare_config.update(user_input)
title = self.cloudflare_config[CONF_ZONE]
return self.async_crea... | [
"async",
"def",
"async_step_records",
"(",
"self",
",",
"user_input",
":",
"Optional",
"[",
"Dict",
"]",
"=",
"None",
")",
":",
"errors",
"=",
"{",
"}",
"if",
"user_input",
"is",
"not",
"None",
":",
"self",
".",
"cloudflare_config",
".",
"update",
"(",
... | [
136,
4
] | [
149,
9
] | python | en | ['en', 'en', 'en'] | True |
validate_input | (hass: core.HomeAssistant, data) | Validate the user input allows us to connect.
Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user.
| Validate the user input allows us to connect. | async def validate_input(hass: core.HomeAssistant, data):
"""Validate the user input allows us to connect.
Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user.
"""
# TODO validate the data can be used to set up a connection.
# If your PyPI package is not built with async,... | [
"async",
"def",
"validate_input",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
",",
"data",
")",
":",
"# TODO validate the data can be used to set up a connection.",
"# If your PyPI package is not built with async, pass your methods",
"# to the executor:",
"# await hass.async_add_... | [
30,
0
] | [
54,
42
] | python | en | ['en', 'en', 'en'] | True |
PlaceholderHub.__init__ | (self, host) | Initialize. | Initialize. | def __init__(self, host):
"""Initialize."""
self.host = host | [
"def",
"__init__",
"(",
"self",
",",
"host",
")",
":",
"self",
".",
"host",
"=",
"host"
] | [
21,
4
] | [
23,
24
] | python | en | ['en', 'en', 'it'] | False |
PlaceholderHub.authenticate | (self, username, password) | Test if we can authenticate with the host. | Test if we can authenticate with the host. | async def authenticate(self, username, password) -> bool:
"""Test if we can authenticate with the host."""
return True | [
"async",
"def",
"authenticate",
"(",
"self",
",",
"username",
",",
"password",
")",
"->",
"bool",
":",
"return",
"True"
] | [
25,
4
] | [
27,
19
] | python | en | ['en', 'en', 'en'] | True |
ConfigFlow.async_step_user | (self, user_input=None) | Handle the initial step. | Handle the initial step. | async def async_step_user(self, user_input=None):
"""Handle the initial step."""
if user_input is None:
return self.async_show_form(
step_id="user", data_schema=STEP_USER_DATA_SCHEMA
)
errors = {}
try:
info = await validate_input(self... | [
"async",
"def",
"async_step_user",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"if",
"user_input",
"is",
"None",
":",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"user\"",
",",
"data_schema",
"=",
"STEP_USER_DATA_SCHEMA",
")",
... | [
64,
4
] | [
87,
9
] | python | en | ['en', 'en', 'en'] | True |
keras_serializable | (cls) |
Decorate a Keras Layer class to support Keras serialization.
This is done by:
1. Adding a :obj:`transformers_config` dict to the Keras config dictionary in :obj:`get_config` (called by Keras at
serialization time.
2. Wrapping :obj:`__init__` to accept that :obj:`transformers_config` dict (pass... |
Decorate a Keras Layer class to support Keras serialization. | def keras_serializable(cls):
"""
Decorate a Keras Layer class to support Keras serialization.
This is done by:
1. Adding a :obj:`transformers_config` dict to the Keras config dictionary in :obj:`get_config` (called by Keras at
serialization time.
2. Wrapping :obj:`__init__` to accept that :... | [
"def",
"keras_serializable",
"(",
"cls",
")",
":",
"initializer",
"=",
"cls",
".",
"__init__",
"config_class",
"=",
"getattr",
"(",
"cls",
",",
"\"config_class\"",
",",
"None",
")",
"if",
"config_class",
"is",
"None",
":",
"raise",
"AttributeError",
"(",
"\"... | [
76,
0
] | [
138,
14
] | python | en | ['en', 'error', 'th'] | False |
booleans_processing | (config, **kwargs) |
Process the input booleans of each model in order to be sure they are compliant with the execution mode (eager or
graph)
Args:
config (:class:`~transformers.PretrainedConfig`):
The config of the running model.
**kwargs:
The boolean parameters
Returns:
A... |
Process the input booleans of each model in order to be sure they are compliant with the execution mode (eager or
graph) | def booleans_processing(config, **kwargs):
"""
Process the input booleans of each model in order to be sure they are compliant with the execution mode (eager or
graph)
Args:
config (:class:`~transformers.PretrainedConfig`):
The config of the running model.
**kwargs:
... | [
"def",
"booleans_processing",
"(",
"config",
",",
"*",
"*",
"kwargs",
")",
":",
"final_booleans",
"=",
"{",
"}",
"if",
"tf",
".",
"executing_eagerly",
"(",
")",
":",
"final_booleans",
"[",
"\"output_attentions\"",
"]",
"=",
"(",
"kwargs",
"[",
"\"output_atte... | [
255,
0
] | [
307,
25
] | python | en | ['en', 'error', 'th'] | False |
input_processing | (func, config, input_ids, **kwargs) |
Process the input of each TensorFlow model including the booleans. In case of a list of symbolic inputs, each input
has to be named accordingly to the parameters name, i.e. `input_ids = tf.keras.Input(shape=(128,), dtype='int32',
name="input_ids")` otherwise the order of the tensors will not be guaranteed ... |
Process the input of each TensorFlow model including the booleans. In case of a list of symbolic inputs, each input
has to be named accordingly to the parameters name, i.e. `input_ids = tf.keras.Input(shape=(128,), dtype='int32',
name="input_ids")` otherwise the order of the tensors will not be guaranteed ... | def input_processing(func, config, input_ids, **kwargs):
"""
Process the input of each TensorFlow model including the booleans. In case of a list of symbolic inputs, each input
has to be named accordingly to the parameters name, i.e. `input_ids = tf.keras.Input(shape=(128,), dtype='int32',
name="input_i... | [
"def",
"input_processing",
"(",
"func",
",",
"config",
",",
"input_ids",
",",
"*",
"*",
"kwargs",
")",
":",
"signature",
"=",
"dict",
"(",
"inspect",
".",
"signature",
"(",
"func",
")",
".",
"parameters",
")",
"signature",
".",
"pop",
"(",
"\"kwargs\"",
... | [
310,
0
] | [
446,
17
] | python | en | ['en', 'error', 'th'] | False |
load_tf_weights | (model, resolved_archive_file, _prefix=None) |
Detect missing and unexpected layers and load the TF weights accordingly to their names and shapes.
Args:
model (:obj:`tf.keras.models.Model`):
The model to load the weights into.
resolved_archive_file (:obj:`str`):
The location of the H5 file.
Returns:
Two... |
Detect missing and unexpected layers and load the TF weights accordingly to their names and shapes. | def load_tf_weights(model, resolved_archive_file, _prefix=None):
"""
Detect missing and unexpected layers and load the TF weights accordingly to their names and shapes.
Args:
model (:obj:`tf.keras.models.Model`):
The model to load the weights into.
resolved_archive_file (:obj:`s... | [
"def",
"load_tf_weights",
"(",
"model",
",",
"resolved_archive_file",
",",
"_prefix",
"=",
"None",
")",
":",
"missing_layers",
"=",
"[",
"]",
"unexpected_layers",
"=",
"[",
"]",
"# Read the H5 file",
"with",
"h5py",
".",
"File",
"(",
"resolved_archive_file",
","... | [
449,
0
] | [
548,
44
] | python | en | ['en', 'error', 'th'] | False |
init_copy_embeddings | (old_embeddings, new_num_tokens) | r"""
This function aims to reduce the embeddings in case new_num_tokens < old_num_tokens or to pad with -1 in case
new_num_tokens > old_num_tokens. A mask is also computed in order to know which weight in the embeddings should be
kept or not. Example:
- if new_num_tokens=5 and old_num_tokens=4 and ... | r"""
This function aims to reduce the embeddings in case new_num_tokens < old_num_tokens or to pad with -1 in case
new_num_tokens > old_num_tokens. A mask is also computed in order to know which weight in the embeddings should be
kept or not. Example: | def init_copy_embeddings(old_embeddings, new_num_tokens):
r"""
This function aims to reduce the embeddings in case new_num_tokens < old_num_tokens or to pad with -1 in case
new_num_tokens > old_num_tokens. A mask is also computed in order to know which weight in the embeddings should be
kept or not. Exa... | [
"def",
"init_copy_embeddings",
"(",
"old_embeddings",
",",
"new_num_tokens",
")",
":",
"old_num_tokens",
",",
"old_embedding_dim",
"=",
"shape_list",
"(",
"old_embeddings",
")",
"size_diff",
"=",
"new_num_tokens",
"-",
"old_num_tokens",
"# initialize new embeddings",
"# C... | [
551,
0
] | [
588,
32
] | python | cy | ['en', 'cy', 'hi'] | False |
shape_list | (tensor: tf.Tensor) |
Deal with dynamic shape in tensorflow cleanly.
Args:
tensor (:obj:`tf.Tensor`): The tensor we want the shape of.
Returns:
:obj:`List[int]`: The shape of the tensor as a list.
|
Deal with dynamic shape in tensorflow cleanly. | def shape_list(tensor: tf.Tensor) -> List[int]:
"""
Deal with dynamic shape in tensorflow cleanly.
Args:
tensor (:obj:`tf.Tensor`): The tensor we want the shape of.
Returns:
:obj:`List[int]`: The shape of the tensor as a list.
"""
dynamic = tf.shape(tensor)
if tensor.shape... | [
"def",
"shape_list",
"(",
"tensor",
":",
"tf",
".",
"Tensor",
")",
"->",
"List",
"[",
"int",
"]",
":",
"dynamic",
"=",
"tf",
".",
"shape",
"(",
"tensor",
")",
"if",
"tensor",
".",
"shape",
"==",
"tf",
".",
"TensorShape",
"(",
"None",
")",
":",
"r... | [
1574,
0
] | [
1591,
73
] | python | en | ['en', 'error', 'th'] | False |
get_initializer | (initializer_range: float = 0.02) |
Creates a :obj:`tf.initializers.TruncatedNormal` with the given range.
Args:
initializer_range (`float`, defaults to 0.02): Standard deviation of the initializer range.
Returns:
:obj:`tf.initializers.TruncatedNormal`: The truncated normal initializer.
|
Creates a :obj:`tf.initializers.TruncatedNormal` with the given range. | def get_initializer(initializer_range: float = 0.02) -> tf.initializers.TruncatedNormal:
"""
Creates a :obj:`tf.initializers.TruncatedNormal` with the given range.
Args:
initializer_range (`float`, defaults to 0.02): Standard deviation of the initializer range.
Returns:
:obj:`tf.initia... | [
"def",
"get_initializer",
"(",
"initializer_range",
":",
"float",
"=",
"0.02",
")",
"->",
"tf",
".",
"initializers",
".",
"TruncatedNormal",
":",
"return",
"tf",
".",
"keras",
".",
"initializers",
".",
"TruncatedNormal",
"(",
"stddev",
"=",
"initializer_range",
... | [
1594,
0
] | [
1604,
74
] | python | en | ['en', 'error', 'th'] | False |
TFModelUtilsMixin.num_parameters | (self, only_trainable: bool = False) |
Get the number of (optionally, trainable) parameters in the model.
Args:
only_trainable (:obj:`bool`, `optional`, defaults to :obj:`False`):
Whether or not to return only the number of trainable parameters
Returns:
:obj:`int`: The number of parameters.
... |
Get the number of (optionally, trainable) parameters in the model. | def num_parameters(self, only_trainable: bool = False) -> int:
"""
Get the number of (optionally, trainable) parameters in the model.
Args:
only_trainable (:obj:`bool`, `optional`, defaults to :obj:`False`):
Whether or not to return only the number of trainable param... | [
"def",
"num_parameters",
"(",
"self",
",",
"only_trainable",
":",
"bool",
"=",
"False",
")",
"->",
"int",
":",
"if",
"only_trainable",
":",
"return",
"int",
"(",
"sum",
"(",
"np",
".",
"prod",
"(",
"w",
".",
"shape",
".",
"as_list",
"(",
")",
")",
... | [
59,
4
] | [
73,
38
] | python | en | ['en', 'error', 'th'] | False |
TFPreTrainedModel.dummy_inputs | (self) |
Dummy inputs to build the network.
Returns:
:obj:`Dict[str, tf.Tensor]`: The dummy inputs.
|
Dummy inputs to build the network. | def dummy_inputs(self) -> Dict[str, tf.Tensor]:
"""
Dummy inputs to build the network.
Returns:
:obj:`Dict[str, tf.Tensor]`: The dummy inputs.
"""
return {
"input_ids": tf.constant(DUMMY_INPUTS),
} | [
"def",
"dummy_inputs",
"(",
"self",
")",
"->",
"Dict",
"[",
"str",
",",
"tf",
".",
"Tensor",
"]",
":",
"return",
"{",
"\"input_ids\"",
":",
"tf",
".",
"constant",
"(",
"DUMMY_INPUTS",
")",
",",
"}"
] | [
619,
4
] | [
628,
9
] | python | en | ['en', 'error', 'th'] | False |
TFPreTrainedModel.serving | (self, inputs) |
Method used for serving the model.
Args:
inputs (:obj:`Dict[str, tf.Tensor]`):
The input of the saved model as a dictionnary of tensors.
|
Method used for serving the model. | def serving(self, inputs):
"""
Method used for serving the model.
Args:
inputs (:obj:`Dict[str, tf.Tensor]`):
The input of the saved model as a dictionnary of tensors.
"""
output = self.call(inputs)
return self.serving_output(output) | [
"def",
"serving",
"(",
"self",
",",
"inputs",
")",
":",
"output",
"=",
"self",
".",
"call",
"(",
"inputs",
")",
"return",
"self",
".",
"serving_output",
"(",
"output",
")"
] | [
653,
4
] | [
663,
42
] | python | en | ['en', 'error', 'th'] | False |
TFPreTrainedModel.serving_output | (output) |
Prepare the output of the saved model. Each model must implement this function.
Args:
output (:obj:`~transformers.TFBaseModelOutput`):
The output returned by the model.
|
Prepare the output of the saved model. Each model must implement this function. | def serving_output(output):
"""
Prepare the output of the saved model. Each model must implement this function.
Args:
output (:obj:`~transformers.TFBaseModelOutput`):
The output returned by the model.
"""
raise NotImplementedError | [
"def",
"serving_output",
"(",
"output",
")",
":",
"raise",
"NotImplementedError"
] | [
665,
4
] | [
673,
33
] | python | en | ['en', 'error', 'th'] | False |
TFPreTrainedModel.get_input_embeddings | (self) |
Returns the model's input embeddings layer.
Returns:
:obj:`tf.Variable`: The embeddings layer mapping vocabulary to hidden states.
|
Returns the model's input embeddings layer. | def get_input_embeddings(self) -> tf.keras.layers.Layer:
"""
Returns the model's input embeddings layer.
Returns:
:obj:`tf.Variable`: The embeddings layer mapping vocabulary to hidden states.
"""
main_layer = getattr(self, self.base_model_prefix, self)
if ma... | [
"def",
"get_input_embeddings",
"(",
"self",
")",
"->",
"tf",
".",
"keras",
".",
"layers",
".",
"Layer",
":",
"main_layer",
"=",
"getattr",
"(",
"self",
",",
"self",
".",
"base_model_prefix",
",",
"self",
")",
"if",
"main_layer",
"is",
"not",
"self",
":",... | [
675,
4
] | [
687,
37
] | python | en | ['en', 'error', 'th'] | False |
TFPreTrainedModel.set_input_embeddings | (self, value) |
Set model's input embeddings
Args:
value (:obj:`tf.Variable`):
The new weights mapping hidden states to vocabulary.
|
Set model's input embeddings | def set_input_embeddings(self, value):
"""
Set model's input embeddings
Args:
value (:obj:`tf.Variable`):
The new weights mapping hidden states to vocabulary.
"""
main_layer = getattr(self, self.base_model_prefix)
if main_layer is None:
... | [
"def",
"set_input_embeddings",
"(",
"self",
",",
"value",
")",
":",
"main_layer",
"=",
"getattr",
"(",
"self",
",",
"self",
".",
"base_model_prefix",
")",
"if",
"main_layer",
"is",
"None",
":",
"raise",
"NotImplementedError",
"(",
"\"The model does not implements ... | [
689,
4
] | [
707,
50
] | python | en | ['en', 'error', 'th'] | False |
TFPreTrainedModel.get_output_embeddings | (self) |
Returns the model's output embeddings
Returns:
:obj:`tf.Variable`: The new weights mapping vocabulary to hidden states.
|
Returns the model's output embeddings | def get_output_embeddings(self) -> Union[None, tf.keras.layers.Layer]:
"""
Returns the model's output embeddings
Returns:
:obj:`tf.Variable`: The new weights mapping vocabulary to hidden states.
"""
if self.get_lm_head() is not None:
lm_head = self.get_lm... | [
"def",
"get_output_embeddings",
"(",
"self",
")",
"->",
"Union",
"[",
"None",
",",
"tf",
".",
"keras",
".",
"layers",
".",
"Layer",
"]",
":",
"if",
"self",
".",
"get_lm_head",
"(",
")",
"is",
"not",
"None",
":",
"lm_head",
"=",
"self",
".",
"get_lm_h... | [
709,
4
] | [
721,
19
] | python | en | ['en', 'error', 'th'] | False |
TFPreTrainedModel.set_output_embeddings | (self, value) |
Set model's output embeddings
Args:
value (:obj:`tf.Variable`):
The new weights mapping hidden states to vocabulary.
|
Set model's output embeddings | def set_output_embeddings(self, value):
"""
Set model's output embeddings
Args:
value (:obj:`tf.Variable`):
The new weights mapping hidden states to vocabulary.
"""
if self.get_lm_head() is not None:
lm_head = self.get_lm_head()
... | [
"def",
"set_output_embeddings",
"(",
"self",
",",
"value",
")",
":",
"if",
"self",
".",
"get_lm_head",
"(",
")",
"is",
"not",
"None",
":",
"lm_head",
"=",
"self",
".",
"get_lm_head",
"(",
")",
"try",
":",
"lm_head",
".",
"set_output_embeddings",
"(",
"va... | [
723,
4
] | [
738,
52
] | python | en | ['en', 'error', 'th'] | False |
TFPreTrainedModel.get_output_layer_with_bias | (self) |
Get the layer that handles a bias attribute in case the model has an LM head with weights tied to the
embeddings
Return:
:obj:`tf.keras.layers.Layer`: The layer that handles the bias, None if not an LM model.
|
Get the layer that handles a bias attribute in case the model has an LM head with weights tied to the
embeddings | def get_output_layer_with_bias(self) -> Union[None, tf.keras.layers.Layer]:
"""
Get the layer that handles a bias attribute in case the model has an LM head with weights tied to the
embeddings
Return:
:obj:`tf.keras.layers.Layer`: The layer that handles the bias, None if not... | [
"def",
"get_output_layer_with_bias",
"(",
"self",
")",
"->",
"Union",
"[",
"None",
",",
"tf",
".",
"keras",
".",
"layers",
".",
"Layer",
"]",
":",
"warnings",
".",
"warn",
"(",
"\"The method get_output_layer_with_bias is deprecated. Please use `get_lm_head` instead.\"",... | [
740,
4
] | [
751,
33
] | python | en | ['en', 'error', 'th'] | False |
TFPreTrainedModel.get_prefix_bias_name | (self) |
Get the concatenated _prefix name of the bias from the model name to the parent layer
Return:
:obj:`str`: The _prefix name of the bias.
|
Get the concatenated _prefix name of the bias from the model name to the parent layer | def get_prefix_bias_name(self) -> Union[None, str]:
"""
Get the concatenated _prefix name of the bias from the model name to the parent layer
Return:
:obj:`str`: The _prefix name of the bias.
"""
warnings.warn("The method get_prefix_bias_name is deprecated. Please us... | [
"def",
"get_prefix_bias_name",
"(",
"self",
")",
"->",
"Union",
"[",
"None",
",",
"str",
"]",
":",
"warnings",
".",
"warn",
"(",
"\"The method get_prefix_bias_name is deprecated. Please use `get_bias` instead.\"",
",",
"FutureWarning",
")",
"return",
"None"
] | [
753,
4
] | [
761,
19
] | python | en | ['en', 'error', 'th'] | False |
TFPreTrainedModel.get_bias | (self) |
Dict of bias attached to an LM head. The key represents the name of the bias attribute.
Return:
:obj:`tf.Variable`: The weights representing the bias, None if not an LM model.
|
Dict of bias attached to an LM head. The key represents the name of the bias attribute. | def get_bias(self) -> Union[None, Dict[str, tf.Variable]]:
"""
Dict of bias attached to an LM head. The key represents the name of the bias attribute.
Return:
:obj:`tf.Variable`: The weights representing the bias, None if not an LM model.
"""
if self.get_lm_head() is... | [
"def",
"get_bias",
"(",
"self",
")",
"->",
"Union",
"[",
"None",
",",
"Dict",
"[",
"str",
",",
"tf",
".",
"Variable",
"]",
"]",
":",
"if",
"self",
".",
"get_lm_head",
"(",
")",
"is",
"not",
"None",
":",
"lm_head",
"=",
"self",
".",
"get_lm_head",
... | [
763,
4
] | [
778,
19
] | python | en | ['en', 'error', 'th'] | False |
TFPreTrainedModel.set_bias | (self, value) |
Set all the bias in the LM head.
Args:
value (:obj:`Dict[tf.Variable]`):
All the new bias attached to an LM head.
|
Set all the bias in the LM head. | def set_bias(self, value):
"""
Set all the bias in the LM head.
Args:
value (:obj:`Dict[tf.Variable]`):
All the new bias attached to an LM head.
"""
if self.get_lm_head() is not None:
lm_head = self.get_lm_head()
try:
... | [
"def",
"set_bias",
"(",
"self",
",",
"value",
")",
":",
"if",
"self",
".",
"get_lm_head",
"(",
")",
"is",
"not",
"None",
":",
"lm_head",
"=",
"self",
".",
"get_lm_head",
"(",
")",
"try",
":",
"lm_head",
".",
"set_bias",
"(",
"value",
")",
"except",
... | [
780,
4
] | [
794,
39
] | python | en | ['en', 'error', 'th'] | False |
TFPreTrainedModel.get_lm_head | (self) |
The LM Head layer. This method must be overwritten by all the models that have a lm head.
Return:
:obj:`tf.keras.layers.Layer`: The LM head layer if the model has one, None if not.
|
The LM Head layer. This method must be overwritten by all the models that have a lm head. | def get_lm_head(self) -> tf.keras.layers.Layer:
"""
The LM Head layer. This method must be overwritten by all the models that have a lm head.
Return:
:obj:`tf.keras.layers.Layer`: The LM head layer if the model has one, None if not.
"""
return None | [
"def",
"get_lm_head",
"(",
"self",
")",
"->",
"tf",
".",
"keras",
".",
"layers",
".",
"Layer",
":",
"return",
"None"
] | [
796,
4
] | [
803,
19
] | python | en | ['en', 'error', 'th'] | False |
TFPreTrainedModel.resize_token_embeddings | (self, new_num_tokens=None) |
Resizes input token embeddings matrix of the model if :obj:`new_num_tokens != config.vocab_size`.
Takes care of tying weights embeddings afterwards if the model class has a :obj:`tie_weights()` method.
Arguments:
new_num_tokens (:obj:`int`, `optional`):
The number ... |
Resizes input token embeddings matrix of the model if :obj:`new_num_tokens != config.vocab_size`. | def resize_token_embeddings(self, new_num_tokens=None) -> tf.Variable:
"""
Resizes input token embeddings matrix of the model if :obj:`new_num_tokens != config.vocab_size`.
Takes care of tying weights embeddings afterwards if the model class has a :obj:`tie_weights()` method.
Arguments... | [
"def",
"resize_token_embeddings",
"(",
"self",
",",
"new_num_tokens",
"=",
"None",
")",
"->",
"tf",
".",
"Variable",
":",
"if",
"new_num_tokens",
"is",
"None",
"or",
"new_num_tokens",
"==",
"self",
".",
"config",
".",
"vocab_size",
":",
"return",
"self",
"."... | [
805,
4
] | [
829,
27
] | python | en | ['en', 'error', 'th'] | False |
TFPreTrainedModel._get_resized_lm_head_bias | (self, old_lm_head_bias, new_num_tokens) |
Build a resized bias from the old ones. Increasing the size will add newly initialized vectors at the end.
Reducing the size will remove vectors from the end
Args:
old_lm_head_bias (:obj:`tf.Variable`):
Old lm head bias to be resized.
new_num_tokens (:ob... |
Build a resized bias from the old ones. Increasing the size will add newly initialized vectors at the end.
Reducing the size will remove vectors from the end | def _get_resized_lm_head_bias(self, old_lm_head_bias, new_num_tokens):
"""
Build a resized bias from the old ones. Increasing the size will add newly initialized vectors at the end.
Reducing the size will remove vectors from the end
Args:
old_lm_head_bias (:obj:`tf.Variable`... | [
"def",
"_get_resized_lm_head_bias",
"(",
"self",
",",
"old_lm_head_bias",
",",
"new_num_tokens",
")",
":",
"new_lm_head_bias",
"=",
"{",
"}",
"for",
"attr",
",",
"weight",
"in",
"old_lm_head_bias",
".",
"items",
"(",
")",
":",
"first_dim",
",",
"old_num_tokens",... | [
877,
4
] | [
927,
31
] | python | en | ['en', 'error', 'th'] | False |
TFPreTrainedModel._get_resized_lm_head_decoder | (self, old_lm_head_decoder, new_num_tokens) |
Build a resized decoder from the old ones. Increasing the size will add newly initialized vectors at the end.
Reducing the size will remove vectors from the end
Args:
old_lm_head_decoder (:obj:`tf.Variable`):
Old lm head decoder to be resized.
new_num_to... |
Build a resized decoder from the old ones. Increasing the size will add newly initialized vectors at the end.
Reducing the size will remove vectors from the end | def _get_resized_lm_head_decoder(self, old_lm_head_decoder, new_num_tokens):
"""
Build a resized decoder from the old ones. Increasing the size will add newly initialized vectors at the end.
Reducing the size will remove vectors from the end
Args:
old_lm_head_decoder (:obj:`... | [
"def",
"_get_resized_lm_head_decoder",
"(",
"self",
",",
"old_lm_head_decoder",
",",
"new_num_tokens",
")",
":",
"new_lm_head_decoder",
"=",
"old_lm_head_decoder",
"is_input_output_equals",
"=",
"tf",
".",
"reduce_any",
"(",
"self",
".",
"_get_word_embedding_weight",
"(",... | [
929,
4
] | [
965,
34
] | python | en | ['en', 'error', 'th'] | False |
TFPreTrainedModel._get_resized_embeddings | (self, old_embeddings, new_num_tokens=None) |
Build a resized Embedding weights from a provided token Embedding weights. Increasing the size will add newly
initialized vectors at the end. Reducing the size will remove vectors from the end
Args:
old_embeddings (:obj:`tf.Variable`):
Old embeddings to be resized.
... |
Build a resized Embedding weights from a provided token Embedding weights. Increasing the size will add newly
initialized vectors at the end. Reducing the size will remove vectors from the end | def _get_resized_embeddings(self, old_embeddings, new_num_tokens=None) -> tf.Variable:
"""
Build a resized Embedding weights from a provided token Embedding weights. Increasing the size will add newly
initialized vectors at the end. Reducing the size will remove vectors from the end
Arg... | [
"def",
"_get_resized_embeddings",
"(",
"self",
",",
"old_embeddings",
",",
"new_num_tokens",
"=",
"None",
")",
"->",
"tf",
".",
"Variable",
":",
"old_embedding_dim",
"=",
"shape_list",
"(",
"old_embeddings",
")",
"[",
"1",
"]",
"init_range",
"=",
"getattr",
"(... | [
967,
4
] | [
999,
29
] | python | en | ['en', 'error', 'th'] | False |
TFPreTrainedModel.prune_heads | (self, heads_to_prune) |
Prunes heads of the base model.
Arguments:
heads_to_prune (:obj:`Dict[int, List[int]]`):
Dictionary with keys being selected layer indices (:obj:`int`) and associated values being the list of
heads to prune in said layer (list of :obj:`int`). For instance {1... |
Prunes heads of the base model. | def prune_heads(self, heads_to_prune):
"""
Prunes heads of the base model.
Arguments:
heads_to_prune (:obj:`Dict[int, List[int]]`):
Dictionary with keys being selected layer indices (:obj:`int`) and associated values being the list of
heads to prune i... | [
"def",
"prune_heads",
"(",
"self",
",",
"heads_to_prune",
")",
":",
"raise",
"NotImplementedError"
] | [
1001,
4
] | [
1011,
33
] | python | en | ['en', 'error', 'th'] | False |
TFPreTrainedModel.save_pretrained | (self, save_directory, saved_model=False, version=1) |
Save a model and its configuration file to a directory, so that it can be re-loaded using the
:func:`~transformers.TFPreTrainedModel.from_pretrained` class method.
Arguments:
save_directory (:obj:`str`):
Directory to which to save. Will be created if it doesn't exis... |
Save a model and its configuration file to a directory, so that it can be re-loaded using the
:func:`~transformers.TFPreTrainedModel.from_pretrained` class method. | def save_pretrained(self, save_directory, saved_model=False, version=1):
"""
Save a model and its configuration file to a directory, so that it can be re-loaded using the
:func:`~transformers.TFPreTrainedModel.from_pretrained` class method.
Arguments:
save_directory (:obj:`s... | [
"def",
"save_pretrained",
"(",
"self",
",",
"save_directory",
",",
"saved_model",
"=",
"False",
",",
"version",
"=",
"1",
")",
":",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"save_directory",
")",
":",
"logger",
".",
"error",
"(",
"\"Provided path ({}) ... | [
1013,
4
] | [
1044,
74
] | python | en | ['en', 'error', 'th'] | False |
TFPreTrainedModel.from_pretrained | (cls, pretrained_model_name_or_path, *model_args, **kwargs) | r"""
Instantiate a pretrained TF 2.0 model from a pre-trained model configuration.
The warning `Weights from XXX not initialized from pretrained model` means that the weights of XXX do not come
pretrained with the rest of the model. It is up to you to train those weights with a downstream fine-... | r"""
Instantiate a pretrained TF 2.0 model from a pre-trained model configuration. | def from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs):
r"""
Instantiate a pretrained TF 2.0 model from a pre-trained model configuration.
The warning `Weights from XXX not initialized from pretrained model` means that the weights of XXX do not come
pretrained wi... | [
"def",
"from_pretrained",
"(",
"cls",
",",
"pretrained_model_name_or_path",
",",
"*",
"model_args",
",",
"*",
"*",
"kwargs",
")",
":",
"config",
"=",
"kwargs",
".",
"pop",
"(",
"\"config\"",
",",
"None",
")",
"cache_dir",
"=",
"kwargs",
".",
"pop",
"(",
... | [
1047,
4
] | [
1317,
20
] | python | cy | ['en', 'cy', 'hi'] | False |
TFSharedEmbeddings.build | (self, input_shape) |
Build shared token embedding layer Shared weights logic adapted from
https://github.com/tensorflow/models/blob/a009f4fb9d2fc4949e32192a944688925ef78659/official/transformer/v2/embedding_layer.py#L24
|
Build shared token embedding layer Shared weights logic adapted from
https://github.com/tensorflow/models/blob/a009f4fb9d2fc4949e32192a944688925ef78659/official/transformer/v2/embedding_layer.py#L24
| def build(self, input_shape):
"""
Build shared token embedding layer Shared weights logic adapted from
https://github.com/tensorflow/models/blob/a009f4fb9d2fc4949e32192a944688925ef78659/official/transformer/v2/embedding_layer.py#L24
"""
self.weight = self.add_weight(
... | [
"def",
"build",
"(",
"self",
",",
"input_shape",
")",
":",
"self",
".",
"weight",
"=",
"self",
".",
"add_weight",
"(",
"\"weight\"",
",",
"shape",
"=",
"[",
"self",
".",
"vocab_size",
",",
"self",
".",
"hidden_size",
"]",
",",
"initializer",
"=",
"get_... | [
1385,
4
] | [
1393,
34
] | python | en | ['en', 'error', 'th'] | False |
TFSharedEmbeddings.call | (self, inputs: tf.Tensor, mode: str = "embedding") |
Get token embeddings of inputs or decode final hidden state.
Args:
inputs (:obj:`tf.Tensor`):
In embedding mode, should be an int64 tensor with shape :obj:`[batch_size, length]`.
In linear mode, should be a float tensor with shape :obj:`[batch_size, length,... |
Get token embeddings of inputs or decode final hidden state. | def call(self, inputs: tf.Tensor, mode: str = "embedding") -> tf.Tensor:
"""
Get token embeddings of inputs or decode final hidden state.
Args:
inputs (:obj:`tf.Tensor`):
In embedding mode, should be an int64 tensor with shape :obj:`[batch_size, length]`.
... | [
"def",
"call",
"(",
"self",
",",
"inputs",
":",
"tf",
".",
"Tensor",
",",
"mode",
":",
"str",
"=",
"\"embedding\"",
")",
"->",
"tf",
".",
"Tensor",
":",
"if",
"mode",
"==",
"\"embedding\"",
":",
"return",
"self",
".",
"_embedding",
"(",
"inputs",
")"... | [
1405,
4
] | [
1435,
66
] | python | en | ['en', 'error', 'th'] | False |
TFSharedEmbeddings._embedding | (self, input_ids) | Applies embedding based on inputs tensor. | Applies embedding based on inputs tensor. | def _embedding(self, input_ids):
"""Applies embedding based on inputs tensor."""
return tf.gather(self.weight, input_ids) | [
"def",
"_embedding",
"(",
"self",
",",
"input_ids",
")",
":",
"return",
"tf",
".",
"gather",
"(",
"self",
".",
"weight",
",",
"input_ids",
")"
] | [
1437,
4
] | [
1439,
48
] | python | en | ['en', 'ceb', 'en'] | True |
TFSharedEmbeddings._linear | (self, inputs) |
Computes logits by running inputs through a linear layer.
Args:
inputs: A float32 tensor with shape [..., hidden_size]
Returns:
float32 tensor with shape [..., vocab_size].
|
Computes logits by running inputs through a linear layer. | def _linear(self, inputs):
"""
Computes logits by running inputs through a linear layer.
Args:
inputs: A float32 tensor with shape [..., hidden_size]
Returns:
float32 tensor with shape [..., vocab_size].
"""
first_dims = shape_list(inputs)[:-1]
... | [
"def",
"_linear",
"(",
"self",
",",
"inputs",
")",
":",
"first_dims",
"=",
"shape_list",
"(",
"inputs",
")",
"[",
":",
"-",
"1",
"]",
"x",
"=",
"tf",
".",
"reshape",
"(",
"inputs",
",",
"[",
"-",
"1",
",",
"self",
".",
"hidden_size",
"]",
")",
... | [
1441,
4
] | [
1455,
65
] | python | en | ['en', 'error', 'th'] | False |
setup | (hass, config) | Set up the RSS feed template component. | Set up the RSS feed template component. | def setup(hass, config):
"""Set up the RSS feed template component."""
for (feeduri, feedconfig) in config[DOMAIN].items():
url = "/api/rss_template/%s" % feeduri
requires_auth = feedconfig.get("requires_api_password")
title = feedconfig.get("title")
if title is not None:
... | [
"def",
"setup",
"(",
"hass",
",",
"config",
")",
":",
"for",
"(",
"feeduri",
",",
"feedconfig",
")",
"in",
"config",
"[",
"DOMAIN",
"]",
".",
"items",
"(",
")",
":",
"url",
"=",
"\"/api/rss_template/%s\"",
"%",
"feeduri",
"requires_auth",
"=",
"feedconfi... | [
39,
0
] | [
60,
15
] | python | en | ['en', 'en', 'en'] | True |
RssView.__init__ | (self, url, requires_auth, title, items) | Initialize the rss view. | Initialize the rss view. | def __init__(self, url, requires_auth, title, items):
"""Initialize the rss view."""
self.url = url
self.requires_auth = requires_auth
self._title = title
self._items = items | [
"def",
"__init__",
"(",
"self",
",",
"url",
",",
"requires_auth",
",",
"title",
",",
"items",
")",
":",
"self",
".",
"url",
"=",
"url",
"self",
".",
"requires_auth",
"=",
"requires_auth",
"self",
".",
"_title",
"=",
"title",
"self",
".",
"_items",
"=",... | [
72,
4
] | [
77,
27
] | python | en | ['en', 'en', 'en'] | True |
RssView.get | (self, request, entity_id=None) | Generate the RSS view XML. | Generate the RSS view XML. | async def get(self, request, entity_id=None):
"""Generate the RSS view XML."""
response = '<?xml version="1.0" encoding="utf-8"?>\n\n'
response += "<rss>\n"
if self._title is not None:
response += " <title>%s</title>\n" % escape(
self._title.async_render(par... | [
"async",
"def",
"get",
"(",
"self",
",",
"request",
",",
"entity_id",
"=",
"None",
")",
":",
"response",
"=",
"'<?xml version=\"1.0\" encoding=\"utf-8\"?>\\n\\n'",
"response",
"+=",
"\"<rss>\\n\"",
"if",
"self",
".",
"_title",
"is",
"not",
"None",
":",
"response... | [
79,
4
] | [
105,
9
] | 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.