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
do_vcs_install
(manifest_in, versionfile_source, ipy)
Git-specific installation logic for Versioneer. For Git, this means creating/changing .gitattributes to mark _version.py for export-subst keyword substitution.
Git-specific installation logic for Versioneer.
def do_vcs_install(manifest_in, versionfile_source, ipy): """Git-specific installation logic for Versioneer. For Git, this means creating/changing .gitattributes to mark _version.py for export-subst keyword substitution. """ GITS = ["git"] if sys.platform == "win32": GITS = ["git.cmd", ...
[ "def", "do_vcs_install", "(", "manifest_in", ",", "versionfile_source", ",", "ipy", ")", ":", "GITS", "=", "[", "\"git\"", "]", "if", "sys", ".", "platform", "==", "\"win32\"", ":", "GITS", "=", "[", "\"git.cmd\"", ",", "\"git.exe\"", "]", "files", "=", ...
[ 1146, 0 ]
[ 1181, 44 ]
python
en
['en', 'en', 'en']
True
versions_from_parentdir
(parentdir_prefix, root, verbose)
Try to determine the version from the parent directory name. Source tarballs conventionally unpack into a directory that includes both the project name and a version string. We will also support searching up two directory levels for an appropriately named parent directory
Try to determine the version from the parent directory name.
def versions_from_parentdir(parentdir_prefix, root, verbose): """Try to determine the version from the parent directory name. Source tarballs conventionally unpack into a directory that includes both the project name and a version string. We will also support searching up two directory levels for an ap...
[ "def", "versions_from_parentdir", "(", "parentdir_prefix", ",", "root", ",", "verbose", ")", ":", "rootdirs", "=", "[", "]", "for", "i", "in", "range", "(", "3", ")", ":", "dirname", "=", "os", ".", "path", ".", "basename", "(", "root", ")", "if", "d...
[ 1184, 0 ]
[ 1212, 70 ]
python
en
['en', 'en', 'en']
True
versions_from_file
(filename)
Try to determine the version from _version.py if present.
Try to determine the version from _version.py if present.
def versions_from_file(filename): """Try to determine the version from _version.py if present.""" try: with open(filename) as f: contents = f.read() except EnvironmentError: raise NotThisMethod("unable to read _version.py") mo = re.search( r"version_json = '''\n(.*)''...
[ "def", "versions_from_file", "(", "filename", ")", ":", "try", ":", "with", "open", "(", "filename", ")", "as", "f", ":", "contents", "=", "f", ".", "read", "(", ")", "except", "EnvironmentError", ":", "raise", "NotThisMethod", "(", "\"unable to read _versio...
[ 1233, 0 ]
[ 1249, 34 ]
python
en
['en', 'en', 'en']
True
write_to_version_file
(filename, versions)
Write the given version number to the given _version.py file.
Write the given version number to the given _version.py file.
def write_to_version_file(filename, versions): """Write the given version number to the given _version.py file.""" os.unlink(filename) contents = json.dumps(versions, sort_keys=True, indent=1, separators=(",", ": ")) with open(filename, "w") as f: f.write(SHORT_VERSION_PY % contents) print(...
[ "def", "write_to_version_file", "(", "filename", ",", "versions", ")", ":", "os", ".", "unlink", "(", "filename", ")", "contents", "=", "json", ".", "dumps", "(", "versions", ",", "sort_keys", "=", "True", ",", "indent", "=", "1", ",", "separators", "=",...
[ 1252, 0 ]
[ 1259, 61 ]
python
en
['en', 'en', 'en']
True
plus_or_dot
(pieces)
Return a + if we don't already have one, else return a .
Return a + if we don't already have one, else return a .
def plus_or_dot(pieces): """Return a + if we don't already have one, else return a .""" if "+" in pieces.get("closest-tag", ""): return "." return "+"
[ "def", "plus_or_dot", "(", "pieces", ")", ":", "if", "\"+\"", "in", "pieces", ".", "get", "(", "\"closest-tag\"", ",", "\"\"", ")", ":", "return", "\".\"", "return", "\"+\"" ]
[ 1262, 0 ]
[ 1266, 14 ]
python
en
['en', 'en', 'en']
True
render_pep440
(pieces)
Build up version string, with post-release "local version identifier". Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty Exceptions: 1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty]
Build up version string, with post-release "local version identifier".
def render_pep440(pieces): """Build up version string, with post-release "local version identifier". Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty Exceptions: 1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHE...
[ "def", "render_pep440", "(", "pieces", ")", ":", "if", "pieces", "[", "\"closest-tag\"", "]", ":", "rendered", "=", "pieces", "[", "\"closest-tag\"", "]", "if", "pieces", "[", "\"distance\"", "]", "or", "pieces", "[", "\"dirty\"", "]", ":", "rendered", "+=...
[ 1269, 0 ]
[ 1290, 19 ]
python
en
['en', 'en', 'en']
True
render_pep440_pre
(pieces)
TAG[.post.devDISTANCE] -- No -dirty. Exceptions: 1: no tags. 0.post.devDISTANCE
TAG[.post.devDISTANCE] -- No -dirty.
def render_pep440_pre(pieces): """TAG[.post.devDISTANCE] -- No -dirty. Exceptions: 1: no tags. 0.post.devDISTANCE """ if pieces["closest-tag"]: rendered = pieces["closest-tag"] if pieces["distance"]: rendered += ".post.dev%d" % pieces["distance"] else: # exce...
[ "def", "render_pep440_pre", "(", "pieces", ")", ":", "if", "pieces", "[", "\"closest-tag\"", "]", ":", "rendered", "=", "pieces", "[", "\"closest-tag\"", "]", "if", "pieces", "[", "\"distance\"", "]", ":", "rendered", "+=", "\".post.dev%d\"", "%", "pieces", ...
[ 1293, 0 ]
[ 1306, 19 ]
python
en
['en', 'en', 'pt']
True
render_pep440_post
(pieces)
TAG[.postDISTANCE[.dev0]+gHEX] . The ".dev0" means dirty. Note that .dev0 sorts backwards (a dirty tree will appear "older" than the corresponding clean one), but you shouldn't be releasing software with -dirty anyways. Exceptions: 1: no tags. 0.postDISTANCE[.dev0]
TAG[.postDISTANCE[.dev0]+gHEX] .
def render_pep440_post(pieces): """TAG[.postDISTANCE[.dev0]+gHEX] . The ".dev0" means dirty. Note that .dev0 sorts backwards (a dirty tree will appear "older" than the corresponding clean one), but you shouldn't be releasing software with -dirty anyways. Exceptions: 1: no tags. 0.postDISTANCE[...
[ "def", "render_pep440_post", "(", "pieces", ")", ":", "if", "pieces", "[", "\"closest-tag\"", "]", ":", "rendered", "=", "pieces", "[", "\"closest-tag\"", "]", "if", "pieces", "[", "\"distance\"", "]", "or", "pieces", "[", "\"dirty\"", "]", ":", "rendered", ...
[ 1309, 0 ]
[ 1333, 19 ]
python
cy
['en', 'cy', 'hi']
False
render_pep440_old
(pieces)
TAG[.postDISTANCE[.dev0]] . The ".dev0" means dirty. Eexceptions: 1: no tags. 0.postDISTANCE[.dev0]
TAG[.postDISTANCE[.dev0]] .
def render_pep440_old(pieces): """TAG[.postDISTANCE[.dev0]] . The ".dev0" means dirty. Eexceptions: 1: no tags. 0.postDISTANCE[.dev0] """ if pieces["closest-tag"]: rendered = pieces["closest-tag"] if pieces["distance"] or pieces["dirty"]: rendered += ".post%d" % pie...
[ "def", "render_pep440_old", "(", "pieces", ")", ":", "if", "pieces", "[", "\"closest-tag\"", "]", ":", "rendered", "=", "pieces", "[", "\"closest-tag\"", "]", "if", "pieces", "[", "\"distance\"", "]", "or", "pieces", "[", "\"dirty\"", "]", ":", "rendered", ...
[ 1336, 0 ]
[ 1355, 19 ]
python
en
['en', 'mt', 'hi']
False
render_git_describe
(pieces)
TAG[-DISTANCE-gHEX][-dirty]. Like 'git describe --tags --dirty --always'. Exceptions: 1: no tags. HEX[-dirty] (note: no 'g' prefix)
TAG[-DISTANCE-gHEX][-dirty].
def render_git_describe(pieces): """TAG[-DISTANCE-gHEX][-dirty]. Like 'git describe --tags --dirty --always'. Exceptions: 1: no tags. HEX[-dirty] (note: no 'g' prefix) """ if pieces["closest-tag"]: rendered = pieces["closest-tag"] if pieces["distance"]: rendered +=...
[ "def", "render_git_describe", "(", "pieces", ")", ":", "if", "pieces", "[", "\"closest-tag\"", "]", ":", "rendered", "=", "pieces", "[", "\"closest-tag\"", "]", "if", "pieces", "[", "\"distance\"", "]", ":", "rendered", "+=", "\"-%d-g%s\"", "%", "(", "pieces...
[ 1358, 0 ]
[ 1375, 19 ]
python
en
['en', 'en', 'en']
False
render_git_describe_long
(pieces)
TAG-DISTANCE-gHEX[-dirty]. Like 'git describe --tags --dirty --always -long'. The distance/hash is unconditional. Exceptions: 1: no tags. HEX[-dirty] (note: no 'g' prefix)
TAG-DISTANCE-gHEX[-dirty].
def render_git_describe_long(pieces): """TAG-DISTANCE-gHEX[-dirty]. Like 'git describe --tags --dirty --always -long'. The distance/hash is unconditional. Exceptions: 1: no tags. HEX[-dirty] (note: no 'g' prefix) """ if pieces["closest-tag"]: rendered = pieces["closest-tag"] ...
[ "def", "render_git_describe_long", "(", "pieces", ")", ":", "if", "pieces", "[", "\"closest-tag\"", "]", ":", "rendered", "=", "pieces", "[", "\"closest-tag\"", "]", "rendered", "+=", "\"-%d-g%s\"", "%", "(", "pieces", "[", "\"distance\"", "]", ",", "pieces", ...
[ 1378, 0 ]
[ 1395, 19 ]
python
en
['en', 'en', 'pt']
False
render
(pieces, style)
Render the given version pieces into the requested style.
Render the given version pieces into the requested style.
def render(pieces, style): """Render the given version pieces into the requested style.""" if pieces["error"]: return { "version": "unknown", "full-revisionid": pieces.get("long"), "dirty": None, "error": pieces["error"], "date": None, ...
[ "def", "render", "(", "pieces", ",", "style", ")", ":", "if", "pieces", "[", "\"error\"", "]", ":", "return", "{", "\"version\"", ":", "\"unknown\"", ",", "\"full-revisionid\"", ":", "pieces", ".", "get", "(", "\"long\"", ")", ",", "\"dirty\"", ":", "Non...
[ 1398, 0 ]
[ 1433, 5 ]
python
en
['en', 'en', 'en']
True
get_versions
(verbose=False)
Get the project version from whatever source is available. Returns dict with two keys: 'version' and 'full'.
Get the project version from whatever source is available.
def get_versions(verbose=False): """Get the project version from whatever source is available. Returns dict with two keys: 'version' and 'full'. """ if "versioneer" in sys.modules: # see the discussion in cmdclass.py:get_cmdclass() del sys.modules["versioneer"] root = get_root() ...
[ "def", "get_versions", "(", "verbose", "=", "False", ")", ":", "if", "\"versioneer\"", "in", "sys", ".", "modules", ":", "# see the discussion in cmdclass.py:get_cmdclass()", "del", "sys", ".", "modules", "[", "\"versioneer\"", "]", "root", "=", "get_root", "(", ...
[ 1440, 0 ]
[ 1518, 5 ]
python
en
['en', 'en', 'en']
True
get_version
()
Get the short version string for this project.
Get the short version string for this project.
def get_version(): """Get the short version string for this project.""" return get_versions()["version"]
[ "def", "get_version", "(", ")", ":", "return", "get_versions", "(", ")", "[", "\"version\"", "]" ]
[ 1521, 0 ]
[ 1523, 36 ]
python
en
['en', 'en', 'en']
True
get_cmdclass
()
Get the custom setuptools/distutils subclasses used by Versioneer.
Get the custom setuptools/distutils subclasses used by Versioneer.
def get_cmdclass(): """Get the custom setuptools/distutils subclasses used by Versioneer.""" if "versioneer" in sys.modules: del sys.modules["versioneer"] # this fixes the "python setup.py develop" case (also 'install' and # 'easy_install .'), in which subdependencies of the main project...
[ "def", "get_cmdclass", "(", ")", ":", "if", "\"versioneer\"", "in", "sys", ".", "modules", ":", "del", "sys", ".", "modules", "[", "\"versioneer\"", "]", "# this fixes the \"python setup.py develop\" case (also 'install' and", "# 'easy_install .'), in which subdependencies of...
[ 1526, 0 ]
[ 1705, 15 ]
python
en
['en', 'et', 'en']
True
do_setup
()
Main VCS-independent setup function for installing Versioneer.
Main VCS-independent setup function for installing Versioneer.
def do_setup(): """Main VCS-independent setup function for installing Versioneer.""" root = get_root() try: cfg = get_config_from_root(root) except ( EnvironmentError, configparser.NoSectionError, configparser.NoOptionError, ) as e: if isinstance(e, (Environme...
[ "def", "do_setup", "(", ")", ":", "root", "=", "get_root", "(", ")", "try", ":", "cfg", "=", "get_config_from_root", "(", "root", ")", "except", "(", "EnvironmentError", ",", "configparser", ".", "NoSectionError", ",", "configparser", ".", "NoOptionError", "...
[ 1752, 0 ]
[ 1838, 12 ]
python
en
['en', 'en', 'en']
True
scan_setup_py
()
Validate the contents of setup.py against Versioneer's expectations.
Validate the contents of setup.py against Versioneer's expectations.
def scan_setup_py(): """Validate the contents of setup.py against Versioneer's expectations.""" found = set() setters = False errors = 0 with open("setup.py", "r") as f: for line in f.readlines(): if "import versioneer" in line: found.add("import") if ...
[ "def", "scan_setup_py", "(", ")", ":", "found", "=", "set", "(", ")", "setters", "=", "False", "errors", "=", "0", "with", "open", "(", "\"setup.py\"", ",", "\"r\"", ")", "as", "f", ":", "for", "line", "in", "f", ".", "readlines", "(", ")", ":", ...
[ 1841, 0 ]
[ 1875, 17 ]
python
en
['en', 'en', 'en']
True
parse_ansi_to_irc
(string)
Parse |-type syntax and replace with IRC color markers Args: string (str): String to parse for ANSI colors. Returns: parsed_string (str): String with replaced ANSI colors.
Parse |-type syntax and replace with IRC color markers
def parse_ansi_to_irc(string): """ Parse |-type syntax and replace with IRC color markers Args: string (str): String to parse for ANSI colors. Returns: parsed_string (str): String with replaced ANSI colors. """ def _sub_to_irc(ansi_match): return IRC_COLOR_MAP.get(ans...
[ "def", "parse_ansi_to_irc", "(", "string", ")", ":", "def", "_sub_to_irc", "(", "ansi_match", ")", ":", "return", "IRC_COLOR_MAP", ".", "get", "(", "ansi_match", ".", "group", "(", ")", ",", "\"\"", ")", "in_string", "=", "utils", ".", "to_str", "(", "st...
[ 103, 0 ]
[ 126, 24 ]
python
en
['en', 'error', 'th']
False
parse_irc_to_ansi
(string)
Parse IRC mIRC color syntax and replace with Evennia ANSI color markers Args: string (str): String to parse for IRC colors. Returns: parsed_string (str): String with replaced IRC colors.
Parse IRC mIRC color syntax and replace with Evennia ANSI color markers
def parse_irc_to_ansi(string): """ Parse IRC mIRC color syntax and replace with Evennia ANSI color markers Args: string (str): String to parse for IRC colors. Returns: parsed_string (str): String with replaced IRC colors. """ def _sub_to_ansi(irc_match): return ANSI_C...
[ "def", "parse_irc_to_ansi", "(", "string", ")", ":", "def", "_sub_to_ansi", "(", "irc_match", ")", ":", "return", "ANSI_COLOR_MAP", ".", "get", "(", "irc_match", ".", "group", "(", ")", ",", "\"\"", ")", "in_string", "=", "utils", ".", "to_str", "(", "st...
[ 129, 0 ]
[ 146, 18 ]
python
en
['en', 'error', 'th']
False
IRCBot.signedOn
(self)
This is called when we successfully connect to the network. We make sure to now register with the game as a full session.
This is called when we successfully connect to the network. We make sure to now register with the game as a full session.
def signedOn(self): """ This is called when we successfully connect to the network. We make sure to now register with the game as a full session. """ self.join(self.channel) self.stopping = False self.factory.bot = self address = "%s@%s" % (self.channel, ...
[ "def", "signedOn", "(", "self", ")", ":", "self", ".", "join", "(", "self", ".", "channel", ")", "self", ".", "stopping", "=", "False", "self", ".", "factory", ".", "bot", "=", "self", "address", "=", "\"%s@%s\"", "%", "(", "self", ".", "channel", ...
[ 167, 4 ]
[ 183, 93 ]
python
en
['en', 'error', 'th']
False
IRCBot.disconnect
(self, reason="")
Called by sessionhandler to disconnect this protocol. Args: reason (str): Motivation for the disconnect.
Called by sessionhandler to disconnect this protocol.
def disconnect(self, reason=""): """ Called by sessionhandler to disconnect this protocol. Args: reason (str): Motivation for the disconnect. """ self.sessionhandler.disconnect(self) self.stopping = True self.transport.loseConnection()
[ "def", "disconnect", "(", "self", ",", "reason", "=", "\"\"", ")", ":", "self", ".", "sessionhandler", ".", "disconnect", "(", "self", ")", "self", ".", "stopping", "=", "True", "self", ".", "transport", ".", "loseConnection", "(", ")" ]
[ 185, 4 ]
[ 195, 39 ]
python
en
['en', 'error', 'th']
False
IRCBot.privmsg
(self, user, channel, msg)
Called when the connected channel receives a message. Args: user (str): User name sending the message. channel (str): Channel name seeing the message. msg (str): The message arriving from channel.
Called when the connected channel receives a message.
def privmsg(self, user, channel, msg): """ Called when the connected channel receives a message. Args: user (str): User name sending the message. channel (str): Channel name seeing the message. msg (str): The message arriving from channel. """ ...
[ "def", "privmsg", "(", "self", ",", "user", ",", "channel", ",", "msg", ")", ":", "if", "channel", "==", "self", ".", "nickname", ":", "# private message", "user", "=", "user", ".", "split", "(", "'!'", ",", "1", ")", "[", "0", "]", "self", ".", ...
[ 200, 4 ]
[ 218, 74 ]
python
en
['en', 'error', 'th']
False
IRCBot.action
(self, user, channel, msg)
Called when an action is detected in channel. Args: user (str): User name sending the message. channel (str): Channel name seeing the message. msg (str): The message arriving from channel.
Called when an action is detected in channel.
def action(self, user, channel, msg): """ Called when an action is detected in channel. Args: user (str): User name sending the message. channel (str): Channel name seeing the message. msg (str): The message arriving from channel. """ if not ...
[ "def", "action", "(", "self", ",", "user", ",", "channel", ",", "msg", ")", ":", "if", "not", "msg", ".", "startswith", "(", "'**'", ")", ":", "user", "=", "user", ".", "split", "(", "'!'", ",", "1", ")", "[", "0", "]", "self", ".", "data_in", ...
[ 220, 4 ]
[ 232, 77 ]
python
en
['en', 'error', 'th']
False
IRCBot.get_nicklist
(self)
Retrieve name list from the channel. The return is handled by the catch methods below.
Retrieve name list from the channel. The return is handled by the catch methods below.
def get_nicklist(self): """ Retrieve name list from the channel. The return is handled by the catch methods below. """ if not self.nicklist: self.sendLine("NAMES %s" % self.channel)
[ "def", "get_nicklist", "(", "self", ")", ":", "if", "not", "self", ".", "nicklist", ":", "self", ".", "sendLine", "(", "\"NAMES %s\"", "%", "self", ".", "channel", ")" ]
[ 234, 4 ]
[ 241, 52 ]
python
en
['en', 'error', 'th']
False
IRCBot.irc_RPL_NAMREPLY
(self, prefix, params)
Handles IRC NAME request returns (nicklist)
Handles IRC NAME request returns (nicklist)
def irc_RPL_NAMREPLY(self, prefix, params): """"Handles IRC NAME request returns (nicklist)""" channel = params[2].lower() if channel != self.channel.lower(): return self.nicklist += params[3].split(' ')
[ "def", "irc_RPL_NAMREPLY", "(", "self", ",", "prefix", ",", "params", ")", ":", "channel", "=", "params", "[", "2", "]", ".", "lower", "(", ")", "if", "channel", "!=", "self", ".", "channel", ".", "lower", "(", ")", ":", "return", "self", ".", "nic...
[ 243, 4 ]
[ 248, 45 ]
python
de
['fr', 'de', 'en']
False
IRCBot.irc_RPL_ENDOFNAMES
(self, prefix, params)
Called when the nicklist has finished being returned.
Called when the nicklist has finished being returned.
def irc_RPL_ENDOFNAMES(self, prefix, params): """Called when the nicklist has finished being returned.""" channel = params[1].lower() if channel != self.channel.lower(): return self.data_in(text="", type="nicklist", user="server", channel=channel, nicklist=self.nicklist) ...
[ "def", "irc_RPL_ENDOFNAMES", "(", "self", ",", "prefix", ",", "params", ")", ":", "channel", "=", "params", "[", "1", "]", ".", "lower", "(", ")", "if", "channel", "!=", "self", ".", "channel", ".", "lower", "(", ")", ":", "return", "self", ".", "d...
[ 250, 4 ]
[ 256, 26 ]
python
en
['en', 'en', 'en']
True
IRCBot.pong
(self, user, time)
Called with the return timing from a PING. Args: user (str): Name of user time (float): Ping time in secs.
Called with the return timing from a PING.
def pong(self, user, time): """ Called with the return timing from a PING. Args: user (str): Name of user time (float): Ping time in secs. """ self.data_in(text="", type="ping", user="server", channel=self.channel, timing=time)
[ "def", "pong", "(", "self", ",", "user", ",", "time", ")", ":", "self", ".", "data_in", "(", "text", "=", "\"\"", ",", "type", "=", "\"ping\"", ",", "user", "=", "\"server\"", ",", "channel", "=", "self", ".", "channel", ",", "timing", "=", "time",...
[ 258, 4 ]
[ 267, 92 ]
python
en
['en', 'error', 'th']
False
IRCBot.data_in
(self, text=None, **kwargs)
Data IRC -> Server. Kwargs: text (str): Ingoing text. kwargs (any): Other data from protocol.
Data IRC -> Server.
def data_in(self, text=None, **kwargs): """ Data IRC -> Server. Kwargs: text (str): Ingoing text. kwargs (any): Other data from protocol. """ self.sessionhandler.data_in(self, bot_data_in=[parse_irc_to_ansi(text), kwargs])
[ "def", "data_in", "(", "self", ",", "text", "=", "None", ",", "*", "*", "kwargs", ")", ":", "self", ".", "sessionhandler", ".", "data_in", "(", "self", ",", "bot_data_in", "=", "[", "parse_irc_to_ansi", "(", "text", ")", ",", "kwargs", "]", ")" ]
[ 269, 4 ]
[ 278, 88 ]
python
en
['en', 'error', 'th']
False
IRCBot.send_channel
(self, *args, **kwargs)
Send channel text to IRC channel (visible to all). Note that we don't handle the "text" send (it's rerouted to send_default which does nothing) - this is because the IRC bot is a normal session and would otherwise report anything that happens to it to the IRC channel (such as it...
Send channel text to IRC channel (visible to all). Note that we don't handle the "text" send (it's rerouted to send_default which does nothing) - this is because the IRC bot is a normal session and would otherwise report anything that happens to it to the IRC channel (such as it...
def send_channel(self, *args, **kwargs): """ Send channel text to IRC channel (visible to all). Note that we don't handle the "text" send (it's rerouted to send_default which does nothing) - this is because the IRC bot is a normal session and would otherwise report anything that ...
[ "def", "send_channel", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "text", "=", "args", "[", "0", "]", "if", "args", "else", "\"\"", "if", "text", ":", "text", "=", "parse_ansi_to_irc", "(", "text", ")", "self", ".", "say", ...
[ 280, 4 ]
[ 295, 40 ]
python
en
['en', 'error', 'th']
False
IRCBot.send_privmsg
(self, *args, **kwargs)
Send message only to specific user. Args: text (str): Outgoing text. Kwargs: user (str): the nick to send privately to.
Send message only to specific user.
def send_privmsg(self, *args, **kwargs): """ Send message only to specific user. Args: text (str): Outgoing text. Kwargs: user (str): the nick to send privately to. """ text = args[0] if args else "" user = kwargs.get("us...
[ "def", "send_privmsg", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "text", "=", "args", "[", "0", "]", "if", "args", "else", "\"\"", "user", "=", "kwargs", ".", "get", "(", "\"user\"", ",", "None", ")", "if", "text", "and", ...
[ 297, 4 ]
[ 313, 32 ]
python
en
['en', 'error', 'th']
False
IRCBot.send_request_nicklist
(self, *args, **kwargs)
Send a request for the channel nicklist. The return (handled by `self.irc_RPL_ENDOFNAMES`) will be sent back as a message with type `nicklist'.
Send a request for the channel nicklist. The return (handled by `self.irc_RPL_ENDOFNAMES`) will be sent back as a message with type `nicklist'.
def send_request_nicklist(self, *args, **kwargs): """ Send a request for the channel nicklist. The return (handled by `self.irc_RPL_ENDOFNAMES`) will be sent back as a message with type `nicklist'. """ self.get_nicklist()
[ "def", "send_request_nicklist", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "self", ".", "get_nicklist", "(", ")" ]
[ 315, 4 ]
[ 321, 27 ]
python
en
['en', 'error', 'th']
False
IRCBot.send_ping
(self, *args, **kwargs)
Send a ping. The return (handled by `self.pong`) will be sent back as a message of type 'ping'.
Send a ping. The return (handled by `self.pong`) will be sent back as a message of type 'ping'.
def send_ping(self, *args, **kwargs): """ Send a ping. The return (handled by `self.pong`) will be sent back as a message of type 'ping'. """ self.ping(self.nickname)
[ "def", "send_ping", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "self", ".", "ping", "(", "self", ".", "nickname", ")" ]
[ 323, 4 ]
[ 328, 32 ]
python
en
['en', 'error', 'th']
False
IRCBot.send_reconnect
(self, *args, **kwargs)
The server instructs us to rebuild the connection by force, probably because the client silently lost connection.
The server instructs us to rebuild the connection by force, probably because the client silently lost connection.
def send_reconnect(self, *args, **kwargs): """ The server instructs us to rebuild the connection by force, probably because the client silently lost connection. """ self.factory.reconnect()
[ "def", "send_reconnect", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "self", ".", "factory", ".", "reconnect", "(", ")" ]
[ 330, 4 ]
[ 335, 32 ]
python
en
['en', 'error', 'th']
False
IRCBot.send_default
(self, *args, **kwargs)
Ignore other types of sends.
Ignore other types of sends.
def send_default(self, *args, **kwargs): """ Ignore other types of sends. """ pass
[ "def", "send_default", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "pass" ]
[ 337, 4 ]
[ 342, 12 ]
python
en
['en', 'error', 'th']
False
IRCBotFactory.__init__
(self, sessionhandler, uid=None, botname=None, channel=None, network=None, port=None, ssl=None)
Storing some important protocol properties. Args: sessionhandler (SessionHandler): Reference to the main Sessionhandler. Kwargs: uid (int): Bot user id. botname (str): Bot name (seen in IRC channel). channel (str): IRC channel to connect to. ...
Storing some important protocol properties.
def __init__(self, sessionhandler, uid=None, botname=None, channel=None, network=None, port=None, ssl=None): """ Storing some important protocol properties. Args: sessionhandler (SessionHandler): Reference to the main Sessionhandler. Kwargs: uid (int): Bot user ...
[ "def", "__init__", "(", "self", ",", "sessionhandler", ",", "uid", "=", "None", ",", "botname", "=", "None", ",", "channel", "=", "None", ",", "network", "=", "None", ",", "port", "=", "None", ",", "ssl", "=", "None", ")", ":", "self", ".", "sessio...
[ 356, 4 ]
[ 380, 27 ]
python
en
['en', 'error', 'th']
False
IRCBotFactory.buildProtocol
(self, addr)
Build the protocol and assign it some properties. Args: addr (str): Not used; using factory data.
Build the protocol and assign it some properties.
def buildProtocol(self, addr): """ Build the protocol and assign it some properties. Args: addr (str): Not used; using factory data. """ protocol = IRCBot() protocol.factory = self protocol.nickname = self.nickname protocol.channel = self.cha...
[ "def", "buildProtocol", "(", "self", ",", "addr", ")", ":", "protocol", "=", "IRCBot", "(", ")", "protocol", ".", "factory", "=", "self", "protocol", ".", "nickname", "=", "self", ".", "nickname", "protocol", ".", "channel", "=", "self", ".", "channel", ...
[ 382, 4 ]
[ 398, 23 ]
python
en
['en', 'error', 'th']
False
IRCBotFactory.startedConnecting
(self, connector)
Tracks reconnections for debugging. Args: connector (Connector): Represents the connection.
Tracks reconnections for debugging.
def startedConnecting(self, connector): """ Tracks reconnections for debugging. Args: connector (Connector): Represents the connection. """ logger.log_info("(re)connecting to %s" % self.channel)
[ "def", "startedConnecting", "(", "self", ",", "connector", ")", ":", "logger", ".", "log_info", "(", "\"(re)connecting to %s\"", "%", "self", ".", "channel", ")" ]
[ 400, 4 ]
[ 408, 62 ]
python
en
['en', 'error', 'th']
False
IRCBotFactory.clientConnectionFailed
(self, connector, reason)
Called when Client failed to connect. Args: connector (Connection): Represents the connection. reason (str): The reason for the failure.
Called when Client failed to connect.
def clientConnectionFailed(self, connector, reason): """ Called when Client failed to connect. Args: connector (Connection): Represents the connection. reason (str): The reason for the failure. """ self.retry(connector)
[ "def", "clientConnectionFailed", "(", "self", ",", "connector", ",", "reason", ")", ":", "self", ".", "retry", "(", "connector", ")" ]
[ 410, 4 ]
[ 419, 29 ]
python
en
['en', 'error', 'th']
False
IRCBotFactory.clientConnectionLost
(self, connector, reason)
Called when Client loses connection. Args: connector (Connection): Represents the connection. reason (str): The reason for the failure.
Called when Client loses connection.
def clientConnectionLost(self, connector, reason): """ Called when Client loses connection. Args: connector (Connection): Represents the connection. reason (str): The reason for the failure. """ if not (self.bot or (self.bot and self.bot.stopping)): ...
[ "def", "clientConnectionLost", "(", "self", ",", "connector", ",", "reason", ")", ":", "if", "not", "(", "self", ".", "bot", "or", "(", "self", ".", "bot", "and", "self", ".", "bot", ".", "stopping", ")", ")", ":", "self", ".", "retry", "(", "conne...
[ 421, 4 ]
[ 431, 33 ]
python
en
['en', 'error', 'th']
False
IRCBotFactory.reconnect
(self)
Force a reconnection of the bot protocol. This requires de-registering the session and then reattaching a new one, otherwise you end up with an ever growing number of bot sessions.
Force a reconnection of the bot protocol. This requires de-registering the session and then reattaching a new one, otherwise you end up with an ever growing number of bot sessions.
def reconnect(self): """ Force a reconnection of the bot protocol. This requires de-registering the session and then reattaching a new one, otherwise you end up with an ever growing number of bot sessions. """ self.bot.stopping = True self.bot.transport.l...
[ "def", "reconnect", "(", "self", ")", ":", "self", ".", "bot", ".", "stopping", "=", "True", "self", ".", "bot", ".", "transport", ".", "loseConnection", "(", ")", "self", ".", "sessionhandler", ".", "server_disconnect", "(", "self", ".", "bot", ")", "...
[ 433, 4 ]
[ 444, 20 ]
python
en
['en', 'error', 'th']
False
IRCBotFactory.start
(self)
Connect session to sessionhandler.
Connect session to sessionhandler.
def start(self): """ Connect session to sessionhandler. """ if self.port: if self.ssl: try: from twisted.internet import ssl service = reactor.connectSSL(self.network, int(self.port), self, ssl.ClientContextFactory()) ...
[ "def", "start", "(", "self", ")", ":", "if", "self", ".", "port", ":", "if", "self", ".", "ssl", ":", "try", ":", "from", "twisted", ".", "internet", "import", "ssl", "service", "=", "reactor", ".", "connectSSL", "(", "self", ".", "network", ",", "...
[ 446, 4 ]
[ 460, 67 ]
python
en
['en', 'error', 'th']
False
Marker.color
(self)
Sets the marker color of selected points. The 'color' property is a color and may be specified as: - A hex string (e.g. '#ff0000') - An rgb/rgba string (e.g. 'rgb(255,0,0)') - An hsl/hsla string (e.g. 'hsl(0,100%,50%)') - An hsv/hsva string (e.g. 'hsv(0,100%...
Sets the marker color of selected points. The 'color' property is a color and may be specified as: - A hex string (e.g. '#ff0000') - An rgb/rgba string (e.g. 'rgb(255,0,0)') - An hsl/hsla string (e.g. 'hsl(0,100%,50%)') - An hsv/hsva string (e.g. 'hsv(0,100%...
def color(self): """ Sets the marker color of selected points. The 'color' property is a color and may be specified as: - A hex string (e.g. '#ff0000') - An rgb/rgba string (e.g. 'rgb(255,0,0)') - An hsl/hsla string (e.g. 'hsl(0,100%,50%)') - An hsv/h...
[ "def", "color", "(", "self", ")", ":", "return", "self", "[", "\"color\"", "]" ]
[ 15, 4 ]
[ 65, 28 ]
python
en
['en', 'error', 'th']
False
Marker.opacity
(self)
Sets the marker opacity of selected points. The 'opacity' property is a number and may be specified as: - An int or float in the interval [0, 1] Returns ------- int|float
Sets the marker opacity of selected points. The 'opacity' property is a number and may be specified as: - An int or float in the interval [0, 1]
def opacity(self): """ Sets the marker opacity of selected points. The 'opacity' property is a number and may be specified as: - An int or float in the interval [0, 1] Returns ------- int|float """ return self["opacity"]
[ "def", "opacity", "(", "self", ")", ":", "return", "self", "[", "\"opacity\"", "]" ]
[ 74, 4 ]
[ 85, 30 ]
python
en
['en', 'error', 'th']
False
Marker.size
(self)
Sets the marker size of selected points. The 'size' property is a number and may be specified as: - An int or float in the interval [0, inf] Returns ------- int|float
Sets the marker size of selected points. The 'size' property is a number and may be specified as: - An int or float in the interval [0, inf]
def size(self): """ Sets the marker size of selected points. The 'size' property is a number and may be specified as: - An int or float in the interval [0, inf] Returns ------- int|float """ return self["size"]
[ "def", "size", "(", "self", ")", ":", "return", "self", "[", "\"size\"", "]" ]
[ 94, 4 ]
[ 105, 27 ]
python
en
['en', 'error', 'th']
False
Marker.__init__
(self, arg=None, color=None, opacity=None, size=None, **kwargs)
Construct a new Marker object Parameters ---------- arg dict of properties compatible with this constructor or an instance of :class:`plotly.graph_objs.scatterternary .selected.Marker` color Sets the marker color of select...
Construct a new Marker object Parameters ---------- arg dict of properties compatible with this constructor or an instance of :class:`plotly.graph_objs.scatterternary .selected.Marker` color Sets the marker color of select...
def __init__(self, arg=None, color=None, opacity=None, size=None, **kwargs): """ Construct a new Marker object Parameters ---------- arg dict of properties compatible with this constructor or an instance of :class:`plotly.graph_objs.scatterternary...
[ "def", "__init__", "(", "self", ",", "arg", "=", "None", ",", "color", "=", "None", ",", "opacity", "=", "None", ",", "size", "=", "None", ",", "*", "*", "kwargs", ")", ":", "super", "(", "Marker", ",", "self", ")", ".", "__init__", "(", "\"marke...
[ 124, 4 ]
[ 193, 34 ]
python
en
['en', 'error', 'th']
False
BodyFunctions.at_repeat
(self)
This gets called every self.interval seconds. We make a random check here so as to only return 33% of the time.
This gets called every self.interval seconds. We make a random check here so as to only return 33% of the time.
def at_repeat(self): """ This gets called every self.interval seconds. We make a random check here so as to only return 33% of the time. """ if random.random() < 0.66: # no message this time return self.send_random_message()
[ "def", "at_repeat", "(", "self", ")", ":", "if", "random", ".", "random", "(", ")", "<", "0.66", ":", "# no message this time", "return", "self", ".", "send_random_message", "(", ")" ]
[ 28, 4 ]
[ 36, 34 ]
python
en
['en', 'error', 'th']
False
Integral.forward
(self, x)
Forward feature from the regression head to get integral result of bounding box location. Args: x (Tensor): Features of the regression head, shape (N, 4*(n+1)), n is self.reg_max. Returns: x (Tensor): Integral result of box locations, i.e., distance ...
Forward feature from the regression head to get integral result of bounding box location.
def forward(self, x): """Forward feature from the regression head to get integral result of bounding box location. Args: x (Tensor): Features of the regression head, shape (N, 4*(n+1)), n is self.reg_max. Returns: x (Tensor): Integral result of b...
[ "def", "forward", "(", "self", ",", "x", ")", ":", "x", "=", "F", ".", "softmax", "(", "x", ".", "reshape", "(", "-", "1", ",", "self", ".", "reg_max", "+", "1", ")", ",", "dim", "=", "1", ")", "x", "=", "F", ".", "linear", "(", "x", ",",...
[ 41, 4 ]
[ 55, 16 ]
python
en
['en', 'en', 'en']
True
MenuOption.__init__
( self, *, name: str = None, title: str = None, description: str = None, disabled: bool = None, form: MenuForm = None, )
Initialize a MenuOption instance. Args: name: The menu option name (unique ID) title: The menu option title description: Additional descriptive text for the menu option disabled: If the option should be shown as disabled form: A form to displ...
Initialize a MenuOption instance.
def __init__( self, *, name: str = None, title: str = None, description: str = None, disabled: bool = None, form: MenuForm = None, ): """ Initialize a MenuOption instance. Args: name: The menu option name (unique ID) ...
[ "def", "__init__", "(", "self", ",", "*", ",", "name", ":", "str", "=", "None", ",", "title", ":", "str", "=", "None", ",", "description", ":", "str", "=", "None", ",", "disabled", ":", "bool", "=", "None", ",", "form", ":", "MenuForm", "=", "Non...
[ 17, 4 ]
[ 40, 24 ]
python
en
['en', 'error', 'th']
False
wrap_fp16_model
(model)
Wrap the FP32 model to FP16. 1. Convert FP32 model to FP16. 2. Remain some necessary layers to be FP32, e.g., normalization layers. Args: model (nn.Module): Model in FP32.
Wrap the FP32 model to FP16.
def wrap_fp16_model(model): """Wrap the FP32 model to FP16. 1. Convert FP32 model to FP16. 2. Remain some necessary layers to be FP32, e.g., normalization layers. Args: model (nn.Module): Model in FP32. """ # convert model to fp16 model.half() # patch the normalization layers t...
[ "def", "wrap_fp16_model", "(", "model", ")", ":", "# convert model to fp16", "model", ".", "half", "(", ")", "# patch the normalization layers to make it work in fp32 mode", "patch_norm_fp32", "(", "model", ")", "# set `fp16_enabled` flag", "for", "m", "in", "model", ".",...
[ 98, 0 ]
[ 114, 33 ]
python
en
['en', 'en', 'en']
True
patch_norm_fp32
(module)
Recursively convert normalization layers from FP16 to FP32. Args: module (nn.Module): The modules to be converted in FP16. Returns: nn.Module: The converted module, the normalization layers have been converted to FP32.
Recursively convert normalization layers from FP16 to FP32.
def patch_norm_fp32(module): """Recursively convert normalization layers from FP16 to FP32. Args: module (nn.Module): The modules to be converted in FP16. Returns: nn.Module: The converted module, the normalization layers have been converted to FP32. """ if isinstance(m...
[ "def", "patch_norm_fp32", "(", "module", ")", ":", "if", "isinstance", "(", "module", ",", "(", "nn", ".", "modules", ".", "batchnorm", ".", "_BatchNorm", ",", "nn", ".", "GroupNorm", ")", ")", ":", "module", ".", "float", "(", ")", "if", "isinstance",...
[ 117, 0 ]
[ 134, 17 ]
python
en
['en', 'en', 'en']
True
patch_forward_method
(func, src_type, dst_type, convert_output=True)
Patch the forward method of a module. Args: func (callable): The original forward method. src_type (torch.dtype): Type of input arguments to be converted from. dst_type (torch.dtype): Type of input arguments to be converted to. convert_output (bool): Whether to convert the output ba...
Patch the forward method of a module.
def patch_forward_method(func, src_type, dst_type, convert_output=True): """Patch the forward method of a module. Args: func (callable): The original forward method. src_type (torch.dtype): Type of input arguments to be converted from. dst_type (torch.dtype): Type of input arguments to ...
[ "def", "patch_forward_method", "(", "func", ",", "src_type", ",", "dst_type", ",", "convert_output", "=", "True", ")", ":", "def", "new_forward", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "output", "=", "func", "(", "*", "cast_tensor_type", "(...
[ 137, 0 ]
[ 157, 22 ]
python
en
['en', 'en', 'en']
True
Fp16OptimizerHook.before_run
(self, runner)
Preparing steps before Mixed Precision Training. 1. Make a master copy of fp32 weights for optimization. 2. Convert the main model from fp32 to fp16.
Preparing steps before Mixed Precision Training.
def before_run(self, runner): """Preparing steps before Mixed Precision Training. 1. Make a master copy of fp32 weights for optimization. 2. Convert the main model from fp32 to fp16. """ # keep a copy of fp32 weights runner.optimizer.param_groups = copy.deepcopy( ...
[ "def", "before_run", "(", "self", ",", "runner", ")", ":", "# keep a copy of fp32 weights", "runner", ".", "optimizer", ".", "param_groups", "=", "copy", ".", "deepcopy", "(", "runner", ".", "optimizer", ".", "param_groups", ")", "# convert model to fp16", "wrap_f...
[ 38, 4 ]
[ 48, 37 ]
python
en
['it', 'en', 'en']
True
Fp16OptimizerHook.copy_grads_to_fp32
(self, fp16_net, fp32_weights)
Copy gradients from fp16 model to fp32 weight copy.
Copy gradients from fp16 model to fp32 weight copy.
def copy_grads_to_fp32(self, fp16_net, fp32_weights): """Copy gradients from fp16 model to fp32 weight copy.""" for fp32_param, fp16_param in zip(fp32_weights, fp16_net.parameters()): if fp16_param.grad is not None: if fp32_param.grad is None: fp32_param.g...
[ "def", "copy_grads_to_fp32", "(", "self", ",", "fp16_net", ",", "fp32_weights", ")", ":", "for", "fp32_param", ",", "fp16_param", "in", "zip", "(", "fp32_weights", ",", "fp16_net", ".", "parameters", "(", ")", ")", ":", "if", "fp16_param", ".", "grad", "is...
[ 50, 4 ]
[ 56, 54 ]
python
en
['en', 'en', 'en']
True
Fp16OptimizerHook.copy_params_to_fp16
(self, fp16_net, fp32_weights)
Copy updated params from fp32 weight copy to fp16 model.
Copy updated params from fp32 weight copy to fp16 model.
def copy_params_to_fp16(self, fp16_net, fp32_weights): """Copy updated params from fp32 weight copy to fp16 model.""" for fp16_param, fp32_param in zip(fp16_net.parameters(), fp32_weights): fp16_param.data.copy_(fp32_param.data)
[ "def", "copy_params_to_fp16", "(", "self", ",", "fp16_net", ",", "fp32_weights", ")", ":", "for", "fp16_param", ",", "fp32_param", "in", "zip", "(", "fp16_net", ".", "parameters", "(", ")", ",", "fp32_weights", ")", ":", "fp16_param", ".", "data", ".", "co...
[ 58, 4 ]
[ 61, 50 ]
python
en
['en', 'en', 'en']
True
Fp16OptimizerHook.after_train_iter
(self, runner)
Backward optimization steps for Mixed Precision Training. 1. Scale the loss by a scale factor. 2. Backward the loss to obtain the gradients (fp16). 3. Copy gradients from the model to the fp32 weight copy. 4. Scale the gradients back and update the fp32 weight copy. 5. Copy back...
Backward optimization steps for Mixed Precision Training.
def after_train_iter(self, runner): """Backward optimization steps for Mixed Precision Training. 1. Scale the loss by a scale factor. 2. Backward the loss to obtain the gradients (fp16). 3. Copy gradients from the model to the fp32 weight copy. 4. Scale the gradients back and up...
[ "def", "after_train_iter", "(", "self", ",", "runner", ")", ":", "# clear grads of last iteration", "runner", ".", "model", ".", "zero_grad", "(", ")", "runner", ".", "optimizer", ".", "zero_grad", "(", ")", "# scale the loss value", "scaled_loss", "=", "runner", ...
[ 63, 4 ]
[ 95, 60 ]
python
en
['en', 'en', 'en']
True
Font.color
(self)
The 'color' property is a color and may be specified as: - A hex string (e.g. '#ff0000') - An rgb/rgba string (e.g. 'rgb(255,0,0)') - An hsl/hsla string (e.g. 'hsl(0,100%,50%)') - An hsv/hsva string (e.g. 'hsv(0,100%,100%)') - A named CSS color: ...
The 'color' property is a color and may be specified as: - A hex string (e.g. '#ff0000') - An rgb/rgba string (e.g. 'rgb(255,0,0)') - An hsl/hsla string (e.g. 'hsl(0,100%,50%)') - An hsv/hsva string (e.g. 'hsv(0,100%,100%)') - A named CSS color: ...
def color(self): """ The 'color' property is a color and may be specified as: - A hex string (e.g. '#ff0000') - An rgb/rgba string (e.g. 'rgb(255,0,0)') - An hsl/hsla string (e.g. 'hsl(0,100%,50%)') - An hsv/hsva string (e.g. 'hsv(0,100%,100%)') - A name...
[ "def", "color", "(", "self", ")", ":", "return", "self", "[", "\"color\"", "]" ]
[ 15, 4 ]
[ 64, 28 ]
python
en
['en', 'error', 'th']
False
Font.colorsrc
(self)
Sets the source reference on Chart Studio Cloud for color . The 'colorsrc' property must be specified as a string or as a plotly.grid_objs.Column object Returns ------- str
Sets the source reference on Chart Studio Cloud for color . The 'colorsrc' property must be specified as a string or as a plotly.grid_objs.Column object
def colorsrc(self): """ Sets the source reference on Chart Studio Cloud for color . The 'colorsrc' property must be specified as a string or as a plotly.grid_objs.Column object Returns ------- str """ return self["colorsrc"]
[ "def", "colorsrc", "(", "self", ")", ":", "return", "self", "[", "\"colorsrc\"", "]" ]
[ 73, 4 ]
[ 84, 31 ]
python
en
['en', 'error', 'th']
False
Font.family
(self)
HTML font family - the typeface that will be applied by the web browser. The web browser will only be able to apply a font if it is available on the system which it operates. Provide multiple font families, separated by commas, to indicate the preference in which to apply fonts ...
HTML font family - the typeface that will be applied by the web browser. The web browser will only be able to apply a font if it is available on the system which it operates. Provide multiple font families, separated by commas, to indicate the preference in which to apply fonts ...
def family(self): """ HTML font family - the typeface that will be applied by the web browser. The web browser will only be able to apply a font if it is available on the system which it operates. Provide multiple font families, separated by commas, to indicate the prefer...
[ "def", "family", "(", "self", ")", ":", "return", "self", "[", "\"family\"", "]" ]
[ 93, 4 ]
[ 116, 29 ]
python
en
['en', 'error', 'th']
False
Font.familysrc
(self)
Sets the source reference on Chart Studio Cloud for family . The 'familysrc' property must be specified as a string or as a plotly.grid_objs.Column object Returns ------- str
Sets the source reference on Chart Studio Cloud for family . The 'familysrc' property must be specified as a string or as a plotly.grid_objs.Column object
def familysrc(self): """ Sets the source reference on Chart Studio Cloud for family . The 'familysrc' property must be specified as a string or as a plotly.grid_objs.Column object Returns ------- str """ return self["familysrc"]
[ "def", "familysrc", "(", "self", ")", ":", "return", "self", "[", "\"familysrc\"", "]" ]
[ 125, 4 ]
[ 136, 32 ]
python
en
['en', 'error', 'th']
False
Font.size
(self)
The 'size' property is a number and may be specified as: - An int or float in the interval [1, inf] - A tuple, list, or one-dimensional numpy array of the above Returns ------- int|float|numpy.ndarray
The 'size' property is a number and may be specified as: - An int or float in the interval [1, inf] - A tuple, list, or one-dimensional numpy array of the above
def size(self): """ The 'size' property is a number and may be specified as: - An int or float in the interval [1, inf] - A tuple, list, or one-dimensional numpy array of the above Returns ------- int|float|numpy.ndarray """ return self["size"...
[ "def", "size", "(", "self", ")", ":", "return", "self", "[", "\"size\"", "]" ]
[ 145, 4 ]
[ 155, 27 ]
python
en
['en', 'error', 'th']
False
Font.sizesrc
(self)
Sets the source reference on Chart Studio Cloud for size . The 'sizesrc' property must be specified as a string or as a plotly.grid_objs.Column object Returns ------- str
Sets the source reference on Chart Studio Cloud for size . The 'sizesrc' property must be specified as a string or as a plotly.grid_objs.Column object
def sizesrc(self): """ Sets the source reference on Chart Studio Cloud for size . The 'sizesrc' property must be specified as a string or as a plotly.grid_objs.Column object Returns ------- str """ return self["sizesrc"]
[ "def", "sizesrc", "(", "self", ")", ":", "return", "self", "[", "\"sizesrc\"", "]" ]
[ 164, 4 ]
[ 175, 30 ]
python
en
['en', 'error', 'th']
False
Font.__init__
( self, arg=None, color=None, colorsrc=None, family=None, familysrc=None, size=None, sizesrc=None, **kwargs )
Construct a new Font object Sets the font used in hover labels. Parameters ---------- arg dict of properties compatible with this constructor or an instance of :class:`plotly.graph_objs.cone.hoverlabel.Font` color co...
Construct a new Font object Sets the font used in hover labels.
def __init__( self, arg=None, color=None, colorsrc=None, family=None, familysrc=None, size=None, sizesrc=None, **kwargs ): """ Construct a new Font object Sets the font used in hover labels. Parameters ...
[ "def", "__init__", "(", "self", ",", "arg", "=", "None", ",", "color", "=", "None", ",", "colorsrc", "=", "None", ",", "family", "=", "None", ",", "familysrc", "=", "None", ",", "size", "=", "None", ",", "sizesrc", "=", "None", ",", "*", "*", "kw...
[ 215, 4 ]
[ 329, 34 ]
python
en
['en', 'error', 'th']
False
test_create_deps_for_exotic_version_style
()
Expected return value is: 0 item is package, 1 deps with version for previous package,
Expected return value is: 0 item is package, 1 deps with version for previous package,
def test_create_deps_for_exotic_version_style(): depends = ['package1', 'package2'] versions = ['1.6.74', '0.9.4~+.-AbCd1.2.3.4.EiF'] def mock_info_from_package_manager(*package): pkg_info = """Package: {package} Version: 1.1.26 Priority: extra Section: default Maintainer: Some Organization <some_or...
[ "def", "test_create_deps_for_exotic_version_style", "(", ")", ":", "depends", "=", "[", "'package1'", ",", "'package2'", "]", "versions", "=", "[", "'1.6.74'", ",", "'0.9.4~+.-AbCd1.2.3.4.EiF'", "]", "def", "mock_info_from_package_manager", "(", "*", "package", ")", ...
[ 33, 0 ]
[ 68, 81 ]
python
en
['en', 'error', 'th']
False
GlobalAvgPool2d.__init__
(self)
Global average pooling over the input's spatial dimensions
Global average pooling over the input's spatial dimensions
def __init__(self): """Global average pooling over the input's spatial dimensions""" super(GlobalAvgPool2d, self).__init__()
[ "def", "__init__", "(", "self", ")", ":", "super", "(", "GlobalAvgPool2d", ",", "self", ")", ".", "__init__", "(", ")" ]
[ 123, 4 ]
[ 125, 47 ]
python
en
['en', 'en', 'en']
True
escape
(s)
r""" Replace potential special characters with escaped version. For example, \n => \\n and \t => \\t :param s: string to escape
r""" Replace potential special characters with escaped version.
def escape(s): r""" Replace potential special characters with escaped version. For example, \n => \\n and \t => \\t :param s: string to escape """ return s.replace('\n', '\\n').replace('\t', '\\t').replace('\r', '\\r')
[ "def", "escape", "(", "s", ")", ":", "return", "s", ".", "replace", "(", "'\\n'", ",", "'\\\\n'", ")", ".", "replace", "(", "'\\t'", ",", "'\\\\t'", ")", ".", "replace", "(", "'\\r'", ",", "'\\\\r'", ")" ]
[ 38, 0 ]
[ 47, 75 ]
python
cy
['en', 'cy', 'hi']
False
unescape
(s)
r""" Revert escaped characters back to their special version. For example, \\n => \n and \\t => \t :param s: string to unescape
r""" Revert escaped characters back to their special version.
def unescape(s): r""" Revert escaped characters back to their special version. For example, \\n => \n and \\t => \t :param s: string to unescape """ return s.replace('\\n', '\n').replace('\\t', '\t').replace('\\r', '\r')
[ "def", "unescape", "(", "s", ")", ":", "return", "s", ".", "replace", "(", "'\\\\n'", ",", "'\\n'", ")", ".", "replace", "(", "'\\\\t'", ",", "'\\t'", ")", ".", "replace", "(", "'\\\\r'", ",", "'\\r'", ")" ]
[ 50, 0 ]
[ 59, 75 ]
python
cy
['en', 'cy', 'hi']
False
find_ngrams
(token_dict, text, n)
Break text into ngrams that appear in ``token_dict``. :param token_dict: ``dict`` to check for ngrams :param text: ``str`` to look for ngrams in :param n: ``int`` max size of ngrams
Break text into ngrams that appear in ``token_dict``.
def find_ngrams(token_dict, text, n): """ Break text into ngrams that appear in ``token_dict``. :param token_dict: ``dict`` to check for ngrams :param text: ``str`` to look for ngrams in :param n: ``int`` max size of ngrams """ # base case if n <= 1: retu...
[ "def", "find_ngrams", "(", "token_dict", ",", "text", ",", "n", ")", ":", "# base case", "if", "n", "<=", "1", ":", "return", "text", "# tokens committed to output", "saved_tokens", "=", "[", "]", "# tokens remaining to be searched in sentence", "search_tokens", "="...
[ 62, 0 ]
[ 98, 23 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.add_cmdline_args
( cls, parser: ParlaiParser, partial_opt: Optional[Opt] = None )
Add commandline arguments related to the dictionary.
Add commandline arguments related to the dictionary.
def add_cmdline_args( cls, parser: ParlaiParser, partial_opt: Optional[Opt] = None ) -> ParlaiParser: """ Add commandline arguments related to the dictionary. """ dictionary = parser.add_argument_group('Dictionary Arguments') dictionary.add_argument( '-df'...
[ "def", "add_cmdline_args", "(", "cls", ",", "parser", ":", "ParlaiParser", ",", "partial_opt", ":", "Optional", "[", "Opt", "]", "=", "None", ")", "->", "ParlaiParser", ":", "dictionary", "=", "parser", ".", "add_argument_group", "(", "'Dictionary Arguments'", ...
[ 123, 4 ]
[ 228, 25 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.__init__
(self, opt: Opt, shared=None)
Initialize DictionaryAgent.
Initialize DictionaryAgent.
def __init__(self, opt: Opt, shared=None): """ Initialize DictionaryAgent. """ self.opt = copy.deepcopy(opt) self.minfreq = opt.get('dict_minfreq', DictionaryAgent.default_minfreq) self.null_token = opt.get('dict_nulltoken', DictionaryAgent.default_null) self.end_...
[ "def", "__init__", "(", "self", ",", "opt", ":", "Opt", ",", "shared", "=", "None", ")", ":", "self", ".", "opt", "=", "copy", ".", "deepcopy", "(", "opt", ")", "self", ".", "minfreq", "=", "opt", ".", "get", "(", "'dict_minfreq'", ",", "Dictionary...
[ 230, 4 ]
[ 342, 49 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.add_additional_special_tokens
(self, additional_special_tokens: List[str])
Add additional special tokens to the dictionary. Should only be called after initialization of the existing dictionary.
Add additional special tokens to the dictionary.
def add_additional_special_tokens(self, additional_special_tokens: List[str]): """ Add additional special tokens to the dictionary. Should only be called after initialization of the existing dictionary. """ self.additional_special_tokens = additional_special_tokens for ...
[ "def", "add_additional_special_tokens", "(", "self", ",", "additional_special_tokens", ":", "List", "[", "str", "]", ")", ":", "self", ".", "additional_special_tokens", "=", "additional_special_tokens", "for", "tok", "in", "self", ".", "additional_special_tokens", ":"...
[ 344, 4 ]
[ 368, 13 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.is_prebuilt
(self)
Indicates whether the dictionary is fixed, and does not require building.
Indicates whether the dictionary is fixed, and does not require building.
def is_prebuilt(self): """ Indicates whether the dictionary is fixed, and does not require building. """ return self.tokenizer == 'gpt2'
[ "def", "is_prebuilt", "(", "self", ")", ":", "return", "self", ".", "tokenizer", "==", "'gpt2'" ]
[ 370, 4 ]
[ 374, 39 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.add_token
(self, word)
Add a single token to the dictionary.
Add a single token to the dictionary.
def add_token(self, word): """ Add a single token to the dictionary. """ if word not in self.tok2ind: index = len(self.tok2ind) self.tok2ind[word] = index self.ind2tok[index] = word
[ "def", "add_token", "(", "self", ",", "word", ")", ":", "if", "word", "not", "in", "self", ".", "tok2ind", ":", "index", "=", "len", "(", "self", ".", "tok2ind", ")", "self", ".", "tok2ind", "[", "word", "]", "=", "index", "self", ".", "ind2tok", ...
[ 376, 4 ]
[ 383, 38 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.__contains__
(self, key)
Return if the dictionary contains the key. If key is an int, returns whether the key is in the indices. If key is a str, return if the token is in the dict of tokens.
Return if the dictionary contains the key.
def __contains__(self, key): """ Return if the dictionary contains the key. If key is an int, returns whether the key is in the indices. If key is a str, return if the token is in the dict of tokens. """ if type(key) == int: return key in self.ind2tok ...
[ "def", "__contains__", "(", "self", ",", "key", ")", ":", "if", "type", "(", "key", ")", "==", "int", ":", "return", "key", "in", "self", ".", "ind2tok", "elif", "type", "(", "key", ")", "==", "str", ":", "return", "key", "in", "self", ".", "tok2...
[ 385, 4 ]
[ 395, 38 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.__getitem__
(self, key)
Lookup the word or ID. If key is an int, returns the corresponding token. If it does not exist, return the unknown token. If key is a str, return the token's index. If the token is not in the dictionary, return the index of the unknown token. If there is no unknown token, retur...
Lookup the word or ID.
def __getitem__(self, key): """ Lookup the word or ID. If key is an int, returns the corresponding token. If it does not exist, return the unknown token. If key is a str, return the token's index. If the token is not in the dictionary, return the index of the unknown token. If t...
[ "def", "__getitem__", "(", "self", ",", "key", ")", ":", "if", "type", "(", "key", ")", "==", "str", ":", "return", "self", ".", "_word_lookup", "(", "key", ")", "if", "type", "(", "key", ")", "==", "int", ":", "return", "self", ".", "_index_lookup...
[ 405, 4 ]
[ 417, 42 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.__setitem__
(self, key, value)
Set the frequency for a word to a value. If the key is not in the dictionary, add it to the dictionary and set its frequency to value.
Set the frequency for a word to a value.
def __setitem__(self, key, value): """ Set the frequency for a word to a value. If the key is not in the dictionary, add it to the dictionary and set its frequency to value. """ key = str(key) if self.lower: key = key.lower() self.freq[key] = ...
[ "def", "__setitem__", "(", "self", ",", "key", ",", "value", ")", ":", "key", "=", "str", "(", "key", ")", "if", "self", ".", "lower", ":", "key", "=", "key", ".", "lower", "(", ")", "self", ".", "freq", "[", "key", "]", "=", "int", "(", "val...
[ 422, 4 ]
[ 433, 27 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.keys
(self)
Return all the words in the dictionary.
Return all the words in the dictionary.
def keys(self): """ Return all the words in the dictionary. """ return self.tok2ind.keys()
[ "def", "keys", "(", "self", ")", ":", "return", "self", ".", "tok2ind", ".", "keys", "(", ")" ]
[ 435, 4 ]
[ 439, 34 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.nltk_tokenize
(self, text, building=False)
Tokenize using NLTK PunktTokenizer. Uses nltk-trained PunktTokenizer for sentence tokenization and Treebank Word Tokenizer for tokenizing words within sentences.
Tokenize using NLTK PunktTokenizer.
def nltk_tokenize(self, text, building=False): """ Tokenize using NLTK PunktTokenizer. Uses nltk-trained PunktTokenizer for sentence tokenization and Treebank Word Tokenizer for tokenizing words within sentences. """ return ( token for sent in sel...
[ "def", "nltk_tokenize", "(", "self", ",", "text", ",", "building", "=", "False", ")", ":", "return", "(", "token", "for", "sent", "in", "self", ".", "sent_tok", ".", "tokenize", "(", "text", ")", "for", "token", "in", "self", ".", "word_tok", ".", "t...
[ 441, 4 ]
[ 452, 9 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.gpt2_tokenize
(self, text)
Tokenize using Gpt2 BPE tokenizer.
Tokenize using Gpt2 BPE tokenizer.
def gpt2_tokenize(self, text): """ Tokenize using Gpt2 BPE tokenizer. """ return self.bpe_tokenize(text)
[ "def", "gpt2_tokenize", "(", "self", ",", "text", ")", ":", "return", "self", ".", "bpe_tokenize", "(", "text", ")" ]
[ 454, 4 ]
[ 458, 38 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.slow_bytelevel_bpe_tokenize
(self, text)
Tokenize using Gpt2 BPE tokenizer.
Tokenize using Gpt2 BPE tokenizer.
def slow_bytelevel_bpe_tokenize(self, text): """ Tokenize using Gpt2 BPE tokenizer. """ return self.bpe_tokenize(text)
[ "def", "slow_bytelevel_bpe_tokenize", "(", "self", ",", "text", ")", ":", "return", "self", ".", "bpe_tokenize", "(", "text", ")" ]
[ 460, 4 ]
[ 464, 38 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.bytelevelbpe_tokenize
(self, text)
Tokenize using Gpt2 BPE tokenizer.
Tokenize using Gpt2 BPE tokenizer.
def bytelevelbpe_tokenize(self, text): """ Tokenize using Gpt2 BPE tokenizer. """ return self.bpe_tokenize(text)
[ "def", "bytelevelbpe_tokenize", "(", "self", ",", "text", ")", ":", "return", "self", ".", "bpe_tokenize", "(", "text", ")" ]
[ 466, 4 ]
[ 470, 38 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.re_tokenize
(text)
r""" Tokenize using a liberal regular expression. Find boundaries between word characters, newlines, and non-word non-whitespace tokens ``(r'[\\w\\n]+ | [^\\w\\s] | \\n')``. This splits along whitespace and punctuation and keeps the newline as a token in the returned list. ...
r""" Tokenize using a liberal regular expression.
def re_tokenize(text): r""" Tokenize using a liberal regular expression. Find boundaries between word characters, newlines, and non-word non-whitespace tokens ``(r'[\\w\\n]+ | [^\\w\\s] | \\n')``. This splits along whitespace and punctuation and keeps the newline as a t...
[ "def", "re_tokenize", "(", "text", ")", ":", "return", "RETOK", ".", "findall", "(", "text", ")" ]
[ 473, 4 ]
[ 483, 34 ]
python
cy
['en', 'cy', 'hi']
False
DictionaryAgent.split_tokenize
(text)
Tokenize on whitespace and some limited punctuation. Splits tokens based on whitespace after adding whitespace around punctuation. Use re_tokenize if you want more robust handling of punctuation.
Tokenize on whitespace and some limited punctuation.
def split_tokenize(text): """ Tokenize on whitespace and some limited punctuation. Splits tokens based on whitespace after adding whitespace around punctuation. Use re_tokenize if you want more robust handling of punctuation. """ return ( text.replac...
[ "def", "split_tokenize", "(", "text", ")", ":", "return", "(", "text", ".", "replace", "(", "'.'", ",", "' . '", ")", ".", "replace", "(", "','", ",", "' , '", ")", ".", "replace", "(", "';'", ",", "' ; '", ")", ".", "replace", "(", "':'", ",", "...
[ 486, 4 ]
[ 503, 9 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.space_tokenize
(text)
Tokenize exactly on spaces. Useful when text is pre-tokenized.
Tokenize exactly on spaces.
def space_tokenize(text): """ Tokenize exactly on spaces. Useful when text is pre-tokenized. """ return text.strip().split(' ')
[ "def", "space_tokenize", "(", "text", ")", ":", "return", "text", ".", "strip", "(", ")", ".", "split", "(", "' '", ")" ]
[ 506, 4 ]
[ 512, 38 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.span_tokenize
(self, text)
Tokenize and find starting index of each token in the original string.
Tokenize and find starting index of each token in the original string.
def span_tokenize(self, text): """ Tokenize and find starting index of each token in the original string. """ tokens = self.tokenize(text) curr_idx = 0 indices = [] for t in tokens: while text[curr_idx] != t[0]: curr_idx += 1 ...
[ "def", "span_tokenize", "(", "self", ",", "text", ")", ":", "tokens", "=", "self", ".", "tokenize", "(", "text", ")", "curr_idx", "=", "0", "indices", "=", "[", "]", "for", "t", "in", "tokens", ":", "while", "text", "[", "curr_idx", "]", "!=", "t",...
[ 514, 4 ]
[ 526, 30 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.tokenize
(self, text, building=False)
Return a sequence of tokens from the iterable. Also handles special tokens for some tokenizers
Return a sequence of tokens from the iterable.
def tokenize(self, text, building=False): """ Return a sequence of tokens from the iterable. Also handles special tokens for some tokenizers """ if self.tokenizer in ('re', 'split', 'space'): for special_token in self.additional_special_tokens: index ...
[ "def", "tokenize", "(", "self", ",", "text", ",", "building", "=", "False", ")", ":", "if", "self", ".", "tokenizer", "in", "(", "'re'", ",", "'split'", ",", "'space'", ")", ":", "for", "special_token", "in", "self", ".", "additional_special_tokens", ":"...
[ 528, 4 ]
[ 555, 26 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.bpe_tokenize
(self, text)
Return a sequence of BPE-tokens from the text.
Return a sequence of BPE-tokens from the text.
def bpe_tokenize(self, text): """ Return a sequence of BPE-tokens from the text. """ return self.bpe.encode(text)
[ "def", "bpe_tokenize", "(", "self", ",", "text", ")", ":", "return", "self", ".", "bpe", ".", "encode", "(", "text", ")" ]
[ 557, 4 ]
[ 561, 36 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.add_to_dict
(self, tokens)
Build dictionary from the list of provided tokens.
Build dictionary from the list of provided tokens.
def add_to_dict(self, tokens): """ Build dictionary from the list of provided tokens. """ self.built = False for token in tokens: self.add_token(token) self.freq[token] += 1
[ "def", "add_to_dict", "(", "self", ",", "tokens", ")", ":", "self", ".", "built", "=", "False", "for", "token", "in", "tokens", ":", "self", ".", "add_token", "(", "token", ")", "self", ".", "freq", "[", "token", "]", "+=", "1" ]
[ 563, 4 ]
[ 570, 33 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.remove_tail
(self, min_freq)
Remove elements below the frequency cutoff from the dictionary.
Remove elements below the frequency cutoff from the dictionary.
def remove_tail(self, min_freq): """ Remove elements below the frequency cutoff from the dictionary. """ to_remove = [] for token, freq in self.freq.items(): if freq < min_freq: # queue up removals since can't mutate dict during iteration ...
[ "def", "remove_tail", "(", "self", ",", "min_freq", ")", ":", "to_remove", "=", "[", "]", "for", "token", ",", "freq", "in", "self", ".", "freq", ".", "items", "(", ")", ":", "if", "freq", "<", "min_freq", ":", "# queue up removals since can't mutate dict ...
[ 572, 4 ]
[ 585, 33 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent._remove_non_bpe
(self)
Set the dictionary vocab to the bpe vocab, merging counts.
Set the dictionary vocab to the bpe vocab, merging counts.
def _remove_non_bpe(self): """ Set the dictionary vocab to the bpe vocab, merging counts. """ to_remove = [] to_add = [] for token, freq in self.freq.items(): tokens = self.bpe_tokenize(token) if len(tokens) != 1: for t in tokens: ...
[ "def", "_remove_non_bpe", "(", "self", ")", ":", "to_remove", "=", "[", "]", "to_add", "=", "[", "]", "for", "token", ",", "freq", "in", "self", ".", "freq", ".", "items", "(", ")", ":", "tokens", "=", "self", ".", "bpe_tokenize", "(", "token", ")"...
[ 587, 4 ]
[ 605, 36 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.resize_to_max
(self, maxtokens)
Trims the dictionary to the maximum number of tokens.
Trims the dictionary to the maximum number of tokens.
def resize_to_max(self, maxtokens): """ Trims the dictionary to the maximum number of tokens. """ if maxtokens >= 0 and len(self.tok2ind) > maxtokens: for k in range(maxtokens, len(self.ind2tok)): v = self.ind2tok[k] del self.ind2tok[k] ...
[ "def", "resize_to_max", "(", "self", ",", "maxtokens", ")", ":", "if", "maxtokens", ">=", "0", "and", "len", "(", "self", ".", "tok2ind", ")", ">", "maxtokens", ":", "for", "k", "in", "range", "(", "maxtokens", ",", "len", "(", "self", ".", "ind2tok"...
[ 607, 4 ]
[ 616, 32 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.load
(self, filename)
Load pre-existing dictionary in 'token[<TAB>count]' format. Initialize counts from other dictionary, or 0 if they aren't included.
Load pre-existing dictionary in 'token[<TAB>count]' format.
def load(self, filename): """ Load pre-existing dictionary in 'token[<TAB>count]' format. Initialize counts from other dictionary, or 0 if they aren't included. """ logging.info(f'loading dictionary from {filename}') lower_special = self.null_token == self.null_token.lo...
[ "def", "load", "(", "self", ",", "filename", ")", ":", "logging", ".", "info", "(", "f'loading dictionary from {filename}'", ")", "lower_special", "=", "self", ".", "null_token", "==", "self", ".", "null_token", ".", "lower", "(", ")", "SPECIAL_TOKENS", "=", ...
[ 618, 4 ]
[ 637, 48 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.save
(self, filename=None, append=False, sort=True)
Save dictionary to file. Format is 'token<TAB>count' for every token in the dictionary, sorted by count with the most frequent words first. If ``append`` (default ``False``) is set to ``True``, appends instead of overwriting. If ``sort`` (default ``True``), then first...
Save dictionary to file.
def save(self, filename=None, append=False, sort=True): """ Save dictionary to file. Format is 'token<TAB>count' for every token in the dictionary, sorted by count with the most frequent words first. If ``append`` (default ``False``) is set to ``True``, appends instead of ...
[ "def", "save", "(", "self", ",", "filename", "=", "None", ",", "append", "=", "False", ",", "sort", "=", "True", ")", ":", "filename", "=", "self", ".", "opt", "[", "'dict_file'", "]", "if", "filename", "is", "None", "else", "filename", "make_dir", "...
[ 639, 4 ]
[ 684, 80 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.sort
(self, trim=True)
Sort the dictionary. Inline operation. Rearranges the dictionary so that the elements with the lowest index have the highest counts. This reindexes the dictionary according to the sorted frequencies, breaking ties alphabetically by token. :param bool trim: ...
Sort the dictionary.
def sort(self, trim=True): """ Sort the dictionary. Inline operation. Rearranges the dictionary so that the elements with the lowest index have the highest counts. This reindexes the dictionary according to the sorted frequencies, breaking ties alphabetically by token. ...
[ "def", "sort", "(", "self", ",", "trim", "=", "True", ")", ":", "if", "trim", "and", "self", ".", "tokenizer", "==", "'gpt2'", ":", "raise", "RuntimeError", "(", "\"You should not trim the dictionary when using gpt-2.\"", ")", "if", "trim", "and", "self", ".",...
[ 686, 4 ]
[ 718, 27 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.parse
(self, txt_or_vec, vec_type=list)
Parse either text or a vector of indices. Calls `~txt2vec` if `txt_or_vec is a string, or `~vec2txt` otherwise. :param vec_type: type of the returned vector if the input is a string.
Parse either text or a vector of indices.
def parse(self, txt_or_vec, vec_type=list): """ Parse either text or a vector of indices. Calls `~txt2vec` if `txt_or_vec is a string, or `~vec2txt` otherwise. :param vec_type: type of the returned vector if the input is a string. """ # TODO: try to deprecat...
[ "def", "parse", "(", "self", ",", "txt_or_vec", ",", "vec_type", "=", "list", ")", ":", "# TODO: try to deprecate this, preferring straight txt2vec", "if", "type", "(", "txt_or_vec", ")", "==", "str", ":", "return", "self", ".", "txt2vec", "(", "txt_or_vec", ","...
[ 720, 4 ]
[ 733, 43 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.txt2vec
(self, text, vec_type=list)
Convert a string to a vector (list of ints). First runs a sentence tokenizer, then a word tokenizer. :param type vec_type: The type of the returned vector if the input is a string. Suggested ``list``, ``tuple``, ``set``, or ``np.ndarray``.
Convert a string to a vector (list of ints).
def txt2vec(self, text, vec_type=list): """ Convert a string to a vector (list of ints). First runs a sentence tokenizer, then a word tokenizer. :param type vec_type: The type of the returned vector if the input is a string. Suggested ``list``, ``tuple``, ``set`...
[ "def", "txt2vec", "(", "self", ",", "text", ",", "vec_type", "=", "list", ")", ":", "itr", "=", "(", "self", ".", "_word_lookup", "(", "token", ")", "for", "token", "in", "self", ".", "tokenize", "(", "str", "(", "text", ")", ")", ")", "if", "vec...
[ 735, 4 ]
[ 752, 18 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.vec2txt
(self, vector, delimiter=' ')
Convert a vector of IDs to a string. Converts a vector (iterable of ints) into a string, with each token separated by the delimiter (default ``' '``).
Convert a vector of IDs to a string.
def vec2txt(self, vector, delimiter=' '): """ Convert a vector of IDs to a string. Converts a vector (iterable of ints) into a string, with each token separated by the delimiter (default ``' '``). """ tokens = [self[int(idx)] for idx in vector] if self.tokenizer ...
[ "def", "vec2txt", "(", "self", ",", "vector", ",", "delimiter", "=", "' '", ")", ":", "tokens", "=", "[", "self", "[", "int", "(", "idx", ")", "]", "for", "idx", "in", "vector", "]", "if", "self", ".", "tokenizer", "in", "[", "'gpt2'", ",", "'bpe...
[ 754, 4 ]
[ 780, 19 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.act
(self)
Add words in the last observation to the dictionary. This checks any fields in the message present in the --dict-textfields argument (e.g. "text,labels").
Add words in the last observation to the dictionary.
def act(self): """ Add words in the last observation to the dictionary. This checks any fields in the message present in the --dict-textfields argument (e.g. "text,labels"). """ for textfield in self.textfields: source = self.observation.get(textfield) ...
[ "def", "act", "(", "self", ")", ":", "for", "textfield", "in", "self", ".", "textfields", ":", "source", "=", "self", ".", "observation", ".", "get", "(", "textfield", ")", "if", "source", "is", "None", ":", "continue", "# fields may be singleton strings or ...
[ 782, 4 ]
[ 800, 35 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.share
(self)
Share internal dicts.
Share internal dicts.
def share(self): """ Share internal dicts. """ shared = super().share() shared['freq'] = self.freq shared['tok2ind'] = self.tok2ind shared['ind2tok'] = self.ind2tok return shared
[ "def", "share", "(", "self", ")", ":", "shared", "=", "super", "(", ")", ".", "share", "(", ")", "shared", "[", "'freq'", "]", "=", "self", ".", "freq", "shared", "[", "'tok2ind'", "]", "=", "self", ".", "tok2ind", "shared", "[", "'ind2tok'", "]", ...
[ 802, 4 ]
[ 810, 21 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.shutdown
(self)
Save on shutdown if ``save_path`` is set.
Save on shutdown if ``save_path`` is set.
def shutdown(self): """ Save on shutdown if ``save_path`` is set. """ if hasattr(self, 'save_path'): self.save(self.save_path)
[ "def", "shutdown", "(", "self", ")", ":", "if", "hasattr", "(", "self", ",", "'save_path'", ")", ":", "self", ".", "save", "(", "self", ".", "save_path", ")" ]
[ 812, 4 ]
[ 817, 37 ]
python
en
['en', 'error', 'th']
False
DictionaryAgent.__str__
(self)
Return string representation of frequencies in dictionary.
Return string representation of frequencies in dictionary.
def __str__(self): """ Return string representation of frequencies in dictionary. """ return str(self.freq)
[ "def", "__str__", "(", "self", ")", ":", "return", "str", "(", "self", ".", "freq", ")" ]
[ 819, 4 ]
[ 823, 29 ]
python
en
['en', 'error', 'th']
False