id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
21,200 | explosion/spaCy | examples/pipeline/custom_attr_methods.py | overlap_tokens | def overlap_tokens(doc, other_doc):
"""Get the tokens from the original Doc that are also in the comparison Doc.
"""
overlap = []
other_tokens = [token.text for token in other_doc]
for token in doc:
if token.text in other_tokens:
overlap.append(token)
return overlap | python | def overlap_tokens(doc, other_doc):
"""Get the tokens from the original Doc that are also in the comparison Doc.
"""
overlap = []
other_tokens = [token.text for token in other_doc]
for token in doc:
if token.text in other_tokens:
overlap.append(token)
return overlap | [
"def",
"overlap_tokens",
"(",
"doc",
",",
"other_doc",
")",
":",
"overlap",
"=",
"[",
"]",
"other_tokens",
"=",
"[",
"token",
".",
"text",
"for",
"token",
"in",
"other_doc",
"]",
"for",
"token",
"in",
"doc",
":",
"if",
"token",
".",
"text",
"in",
"ot... | Get the tokens from the original Doc that are also in the comparison Doc. | [
"Get",
"the",
"tokens",
"from",
"the",
"original",
"Doc",
"that",
"are",
"also",
"in",
"the",
"comparison",
"Doc",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/examples/pipeline/custom_attr_methods.py#L61-L69 |
21,201 | explosion/spaCy | spacy/cli/converters/iob2json.py | iob2json | def iob2json(input_data, n_sents=10, *args, **kwargs):
"""
Convert IOB files into JSON format for use with train cli.
"""
docs = []
for group in minibatch(docs, n_sents):
group = list(group)
first = group.pop(0)
to_extend = first["paragraphs"][0]["sentences"]
for sent... | python | def iob2json(input_data, n_sents=10, *args, **kwargs):
"""
Convert IOB files into JSON format for use with train cli.
"""
docs = []
for group in minibatch(docs, n_sents):
group = list(group)
first = group.pop(0)
to_extend = first["paragraphs"][0]["sentences"]
for sent... | [
"def",
"iob2json",
"(",
"input_data",
",",
"n_sents",
"=",
"10",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"docs",
"=",
"[",
"]",
"for",
"group",
"in",
"minibatch",
"(",
"docs",
",",
"n_sents",
")",
":",
"group",
"=",
"list",
"(",
"gro... | Convert IOB files into JSON format for use with train cli. | [
"Convert",
"IOB",
"files",
"into",
"JSON",
"format",
"for",
"use",
"with",
"train",
"cli",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/cli/converters/iob2json.py#L10-L22 |
21,202 | explosion/spaCy | spacy/displacy/__init__.py | render | def render(
docs, style="dep", page=False, minify=False, jupyter=None, options={}, manual=False
):
"""Render displaCy visualisation.
docs (list or Doc): Document(s) to visualise.
style (unicode): Visualisation style, 'dep' or 'ent'.
page (bool): Render markup as full HTML page.
minify (bool): M... | python | def render(
docs, style="dep", page=False, minify=False, jupyter=None, options={}, manual=False
):
"""Render displaCy visualisation.
docs (list or Doc): Document(s) to visualise.
style (unicode): Visualisation style, 'dep' or 'ent'.
page (bool): Render markup as full HTML page.
minify (bool): M... | [
"def",
"render",
"(",
"docs",
",",
"style",
"=",
"\"dep\"",
",",
"page",
"=",
"False",
",",
"minify",
"=",
"False",
",",
"jupyter",
"=",
"None",
",",
"options",
"=",
"{",
"}",
",",
"manual",
"=",
"False",
")",
":",
"factories",
"=",
"{",
"\"dep\"",... | Render displaCy visualisation.
docs (list or Doc): Document(s) to visualise.
style (unicode): Visualisation style, 'dep' or 'ent'.
page (bool): Render markup as full HTML page.
minify (bool): Minify HTML markup.
jupyter (bool): Override Jupyter auto-detection.
options (dict): Visualiser-specifi... | [
"Render",
"displaCy",
"visualisation",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/displacy/__init__.py#L21-L61 |
21,203 | explosion/spaCy | spacy/displacy/__init__.py | serve | def serve(
docs,
style="dep",
page=True,
minify=False,
options={},
manual=False,
port=5000,
host="0.0.0.0",
):
"""Serve displaCy visualisation.
docs (list or Doc): Document(s) to visualise.
style (unicode): Visualisation style, 'dep' or 'ent'.
page (bool): Render markup ... | python | def serve(
docs,
style="dep",
page=True,
minify=False,
options={},
manual=False,
port=5000,
host="0.0.0.0",
):
"""Serve displaCy visualisation.
docs (list or Doc): Document(s) to visualise.
style (unicode): Visualisation style, 'dep' or 'ent'.
page (bool): Render markup ... | [
"def",
"serve",
"(",
"docs",
",",
"style",
"=",
"\"dep\"",
",",
"page",
"=",
"True",
",",
"minify",
"=",
"False",
",",
"options",
"=",
"{",
"}",
",",
"manual",
"=",
"False",
",",
"port",
"=",
"5000",
",",
"host",
"=",
"\"0.0.0.0\"",
",",
")",
":"... | Serve displaCy visualisation.
docs (list or Doc): Document(s) to visualise.
style (unicode): Visualisation style, 'dep' or 'ent'.
page (bool): Render markup as full HTML page.
minify (bool): Minify HTML markup.
options (dict): Visualiser-specific options, e.g. colors.
manual (bool): Don't parse... | [
"Serve",
"displaCy",
"visualisation",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/displacy/__init__.py#L64-L102 |
21,204 | explosion/spaCy | spacy/displacy/__init__.py | set_render_wrapper | def set_render_wrapper(func):
"""Set an optional wrapper function that is called around the generated
HTML markup on displacy.render. This can be used to allow integration into
other platforms, similar to Jupyter Notebooks that require functions to be
called around the HTML. It can also be used to imple... | python | def set_render_wrapper(func):
"""Set an optional wrapper function that is called around the generated
HTML markup on displacy.render. This can be used to allow integration into
other platforms, similar to Jupyter Notebooks that require functions to be
called around the HTML. It can also be used to imple... | [
"def",
"set_render_wrapper",
"(",
"func",
")",
":",
"global",
"RENDER_WRAPPER",
"if",
"not",
"hasattr",
"(",
"func",
",",
"\"__call__\"",
")",
":",
"raise",
"ValueError",
"(",
"Errors",
".",
"E110",
".",
"format",
"(",
"obj",
"=",
"type",
"(",
"func",
")... | Set an optional wrapper function that is called around the generated
HTML markup on displacy.render. This can be used to allow integration into
other platforms, similar to Jupyter Notebooks that require functions to be
called around the HTML. It can also be used to implement custom callbacks
on render, ... | [
"Set",
"an",
"optional",
"wrapper",
"function",
"that",
"is",
"called",
"around",
"the",
"generated",
"HTML",
"markup",
"on",
"displacy",
".",
"render",
".",
"This",
"can",
"be",
"used",
"to",
"allow",
"integration",
"into",
"other",
"platforms",
"similar",
... | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/displacy/__init__.py#L185-L199 |
21,205 | explosion/spaCy | spacy/cli/evaluate.py | evaluate | def evaluate(
model,
data_path,
gpu_id=-1,
gold_preproc=False,
displacy_path=None,
displacy_limit=25,
return_scores=False,
):
"""
Evaluate a model. To render a sample of parses in a HTML file, set an
output directory as the displacy_path argument.
"""
msg = Printer()
... | python | def evaluate(
model,
data_path,
gpu_id=-1,
gold_preproc=False,
displacy_path=None,
displacy_limit=25,
return_scores=False,
):
"""
Evaluate a model. To render a sample of parses in a HTML file, set an
output directory as the displacy_path argument.
"""
msg = Printer()
... | [
"def",
"evaluate",
"(",
"model",
",",
"data_path",
",",
"gpu_id",
"=",
"-",
"1",
",",
"gold_preproc",
"=",
"False",
",",
"displacy_path",
"=",
"None",
",",
"displacy_limit",
"=",
"25",
",",
"return_scores",
"=",
"False",
",",
")",
":",
"msg",
"=",
"Pri... | Evaluate a model. To render a sample of parses in a HTML file, set an
output directory as the displacy_path argument. | [
"Evaluate",
"a",
"model",
".",
"To",
"render",
"a",
"sample",
"of",
"parses",
"in",
"a",
"HTML",
"file",
"set",
"an",
"output",
"directory",
"as",
"the",
"displacy_path",
"argument",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/cli/evaluate.py#L22-L81 |
21,206 | explosion/spaCy | spacy/cli/profile.py | profile | def profile(model, inputs=None, n_texts=10000):
"""
Profile a spaCy pipeline, to find out which functions take the most time.
Input should be formatted as one JSON object per line with a key "text".
It can either be provided as a JSONL file, or be read from sys.sytdin.
If no input file is specified,... | python | def profile(model, inputs=None, n_texts=10000):
"""
Profile a spaCy pipeline, to find out which functions take the most time.
Input should be formatted as one JSON object per line with a key "text".
It can either be provided as a JSONL file, or be read from sys.sytdin.
If no input file is specified,... | [
"def",
"profile",
"(",
"model",
",",
"inputs",
"=",
"None",
",",
"n_texts",
"=",
"10000",
")",
":",
"msg",
"=",
"Printer",
"(",
")",
"if",
"inputs",
"is",
"not",
"None",
":",
"inputs",
"=",
"_read_inputs",
"(",
"inputs",
",",
"msg",
")",
"if",
"inp... | Profile a spaCy pipeline, to find out which functions take the most time.
Input should be formatted as one JSON object per line with a key "text".
It can either be provided as a JSONL file, or be read from sys.sytdin.
If no input file is specified, the IMDB dataset is loaded via Thinc. | [
"Profile",
"a",
"spaCy",
"pipeline",
"to",
"find",
"out",
"which",
"functions",
"take",
"the",
"most",
"time",
".",
"Input",
"should",
"be",
"formatted",
"as",
"one",
"JSON",
"object",
"per",
"line",
"with",
"a",
"key",
"text",
".",
"It",
"can",
"either"... | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/cli/profile.py#L23-L47 |
21,207 | explosion/spaCy | spacy/lang/ja/__init__.py | detailed_tokens | def detailed_tokens(tokenizer, text):
"""Format Mecab output into a nice data structure, based on Janome."""
node = tokenizer.parseToNode(text)
node = node.next # first node is beginning of sentence and empty, skip it
words = []
while node.posid != 0:
surface = node.surface
base = s... | python | def detailed_tokens(tokenizer, text):
"""Format Mecab output into a nice data structure, based on Janome."""
node = tokenizer.parseToNode(text)
node = node.next # first node is beginning of sentence and empty, skip it
words = []
while node.posid != 0:
surface = node.surface
base = s... | [
"def",
"detailed_tokens",
"(",
"tokenizer",
",",
"text",
")",
":",
"node",
"=",
"tokenizer",
".",
"parseToNode",
"(",
"text",
")",
"node",
"=",
"node",
".",
"next",
"# first node is beginning of sentence and empty, skip it",
"words",
"=",
"[",
"]",
"while",
"nod... | Format Mecab output into a nice data structure, based on Janome. | [
"Format",
"Mecab",
"output",
"into",
"a",
"nice",
"data",
"structure",
"based",
"on",
"Janome",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/lang/ja/__init__.py#L52-L68 |
21,208 | explosion/spaCy | spacy/compat.py | symlink_to | def symlink_to(orig, dest):
"""Create a symlink. Used for model shortcut links.
orig (unicode / Path): The origin path.
dest (unicode / Path): The destination path of the symlink.
"""
if is_windows:
import subprocess
subprocess.check_call(
["mklink", "/d", path2str(orig... | python | def symlink_to(orig, dest):
"""Create a symlink. Used for model shortcut links.
orig (unicode / Path): The origin path.
dest (unicode / Path): The destination path of the symlink.
"""
if is_windows:
import subprocess
subprocess.check_call(
["mklink", "/d", path2str(orig... | [
"def",
"symlink_to",
"(",
"orig",
",",
"dest",
")",
":",
"if",
"is_windows",
":",
"import",
"subprocess",
"subprocess",
".",
"check_call",
"(",
"[",
"\"mklink\"",
",",
"\"/d\"",
",",
"path2str",
"(",
"orig",
")",
",",
"path2str",
"(",
"dest",
")",
"]",
... | Create a symlink. Used for model shortcut links.
orig (unicode / Path): The origin path.
dest (unicode / Path): The destination path of the symlink. | [
"Create",
"a",
"symlink",
".",
"Used",
"for",
"model",
"shortcut",
"links",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/compat.py#L86-L99 |
21,209 | explosion/spaCy | spacy/compat.py | symlink_remove | def symlink_remove(link):
"""Remove a symlink. Used for model shortcut links.
link (unicode / Path): The path to the symlink.
"""
# https://stackoverflow.com/q/26554135/6400719
if os.path.isdir(path2str(link)) and is_windows:
# this should only be on Py2.7 and windows
os.rmdir(path2... | python | def symlink_remove(link):
"""Remove a symlink. Used for model shortcut links.
link (unicode / Path): The path to the symlink.
"""
# https://stackoverflow.com/q/26554135/6400719
if os.path.isdir(path2str(link)) and is_windows:
# this should only be on Py2.7 and windows
os.rmdir(path2... | [
"def",
"symlink_remove",
"(",
"link",
")",
":",
"# https://stackoverflow.com/q/26554135/6400719",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"path2str",
"(",
"link",
")",
")",
"and",
"is_windows",
":",
"# this should only be on Py2.7 and windows",
"os",
".",
"rmdir... | Remove a symlink. Used for model shortcut links.
link (unicode / Path): The path to the symlink. | [
"Remove",
"a",
"symlink",
".",
"Used",
"for",
"model",
"shortcut",
"links",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/compat.py#L102-L112 |
21,210 | explosion/spaCy | spacy/compat.py | is_config | def is_config(python2=None, python3=None, windows=None, linux=None, osx=None):
"""Check if a specific configuration of Python version and operating system
matches the user's setup. Mostly used to display targeted error messages.
python2 (bool): spaCy is executed with Python 2.x.
python3 (bool): spaCy i... | python | def is_config(python2=None, python3=None, windows=None, linux=None, osx=None):
"""Check if a specific configuration of Python version and operating system
matches the user's setup. Mostly used to display targeted error messages.
python2 (bool): spaCy is executed with Python 2.x.
python3 (bool): spaCy i... | [
"def",
"is_config",
"(",
"python2",
"=",
"None",
",",
"python3",
"=",
"None",
",",
"windows",
"=",
"None",
",",
"linux",
"=",
"None",
",",
"osx",
"=",
"None",
")",
":",
"return",
"(",
"python2",
"in",
"(",
"None",
",",
"is_python2",
")",
"and",
"py... | Check if a specific configuration of Python version and operating system
matches the user's setup. Mostly used to display targeted error messages.
python2 (bool): spaCy is executed with Python 2.x.
python3 (bool): spaCy is executed with Python 3.x.
windows (bool): spaCy is executed on Windows.
linu... | [
"Check",
"if",
"a",
"specific",
"configuration",
"of",
"Python",
"version",
"and",
"operating",
"system",
"matches",
"the",
"user",
"s",
"setup",
".",
"Mostly",
"used",
"to",
"display",
"targeted",
"error",
"messages",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/compat.py#L115-L134 |
21,211 | explosion/spaCy | spacy/compat.py | import_file | def import_file(name, loc):
"""Import module from a file. Used to load models from a directory.
name (unicode): Name of module to load.
loc (unicode / Path): Path to the file.
RETURNS: The loaded module.
"""
loc = path2str(loc)
if is_python_pre_3_5:
import imp
return imp.lo... | python | def import_file(name, loc):
"""Import module from a file. Used to load models from a directory.
name (unicode): Name of module to load.
loc (unicode / Path): Path to the file.
RETURNS: The loaded module.
"""
loc = path2str(loc)
if is_python_pre_3_5:
import imp
return imp.lo... | [
"def",
"import_file",
"(",
"name",
",",
"loc",
")",
":",
"loc",
"=",
"path2str",
"(",
"loc",
")",
"if",
"is_python_pre_3_5",
":",
"import",
"imp",
"return",
"imp",
".",
"load_source",
"(",
"name",
",",
"loc",
")",
"else",
":",
"import",
"importlib",
".... | Import module from a file. Used to load models from a directory.
name (unicode): Name of module to load.
loc (unicode / Path): Path to the file.
RETURNS: The loaded module. | [
"Import",
"module",
"from",
"a",
"file",
".",
"Used",
"to",
"load",
"models",
"from",
"a",
"directory",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/compat.py#L137-L155 |
21,212 | explosion/spaCy | spacy/util.py | get_lang_class | def get_lang_class(lang):
"""Import and load a Language class.
lang (unicode): Two-letter language code, e.g. 'en'.
RETURNS (Language): Language class.
"""
global LANGUAGES
# Check if an entry point is exposed for the language code
entry_point = get_entry_point("spacy_languages", lang)
... | python | def get_lang_class(lang):
"""Import and load a Language class.
lang (unicode): Two-letter language code, e.g. 'en'.
RETURNS (Language): Language class.
"""
global LANGUAGES
# Check if an entry point is exposed for the language code
entry_point = get_entry_point("spacy_languages", lang)
... | [
"def",
"get_lang_class",
"(",
"lang",
")",
":",
"global",
"LANGUAGES",
"# Check if an entry point is exposed for the language code",
"entry_point",
"=",
"get_entry_point",
"(",
"\"spacy_languages\"",
",",
"lang",
")",
"if",
"entry_point",
"is",
"not",
"None",
":",
"LANG... | Import and load a Language class.
lang (unicode): Two-letter language code, e.g. 'en'.
RETURNS (Language): Language class. | [
"Import",
"and",
"load",
"a",
"Language",
"class",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/util.py#L53-L71 |
21,213 | explosion/spaCy | spacy/util.py | load_model | def load_model(name, **overrides):
"""Load a model from a shortcut link, package or data path.
name (unicode): Package name, shortcut link or model path.
**overrides: Specific overrides, like pipeline components to disable.
RETURNS (Language): `Language` class with the loaded model.
"""
data_pa... | python | def load_model(name, **overrides):
"""Load a model from a shortcut link, package or data path.
name (unicode): Package name, shortcut link or model path.
**overrides: Specific overrides, like pipeline components to disable.
RETURNS (Language): `Language` class with the loaded model.
"""
data_pa... | [
"def",
"load_model",
"(",
"name",
",",
"*",
"*",
"overrides",
")",
":",
"data_path",
"=",
"get_data_path",
"(",
")",
"if",
"not",
"data_path",
"or",
"not",
"data_path",
".",
"exists",
"(",
")",
":",
"raise",
"IOError",
"(",
"Errors",
".",
"E049",
".",
... | Load a model from a shortcut link, package or data path.
name (unicode): Package name, shortcut link or model path.
**overrides: Specific overrides, like pipeline components to disable.
RETURNS (Language): `Language` class with the loaded model. | [
"Load",
"a",
"model",
"from",
"a",
"shortcut",
"link",
"package",
"or",
"data",
"path",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/util.py#L117-L136 |
21,214 | explosion/spaCy | spacy/util.py | load_model_from_link | def load_model_from_link(name, **overrides):
"""Load a model from a shortcut link, or directory in spaCy data path."""
path = get_data_path() / name / "__init__.py"
try:
cls = import_file(name, path)
except AttributeError:
raise IOError(Errors.E051.format(name=name))
return cls.load(... | python | def load_model_from_link(name, **overrides):
"""Load a model from a shortcut link, or directory in spaCy data path."""
path = get_data_path() / name / "__init__.py"
try:
cls = import_file(name, path)
except AttributeError:
raise IOError(Errors.E051.format(name=name))
return cls.load(... | [
"def",
"load_model_from_link",
"(",
"name",
",",
"*",
"*",
"overrides",
")",
":",
"path",
"=",
"get_data_path",
"(",
")",
"/",
"name",
"/",
"\"__init__.py\"",
"try",
":",
"cls",
"=",
"import_file",
"(",
"name",
",",
"path",
")",
"except",
"AttributeError",... | Load a model from a shortcut link, or directory in spaCy data path. | [
"Load",
"a",
"model",
"from",
"a",
"shortcut",
"link",
"or",
"directory",
"in",
"spaCy",
"data",
"path",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/util.py#L139-L146 |
21,215 | explosion/spaCy | spacy/util.py | load_model_from_package | def load_model_from_package(name, **overrides):
"""Load a model from an installed package."""
cls = importlib.import_module(name)
return cls.load(**overrides) | python | def load_model_from_package(name, **overrides):
"""Load a model from an installed package."""
cls = importlib.import_module(name)
return cls.load(**overrides) | [
"def",
"load_model_from_package",
"(",
"name",
",",
"*",
"*",
"overrides",
")",
":",
"cls",
"=",
"importlib",
".",
"import_module",
"(",
"name",
")",
"return",
"cls",
".",
"load",
"(",
"*",
"*",
"overrides",
")"
] | Load a model from an installed package. | [
"Load",
"a",
"model",
"from",
"an",
"installed",
"package",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/util.py#L149-L152 |
21,216 | explosion/spaCy | spacy/util.py | get_model_meta | def get_model_meta(path):
"""Get model meta.json from a directory path and validate its contents.
path (unicode or Path): Path to model directory.
RETURNS (dict): The model's meta data.
"""
model_path = ensure_path(path)
if not model_path.exists():
raise IOError(Errors.E052.format(path=... | python | def get_model_meta(path):
"""Get model meta.json from a directory path and validate its contents.
path (unicode or Path): Path to model directory.
RETURNS (dict): The model's meta data.
"""
model_path = ensure_path(path)
if not model_path.exists():
raise IOError(Errors.E052.format(path=... | [
"def",
"get_model_meta",
"(",
"path",
")",
":",
"model_path",
"=",
"ensure_path",
"(",
"path",
")",
"if",
"not",
"model_path",
".",
"exists",
"(",
")",
":",
"raise",
"IOError",
"(",
"Errors",
".",
"E052",
".",
"format",
"(",
"path",
"=",
"path2str",
"(... | Get model meta.json from a directory path and validate its contents.
path (unicode or Path): Path to model directory.
RETURNS (dict): The model's meta data. | [
"Get",
"model",
"meta",
".",
"json",
"from",
"a",
"directory",
"path",
"and",
"validate",
"its",
"contents",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/util.py#L193-L209 |
21,217 | explosion/spaCy | spacy/util.py | get_package_path | def get_package_path(name):
"""Get the path to an installed package.
name (unicode): Package name.
RETURNS (Path): Path to installed package.
"""
name = name.lower() # use lowercase version to be safe
# Here we're importing the module just to find it. This is worryingly
# indirect, but it'... | python | def get_package_path(name):
"""Get the path to an installed package.
name (unicode): Package name.
RETURNS (Path): Path to installed package.
"""
name = name.lower() # use lowercase version to be safe
# Here we're importing the module just to find it. This is worryingly
# indirect, but it'... | [
"def",
"get_package_path",
"(",
"name",
")",
":",
"name",
"=",
"name",
".",
"lower",
"(",
")",
"# use lowercase version to be safe",
"# Here we're importing the module just to find it. This is worryingly",
"# indirect, but it's otherwise very difficult to find the package.",
"pkg",
... | Get the path to an installed package.
name (unicode): Package name.
RETURNS (Path): Path to installed package. | [
"Get",
"the",
"path",
"to",
"an",
"installed",
"package",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/util.py#L226-L236 |
21,218 | explosion/spaCy | spacy/util.py | get_entry_point | def get_entry_point(key, value):
"""Check if registered entry point is available for a given name and
load it. Otherwise, return None.
key (unicode): Entry point name.
value (unicode): Name of entry point to load.
RETURNS: The loaded entry point or None.
"""
for entry_point in pkg_resources... | python | def get_entry_point(key, value):
"""Check if registered entry point is available for a given name and
load it. Otherwise, return None.
key (unicode): Entry point name.
value (unicode): Name of entry point to load.
RETURNS: The loaded entry point or None.
"""
for entry_point in pkg_resources... | [
"def",
"get_entry_point",
"(",
"key",
",",
"value",
")",
":",
"for",
"entry_point",
"in",
"pkg_resources",
".",
"iter_entry_points",
"(",
"key",
")",
":",
"if",
"entry_point",
".",
"name",
"==",
"value",
":",
"return",
"entry_point",
".",
"load",
"(",
")"
... | Check if registered entry point is available for a given name and
load it. Otherwise, return None.
key (unicode): Entry point name.
value (unicode): Name of entry point to load.
RETURNS: The loaded entry point or None. | [
"Check",
"if",
"registered",
"entry",
"point",
"is",
"available",
"for",
"a",
"given",
"name",
"and",
"load",
"it",
".",
"Otherwise",
"return",
"None",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/util.py#L252-L262 |
21,219 | explosion/spaCy | spacy/util.py | compile_suffix_regex | def compile_suffix_regex(entries):
"""Compile a sequence of suffix rules into a regex object.
entries (tuple): The suffix rules, e.g. spacy.lang.punctuation.TOKENIZER_SUFFIXES.
RETURNS (regex object): The regex object. to be used for Tokenizer.suffix_search.
"""
expression = "|".join([piece + "$" f... | python | def compile_suffix_regex(entries):
"""Compile a sequence of suffix rules into a regex object.
entries (tuple): The suffix rules, e.g. spacy.lang.punctuation.TOKENIZER_SUFFIXES.
RETURNS (regex object): The regex object. to be used for Tokenizer.suffix_search.
"""
expression = "|".join([piece + "$" f... | [
"def",
"compile_suffix_regex",
"(",
"entries",
")",
":",
"expression",
"=",
"\"|\"",
".",
"join",
"(",
"[",
"piece",
"+",
"\"$\"",
"for",
"piece",
"in",
"entries",
"if",
"piece",
".",
"strip",
"(",
")",
"]",
")",
"return",
"re",
".",
"compile",
"(",
... | Compile a sequence of suffix rules into a regex object.
entries (tuple): The suffix rules, e.g. spacy.lang.punctuation.TOKENIZER_SUFFIXES.
RETURNS (regex object): The regex object. to be used for Tokenizer.suffix_search. | [
"Compile",
"a",
"sequence",
"of",
"suffix",
"rules",
"into",
"a",
"regex",
"object",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/util.py#L346-L353 |
21,220 | explosion/spaCy | spacy/util.py | compile_infix_regex | def compile_infix_regex(entries):
"""Compile a sequence of infix rules into a regex object.
entries (tuple): The infix rules, e.g. spacy.lang.punctuation.TOKENIZER_INFIXES.
RETURNS (regex object): The regex object. to be used for Tokenizer.infix_finditer.
"""
expression = "|".join([piece for piece ... | python | def compile_infix_regex(entries):
"""Compile a sequence of infix rules into a regex object.
entries (tuple): The infix rules, e.g. spacy.lang.punctuation.TOKENIZER_INFIXES.
RETURNS (regex object): The regex object. to be used for Tokenizer.infix_finditer.
"""
expression = "|".join([piece for piece ... | [
"def",
"compile_infix_regex",
"(",
"entries",
")",
":",
"expression",
"=",
"\"|\"",
".",
"join",
"(",
"[",
"piece",
"for",
"piece",
"in",
"entries",
"if",
"piece",
".",
"strip",
"(",
")",
"]",
")",
"return",
"re",
".",
"compile",
"(",
"expression",
")"... | Compile a sequence of infix rules into a regex object.
entries (tuple): The infix rules, e.g. spacy.lang.punctuation.TOKENIZER_INFIXES.
RETURNS (regex object): The regex object. to be used for Tokenizer.infix_finditer. | [
"Compile",
"a",
"sequence",
"of",
"infix",
"rules",
"into",
"a",
"regex",
"object",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/util.py#L356-L363 |
21,221 | explosion/spaCy | spacy/util.py | expand_exc | def expand_exc(excs, search, replace):
"""Find string in tokenizer exceptions, duplicate entry and replace string.
For example, to add additional versions with typographic apostrophes.
excs (dict): Tokenizer exceptions.
search (unicode): String to find and replace.
replace (unicode): Replacement.
... | python | def expand_exc(excs, search, replace):
"""Find string in tokenizer exceptions, duplicate entry and replace string.
For example, to add additional versions with typographic apostrophes.
excs (dict): Tokenizer exceptions.
search (unicode): String to find and replace.
replace (unicode): Replacement.
... | [
"def",
"expand_exc",
"(",
"excs",
",",
"search",
",",
"replace",
")",
":",
"def",
"_fix_token",
"(",
"token",
",",
"search",
",",
"replace",
")",
":",
"fixed",
"=",
"dict",
"(",
"token",
")",
"fixed",
"[",
"ORTH",
"]",
"=",
"fixed",
"[",
"ORTH",
"]... | Find string in tokenizer exceptions, duplicate entry and replace string.
For example, to add additional versions with typographic apostrophes.
excs (dict): Tokenizer exceptions.
search (unicode): String to find and replace.
replace (unicode): Replacement.
RETURNS (dict): Combined tokenizer exceptio... | [
"Find",
"string",
"in",
"tokenizer",
"exceptions",
"duplicate",
"entry",
"and",
"replace",
"string",
".",
"For",
"example",
"to",
"add",
"additional",
"versions",
"with",
"typographic",
"apostrophes",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/util.py#L406-L427 |
21,222 | explosion/spaCy | spacy/util.py | minibatch | def minibatch(items, size=8):
"""Iterate over batches of items. `size` may be an iterator,
so that batch-size can vary on each step.
"""
if isinstance(size, int):
size_ = itertools.repeat(size)
else:
size_ = size
items = iter(items)
while True:
batch_size = next(size_... | python | def minibatch(items, size=8):
"""Iterate over batches of items. `size` may be an iterator,
so that batch-size can vary on each step.
"""
if isinstance(size, int):
size_ = itertools.repeat(size)
else:
size_ = size
items = iter(items)
while True:
batch_size = next(size_... | [
"def",
"minibatch",
"(",
"items",
",",
"size",
"=",
"8",
")",
":",
"if",
"isinstance",
"(",
"size",
",",
"int",
")",
":",
"size_",
"=",
"itertools",
".",
"repeat",
"(",
"size",
")",
"else",
":",
"size_",
"=",
"size",
"items",
"=",
"iter",
"(",
"i... | Iterate over batches of items. `size` may be an iterator,
so that batch-size can vary on each step. | [
"Iterate",
"over",
"batches",
"of",
"items",
".",
"size",
"may",
"be",
"an",
"iterator",
"so",
"that",
"batch",
"-",
"size",
"can",
"vary",
"on",
"each",
"step",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/util.py#L446-L460 |
21,223 | explosion/spaCy | spacy/util.py | minibatch_by_words | def minibatch_by_words(items, size, tuples=True, count_words=len):
"""Create minibatches of a given number of words."""
if isinstance(size, int):
size_ = itertools.repeat(size)
else:
size_ = size
items = iter(items)
while True:
batch_size = next(size_)
batch = []
... | python | def minibatch_by_words(items, size, tuples=True, count_words=len):
"""Create minibatches of a given number of words."""
if isinstance(size, int):
size_ = itertools.repeat(size)
else:
size_ = size
items = iter(items)
while True:
batch_size = next(size_)
batch = []
... | [
"def",
"minibatch_by_words",
"(",
"items",
",",
"size",
",",
"tuples",
"=",
"True",
",",
"count_words",
"=",
"len",
")",
":",
"if",
"isinstance",
"(",
"size",
",",
"int",
")",
":",
"size_",
"=",
"itertools",
".",
"repeat",
"(",
"size",
")",
"else",
"... | Create minibatches of a given number of words. | [
"Create",
"minibatches",
"of",
"a",
"given",
"number",
"of",
"words",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/util.py#L516-L542 |
21,224 | explosion/spaCy | spacy/pipeline/entityruler.py | EntityRuler.labels | def labels(self):
"""All labels present in the match patterns.
RETURNS (set): The string labels.
DOCS: https://spacy.io/api/entityruler#labels
"""
all_labels = set(self.token_patterns.keys())
all_labels.update(self.phrase_patterns.keys())
return tuple(all_labels... | python | def labels(self):
"""All labels present in the match patterns.
RETURNS (set): The string labels.
DOCS: https://spacy.io/api/entityruler#labels
"""
all_labels = set(self.token_patterns.keys())
all_labels.update(self.phrase_patterns.keys())
return tuple(all_labels... | [
"def",
"labels",
"(",
"self",
")",
":",
"all_labels",
"=",
"set",
"(",
"self",
".",
"token_patterns",
".",
"keys",
"(",
")",
")",
"all_labels",
".",
"update",
"(",
"self",
".",
"phrase_patterns",
".",
"keys",
"(",
")",
")",
"return",
"tuple",
"(",
"a... | All labels present in the match patterns.
RETURNS (set): The string labels.
DOCS: https://spacy.io/api/entityruler#labels | [
"All",
"labels",
"present",
"in",
"the",
"match",
"patterns",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/pipeline/entityruler.py#L96-L105 |
21,225 | explosion/spaCy | spacy/pipeline/entityruler.py | EntityRuler.patterns | def patterns(self):
"""Get all patterns that were added to the entity ruler.
RETURNS (list): The original patterns, one dictionary per pattern.
DOCS: https://spacy.io/api/entityruler#patterns
"""
all_patterns = []
for label, patterns in self.token_patterns.items():
... | python | def patterns(self):
"""Get all patterns that were added to the entity ruler.
RETURNS (list): The original patterns, one dictionary per pattern.
DOCS: https://spacy.io/api/entityruler#patterns
"""
all_patterns = []
for label, patterns in self.token_patterns.items():
... | [
"def",
"patterns",
"(",
"self",
")",
":",
"all_patterns",
"=",
"[",
"]",
"for",
"label",
",",
"patterns",
"in",
"self",
".",
"token_patterns",
".",
"items",
"(",
")",
":",
"for",
"pattern",
"in",
"patterns",
":",
"all_patterns",
".",
"append",
"(",
"{"... | Get all patterns that were added to the entity ruler.
RETURNS (list): The original patterns, one dictionary per pattern.
DOCS: https://spacy.io/api/entityruler#patterns | [
"Get",
"all",
"patterns",
"that",
"were",
"added",
"to",
"the",
"entity",
"ruler",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/pipeline/entityruler.py#L108-L122 |
21,226 | explosion/spaCy | spacy/pipeline/entityruler.py | EntityRuler.from_bytes | def from_bytes(self, patterns_bytes, **kwargs):
"""Load the entity ruler from a bytestring.
patterns_bytes (bytes): The bytestring to load.
**kwargs: Other config paramters, mostly for consistency.
RETURNS (EntityRuler): The loaded entity ruler.
DOCS: https://spacy.io/api/entit... | python | def from_bytes(self, patterns_bytes, **kwargs):
"""Load the entity ruler from a bytestring.
patterns_bytes (bytes): The bytestring to load.
**kwargs: Other config paramters, mostly for consistency.
RETURNS (EntityRuler): The loaded entity ruler.
DOCS: https://spacy.io/api/entit... | [
"def",
"from_bytes",
"(",
"self",
",",
"patterns_bytes",
",",
"*",
"*",
"kwargs",
")",
":",
"patterns",
"=",
"srsly",
".",
"msgpack_loads",
"(",
"patterns_bytes",
")",
"self",
".",
"add_patterns",
"(",
"patterns",
")",
"return",
"self"
] | Load the entity ruler from a bytestring.
patterns_bytes (bytes): The bytestring to load.
**kwargs: Other config paramters, mostly for consistency.
RETURNS (EntityRuler): The loaded entity ruler.
DOCS: https://spacy.io/api/entityruler#from_bytes | [
"Load",
"the",
"entity",
"ruler",
"from",
"a",
"bytestring",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/pipeline/entityruler.py#L148-L159 |
21,227 | explosion/spaCy | bin/ud/ud_train.py | golds_to_gold_tuples | def golds_to_gold_tuples(docs, golds):
"""Get out the annoying 'tuples' format used by begin_training, given the
GoldParse objects."""
tuples = []
for doc, gold in zip(docs, golds):
text = doc.text
ids, words, tags, heads, labels, iob = zip(*gold.orig_annot)
sents = [((ids, words... | python | def golds_to_gold_tuples(docs, golds):
"""Get out the annoying 'tuples' format used by begin_training, given the
GoldParse objects."""
tuples = []
for doc, gold in zip(docs, golds):
text = doc.text
ids, words, tags, heads, labels, iob = zip(*gold.orig_annot)
sents = [((ids, words... | [
"def",
"golds_to_gold_tuples",
"(",
"docs",
",",
"golds",
")",
":",
"tuples",
"=",
"[",
"]",
"for",
"doc",
",",
"gold",
"in",
"zip",
"(",
"docs",
",",
"golds",
")",
":",
"text",
"=",
"doc",
".",
"text",
"ids",
",",
"words",
",",
"tags",
",",
"hea... | Get out the annoying 'tuples' format used by begin_training, given the
GoldParse objects. | [
"Get",
"out",
"the",
"annoying",
"tuples",
"format",
"used",
"by",
"begin_training",
"given",
"the",
"GoldParse",
"objects",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/bin/ud/ud_train.py#L173-L182 |
21,228 | explosion/spaCy | spacy/tokens/_serialize.py | merge_bytes | def merge_bytes(binder_strings):
"""Concatenate multiple serialized binders into one byte string."""
output = None
for byte_string in binder_strings:
binder = Binder().from_bytes(byte_string)
if output is None:
output = binder
else:
output.merge(binder)
re... | python | def merge_bytes(binder_strings):
"""Concatenate multiple serialized binders into one byte string."""
output = None
for byte_string in binder_strings:
binder = Binder().from_bytes(byte_string)
if output is None:
output = binder
else:
output.merge(binder)
re... | [
"def",
"merge_bytes",
"(",
"binder_strings",
")",
":",
"output",
"=",
"None",
"for",
"byte_string",
"in",
"binder_strings",
":",
"binder",
"=",
"Binder",
"(",
")",
".",
"from_bytes",
"(",
"byte_string",
")",
"if",
"output",
"is",
"None",
":",
"output",
"="... | Concatenate multiple serialized binders into one byte string. | [
"Concatenate",
"multiple",
"serialized",
"binders",
"into",
"one",
"byte",
"string",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/tokens/_serialize.py#L97-L106 |
21,229 | explosion/spaCy | spacy/tokens/_serialize.py | Binder.add | def add(self, doc):
"""Add a doc's annotations to the binder for serialization."""
array = doc.to_array(self.attrs)
if len(array.shape) == 1:
array = array.reshape((array.shape[0], 1))
self.tokens.append(array)
spaces = doc.to_array(SPACY)
assert array.shape[0... | python | def add(self, doc):
"""Add a doc's annotations to the binder for serialization."""
array = doc.to_array(self.attrs)
if len(array.shape) == 1:
array = array.reshape((array.shape[0], 1))
self.tokens.append(array)
spaces = doc.to_array(SPACY)
assert array.shape[0... | [
"def",
"add",
"(",
"self",
",",
"doc",
")",
":",
"array",
"=",
"doc",
".",
"to_array",
"(",
"self",
".",
"attrs",
")",
"if",
"len",
"(",
"array",
".",
"shape",
")",
"==",
"1",
":",
"array",
"=",
"array",
".",
"reshape",
"(",
"(",
"array",
".",
... | Add a doc's annotations to the binder for serialization. | [
"Add",
"a",
"doc",
"s",
"annotations",
"to",
"the",
"binder",
"for",
"serialization",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/tokens/_serialize.py#L35-L45 |
21,230 | explosion/spaCy | spacy/tokens/_serialize.py | Binder.get_docs | def get_docs(self, vocab):
"""Recover Doc objects from the annotations, using the given vocab."""
for string in self.strings:
vocab[string]
orth_col = self.attrs.index(ORTH)
for tokens, spaces in zip(self.tokens, self.spaces):
words = [vocab.strings[orth] for orth... | python | def get_docs(self, vocab):
"""Recover Doc objects from the annotations, using the given vocab."""
for string in self.strings:
vocab[string]
orth_col = self.attrs.index(ORTH)
for tokens, spaces in zip(self.tokens, self.spaces):
words = [vocab.strings[orth] for orth... | [
"def",
"get_docs",
"(",
"self",
",",
"vocab",
")",
":",
"for",
"string",
"in",
"self",
".",
"strings",
":",
"vocab",
"[",
"string",
"]",
"orth_col",
"=",
"self",
".",
"attrs",
".",
"index",
"(",
"ORTH",
")",
"for",
"tokens",
",",
"spaces",
"in",
"z... | Recover Doc objects from the annotations, using the given vocab. | [
"Recover",
"Doc",
"objects",
"from",
"the",
"annotations",
"using",
"the",
"given",
"vocab",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/tokens/_serialize.py#L47-L56 |
21,231 | explosion/spaCy | spacy/tokens/_serialize.py | Binder.merge | def merge(self, other):
"""Extend the annotations of this binder with the annotations from another."""
assert self.attrs == other.attrs
self.tokens.extend(other.tokens)
self.spaces.extend(other.spaces)
self.strings.update(other.strings) | python | def merge(self, other):
"""Extend the annotations of this binder with the annotations from another."""
assert self.attrs == other.attrs
self.tokens.extend(other.tokens)
self.spaces.extend(other.spaces)
self.strings.update(other.strings) | [
"def",
"merge",
"(",
"self",
",",
"other",
")",
":",
"assert",
"self",
".",
"attrs",
"==",
"other",
".",
"attrs",
"self",
".",
"tokens",
".",
"extend",
"(",
"other",
".",
"tokens",
")",
"self",
".",
"spaces",
".",
"extend",
"(",
"other",
".",
"spac... | Extend the annotations of this binder with the annotations from another. | [
"Extend",
"the",
"annotations",
"of",
"this",
"binder",
"with",
"the",
"annotations",
"from",
"another",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/tokens/_serialize.py#L58-L63 |
21,232 | explosion/spaCy | spacy/tokens/_serialize.py | Binder.to_bytes | def to_bytes(self):
"""Serialize the binder's annotations into a byte string."""
for tokens in self.tokens:
assert len(tokens.shape) == 2, tokens.shape
lengths = [len(tokens) for tokens in self.tokens]
msg = {
"attrs": self.attrs,
"tokens": numpy.vstac... | python | def to_bytes(self):
"""Serialize the binder's annotations into a byte string."""
for tokens in self.tokens:
assert len(tokens.shape) == 2, tokens.shape
lengths = [len(tokens) for tokens in self.tokens]
msg = {
"attrs": self.attrs,
"tokens": numpy.vstac... | [
"def",
"to_bytes",
"(",
"self",
")",
":",
"for",
"tokens",
"in",
"self",
".",
"tokens",
":",
"assert",
"len",
"(",
"tokens",
".",
"shape",
")",
"==",
"2",
",",
"tokens",
".",
"shape",
"lengths",
"=",
"[",
"len",
"(",
"tokens",
")",
"for",
"tokens",... | Serialize the binder's annotations into a byte string. | [
"Serialize",
"the",
"binder",
"s",
"annotations",
"into",
"a",
"byte",
"string",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/tokens/_serialize.py#L65-L77 |
21,233 | explosion/spaCy | spacy/tokens/_serialize.py | Binder.from_bytes | def from_bytes(self, string):
"""Deserialize the binder's annotations from a byte string."""
msg = srsly.msgpack_loads(gzip.decompress(string))
self.attrs = msg["attrs"]
self.strings = set(msg["strings"])
lengths = numpy.fromstring(msg["lengths"], dtype="int32")
flat_spac... | python | def from_bytes(self, string):
"""Deserialize the binder's annotations from a byte string."""
msg = srsly.msgpack_loads(gzip.decompress(string))
self.attrs = msg["attrs"]
self.strings = set(msg["strings"])
lengths = numpy.fromstring(msg["lengths"], dtype="int32")
flat_spac... | [
"def",
"from_bytes",
"(",
"self",
",",
"string",
")",
":",
"msg",
"=",
"srsly",
".",
"msgpack_loads",
"(",
"gzip",
".",
"decompress",
"(",
"string",
")",
")",
"self",
".",
"attrs",
"=",
"msg",
"[",
"\"attrs\"",
"]",
"self",
".",
"strings",
"=",
"set"... | Deserialize the binder's annotations from a byte string. | [
"Deserialize",
"the",
"binder",
"s",
"annotations",
"from",
"a",
"byte",
"string",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/tokens/_serialize.py#L79-L94 |
21,234 | explosion/spaCy | spacy/lang/fr/lemmatizer/lemmatizer.py | FrenchLemmatizer.is_base_form | def is_base_form(self, univ_pos, morphology=None):
"""
Check whether we're dealing with an uninflected paradigm, so we can
avoid lemmatization entirely.
"""
morphology = {} if morphology is None else morphology
others = [key for key in morphology
if key ... | python | def is_base_form(self, univ_pos, morphology=None):
"""
Check whether we're dealing with an uninflected paradigm, so we can
avoid lemmatization entirely.
"""
morphology = {} if morphology is None else morphology
others = [key for key in morphology
if key ... | [
"def",
"is_base_form",
"(",
"self",
",",
"univ_pos",
",",
"morphology",
"=",
"None",
")",
":",
"morphology",
"=",
"{",
"}",
"if",
"morphology",
"is",
"None",
"else",
"morphology",
"others",
"=",
"[",
"key",
"for",
"key",
"in",
"morphology",
"if",
"key",
... | Check whether we're dealing with an uninflected paradigm, so we can
avoid lemmatization entirely. | [
"Check",
"whether",
"we",
"re",
"dealing",
"with",
"an",
"uninflected",
"paradigm",
"so",
"we",
"can",
"avoid",
"lemmatization",
"entirely",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/lang/fr/lemmatizer/lemmatizer.py#L63-L93 |
21,235 | explosion/spaCy | examples/training/train_new_entity_type.py | main | def main(model=None, new_model_name="animal", output_dir=None, n_iter=30):
"""Set up the pipeline and entity recognizer, and train the new entity."""
random.seed(0)
if model is not None:
nlp = spacy.load(model) # load existing spaCy model
print("Loaded model '%s'" % model)
else:
... | python | def main(model=None, new_model_name="animal", output_dir=None, n_iter=30):
"""Set up the pipeline and entity recognizer, and train the new entity."""
random.seed(0)
if model is not None:
nlp = spacy.load(model) # load existing spaCy model
print("Loaded model '%s'" % model)
else:
... | [
"def",
"main",
"(",
"model",
"=",
"None",
",",
"new_model_name",
"=",
"\"animal\"",
",",
"output_dir",
"=",
"None",
",",
"n_iter",
"=",
"30",
")",
":",
"random",
".",
"seed",
"(",
"0",
")",
"if",
"model",
"is",
"not",
"None",
":",
"nlp",
"=",
"spac... | Set up the pipeline and entity recognizer, and train the new entity. | [
"Set",
"up",
"the",
"pipeline",
"and",
"entity",
"recognizer",
"and",
"train",
"the",
"new",
"entity",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/examples/training/train_new_entity_type.py#L71-L134 |
21,236 | explosion/spaCy | spacy/cli/converters/conll_ner2json.py | conll_ner2json | def conll_ner2json(input_data, **kwargs):
"""
Convert files in the CoNLL-2003 NER format into JSON format for use with
train cli.
"""
delimit_docs = "-DOCSTART- -X- O O"
output_docs = []
for doc in input_data.strip().split(delimit_docs):
doc = doc.strip()
if not doc:
... | python | def conll_ner2json(input_data, **kwargs):
"""
Convert files in the CoNLL-2003 NER format into JSON format for use with
train cli.
"""
delimit_docs = "-DOCSTART- -X- O O"
output_docs = []
for doc in input_data.strip().split(delimit_docs):
doc = doc.strip()
if not doc:
... | [
"def",
"conll_ner2json",
"(",
"input_data",
",",
"*",
"*",
"kwargs",
")",
":",
"delimit_docs",
"=",
"\"-DOCSTART- -X- O O\"",
"output_docs",
"=",
"[",
"]",
"for",
"doc",
"in",
"input_data",
".",
"strip",
"(",
")",
".",
"split",
"(",
"delimit_docs",
")",
":... | Convert files in the CoNLL-2003 NER format into JSON format for use with
train cli. | [
"Convert",
"files",
"in",
"the",
"CoNLL",
"-",
"2003",
"NER",
"format",
"into",
"JSON",
"format",
"for",
"use",
"with",
"train",
"cli",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/cli/converters/conll_ner2json.py#L7-L38 |
21,237 | explosion/spaCy | examples/training/train_tagger.py | main | def main(lang="en", output_dir=None, n_iter=25):
"""Create a new model, set up the pipeline and train the tagger. In order to
train the tagger with a custom tag map, we're creating a new Language
instance with a custom vocab.
"""
nlp = spacy.blank(lang)
# add the tagger to the pipeline
# nlp... | python | def main(lang="en", output_dir=None, n_iter=25):
"""Create a new model, set up the pipeline and train the tagger. In order to
train the tagger with a custom tag map, we're creating a new Language
instance with a custom vocab.
"""
nlp = spacy.blank(lang)
# add the tagger to the pipeline
# nlp... | [
"def",
"main",
"(",
"lang",
"=",
"\"en\"",
",",
"output_dir",
"=",
"None",
",",
"n_iter",
"=",
"25",
")",
":",
"nlp",
"=",
"spacy",
".",
"blank",
"(",
"lang",
")",
"# add the tagger to the pipeline",
"# nlp.create_pipe works for built-ins that are registered with sp... | Create a new model, set up the pipeline and train the tagger. In order to
train the tagger with a custom tag map, we're creating a new Language
instance with a custom vocab. | [
"Create",
"a",
"new",
"model",
"set",
"up",
"the",
"pipeline",
"and",
"train",
"the",
"tagger",
".",
"In",
"order",
"to",
"train",
"the",
"tagger",
"with",
"a",
"custom",
"tag",
"map",
"we",
"re",
"creating",
"a",
"new",
"Language",
"instance",
"with",
... | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/examples/training/train_tagger.py#L47-L89 |
21,238 | explosion/spaCy | spacy/cli/init_model.py | init_model | def init_model(
lang,
output_dir,
freqs_loc=None,
clusters_loc=None,
jsonl_loc=None,
vectors_loc=None,
prune_vectors=-1,
):
"""
Create a new model from raw data, like word frequencies, Brown clusters
and word vectors. If vectors are provided in Word2Vec format, they can
be ei... | python | def init_model(
lang,
output_dir,
freqs_loc=None,
clusters_loc=None,
jsonl_loc=None,
vectors_loc=None,
prune_vectors=-1,
):
"""
Create a new model from raw data, like word frequencies, Brown clusters
and word vectors. If vectors are provided in Word2Vec format, they can
be ei... | [
"def",
"init_model",
"(",
"lang",
",",
"output_dir",
",",
"freqs_loc",
"=",
"None",
",",
"clusters_loc",
"=",
"None",
",",
"jsonl_loc",
"=",
"None",
",",
"vectors_loc",
"=",
"None",
",",
"prune_vectors",
"=",
"-",
"1",
",",
")",
":",
"if",
"jsonl_loc",
... | Create a new model from raw data, like word frequencies, Brown clusters
and word vectors. If vectors are provided in Word2Vec format, they can
be either a .txt or zipped as a .zip or .tar.gz. | [
"Create",
"a",
"new",
"model",
"from",
"raw",
"data",
"like",
"word",
"frequencies",
"Brown",
"clusters",
"and",
"word",
"vectors",
".",
"If",
"vectors",
"are",
"provided",
"in",
"Word2Vec",
"format",
"they",
"can",
"be",
"either",
"a",
".",
"txt",
"or",
... | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/cli/init_model.py#L39-L91 |
21,239 | explosion/spaCy | examples/training/train_ner.py | main | def main(model=None, output_dir=None, n_iter=100):
"""Load the model, set up the pipeline and train the entity recognizer."""
if model is not None:
nlp = spacy.load(model) # load existing spaCy model
print("Loaded model '%s'" % model)
else:
nlp = spacy.blank("en") # create blank La... | python | def main(model=None, output_dir=None, n_iter=100):
"""Load the model, set up the pipeline and train the entity recognizer."""
if model is not None:
nlp = spacy.load(model) # load existing spaCy model
print("Loaded model '%s'" % model)
else:
nlp = spacy.blank("en") # create blank La... | [
"def",
"main",
"(",
"model",
"=",
"None",
",",
"output_dir",
"=",
"None",
",",
"n_iter",
"=",
"100",
")",
":",
"if",
"model",
"is",
"not",
"None",
":",
"nlp",
"=",
"spacy",
".",
"load",
"(",
"model",
")",
"# load existing spaCy model",
"print",
"(",
... | Load the model, set up the pipeline and train the entity recognizer. | [
"Load",
"the",
"model",
"set",
"up",
"the",
"pipeline",
"and",
"train",
"the",
"entity",
"recognizer",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/examples/training/train_ner.py#L34-L99 |
21,240 | explosion/spaCy | spacy/cli/pretrain.py | make_update | def make_update(model, docs, optimizer, drop=0.0, objective="L2"):
"""Perform an update over a single batch of documents.
docs (iterable): A batch of `Doc` objects.
drop (float): The droput rate.
optimizer (callable): An optimizer.
RETURNS loss: A float for the loss.
"""
predictions, backpr... | python | def make_update(model, docs, optimizer, drop=0.0, objective="L2"):
"""Perform an update over a single batch of documents.
docs (iterable): A batch of `Doc` objects.
drop (float): The droput rate.
optimizer (callable): An optimizer.
RETURNS loss: A float for the loss.
"""
predictions, backpr... | [
"def",
"make_update",
"(",
"model",
",",
"docs",
",",
"optimizer",
",",
"drop",
"=",
"0.0",
",",
"objective",
"=",
"\"L2\"",
")",
":",
"predictions",
",",
"backprop",
"=",
"model",
".",
"begin_update",
"(",
"docs",
",",
"drop",
"=",
"drop",
")",
"loss"... | Perform an update over a single batch of documents.
docs (iterable): A batch of `Doc` objects.
drop (float): The droput rate.
optimizer (callable): An optimizer.
RETURNS loss: A float for the loss. | [
"Perform",
"an",
"update",
"over",
"a",
"single",
"batch",
"of",
"documents",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/cli/pretrain.py#L164-L178 |
21,241 | explosion/spaCy | spacy/cli/pretrain.py | get_vectors_loss | def get_vectors_loss(ops, docs, prediction, objective="L2"):
"""Compute a mean-squared error loss between the documents' vectors and
the prediction.
Note that this is ripe for customization! We could compute the vectors
in some other word, e.g. with an LSTM language model, or use some other
type of... | python | def get_vectors_loss(ops, docs, prediction, objective="L2"):
"""Compute a mean-squared error loss between the documents' vectors and
the prediction.
Note that this is ripe for customization! We could compute the vectors
in some other word, e.g. with an LSTM language model, or use some other
type of... | [
"def",
"get_vectors_loss",
"(",
"ops",
",",
"docs",
",",
"prediction",
",",
"objective",
"=",
"\"L2\"",
")",
":",
"# The simplest way to implement this would be to vstack the",
"# token.vector values, but that's a bit inefficient, especially on GPU.",
"# Instead we fetch the index in... | Compute a mean-squared error loss between the documents' vectors and
the prediction.
Note that this is ripe for customization! We could compute the vectors
in some other word, e.g. with an LSTM language model, or use some other
type of objective. | [
"Compute",
"a",
"mean",
"-",
"squared",
"error",
"loss",
"between",
"the",
"documents",
"vectors",
"and",
"the",
"prediction",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/cli/pretrain.py#L199-L218 |
21,242 | explosion/spaCy | spacy/cli/pretrain.py | _smart_round | def _smart_round(figure, width=10, max_decimal=4):
"""Round large numbers as integers, smaller numbers as decimals."""
n_digits = len(str(int(figure)))
n_decimal = width - (n_digits + 1)
if n_decimal <= 1:
return str(int(figure))
else:
n_decimal = min(n_decimal, max_decimal)
... | python | def _smart_round(figure, width=10, max_decimal=4):
"""Round large numbers as integers, smaller numbers as decimals."""
n_digits = len(str(int(figure)))
n_decimal = width - (n_digits + 1)
if n_decimal <= 1:
return str(int(figure))
else:
n_decimal = min(n_decimal, max_decimal)
... | [
"def",
"_smart_round",
"(",
"figure",
",",
"width",
"=",
"10",
",",
"max_decimal",
"=",
"4",
")",
":",
"n_digits",
"=",
"len",
"(",
"str",
"(",
"int",
"(",
"figure",
")",
")",
")",
"n_decimal",
"=",
"width",
"-",
"(",
"n_digits",
"+",
"1",
")",
"... | Round large numbers as integers, smaller numbers as decimals. | [
"Round",
"large",
"numbers",
"as",
"integers",
"smaller",
"numbers",
"as",
"decimals",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/cli/pretrain.py#L295-L304 |
21,243 | explosion/spaCy | spacy/lang/el/syntax_iterators.py | noun_chunks | def noun_chunks(obj):
"""
Detect base noun phrases. Works on both Doc and Span.
"""
# It follows the logic of the noun chunks finder of English language,
# adjusted to some Greek language special characteristics.
# obj tag corrects some DEP tagger mistakes.
# Further improvement of the model... | python | def noun_chunks(obj):
"""
Detect base noun phrases. Works on both Doc and Span.
"""
# It follows the logic of the noun chunks finder of English language,
# adjusted to some Greek language special characteristics.
# obj tag corrects some DEP tagger mistakes.
# Further improvement of the model... | [
"def",
"noun_chunks",
"(",
"obj",
")",
":",
"# It follows the logic of the noun chunks finder of English language,",
"# adjusted to some Greek language special characteristics.",
"# obj tag corrects some DEP tagger mistakes.",
"# Further improvement of the models will eliminate the need for this t... | Detect base noun phrases. Works on both Doc and Span. | [
"Detect",
"base",
"noun",
"phrases",
".",
"Works",
"on",
"both",
"Doc",
"and",
"Span",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/lang/el/syntax_iterators.py#L7-L55 |
21,244 | explosion/spaCy | spacy/tokens/underscore.py | get_ext_args | def get_ext_args(**kwargs):
"""Validate and convert arguments. Reused in Doc, Token and Span."""
default = kwargs.get("default")
getter = kwargs.get("getter")
setter = kwargs.get("setter")
method = kwargs.get("method")
if getter is None and setter is not None:
raise ValueError(Errors.E08... | python | def get_ext_args(**kwargs):
"""Validate and convert arguments. Reused in Doc, Token and Span."""
default = kwargs.get("default")
getter = kwargs.get("getter")
setter = kwargs.get("setter")
method = kwargs.get("method")
if getter is None and setter is not None:
raise ValueError(Errors.E08... | [
"def",
"get_ext_args",
"(",
"*",
"*",
"kwargs",
")",
":",
"default",
"=",
"kwargs",
".",
"get",
"(",
"\"default\"",
")",
"getter",
"=",
"kwargs",
".",
"get",
"(",
"\"getter\"",
")",
"setter",
"=",
"kwargs",
".",
"get",
"(",
"\"setter\"",
")",
"method",... | Validate and convert arguments. Reused in Doc, Token and Span. | [
"Validate",
"and",
"convert",
"arguments",
".",
"Reused",
"in",
"Doc",
"Token",
"and",
"Span",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/tokens/underscore.py#L69-L87 |
21,245 | explosion/spaCy | setup.py | is_new_osx | def is_new_osx():
"""Check whether we're on OSX >= 10.10"""
name = distutils.util.get_platform()
if sys.platform != "darwin":
return False
elif name.startswith("macosx-10"):
minor_version = int(name.split("-")[1].split(".")[1])
if minor_version >= 7:
return True
... | python | def is_new_osx():
"""Check whether we're on OSX >= 10.10"""
name = distutils.util.get_platform()
if sys.platform != "darwin":
return False
elif name.startswith("macosx-10"):
minor_version = int(name.split("-")[1].split(".")[1])
if minor_version >= 7:
return True
... | [
"def",
"is_new_osx",
"(",
")",
":",
"name",
"=",
"distutils",
".",
"util",
".",
"get_platform",
"(",
")",
"if",
"sys",
".",
"platform",
"!=",
"\"darwin\"",
":",
"return",
"False",
"elif",
"name",
".",
"startswith",
"(",
"\"macosx-10\"",
")",
":",
"minor_... | Check whether we're on OSX >= 10.10 | [
"Check",
"whether",
"we",
"re",
"on",
"OSX",
">",
"=",
"10",
".",
"10"
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/setup.py#L15-L27 |
21,246 | explosion/spaCy | examples/training/ner_multitask_objective.py | get_position_label | def get_position_label(i, words, tags, heads, labels, ents):
"""Return labels indicating the position of the word in the document.
"""
if len(words) < 20:
return "short-doc"
elif i == 0:
return "first-word"
elif i < 10:
return "early-word"
elif i < 20:
return "mid... | python | def get_position_label(i, words, tags, heads, labels, ents):
"""Return labels indicating the position of the word in the document.
"""
if len(words) < 20:
return "short-doc"
elif i == 0:
return "first-word"
elif i < 10:
return "early-word"
elif i < 20:
return "mid... | [
"def",
"get_position_label",
"(",
"i",
",",
"words",
",",
"tags",
",",
"heads",
",",
"labels",
",",
"ents",
")",
":",
"if",
"len",
"(",
"words",
")",
"<",
"20",
":",
"return",
"\"short-doc\"",
"elif",
"i",
"==",
"0",
":",
"return",
"\"first-word\"",
... | Return labels indicating the position of the word in the document. | [
"Return",
"labels",
"indicating",
"the",
"position",
"of",
"the",
"word",
"in",
"the",
"document",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/examples/training/ner_multitask_objective.py#L36-L50 |
21,247 | explosion/spaCy | bin/ud/run_eval.py | load_model | def load_model(modelname, add_sentencizer=False):
""" Load a specific spaCy model """
loading_start = time.time()
nlp = spacy.load(modelname)
if add_sentencizer:
nlp.add_pipe(nlp.create_pipe('sentencizer'))
loading_end = time.time()
loading_time = loading_end - loading_start
if add_s... | python | def load_model(modelname, add_sentencizer=False):
""" Load a specific spaCy model """
loading_start = time.time()
nlp = spacy.load(modelname)
if add_sentencizer:
nlp.add_pipe(nlp.create_pipe('sentencizer'))
loading_end = time.time()
loading_time = loading_end - loading_start
if add_s... | [
"def",
"load_model",
"(",
"modelname",
",",
"add_sentencizer",
"=",
"False",
")",
":",
"loading_start",
"=",
"time",
".",
"time",
"(",
")",
"nlp",
"=",
"spacy",
".",
"load",
"(",
"modelname",
")",
"if",
"add_sentencizer",
":",
"nlp",
".",
"add_pipe",
"("... | Load a specific spaCy model | [
"Load",
"a",
"specific",
"spaCy",
"model"
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/bin/ud/run_eval.py#L34-L44 |
21,248 | explosion/spaCy | bin/ud/run_eval.py | load_default_model_sentencizer | def load_default_model_sentencizer(lang):
""" Load a generic spaCy model and add the sentencizer for sentence tokenization"""
loading_start = time.time()
lang_class = get_lang_class(lang)
nlp = lang_class()
nlp.add_pipe(nlp.create_pipe('sentencizer'))
loading_end = time.time()
loading_time =... | python | def load_default_model_sentencizer(lang):
""" Load a generic spaCy model and add the sentencizer for sentence tokenization"""
loading_start = time.time()
lang_class = get_lang_class(lang)
nlp = lang_class()
nlp.add_pipe(nlp.create_pipe('sentencizer'))
loading_end = time.time()
loading_time =... | [
"def",
"load_default_model_sentencizer",
"(",
"lang",
")",
":",
"loading_start",
"=",
"time",
".",
"time",
"(",
")",
"lang_class",
"=",
"get_lang_class",
"(",
"lang",
")",
"nlp",
"=",
"lang_class",
"(",
")",
"nlp",
".",
"add_pipe",
"(",
"nlp",
".",
"create... | Load a generic spaCy model and add the sentencizer for sentence tokenization | [
"Load",
"a",
"generic",
"spaCy",
"model",
"and",
"add",
"the",
"sentencizer",
"for",
"sentence",
"tokenization"
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/bin/ud/run_eval.py#L47-L55 |
21,249 | explosion/spaCy | bin/ud/run_eval.py | get_freq_tuples | def get_freq_tuples(my_list, print_total_threshold):
""" Turn a list of errors into frequency-sorted tuples thresholded by a certain total number """
d = {}
for token in my_list:
d.setdefault(token, 0)
d[token] += 1
return sorted(d.items(), key=operator.itemgetter(1), reverse=True)[:prin... | python | def get_freq_tuples(my_list, print_total_threshold):
""" Turn a list of errors into frequency-sorted tuples thresholded by a certain total number """
d = {}
for token in my_list:
d.setdefault(token, 0)
d[token] += 1
return sorted(d.items(), key=operator.itemgetter(1), reverse=True)[:prin... | [
"def",
"get_freq_tuples",
"(",
"my_list",
",",
"print_total_threshold",
")",
":",
"d",
"=",
"{",
"}",
"for",
"token",
"in",
"my_list",
":",
"d",
".",
"setdefault",
"(",
"token",
",",
"0",
")",
"d",
"[",
"token",
"]",
"+=",
"1",
"return",
"sorted",
"(... | Turn a list of errors into frequency-sorted tuples thresholded by a certain total number | [
"Turn",
"a",
"list",
"of",
"errors",
"into",
"frequency",
"-",
"sorted",
"tuples",
"thresholded",
"by",
"a",
"certain",
"total",
"number"
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/bin/ud/run_eval.py#L62-L68 |
21,250 | explosion/spaCy | bin/ud/run_eval.py | _contains_blinded_text | def _contains_blinded_text(stats_xml):
""" Heuristic to determine whether the treebank has blinded texts or not """
tree = ET.parse(stats_xml)
root = tree.getroot()
total_tokens = int(root.find('size/total/tokens').text)
unique_lemmas = int(root.find('lemmas').get('unique'))
# assume the corpus... | python | def _contains_blinded_text(stats_xml):
""" Heuristic to determine whether the treebank has blinded texts or not """
tree = ET.parse(stats_xml)
root = tree.getroot()
total_tokens = int(root.find('size/total/tokens').text)
unique_lemmas = int(root.find('lemmas').get('unique'))
# assume the corpus... | [
"def",
"_contains_blinded_text",
"(",
"stats_xml",
")",
":",
"tree",
"=",
"ET",
".",
"parse",
"(",
"stats_xml",
")",
"root",
"=",
"tree",
".",
"getroot",
"(",
")",
"total_tokens",
"=",
"int",
"(",
"root",
".",
"find",
"(",
"'size/total/tokens'",
")",
"."... | Heuristic to determine whether the treebank has blinded texts or not | [
"Heuristic",
"to",
"determine",
"whether",
"the",
"treebank",
"has",
"blinded",
"texts",
"or",
"not"
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/bin/ud/run_eval.py#L71-L79 |
21,251 | explosion/spaCy | bin/ud/run_eval.py | fetch_all_treebanks | def fetch_all_treebanks(ud_dir, languages, corpus, best_per_language):
"""" Fetch the txt files for all treebanks for a given set of languages """
all_treebanks = dict()
treebank_size = dict()
for l in languages:
all_treebanks[l] = []
treebank_size[l] = 0
for treebank_dir in ud_dir.... | python | def fetch_all_treebanks(ud_dir, languages, corpus, best_per_language):
"""" Fetch the txt files for all treebanks for a given set of languages """
all_treebanks = dict()
treebank_size = dict()
for l in languages:
all_treebanks[l] = []
treebank_size[l] = 0
for treebank_dir in ud_dir.... | [
"def",
"fetch_all_treebanks",
"(",
"ud_dir",
",",
"languages",
",",
"corpus",
",",
"best_per_language",
")",
":",
"all_treebanks",
"=",
"dict",
"(",
")",
"treebank_size",
"=",
"dict",
"(",
")",
"for",
"l",
"in",
"languages",
":",
"all_treebanks",
"[",
"l",
... | Fetch the txt files for all treebanks for a given set of languages | [
"Fetch",
"the",
"txt",
"files",
"for",
"all",
"treebanks",
"for",
"a",
"given",
"set",
"of",
"languages"
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/bin/ud/run_eval.py#L82-L111 |
21,252 | explosion/spaCy | bin/ud/run_eval.py | run_all_evals | def run_all_evals(models, treebanks, out_file, check_parse, print_freq_tasks):
"""" Run an evaluation for each language with its specified models and treebanks """
print_header = True
for tb_lang, treebank_list in treebanks.items():
print()
print("Language", tb_lang)
for text_path i... | python | def run_all_evals(models, treebanks, out_file, check_parse, print_freq_tasks):
"""" Run an evaluation for each language with its specified models and treebanks """
print_header = True
for tb_lang, treebank_list in treebanks.items():
print()
print("Language", tb_lang)
for text_path i... | [
"def",
"run_all_evals",
"(",
"models",
",",
"treebanks",
",",
"out_file",
",",
"check_parse",
",",
"print_freq_tasks",
")",
":",
"print_header",
"=",
"True",
"for",
"tb_lang",
",",
"treebank_list",
"in",
"treebanks",
".",
"items",
"(",
")",
":",
"print",
"("... | Run an evaluation for each language with its specified models and treebanks | [
"Run",
"an",
"evaluation",
"for",
"each",
"language",
"with",
"its",
"specified",
"models",
"and",
"treebanks"
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/bin/ud/run_eval.py#L184-L212 |
21,253 | explosion/spaCy | bin/ud/run_eval.py | main | def main(out_path, ud_dir, check_parse=False, langs=ALL_LANGUAGES, exclude_trained_models=False, exclude_multi=False,
hide_freq=False, corpus='train', best_per_language=False):
""""
Assemble all treebanks and models to run evaluations with.
When setting check_parse to True, the default models will ... | python | def main(out_path, ud_dir, check_parse=False, langs=ALL_LANGUAGES, exclude_trained_models=False, exclude_multi=False,
hide_freq=False, corpus='train', best_per_language=False):
""""
Assemble all treebanks and models to run evaluations with.
When setting check_parse to True, the default models will ... | [
"def",
"main",
"(",
"out_path",
",",
"ud_dir",
",",
"check_parse",
"=",
"False",
",",
"langs",
"=",
"ALL_LANGUAGES",
",",
"exclude_trained_models",
"=",
"False",
",",
"exclude_multi",
"=",
"False",
",",
"hide_freq",
"=",
"False",
",",
"corpus",
"=",
"'train'... | Assemble all treebanks and models to run evaluations with.
When setting check_parse to True, the default models will not be evaluated as they don't have parsing functionality | [
"Assemble",
"all",
"treebanks",
"and",
"models",
"to",
"run",
"evaluations",
"with",
".",
"When",
"setting",
"check_parse",
"to",
"True",
"the",
"default",
"models",
"will",
"not",
"be",
"evaluated",
"as",
"they",
"don",
"t",
"have",
"parsing",
"functionality"... | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/bin/ud/run_eval.py#L226-L283 |
21,254 | explosion/spaCy | spacy/lang/de/syntax_iterators.py | noun_chunks | def noun_chunks(obj):
"""
Detect base noun phrases from a dependency parse. Works on both Doc and Span.
"""
# this iterator extracts spans headed by NOUNs starting from the left-most
# syntactic dependent until the NOUN itself for close apposition and
# measurement construction, the span is some... | python | def noun_chunks(obj):
"""
Detect base noun phrases from a dependency parse. Works on both Doc and Span.
"""
# this iterator extracts spans headed by NOUNs starting from the left-most
# syntactic dependent until the NOUN itself for close apposition and
# measurement construction, the span is some... | [
"def",
"noun_chunks",
"(",
"obj",
")",
":",
"# this iterator extracts spans headed by NOUNs starting from the left-most",
"# syntactic dependent until the NOUN itself for close apposition and",
"# measurement construction, the span is sometimes extended to the right of",
"# the NOUN. Example: \"ei... | Detect base noun phrases from a dependency parse. Works on both Doc and Span. | [
"Detect",
"base",
"noun",
"phrases",
"from",
"a",
"dependency",
"parse",
".",
"Works",
"on",
"both",
"Doc",
"and",
"Span",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/lang/de/syntax_iterators.py#L7-L46 |
21,255 | explosion/spaCy | spacy/_ml.py | with_cpu | def with_cpu(ops, model):
"""Wrap a model that should run on CPU, transferring inputs and outputs
as necessary."""
model.to_cpu()
def with_cpu_forward(inputs, drop=0.0):
cpu_outputs, backprop = model.begin_update(_to_cpu(inputs), drop=drop)
gpu_outputs = _to_device(ops, cpu_outputs)
... | python | def with_cpu(ops, model):
"""Wrap a model that should run on CPU, transferring inputs and outputs
as necessary."""
model.to_cpu()
def with_cpu_forward(inputs, drop=0.0):
cpu_outputs, backprop = model.begin_update(_to_cpu(inputs), drop=drop)
gpu_outputs = _to_device(ops, cpu_outputs)
... | [
"def",
"with_cpu",
"(",
"ops",
",",
"model",
")",
":",
"model",
".",
"to_cpu",
"(",
")",
"def",
"with_cpu_forward",
"(",
"inputs",
",",
"drop",
"=",
"0.0",
")",
":",
"cpu_outputs",
",",
"backprop",
"=",
"model",
".",
"begin_update",
"(",
"_to_cpu",
"("... | Wrap a model that should run on CPU, transferring inputs and outputs
as necessary. | [
"Wrap",
"a",
"model",
"that",
"should",
"run",
"on",
"CPU",
"transferring",
"inputs",
"and",
"outputs",
"as",
"necessary",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/_ml.py#L84-L99 |
21,256 | explosion/spaCy | spacy/_ml.py | masked_language_model | def masked_language_model(vocab, model, mask_prob=0.15):
"""Convert a model into a BERT-style masked language model"""
random_words = _RandomWords(vocab)
def mlm_forward(docs, drop=0.0):
mask, docs = _apply_mask(docs, random_words, mask_prob=mask_prob)
mask = model.ops.asarray(mask).reshap... | python | def masked_language_model(vocab, model, mask_prob=0.15):
"""Convert a model into a BERT-style masked language model"""
random_words = _RandomWords(vocab)
def mlm_forward(docs, drop=0.0):
mask, docs = _apply_mask(docs, random_words, mask_prob=mask_prob)
mask = model.ops.asarray(mask).reshap... | [
"def",
"masked_language_model",
"(",
"vocab",
",",
"model",
",",
"mask_prob",
"=",
"0.15",
")",
":",
"random_words",
"=",
"_RandomWords",
"(",
"vocab",
")",
"def",
"mlm_forward",
"(",
"docs",
",",
"drop",
"=",
"0.0",
")",
":",
"mask",
",",
"docs",
"=",
... | Convert a model into a BERT-style masked language model | [
"Convert",
"a",
"model",
"into",
"a",
"BERT",
"-",
"style",
"masked",
"language",
"model"
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/_ml.py#L693-L709 |
21,257 | explosion/spaCy | spacy/pipeline/hooks.py | SimilarityHook.begin_training | def begin_training(self, _=tuple(), pipeline=None, sgd=None, **kwargs):
"""Allocate model, using width from tensorizer in pipeline.
gold_tuples (iterable): Gold-standard training data.
pipeline (list): The pipeline the model is part of.
"""
if self.model is True:
sel... | python | def begin_training(self, _=tuple(), pipeline=None, sgd=None, **kwargs):
"""Allocate model, using width from tensorizer in pipeline.
gold_tuples (iterable): Gold-standard training data.
pipeline (list): The pipeline the model is part of.
"""
if self.model is True:
sel... | [
"def",
"begin_training",
"(",
"self",
",",
"_",
"=",
"tuple",
"(",
")",
",",
"pipeline",
"=",
"None",
",",
"sgd",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"model",
"is",
"True",
":",
"self",
".",
"model",
"=",
"self",
... | Allocate model, using width from tensorizer in pipeline.
gold_tuples (iterable): Gold-standard training data.
pipeline (list): The pipeline the model is part of. | [
"Allocate",
"model",
"using",
"width",
"from",
"tensorizer",
"in",
"pipeline",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/pipeline/hooks.py#L89-L100 |
21,258 | explosion/spaCy | spacy/displacy/render.py | DependencyRenderer.render_svg | def render_svg(self, render_id, words, arcs):
"""Render SVG.
render_id (int): Unique ID, typically index of document.
words (list): Individual words and their tags.
arcs (list): Individual arcs and their start, end, direction and label.
RETURNS (unicode): Rendered SVG markup.
... | python | def render_svg(self, render_id, words, arcs):
"""Render SVG.
render_id (int): Unique ID, typically index of document.
words (list): Individual words and their tags.
arcs (list): Individual arcs and their start, end, direction and label.
RETURNS (unicode): Rendered SVG markup.
... | [
"def",
"render_svg",
"(",
"self",
",",
"render_id",
",",
"words",
",",
"arcs",
")",
":",
"self",
".",
"levels",
"=",
"self",
".",
"get_levels",
"(",
"arcs",
")",
"self",
".",
"highest_level",
"=",
"len",
"(",
"self",
".",
"levels",
")",
"self",
".",
... | Render SVG.
render_id (int): Unique ID, typically index of document.
words (list): Individual words and their tags.
arcs (list): Individual arcs and their start, end, direction and label.
RETURNS (unicode): Rendered SVG markup. | [
"Render",
"SVG",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/displacy/render.py#L70-L100 |
21,259 | explosion/spaCy | spacy/displacy/render.py | DependencyRenderer.render_word | def render_word(self, text, tag, i):
"""Render individual word.
text (unicode): Word text.
tag (unicode): Part-of-speech tag.
i (int): Unique ID, typically word index.
RETURNS (unicode): Rendered SVG markup.
"""
y = self.offset_y + self.word_spacing
x = s... | python | def render_word(self, text, tag, i):
"""Render individual word.
text (unicode): Word text.
tag (unicode): Part-of-speech tag.
i (int): Unique ID, typically word index.
RETURNS (unicode): Rendered SVG markup.
"""
y = self.offset_y + self.word_spacing
x = s... | [
"def",
"render_word",
"(",
"self",
",",
"text",
",",
"tag",
",",
"i",
")",
":",
"y",
"=",
"self",
".",
"offset_y",
"+",
"self",
".",
"word_spacing",
"x",
"=",
"self",
".",
"offset_x",
"+",
"i",
"*",
"self",
".",
"distance",
"if",
"self",
".",
"di... | Render individual word.
text (unicode): Word text.
tag (unicode): Part-of-speech tag.
i (int): Unique ID, typically word index.
RETURNS (unicode): Rendered SVG markup. | [
"Render",
"individual",
"word",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/displacy/render.py#L102-L115 |
21,260 | explosion/spaCy | spacy/displacy/render.py | DependencyRenderer.render_arrow | def render_arrow(self, label, start, end, direction, i):
"""Render individual arrow.
label (unicode): Dependency label.
start (int): Index of start word.
end (int): Index of end word.
direction (unicode): Arrow direction, 'left' or 'right'.
i (int): Unique ID, typically ... | python | def render_arrow(self, label, start, end, direction, i):
"""Render individual arrow.
label (unicode): Dependency label.
start (int): Index of start word.
end (int): Index of end word.
direction (unicode): Arrow direction, 'left' or 'right'.
i (int): Unique ID, typically ... | [
"def",
"render_arrow",
"(",
"self",
",",
"label",
",",
"start",
",",
"end",
",",
"direction",
",",
"i",
")",
":",
"level",
"=",
"self",
".",
"levels",
".",
"index",
"(",
"end",
"-",
"start",
")",
"+",
"1",
"x_start",
"=",
"self",
".",
"offset_x",
... | Render individual arrow.
label (unicode): Dependency label.
start (int): Index of start word.
end (int): Index of end word.
direction (unicode): Arrow direction, 'left' or 'right'.
i (int): Unique ID, typically arrow index.
RETURNS (unicode): Rendered SVG markup. | [
"Render",
"individual",
"arrow",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/displacy/render.py#L117-L156 |
21,261 | explosion/spaCy | spacy/displacy/render.py | DependencyRenderer.get_arc | def get_arc(self, x_start, y, y_curve, x_end):
"""Render individual arc.
x_start (int): X-coordinate of arrow start point.
y (int): Y-coordinate of arrow start and end point.
y_curve (int): Y-corrdinate of Cubic Bézier y_curve point.
x_end (int): X-coordinate of arrow end point.... | python | def get_arc(self, x_start, y, y_curve, x_end):
"""Render individual arc.
x_start (int): X-coordinate of arrow start point.
y (int): Y-coordinate of arrow start and end point.
y_curve (int): Y-corrdinate of Cubic Bézier y_curve point.
x_end (int): X-coordinate of arrow end point.... | [
"def",
"get_arc",
"(",
"self",
",",
"x_start",
",",
"y",
",",
"y_curve",
",",
"x_end",
")",
":",
"template",
"=",
"\"M{x},{y} C{x},{c} {e},{c} {e},{y}\"",
"if",
"self",
".",
"compact",
":",
"template",
"=",
"\"M{x},{y} {x},{c} {e},{c} {e},{y}\"",
"return",
"templa... | Render individual arc.
x_start (int): X-coordinate of arrow start point.
y (int): Y-coordinate of arrow start and end point.
y_curve (int): Y-corrdinate of Cubic Bézier y_curve point.
x_end (int): X-coordinate of arrow end point.
RETURNS (unicode): Definition of the arc path ('d... | [
"Render",
"individual",
"arc",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/displacy/render.py#L158-L170 |
21,262 | explosion/spaCy | spacy/displacy/render.py | DependencyRenderer.get_arrowhead | def get_arrowhead(self, direction, x, y, end):
"""Render individual arrow head.
direction (unicode): Arrow direction, 'left' or 'right'.
x (int): X-coordinate of arrow start point.
y (int): Y-coordinate of arrow start and end point.
end (int): X-coordinate of arrow end point.
... | python | def get_arrowhead(self, direction, x, y, end):
"""Render individual arrow head.
direction (unicode): Arrow direction, 'left' or 'right'.
x (int): X-coordinate of arrow start point.
y (int): Y-coordinate of arrow start and end point.
end (int): X-coordinate of arrow end point.
... | [
"def",
"get_arrowhead",
"(",
"self",
",",
"direction",
",",
"x",
",",
"y",
",",
"end",
")",
":",
"if",
"direction",
"==",
"\"left\"",
":",
"pos1",
",",
"pos2",
",",
"pos3",
"=",
"(",
"x",
",",
"x",
"-",
"self",
".",
"arrow_width",
"+",
"2",
",",
... | Render individual arrow head.
direction (unicode): Arrow direction, 'left' or 'right'.
x (int): X-coordinate of arrow start point.
y (int): Y-coordinate of arrow start and end point.
end (int): X-coordinate of arrow end point.
RETURNS (unicode): Definition of the arrow head path... | [
"Render",
"individual",
"arrow",
"head",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/displacy/render.py#L172-L197 |
21,263 | explosion/spaCy | spacy/displacy/render.py | DependencyRenderer.get_levels | def get_levels(self, arcs):
"""Calculate available arc height "levels".
Used to calculate arrow heights dynamically and without wasting space.
args (list): Individual arcs and their start, end, direction and label.
RETURNS (list): Arc levels sorted from lowest to highest.
"""
... | python | def get_levels(self, arcs):
"""Calculate available arc height "levels".
Used to calculate arrow heights dynamically and without wasting space.
args (list): Individual arcs and their start, end, direction and label.
RETURNS (list): Arc levels sorted from lowest to highest.
"""
... | [
"def",
"get_levels",
"(",
"self",
",",
"arcs",
")",
":",
"levels",
"=",
"set",
"(",
"map",
"(",
"lambda",
"arc",
":",
"arc",
"[",
"\"end\"",
"]",
"-",
"arc",
"[",
"\"start\"",
"]",
",",
"arcs",
")",
")",
"return",
"sorted",
"(",
"list",
"(",
"lev... | Calculate available arc height "levels".
Used to calculate arrow heights dynamically and without wasting space.
args (list): Individual arcs and their start, end, direction and label.
RETURNS (list): Arc levels sorted from lowest to highest. | [
"Calculate",
"available",
"arc",
"height",
"levels",
".",
"Used",
"to",
"calculate",
"arrow",
"heights",
"dynamically",
"and",
"without",
"wasting",
"space",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/displacy/render.py#L199-L207 |
21,264 | explosion/spaCy | spacy/displacy/render.py | EntityRenderer.render_ents | def render_ents(self, text, spans, title):
"""Render entities in text.
text (unicode): Original text.
spans (list): Individual entity spans and their start, end and label.
title (unicode or None): Document title set in Doc.user_data['title'].
"""
markup = ""
offs... | python | def render_ents(self, text, spans, title):
"""Render entities in text.
text (unicode): Original text.
spans (list): Individual entity spans and their start, end and label.
title (unicode or None): Document title set in Doc.user_data['title'].
"""
markup = ""
offs... | [
"def",
"render_ents",
"(",
"self",
",",
"text",
",",
"spans",
",",
"title",
")",
":",
"markup",
"=",
"\"\"",
"offset",
"=",
"0",
"for",
"span",
"in",
"spans",
":",
"label",
"=",
"span",
"[",
"\"label\"",
"]",
"start",
"=",
"span",
"[",
"\"start\"",
... | Render entities in text.
text (unicode): Original text.
spans (list): Individual entity spans and their start, end and label.
title (unicode or None): Document title set in Doc.user_data['title']. | [
"Render",
"entities",
"in",
"text",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/displacy/render.py#L271-L304 |
21,265 | explosion/spaCy | spacy/pipeline/functions.py | merge_noun_chunks | def merge_noun_chunks(doc):
"""Merge noun chunks into a single token.
doc (Doc): The Doc object.
RETURNS (Doc): The Doc object with merged noun chunks.
DOCS: https://spacy.io/api/pipeline-functions#merge_noun_chunks
"""
if not doc.is_parsed:
return doc
with doc.retokenize() as reto... | python | def merge_noun_chunks(doc):
"""Merge noun chunks into a single token.
doc (Doc): The Doc object.
RETURNS (Doc): The Doc object with merged noun chunks.
DOCS: https://spacy.io/api/pipeline-functions#merge_noun_chunks
"""
if not doc.is_parsed:
return doc
with doc.retokenize() as reto... | [
"def",
"merge_noun_chunks",
"(",
"doc",
")",
":",
"if",
"not",
"doc",
".",
"is_parsed",
":",
"return",
"doc",
"with",
"doc",
".",
"retokenize",
"(",
")",
"as",
"retokenizer",
":",
"for",
"np",
"in",
"doc",
".",
"noun_chunks",
":",
"attrs",
"=",
"{",
... | Merge noun chunks into a single token.
doc (Doc): The Doc object.
RETURNS (Doc): The Doc object with merged noun chunks.
DOCS: https://spacy.io/api/pipeline-functions#merge_noun_chunks | [
"Merge",
"noun",
"chunks",
"into",
"a",
"single",
"token",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/pipeline/functions.py#L7-L21 |
21,266 | explosion/spaCy | spacy/pipeline/functions.py | merge_entities | def merge_entities(doc):
"""Merge entities into a single token.
doc (Doc): The Doc object.
RETURNS (Doc): The Doc object with merged entities.
DOCS: https://spacy.io/api/pipeline-functions#merge_entities
"""
with doc.retokenize() as retokenizer:
for ent in doc.ents:
attrs =... | python | def merge_entities(doc):
"""Merge entities into a single token.
doc (Doc): The Doc object.
RETURNS (Doc): The Doc object with merged entities.
DOCS: https://spacy.io/api/pipeline-functions#merge_entities
"""
with doc.retokenize() as retokenizer:
for ent in doc.ents:
attrs =... | [
"def",
"merge_entities",
"(",
"doc",
")",
":",
"with",
"doc",
".",
"retokenize",
"(",
")",
"as",
"retokenizer",
":",
"for",
"ent",
"in",
"doc",
".",
"ents",
":",
"attrs",
"=",
"{",
"\"tag\"",
":",
"ent",
".",
"root",
".",
"tag",
",",
"\"dep\"",
":"... | Merge entities into a single token.
doc (Doc): The Doc object.
RETURNS (Doc): The Doc object with merged entities.
DOCS: https://spacy.io/api/pipeline-functions#merge_entities | [
"Merge",
"entities",
"into",
"a",
"single",
"token",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/pipeline/functions.py#L24-L36 |
21,267 | explosion/spaCy | spacy/pipeline/functions.py | merge_subtokens | def merge_subtokens(doc, label="subtok"):
"""Merge subtokens into a single token.
doc (Doc): The Doc object.
label (unicode): The subtoken dependency label.
RETURNS (Doc): The Doc object with merged subtokens.
DOCS: https://spacy.io/api/pipeline-functions#merge_subtokens
"""
merger = Match... | python | def merge_subtokens(doc, label="subtok"):
"""Merge subtokens into a single token.
doc (Doc): The Doc object.
label (unicode): The subtoken dependency label.
RETURNS (Doc): The Doc object with merged subtokens.
DOCS: https://spacy.io/api/pipeline-functions#merge_subtokens
"""
merger = Match... | [
"def",
"merge_subtokens",
"(",
"doc",
",",
"label",
"=",
"\"subtok\"",
")",
":",
"merger",
"=",
"Matcher",
"(",
"doc",
".",
"vocab",
")",
"merger",
".",
"add",
"(",
"\"SUBTOK\"",
",",
"None",
",",
"[",
"{",
"\"DEP\"",
":",
"label",
",",
"\"op\"",
":"... | Merge subtokens into a single token.
doc (Doc): The Doc object.
label (unicode): The subtoken dependency label.
RETURNS (Doc): The Doc object with merged subtokens.
DOCS: https://spacy.io/api/pipeline-functions#merge_subtokens | [
"Merge",
"subtokens",
"into",
"a",
"single",
"token",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/pipeline/functions.py#L39-L55 |
21,268 | explosion/spaCy | spacy/cli/train.py | _score_for_model | def _score_for_model(meta):
""" Returns mean score between tasks in pipeline that can be used for early stopping. """
mean_acc = list()
pipes = meta["pipeline"]
acc = meta["accuracy"]
if "tagger" in pipes:
mean_acc.append(acc["tags_acc"])
if "parser" in pipes:
mean_acc.append((ac... | python | def _score_for_model(meta):
""" Returns mean score between tasks in pipeline that can be used for early stopping. """
mean_acc = list()
pipes = meta["pipeline"]
acc = meta["accuracy"]
if "tagger" in pipes:
mean_acc.append(acc["tags_acc"])
if "parser" in pipes:
mean_acc.append((ac... | [
"def",
"_score_for_model",
"(",
"meta",
")",
":",
"mean_acc",
"=",
"list",
"(",
")",
"pipes",
"=",
"meta",
"[",
"\"pipeline\"",
"]",
"acc",
"=",
"meta",
"[",
"\"accuracy\"",
"]",
"if",
"\"tagger\"",
"in",
"pipes",
":",
"mean_acc",
".",
"append",
"(",
"... | Returns mean score between tasks in pipeline that can be used for early stopping. | [
"Returns",
"mean",
"score",
"between",
"tasks",
"in",
"pipeline",
"that",
"can",
"be",
"used",
"for",
"early",
"stopping",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/cli/train.py#L371-L382 |
21,269 | explosion/spaCy | spacy/cli/train.py | _load_pretrained_tok2vec | def _load_pretrained_tok2vec(nlp, loc):
"""Load pre-trained weights for the 'token-to-vector' part of the component
models, which is typically a CNN. See 'spacy pretrain'. Experimental.
"""
with loc.open("rb") as file_:
weights_data = file_.read()
loaded = []
for name, component in nlp.p... | python | def _load_pretrained_tok2vec(nlp, loc):
"""Load pre-trained weights for the 'token-to-vector' part of the component
models, which is typically a CNN. See 'spacy pretrain'. Experimental.
"""
with loc.open("rb") as file_:
weights_data = file_.read()
loaded = []
for name, component in nlp.p... | [
"def",
"_load_pretrained_tok2vec",
"(",
"nlp",
",",
"loc",
")",
":",
"with",
"loc",
".",
"open",
"(",
"\"rb\"",
")",
"as",
"file_",
":",
"weights_data",
"=",
"file_",
".",
"read",
"(",
")",
"loaded",
"=",
"[",
"]",
"for",
"name",
",",
"component",
"i... | Load pre-trained weights for the 'token-to-vector' part of the component
models, which is typically a CNN. See 'spacy pretrain'. Experimental. | [
"Load",
"pre",
"-",
"trained",
"weights",
"for",
"the",
"token",
"-",
"to",
"-",
"vector",
"part",
"of",
"the",
"component",
"models",
"which",
"is",
"typically",
"a",
"CNN",
".",
"See",
"spacy",
"pretrain",
".",
"Experimental",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/cli/train.py#L407-L418 |
21,270 | explosion/spaCy | spacy/cli/converters/conllu2json.py | conllu2json | def conllu2json(input_data, n_sents=10, use_morphology=False, lang=None):
"""
Convert conllu files into JSON format for use with train cli.
use_morphology parameter enables appending morphology to tags, which is
useful for languages such as Spanish, where UD tags are not so rich.
Extract NER tags i... | python | def conllu2json(input_data, n_sents=10, use_morphology=False, lang=None):
"""
Convert conllu files into JSON format for use with train cli.
use_morphology parameter enables appending morphology to tags, which is
useful for languages such as Spanish, where UD tags are not so rich.
Extract NER tags i... | [
"def",
"conllu2json",
"(",
"input_data",
",",
"n_sents",
"=",
"10",
",",
"use_morphology",
"=",
"False",
",",
"lang",
"=",
"None",
")",
":",
"# by @dvsrepo, via #11 explosion/spacy-dev-resources",
"# by @katarkor",
"docs",
"=",
"[",
"]",
"sentences",
"=",
"[",
"... | Convert conllu files into JSON format for use with train cli.
use_morphology parameter enables appending morphology to tags, which is
useful for languages such as Spanish, where UD tags are not so rich.
Extract NER tags if available and convert them so that they follow
BILUO and the Wikipedia scheme | [
"Convert",
"conllu",
"files",
"into",
"JSON",
"format",
"for",
"use",
"with",
"train",
"cli",
".",
"use_morphology",
"parameter",
"enables",
"appending",
"morphology",
"to",
"tags",
"which",
"is",
"useful",
"for",
"languages",
"such",
"as",
"Spanish",
"where",
... | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/cli/converters/conllu2json.py#L9-L37 |
21,271 | explosion/spaCy | spacy/cli/converters/conllu2json.py | is_ner | def is_ner(tag):
"""
Check the 10th column of the first token to determine if the file contains
NER tags
"""
tag_match = re.match("([A-Z_]+)-([A-Z_]+)", tag)
if tag_match:
return True
elif tag == "O":
return True
else:
return False | python | def is_ner(tag):
"""
Check the 10th column of the first token to determine if the file contains
NER tags
"""
tag_match = re.match("([A-Z_]+)-([A-Z_]+)", tag)
if tag_match:
return True
elif tag == "O":
return True
else:
return False | [
"def",
"is_ner",
"(",
"tag",
")",
":",
"tag_match",
"=",
"re",
".",
"match",
"(",
"\"([A-Z_]+)-([A-Z_]+)\"",
",",
"tag",
")",
"if",
"tag_match",
":",
"return",
"True",
"elif",
"tag",
"==",
"\"O\"",
":",
"return",
"True",
"else",
":",
"return",
"False"
] | Check the 10th column of the first token to determine if the file contains
NER tags | [
"Check",
"the",
"10th",
"column",
"of",
"the",
"first",
"token",
"to",
"determine",
"if",
"the",
"file",
"contains",
"NER",
"tags"
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/cli/converters/conllu2json.py#L40-L51 |
21,272 | explosion/spaCy | examples/training/train_intent_parser.py | main | def main(model=None, output_dir=None, n_iter=15):
"""Load the model, set up the pipeline and train the parser."""
if model is not None:
nlp = spacy.load(model) # load existing spaCy model
print("Loaded model '%s'" % model)
else:
nlp = spacy.blank("en") # create blank Language class... | python | def main(model=None, output_dir=None, n_iter=15):
"""Load the model, set up the pipeline and train the parser."""
if model is not None:
nlp = spacy.load(model) # load existing spaCy model
print("Loaded model '%s'" % model)
else:
nlp = spacy.blank("en") # create blank Language class... | [
"def",
"main",
"(",
"model",
"=",
"None",
",",
"output_dir",
"=",
"None",
",",
"n_iter",
"=",
"15",
")",
":",
"if",
"model",
"is",
"not",
"None",
":",
"nlp",
"=",
"spacy",
".",
"load",
"(",
"model",
")",
"# load existing spaCy model",
"print",
"(",
"... | Load the model, set up the pipeline and train the parser. | [
"Load",
"the",
"model",
"set",
"up",
"the",
"pipeline",
"and",
"train",
"the",
"parser",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/examples/training/train_intent_parser.py#L107-L154 |
21,273 | explosion/spaCy | spacy/language.py | Language.get_pipe | def get_pipe(self, name):
"""Get a pipeline component for a given component name.
name (unicode): Name of pipeline component to get.
RETURNS (callable): The pipeline component.
DOCS: https://spacy.io/api/language#get_pipe
"""
for pipe_name, component in self.pipeline:
... | python | def get_pipe(self, name):
"""Get a pipeline component for a given component name.
name (unicode): Name of pipeline component to get.
RETURNS (callable): The pipeline component.
DOCS: https://spacy.io/api/language#get_pipe
"""
for pipe_name, component in self.pipeline:
... | [
"def",
"get_pipe",
"(",
"self",
",",
"name",
")",
":",
"for",
"pipe_name",
",",
"component",
"in",
"self",
".",
"pipeline",
":",
"if",
"pipe_name",
"==",
"name",
":",
"return",
"component",
"raise",
"KeyError",
"(",
"Errors",
".",
"E001",
".",
"format",
... | Get a pipeline component for a given component name.
name (unicode): Name of pipeline component to get.
RETURNS (callable): The pipeline component.
DOCS: https://spacy.io/api/language#get_pipe | [
"Get",
"a",
"pipeline",
"component",
"for",
"a",
"given",
"component",
"name",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/language.py#L232-L243 |
21,274 | explosion/spaCy | spacy/language.py | Language.replace_pipe | def replace_pipe(self, name, component):
"""Replace a component in the pipeline.
name (unicode): Name of the component to replace.
component (callable): Pipeline component.
DOCS: https://spacy.io/api/language#replace_pipe
"""
if name not in self.pipe_names:
... | python | def replace_pipe(self, name, component):
"""Replace a component in the pipeline.
name (unicode): Name of the component to replace.
component (callable): Pipeline component.
DOCS: https://spacy.io/api/language#replace_pipe
"""
if name not in self.pipe_names:
... | [
"def",
"replace_pipe",
"(",
"self",
",",
"name",
",",
"component",
")",
":",
"if",
"name",
"not",
"in",
"self",
".",
"pipe_names",
":",
"raise",
"ValueError",
"(",
"Errors",
".",
"E001",
".",
"format",
"(",
"name",
"=",
"name",
",",
"opts",
"=",
"sel... | Replace a component in the pipeline.
name (unicode): Name of the component to replace.
component (callable): Pipeline component.
DOCS: https://spacy.io/api/language#replace_pipe | [
"Replace",
"a",
"component",
"in",
"the",
"pipeline",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/language.py#L326-L336 |
21,275 | explosion/spaCy | spacy/language.py | Language.rename_pipe | def rename_pipe(self, old_name, new_name):
"""Rename a pipeline component.
old_name (unicode): Name of the component to rename.
new_name (unicode): New name of the component.
DOCS: https://spacy.io/api/language#rename_pipe
"""
if old_name not in self.pipe_names:
... | python | def rename_pipe(self, old_name, new_name):
"""Rename a pipeline component.
old_name (unicode): Name of the component to rename.
new_name (unicode): New name of the component.
DOCS: https://spacy.io/api/language#rename_pipe
"""
if old_name not in self.pipe_names:
... | [
"def",
"rename_pipe",
"(",
"self",
",",
"old_name",
",",
"new_name",
")",
":",
"if",
"old_name",
"not",
"in",
"self",
".",
"pipe_names",
":",
"raise",
"ValueError",
"(",
"Errors",
".",
"E001",
".",
"format",
"(",
"name",
"=",
"old_name",
",",
"opts",
"... | Rename a pipeline component.
old_name (unicode): Name of the component to rename.
new_name (unicode): New name of the component.
DOCS: https://spacy.io/api/language#rename_pipe | [
"Rename",
"a",
"pipeline",
"component",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/language.py#L338-L351 |
21,276 | explosion/spaCy | spacy/language.py | Language.remove_pipe | def remove_pipe(self, name):
"""Remove a component from the pipeline.
name (unicode): Name of the component to remove.
RETURNS (tuple): A `(name, component)` tuple of the removed component.
DOCS: https://spacy.io/api/language#remove_pipe
"""
if name not in self.pipe_nam... | python | def remove_pipe(self, name):
"""Remove a component from the pipeline.
name (unicode): Name of the component to remove.
RETURNS (tuple): A `(name, component)` tuple of the removed component.
DOCS: https://spacy.io/api/language#remove_pipe
"""
if name not in self.pipe_nam... | [
"def",
"remove_pipe",
"(",
"self",
",",
"name",
")",
":",
"if",
"name",
"not",
"in",
"self",
".",
"pipe_names",
":",
"raise",
"ValueError",
"(",
"Errors",
".",
"E001",
".",
"format",
"(",
"name",
"=",
"name",
",",
"opts",
"=",
"self",
".",
"pipe_name... | Remove a component from the pipeline.
name (unicode): Name of the component to remove.
RETURNS (tuple): A `(name, component)` tuple of the removed component.
DOCS: https://spacy.io/api/language#remove_pipe | [
"Remove",
"a",
"component",
"from",
"the",
"pipeline",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/language.py#L353-L363 |
21,277 | explosion/spaCy | spacy/language.py | Language.update | def update(self, docs, golds, drop=0.0, sgd=None, losses=None, component_cfg=None):
"""Update the models in the pipeline.
docs (iterable): A batch of `Doc` objects.
golds (iterable): A batch of `GoldParse` objects.
drop (float): The droput rate.
sgd (callable): An optimizer.
... | python | def update(self, docs, golds, drop=0.0, sgd=None, losses=None, component_cfg=None):
"""Update the models in the pipeline.
docs (iterable): A batch of `Doc` objects.
golds (iterable): A batch of `GoldParse` objects.
drop (float): The droput rate.
sgd (callable): An optimizer.
... | [
"def",
"update",
"(",
"self",
",",
"docs",
",",
"golds",
",",
"drop",
"=",
"0.0",
",",
"sgd",
"=",
"None",
",",
"losses",
"=",
"None",
",",
"component_cfg",
"=",
"None",
")",
":",
"if",
"len",
"(",
"docs",
")",
"!=",
"len",
"(",
"golds",
")",
"... | Update the models in the pipeline.
docs (iterable): A batch of `Doc` objects.
golds (iterable): A batch of `GoldParse` objects.
drop (float): The droput rate.
sgd (callable): An optimizer.
RETURNS (dict): Results from the update.
DOCS: https://spacy.io/api/language#upda... | [
"Update",
"the",
"models",
"in",
"the",
"pipeline",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/language.py#L408-L459 |
21,278 | explosion/spaCy | spacy/language.py | Language.rehearse | def rehearse(self, docs, sgd=None, losses=None, config=None):
"""Make a "rehearsal" update to the models in the pipeline, to prevent
forgetting. Rehearsal updates run an initial copy of the model over some
data, and update the model so its current predictions are more like the
initial on... | python | def rehearse(self, docs, sgd=None, losses=None, config=None):
"""Make a "rehearsal" update to the models in the pipeline, to prevent
forgetting. Rehearsal updates run an initial copy of the model over some
data, and update the model so its current predictions are more like the
initial on... | [
"def",
"rehearse",
"(",
"self",
",",
"docs",
",",
"sgd",
"=",
"None",
",",
"losses",
"=",
"None",
",",
"config",
"=",
"None",
")",
":",
"# TODO: document",
"if",
"len",
"(",
"docs",
")",
"==",
"0",
":",
"return",
"if",
"sgd",
"is",
"None",
":",
"... | Make a "rehearsal" update to the models in the pipeline, to prevent
forgetting. Rehearsal updates run an initial copy of the model over some
data, and update the model so its current predictions are more like the
initial ones. This is useful for keeping a pre-trained model on-track,
even... | [
"Make",
"a",
"rehearsal",
"update",
"to",
"the",
"models",
"in",
"the",
"pipeline",
"to",
"prevent",
"forgetting",
".",
"Rehearsal",
"updates",
"run",
"an",
"initial",
"copy",
"of",
"the",
"model",
"over",
"some",
"data",
"and",
"update",
"the",
"model",
"... | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/language.py#L461-L511 |
21,279 | explosion/spaCy | spacy/language.py | Language.preprocess_gold | def preprocess_gold(self, docs_golds):
"""Can be called before training to pre-process gold data. By default,
it handles nonprojectivity and adds missing tags to the tag map.
docs_golds (iterable): Tuples of `Doc` and `GoldParse` objects.
YIELDS (tuple): Tuples of preprocessed `Doc` and... | python | def preprocess_gold(self, docs_golds):
"""Can be called before training to pre-process gold data. By default,
it handles nonprojectivity and adds missing tags to the tag map.
docs_golds (iterable): Tuples of `Doc` and `GoldParse` objects.
YIELDS (tuple): Tuples of preprocessed `Doc` and... | [
"def",
"preprocess_gold",
"(",
"self",
",",
"docs_golds",
")",
":",
"for",
"name",
",",
"proc",
"in",
"self",
".",
"pipeline",
":",
"if",
"hasattr",
"(",
"proc",
",",
"\"preprocess_gold\"",
")",
":",
"docs_golds",
"=",
"proc",
".",
"preprocess_gold",
"(",
... | Can be called before training to pre-process gold data. By default,
it handles nonprojectivity and adds missing tags to the tag map.
docs_golds (iterable): Tuples of `Doc` and `GoldParse` objects.
YIELDS (tuple): Tuples of preprocessed `Doc` and `GoldParse` objects. | [
"Can",
"be",
"called",
"before",
"training",
"to",
"pre",
"-",
"process",
"gold",
"data",
".",
"By",
"default",
"it",
"handles",
"nonprojectivity",
"and",
"adds",
"missing",
"tags",
"to",
"the",
"tag",
"map",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/language.py#L513-L524 |
21,280 | explosion/spaCy | spacy/language.py | Language.begin_training | def begin_training(self, get_gold_tuples=None, sgd=None, component_cfg=None, **cfg):
"""Allocate models, pre-process training data and acquire a trainer and
optimizer. Used as a contextmanager.
get_gold_tuples (function): Function returning gold data
component_cfg (dict): Config paramet... | python | def begin_training(self, get_gold_tuples=None, sgd=None, component_cfg=None, **cfg):
"""Allocate models, pre-process training data and acquire a trainer and
optimizer. Used as a contextmanager.
get_gold_tuples (function): Function returning gold data
component_cfg (dict): Config paramet... | [
"def",
"begin_training",
"(",
"self",
",",
"get_gold_tuples",
"=",
"None",
",",
"sgd",
"=",
"None",
",",
"component_cfg",
"=",
"None",
",",
"*",
"*",
"cfg",
")",
":",
"if",
"get_gold_tuples",
"is",
"None",
":",
"get_gold_tuples",
"=",
"lambda",
":",
"[",... | Allocate models, pre-process training data and acquire a trainer and
optimizer. Used as a contextmanager.
get_gold_tuples (function): Function returning gold data
component_cfg (dict): Config parameters for specific components.
**cfg: Config parameters.
RETURNS: An optimizer.
... | [
"Allocate",
"models",
"pre",
"-",
"process",
"training",
"data",
"and",
"acquire",
"a",
"trainer",
"and",
"optimizer",
".",
"Used",
"as",
"a",
"contextmanager",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/language.py#L526-L567 |
21,281 | explosion/spaCy | spacy/language.py | Language.resume_training | def resume_training(self, sgd=None, **cfg):
"""Continue training a pre-trained model.
Create and return an optimizer, and initialize "rehearsal" for any pipeline
component that has a .rehearse() method. Rehearsal is used to prevent
models from "forgetting" their initialised "knowledge".... | python | def resume_training(self, sgd=None, **cfg):
"""Continue training a pre-trained model.
Create and return an optimizer, and initialize "rehearsal" for any pipeline
component that has a .rehearse() method. Rehearsal is used to prevent
models from "forgetting" their initialised "knowledge".... | [
"def",
"resume_training",
"(",
"self",
",",
"sgd",
"=",
"None",
",",
"*",
"*",
"cfg",
")",
":",
"if",
"cfg",
".",
"get",
"(",
"\"device\"",
",",
"-",
"1",
")",
">=",
"0",
":",
"util",
".",
"use_gpu",
"(",
"cfg",
"[",
"\"device\"",
"]",
")",
"if... | Continue training a pre-trained model.
Create and return an optimizer, and initialize "rehearsal" for any pipeline
component that has a .rehearse() method. Rehearsal is used to prevent
models from "forgetting" their initialised "knowledge". To perform
rehearsal, collect samples of text ... | [
"Continue",
"training",
"a",
"pre",
"-",
"trained",
"model",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/language.py#L569-L591 |
21,282 | explosion/spaCy | spacy/language.py | Language.use_params | def use_params(self, params, **cfg):
"""Replace weights of models in the pipeline with those provided in the
params dictionary. Can be used as a contextmanager, in which case,
models go back to their original weights after the block.
params (dict): A dictionary of parameters keyed by mo... | python | def use_params(self, params, **cfg):
"""Replace weights of models in the pipeline with those provided in the
params dictionary. Can be used as a contextmanager, in which case,
models go back to their original weights after the block.
params (dict): A dictionary of parameters keyed by mo... | [
"def",
"use_params",
"(",
"self",
",",
"params",
",",
"*",
"*",
"cfg",
")",
":",
"contexts",
"=",
"[",
"pipe",
".",
"use_params",
"(",
"params",
")",
"for",
"name",
",",
"pipe",
"in",
"self",
".",
"pipeline",
"if",
"hasattr",
"(",
"pipe",
",",
"\"u... | Replace weights of models in the pipeline with those provided in the
params dictionary. Can be used as a contextmanager, in which case,
models go back to their original weights after the block.
params (dict): A dictionary of parameters keyed by model ID.
**cfg: Config parameters.
... | [
"Replace",
"weights",
"of",
"models",
"in",
"the",
"pipeline",
"with",
"those",
"provided",
"in",
"the",
"params",
"dictionary",
".",
"Can",
"be",
"used",
"as",
"a",
"contextmanager",
"in",
"which",
"case",
"models",
"go",
"back",
"to",
"their",
"original",
... | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/language.py#L619-L648 |
21,283 | explosion/spaCy | spacy/language.py | Language.pipe | def pipe(
self,
texts,
as_tuples=False,
n_threads=-1,
batch_size=1000,
disable=[],
cleanup=False,
component_cfg=None,
):
"""Process texts as a stream, and yield `Doc` objects in order.
texts (iterator): A sequence of texts to process.
... | python | def pipe(
self,
texts,
as_tuples=False,
n_threads=-1,
batch_size=1000,
disable=[],
cleanup=False,
component_cfg=None,
):
"""Process texts as a stream, and yield `Doc` objects in order.
texts (iterator): A sequence of texts to process.
... | [
"def",
"pipe",
"(",
"self",
",",
"texts",
",",
"as_tuples",
"=",
"False",
",",
"n_threads",
"=",
"-",
"1",
",",
"batch_size",
"=",
"1000",
",",
"disable",
"=",
"[",
"]",
",",
"cleanup",
"=",
"False",
",",
"component_cfg",
"=",
"None",
",",
")",
":"... | Process texts as a stream, and yield `Doc` objects in order.
texts (iterator): A sequence of texts to process.
as_tuples (bool): If set to True, inputs should be a sequence of
(text, context) tuples. Output will then be a sequence of
(doc, context) tuples. Defaults to False.
... | [
"Process",
"texts",
"as",
"a",
"stream",
"and",
"yield",
"Doc",
"objects",
"in",
"order",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/language.py#L650-L733 |
21,284 | explosion/spaCy | spacy/language.py | Language.to_disk | def to_disk(self, path, exclude=tuple(), disable=None):
"""Save the current state to a directory. If a model is loaded, this
will include the model.
path (unicode or Path): Path to a directory, which will be created if
it doesn't exist.
exclude (list): Names of components o... | python | def to_disk(self, path, exclude=tuple(), disable=None):
"""Save the current state to a directory. If a model is loaded, this
will include the model.
path (unicode or Path): Path to a directory, which will be created if
it doesn't exist.
exclude (list): Names of components o... | [
"def",
"to_disk",
"(",
"self",
",",
"path",
",",
"exclude",
"=",
"tuple",
"(",
")",
",",
"disable",
"=",
"None",
")",
":",
"if",
"disable",
"is",
"not",
"None",
":",
"deprecation_warning",
"(",
"Warnings",
".",
"W014",
")",
"exclude",
"=",
"disable",
... | Save the current state to a directory. If a model is loaded, this
will include the model.
path (unicode or Path): Path to a directory, which will be created if
it doesn't exist.
exclude (list): Names of components or serialization fields to exclude.
DOCS: https://spacy.io/... | [
"Save",
"the",
"current",
"state",
"to",
"a",
"directory",
".",
"If",
"a",
"model",
"is",
"loaded",
"this",
"will",
"include",
"the",
"model",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/language.py#L735-L761 |
21,285 | explosion/spaCy | spacy/language.py | Language.from_disk | def from_disk(self, path, exclude=tuple(), disable=None):
"""Loads state from a directory. Modifies the object in place and
returns it. If the saved `Language` object contains a model, the
model will be loaded.
path (unicode or Path): A path to a directory.
exclude (list): Names... | python | def from_disk(self, path, exclude=tuple(), disable=None):
"""Loads state from a directory. Modifies the object in place and
returns it. If the saved `Language` object contains a model, the
model will be loaded.
path (unicode or Path): A path to a directory.
exclude (list): Names... | [
"def",
"from_disk",
"(",
"self",
",",
"path",
",",
"exclude",
"=",
"tuple",
"(",
")",
",",
"disable",
"=",
"None",
")",
":",
"if",
"disable",
"is",
"not",
"None",
":",
"deprecation_warning",
"(",
"Warnings",
".",
"W014",
")",
"exclude",
"=",
"disable",... | Loads state from a directory. Modifies the object in place and
returns it. If the saved `Language` object contains a model, the
model will be loaded.
path (unicode or Path): A path to a directory.
exclude (list): Names of components or serialization fields to exclude.
RETURNS (L... | [
"Loads",
"state",
"from",
"a",
"directory",
".",
"Modifies",
"the",
"object",
"in",
"place",
"and",
"returns",
"it",
".",
"If",
"the",
"saved",
"Language",
"object",
"contains",
"a",
"model",
"the",
"model",
"will",
"be",
"loaded",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/language.py#L763-L793 |
21,286 | explosion/spaCy | spacy/language.py | Language.to_bytes | def to_bytes(self, exclude=tuple(), disable=None, **kwargs):
"""Serialize the current state to a binary string.
exclude (list): Names of components or serialization fields to exclude.
RETURNS (bytes): The serialized form of the `Language` object.
DOCS: https://spacy.io/api/language#to_... | python | def to_bytes(self, exclude=tuple(), disable=None, **kwargs):
"""Serialize the current state to a binary string.
exclude (list): Names of components or serialization fields to exclude.
RETURNS (bytes): The serialized form of the `Language` object.
DOCS: https://spacy.io/api/language#to_... | [
"def",
"to_bytes",
"(",
"self",
",",
"exclude",
"=",
"tuple",
"(",
")",
",",
"disable",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"disable",
"is",
"not",
"None",
":",
"deprecation_warning",
"(",
"Warnings",
".",
"W014",
")",
"exclude",
"=... | Serialize the current state to a binary string.
exclude (list): Names of components or serialization fields to exclude.
RETURNS (bytes): The serialized form of the `Language` object.
DOCS: https://spacy.io/api/language#to_bytes | [
"Serialize",
"the",
"current",
"state",
"to",
"a",
"binary",
"string",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/language.py#L795-L817 |
21,287 | explosion/spaCy | spacy/language.py | Language.from_bytes | def from_bytes(self, bytes_data, exclude=tuple(), disable=None, **kwargs):
"""Load state from a binary string.
bytes_data (bytes): The data to load from.
exclude (list): Names of components or serialization fields to exclude.
RETURNS (Language): The `Language` object.
DOCS: htt... | python | def from_bytes(self, bytes_data, exclude=tuple(), disable=None, **kwargs):
"""Load state from a binary string.
bytes_data (bytes): The data to load from.
exclude (list): Names of components or serialization fields to exclude.
RETURNS (Language): The `Language` object.
DOCS: htt... | [
"def",
"from_bytes",
"(",
"self",
",",
"bytes_data",
",",
"exclude",
"=",
"tuple",
"(",
")",
",",
"disable",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"disable",
"is",
"not",
"None",
":",
"deprecation_warning",
"(",
"Warnings",
".",
"W014",... | Load state from a binary string.
bytes_data (bytes): The data to load from.
exclude (list): Names of components or serialization fields to exclude.
RETURNS (Language): The `Language` object.
DOCS: https://spacy.io/api/language#from_bytes | [
"Load",
"state",
"from",
"a",
"binary",
"string",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/language.py#L819-L843 |
21,288 | explosion/spaCy | spacy/language.py | DisabledPipes.restore | def restore(self):
"""Restore the pipeline to its state when DisabledPipes was created."""
current, self.nlp.pipeline = self.nlp.pipeline, self.original_pipeline
unexpected = [name for name, pipe in current if not self.nlp.has_pipe(name)]
if unexpected:
# Don't change the pip... | python | def restore(self):
"""Restore the pipeline to its state when DisabledPipes was created."""
current, self.nlp.pipeline = self.nlp.pipeline, self.original_pipeline
unexpected = [name for name, pipe in current if not self.nlp.has_pipe(name)]
if unexpected:
# Don't change the pip... | [
"def",
"restore",
"(",
"self",
")",
":",
"current",
",",
"self",
".",
"nlp",
".",
"pipeline",
"=",
"self",
".",
"nlp",
".",
"pipeline",
",",
"self",
".",
"original_pipeline",
"unexpected",
"=",
"[",
"name",
"for",
"name",
",",
"pipe",
"in",
"current",
... | Restore the pipeline to its state when DisabledPipes was created. | [
"Restore",
"the",
"pipeline",
"to",
"its",
"state",
"when",
"DisabledPipes",
"was",
"created",
"."
] | 8ee4100f8ffb336886208a1ea827bf4c745e2709 | https://github.com/explosion/spaCy/blob/8ee4100f8ffb336886208a1ea827bf4c745e2709/spacy/language.py#L886-L894 |
21,289 | nvbn/thefuck | thefuck/corrector.py | get_loaded_rules | def get_loaded_rules(rules_paths):
"""Yields all available rules.
:type rules_paths: [Path]
:rtype: Iterable[Rule]
"""
for path in rules_paths:
if path.name != '__init__.py':
rule = Rule.from_path(path)
if rule.is_enabled:
yield rule | python | def get_loaded_rules(rules_paths):
"""Yields all available rules.
:type rules_paths: [Path]
:rtype: Iterable[Rule]
"""
for path in rules_paths:
if path.name != '__init__.py':
rule = Rule.from_path(path)
if rule.is_enabled:
yield rule | [
"def",
"get_loaded_rules",
"(",
"rules_paths",
")",
":",
"for",
"path",
"in",
"rules_paths",
":",
"if",
"path",
".",
"name",
"!=",
"'__init__.py'",
":",
"rule",
"=",
"Rule",
".",
"from_path",
"(",
"path",
")",
"if",
"rule",
".",
"is_enabled",
":",
"yield... | Yields all available rules.
:type rules_paths: [Path]
:rtype: Iterable[Rule] | [
"Yields",
"all",
"available",
"rules",
"."
] | 40ab4eb62db57627bff10cf029d29c94704086a2 | https://github.com/nvbn/thefuck/blob/40ab4eb62db57627bff10cf029d29c94704086a2/thefuck/corrector.py#L8-L19 |
21,290 | nvbn/thefuck | thefuck/corrector.py | get_rules_import_paths | def get_rules_import_paths():
"""Yields all rules import paths.
:rtype: Iterable[Path]
"""
# Bundled rules:
yield Path(__file__).parent.joinpath('rules')
# Rules defined by user:
yield settings.user_dir.joinpath('rules')
# Packages with third-party rules:
for path in sys.path:
... | python | def get_rules_import_paths():
"""Yields all rules import paths.
:rtype: Iterable[Path]
"""
# Bundled rules:
yield Path(__file__).parent.joinpath('rules')
# Rules defined by user:
yield settings.user_dir.joinpath('rules')
# Packages with third-party rules:
for path in sys.path:
... | [
"def",
"get_rules_import_paths",
"(",
")",
":",
"# Bundled rules:",
"yield",
"Path",
"(",
"__file__",
")",
".",
"parent",
".",
"joinpath",
"(",
"'rules'",
")",
"# Rules defined by user:",
"yield",
"settings",
".",
"user_dir",
".",
"joinpath",
"(",
"'rules'",
")"... | Yields all rules import paths.
:rtype: Iterable[Path] | [
"Yields",
"all",
"rules",
"import",
"paths",
"."
] | 40ab4eb62db57627bff10cf029d29c94704086a2 | https://github.com/nvbn/thefuck/blob/40ab4eb62db57627bff10cf029d29c94704086a2/thefuck/corrector.py#L22-L37 |
21,291 | nvbn/thefuck | thefuck/corrector.py | get_rules | def get_rules():
"""Returns all enabled rules.
:rtype: [Rule]
"""
paths = [rule_path for path in get_rules_import_paths()
for rule_path in sorted(path.glob('*.py'))]
return sorted(get_loaded_rules(paths),
key=lambda rule: rule.priority) | python | def get_rules():
"""Returns all enabled rules.
:rtype: [Rule]
"""
paths = [rule_path for path in get_rules_import_paths()
for rule_path in sorted(path.glob('*.py'))]
return sorted(get_loaded_rules(paths),
key=lambda rule: rule.priority) | [
"def",
"get_rules",
"(",
")",
":",
"paths",
"=",
"[",
"rule_path",
"for",
"path",
"in",
"get_rules_import_paths",
"(",
")",
"for",
"rule_path",
"in",
"sorted",
"(",
"path",
".",
"glob",
"(",
"'*.py'",
")",
")",
"]",
"return",
"sorted",
"(",
"get_loaded_r... | Returns all enabled rules.
:rtype: [Rule] | [
"Returns",
"all",
"enabled",
"rules",
"."
] | 40ab4eb62db57627bff10cf029d29c94704086a2 | https://github.com/nvbn/thefuck/blob/40ab4eb62db57627bff10cf029d29c94704086a2/thefuck/corrector.py#L40-L49 |
21,292 | nvbn/thefuck | thefuck/corrector.py | organize_commands | def organize_commands(corrected_commands):
"""Yields sorted commands without duplicates.
:type corrected_commands: Iterable[thefuck.types.CorrectedCommand]
:rtype: Iterable[thefuck.types.CorrectedCommand]
"""
try:
first_command = next(corrected_commands)
yield first_command
exc... | python | def organize_commands(corrected_commands):
"""Yields sorted commands without duplicates.
:type corrected_commands: Iterable[thefuck.types.CorrectedCommand]
:rtype: Iterable[thefuck.types.CorrectedCommand]
"""
try:
first_command = next(corrected_commands)
yield first_command
exc... | [
"def",
"organize_commands",
"(",
"corrected_commands",
")",
":",
"try",
":",
"first_command",
"=",
"next",
"(",
"corrected_commands",
")",
"yield",
"first_command",
"except",
"StopIteration",
":",
"return",
"without_duplicates",
"=",
"{",
"command",
"for",
"command"... | Yields sorted commands without duplicates.
:type corrected_commands: Iterable[thefuck.types.CorrectedCommand]
:rtype: Iterable[thefuck.types.CorrectedCommand] | [
"Yields",
"sorted",
"commands",
"without",
"duplicates",
"."
] | 40ab4eb62db57627bff10cf029d29c94704086a2 | https://github.com/nvbn/thefuck/blob/40ab4eb62db57627bff10cf029d29c94704086a2/thefuck/corrector.py#L52-L78 |
21,293 | nvbn/thefuck | thefuck/corrector.py | get_corrected_commands | def get_corrected_commands(command):
"""Returns generator with sorted and unique corrected commands.
:type command: thefuck.types.Command
:rtype: Iterable[thefuck.types.CorrectedCommand]
"""
corrected_commands = (
corrected for rule in get_rules()
if rule.is_match(command)
... | python | def get_corrected_commands(command):
"""Returns generator with sorted and unique corrected commands.
:type command: thefuck.types.Command
:rtype: Iterable[thefuck.types.CorrectedCommand]
"""
corrected_commands = (
corrected for rule in get_rules()
if rule.is_match(command)
... | [
"def",
"get_corrected_commands",
"(",
"command",
")",
":",
"corrected_commands",
"=",
"(",
"corrected",
"for",
"rule",
"in",
"get_rules",
"(",
")",
"if",
"rule",
".",
"is_match",
"(",
"command",
")",
"for",
"corrected",
"in",
"rule",
".",
"get_corrected_comman... | Returns generator with sorted and unique corrected commands.
:type command: thefuck.types.Command
:rtype: Iterable[thefuck.types.CorrectedCommand] | [
"Returns",
"generator",
"with",
"sorted",
"and",
"unique",
"corrected",
"commands",
"."
] | 40ab4eb62db57627bff10cf029d29c94704086a2 | https://github.com/nvbn/thefuck/blob/40ab4eb62db57627bff10cf029d29c94704086a2/thefuck/corrector.py#L81-L92 |
21,294 | nvbn/thefuck | thefuck/entrypoints/fix_command.py | fix_command | def fix_command(known_args):
"""Fixes previous command. Used when `thefuck` called without arguments."""
settings.init(known_args)
with logs.debug_time('Total'):
logs.debug(u'Run with settings: {}'.format(pformat(settings)))
raw_command = _get_raw_command(known_args)
try:
... | python | def fix_command(known_args):
"""Fixes previous command. Used when `thefuck` called without arguments."""
settings.init(known_args)
with logs.debug_time('Total'):
logs.debug(u'Run with settings: {}'.format(pformat(settings)))
raw_command = _get_raw_command(known_args)
try:
... | [
"def",
"fix_command",
"(",
"known_args",
")",
":",
"settings",
".",
"init",
"(",
"known_args",
")",
"with",
"logs",
".",
"debug_time",
"(",
"'Total'",
")",
":",
"logs",
".",
"debug",
"(",
"u'Run with settings: {}'",
".",
"format",
"(",
"pformat",
"(",
"set... | Fixes previous command. Used when `thefuck` called without arguments. | [
"Fixes",
"previous",
"command",
".",
"Used",
"when",
"thefuck",
"called",
"without",
"arguments",
"."
] | 40ab4eb62db57627bff10cf029d29c94704086a2 | https://github.com/nvbn/thefuck/blob/40ab4eb62db57627bff10cf029d29c94704086a2/thefuck/entrypoints/fix_command.py#L28-L47 |
21,295 | nvbn/thefuck | thefuck/output_readers/shell_logger.py | get_output | def get_output(script):
"""Gets command output from shell logger."""
with logs.debug_time(u'Read output from external shell logger'):
commands = _get_last_n(const.SHELL_LOGGER_LIMIT)
for command in commands:
if command['command'] == script:
lines = _get_output_lines(c... | python | def get_output(script):
"""Gets command output from shell logger."""
with logs.debug_time(u'Read output from external shell logger'):
commands = _get_last_n(const.SHELL_LOGGER_LIMIT)
for command in commands:
if command['command'] == script:
lines = _get_output_lines(c... | [
"def",
"get_output",
"(",
"script",
")",
":",
"with",
"logs",
".",
"debug_time",
"(",
"u'Read output from external shell logger'",
")",
":",
"commands",
"=",
"_get_last_n",
"(",
"const",
".",
"SHELL_LOGGER_LIMIT",
")",
"for",
"command",
"in",
"commands",
":",
"i... | Gets command output from shell logger. | [
"Gets",
"command",
"output",
"from",
"shell",
"logger",
"."
] | 40ab4eb62db57627bff10cf029d29c94704086a2 | https://github.com/nvbn/thefuck/blob/40ab4eb62db57627bff10cf029d29c94704086a2/thefuck/output_readers/shell_logger.py#L49-L60 |
21,296 | nvbn/thefuck | thefuck/shells/generic.py | Generic._get_history_lines | def _get_history_lines(self):
"""Returns list of history entries."""
history_file_name = self._get_history_file_name()
if os.path.isfile(history_file_name):
with io.open(history_file_name, 'r',
encoding='utf-8', errors='ignore') as history_file:
... | python | def _get_history_lines(self):
"""Returns list of history entries."""
history_file_name = self._get_history_file_name()
if os.path.isfile(history_file_name):
with io.open(history_file_name, 'r',
encoding='utf-8', errors='ignore') as history_file:
... | [
"def",
"_get_history_lines",
"(",
"self",
")",
":",
"history_file_name",
"=",
"self",
".",
"_get_history_file_name",
"(",
")",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"history_file_name",
")",
":",
"with",
"io",
".",
"open",
"(",
"history_file_name",
",... | Returns list of history entries. | [
"Returns",
"list",
"of",
"history",
"entries",
"."
] | 40ab4eb62db57627bff10cf029d29c94704086a2 | https://github.com/nvbn/thefuck/blob/40ab4eb62db57627bff10cf029d29c94704086a2/thefuck/shells/generic.py#L54-L69 |
21,297 | nvbn/thefuck | thefuck/shells/generic.py | Generic.split_command | def split_command(self, command):
"""Split the command using shell-like syntax."""
encoded = self.encode_utf8(command)
try:
splitted = [s.replace("??", "\\ ") for s in shlex.split(encoded.replace('\\ ', '??'))]
except ValueError:
splitted = encoded.split(' ')
... | python | def split_command(self, command):
"""Split the command using shell-like syntax."""
encoded = self.encode_utf8(command)
try:
splitted = [s.replace("??", "\\ ") for s in shlex.split(encoded.replace('\\ ', '??'))]
except ValueError:
splitted = encoded.split(' ')
... | [
"def",
"split_command",
"(",
"self",
",",
"command",
")",
":",
"encoded",
"=",
"self",
".",
"encode_utf8",
"(",
"command",
")",
"try",
":",
"splitted",
"=",
"[",
"s",
".",
"replace",
"(",
"\"??\"",
",",
"\"\\\\ \"",
")",
"for",
"s",
"in",
"shlex",
".... | Split the command using shell-like syntax. | [
"Split",
"the",
"command",
"using",
"shell",
"-",
"like",
"syntax",
"."
] | 40ab4eb62db57627bff10cf029d29c94704086a2 | https://github.com/nvbn/thefuck/blob/40ab4eb62db57627bff10cf029d29c94704086a2/thefuck/shells/generic.py#L80-L89 |
21,298 | nvbn/thefuck | thefuck/shells/generic.py | Generic.quote | def quote(self, s):
"""Return a shell-escaped version of the string s."""
if six.PY2:
from pipes import quote
else:
from shlex import quote
return quote(s) | python | def quote(self, s):
"""Return a shell-escaped version of the string s."""
if six.PY2:
from pipes import quote
else:
from shlex import quote
return quote(s) | [
"def",
"quote",
"(",
"self",
",",
"s",
")",
":",
"if",
"six",
".",
"PY2",
":",
"from",
"pipes",
"import",
"quote",
"else",
":",
"from",
"shlex",
"import",
"quote",
"return",
"quote",
"(",
"s",
")"
] | Return a shell-escaped version of the string s. | [
"Return",
"a",
"shell",
"-",
"escaped",
"version",
"of",
"the",
"string",
"s",
"."
] | 40ab4eb62db57627bff10cf029d29c94704086a2 | https://github.com/nvbn/thefuck/blob/40ab4eb62db57627bff10cf029d29c94704086a2/thefuck/shells/generic.py#L101-L109 |
21,299 | nvbn/thefuck | thefuck/shells/fish.py | Fish._put_to_history | def _put_to_history(self, command_script):
"""Puts command script to shell history."""
history_file_name = self._get_history_file_name()
if os.path.isfile(history_file_name):
with open(history_file_name, 'a') as history:
entry = self._get_history_line(command_script)
... | python | def _put_to_history(self, command_script):
"""Puts command script to shell history."""
history_file_name = self._get_history_file_name()
if os.path.isfile(history_file_name):
with open(history_file_name, 'a') as history:
entry = self._get_history_line(command_script)
... | [
"def",
"_put_to_history",
"(",
"self",
",",
"command_script",
")",
":",
"history_file_name",
"=",
"self",
".",
"_get_history_file_name",
"(",
")",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"history_file_name",
")",
":",
"with",
"open",
"(",
"history_file_na... | Puts command script to shell history. | [
"Puts",
"command",
"script",
"to",
"shell",
"history",
"."
] | 40ab4eb62db57627bff10cf029d29c94704086a2 | https://github.com/nvbn/thefuck/blob/40ab4eb62db57627bff10cf029d29c94704086a2/thefuck/shells/fish.py#L120-L129 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.