partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | StreamingQuery.lastProgress | Returns the most recent :class:`StreamingQueryProgress` update of this streaming query or
None if there were no progress updates
:return: a map | python/pyspark/sql/streaming.py | def lastProgress(self):
"""
Returns the most recent :class:`StreamingQueryProgress` update of this streaming query or
None if there were no progress updates
:return: a map
"""
lastProgress = self._jsq.lastProgress()
if lastProgress:
return json.loads(l... | def lastProgress(self):
"""
Returns the most recent :class:`StreamingQueryProgress` update of this streaming query or
None if there were no progress updates
:return: a map
"""
lastProgress = self._jsq.lastProgress()
if lastProgress:
return json.loads(l... | [
"Returns",
"the",
"most",
"recent",
":",
"class",
":",
"StreamingQueryProgress",
"update",
"of",
"this",
"streaming",
"query",
"or",
"None",
"if",
"there",
"were",
"no",
"progress",
"updates",
":",
"return",
":",
"a",
"map"
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/streaming.py#L124-L134 | [
"def",
"lastProgress",
"(",
"self",
")",
":",
"lastProgress",
"=",
"self",
".",
"_jsq",
".",
"lastProgress",
"(",
")",
"if",
"lastProgress",
":",
"return",
"json",
".",
"loads",
"(",
"lastProgress",
".",
"json",
"(",
")",
")",
"else",
":",
"return",
"N... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | StreamingQuery.exception | :return: the StreamingQueryException if the query was terminated by an exception, or None. | python/pyspark/sql/streaming.py | def exception(self):
"""
:return: the StreamingQueryException if the query was terminated by an exception, or None.
"""
if self._jsq.exception().isDefined():
je = self._jsq.exception().get()
msg = je.toString().split(': ', 1)[1] # Drop the Java StreamingQueryExce... | def exception(self):
"""
:return: the StreamingQueryException if the query was terminated by an exception, or None.
"""
if self._jsq.exception().isDefined():
je = self._jsq.exception().get()
msg = je.toString().split(': ', 1)[1] # Drop the Java StreamingQueryExce... | [
":",
"return",
":",
"the",
"StreamingQueryException",
"if",
"the",
"query",
"was",
"terminated",
"by",
"an",
"exception",
"or",
"None",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/streaming.py#L181-L191 | [
"def",
"exception",
"(",
"self",
")",
":",
"if",
"self",
".",
"_jsq",
".",
"exception",
"(",
")",
".",
"isDefined",
"(",
")",
":",
"je",
"=",
"self",
".",
"_jsq",
".",
"exception",
"(",
")",
".",
"get",
"(",
")",
"msg",
"=",
"je",
".",
"toStrin... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | StreamingQueryManager.awaitAnyTermination | Wait until any of the queries on the associated SQLContext has terminated since the
creation of the context, or since :func:`resetTerminated()` was called. If any query was
terminated with an exception, then the exception will be thrown.
If `timeout` is set, it returns whether the query has term... | python/pyspark/sql/streaming.py | def awaitAnyTermination(self, timeout=None):
"""Wait until any of the queries on the associated SQLContext has terminated since the
creation of the context, or since :func:`resetTerminated()` was called. If any query was
terminated with an exception, then the exception will be thrown.
If... | def awaitAnyTermination(self, timeout=None):
"""Wait until any of the queries on the associated SQLContext has terminated since the
creation of the context, or since :func:`resetTerminated()` was called. If any query was
terminated with an exception, then the exception will be thrown.
If... | [
"Wait",
"until",
"any",
"of",
"the",
"queries",
"on",
"the",
"associated",
"SQLContext",
"has",
"terminated",
"since",
"the",
"creation",
"of",
"the",
"context",
"or",
"since",
":",
"func",
":",
"resetTerminated",
"()",
"was",
"called",
".",
"If",
"any",
"... | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/streaming.py#L240-L265 | [
"def",
"awaitAnyTermination",
"(",
"self",
",",
"timeout",
"=",
"None",
")",
":",
"if",
"timeout",
"is",
"not",
"None",
":",
"if",
"not",
"isinstance",
"(",
"timeout",
",",
"(",
"int",
",",
"float",
")",
")",
"or",
"timeout",
"<",
"0",
":",
"raise",
... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | DataStreamReader.load | Loads a data stream from a data source and returns it as a :class`DataFrame`.
.. note:: Evolving.
:param path: optional string for file-system backed data sources.
:param format: optional string for format of the data source. Default to 'parquet'.
:param schema: optional :class:`pyspar... | python/pyspark/sql/streaming.py | def load(self, path=None, format=None, schema=None, **options):
"""Loads a data stream from a data source and returns it as a :class`DataFrame`.
.. note:: Evolving.
:param path: optional string for file-system backed data sources.
:param format: optional string for format of the data s... | def load(self, path=None, format=None, schema=None, **options):
"""Loads a data stream from a data source and returns it as a :class`DataFrame`.
.. note:: Evolving.
:param path: optional string for file-system backed data sources.
:param format: optional string for format of the data s... | [
"Loads",
"a",
"data",
"stream",
"from",
"a",
"data",
"source",
"and",
"returns",
"it",
"as",
"a",
":",
"class",
"DataFrame",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/streaming.py#L370-L400 | [
"def",
"load",
"(",
"self",
",",
"path",
"=",
"None",
",",
"format",
"=",
"None",
",",
"schema",
"=",
"None",
",",
"*",
"*",
"options",
")",
":",
"if",
"format",
"is",
"not",
"None",
":",
"self",
".",
"format",
"(",
"format",
")",
"if",
"schema",... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | DataStreamReader.json | Loads a JSON file stream and returns the results as a :class:`DataFrame`.
`JSON Lines <http://jsonlines.org/>`_ (newline-delimited JSON) is supported by default.
For JSON (one record per file), set the ``multiLine`` parameter to ``true``.
If the ``schema`` parameter is not specified, this func... | python/pyspark/sql/streaming.py | def json(self, path, schema=None, primitivesAsString=None, prefersDecimal=None,
allowComments=None, allowUnquotedFieldNames=None, allowSingleQuotes=None,
allowNumericLeadingZero=None, allowBackslashEscapingAnyCharacter=None,
mode=None, columnNameOfCorruptRecord=None, dateFormat=No... | def json(self, path, schema=None, primitivesAsString=None, prefersDecimal=None,
allowComments=None, allowUnquotedFieldNames=None, allowSingleQuotes=None,
allowNumericLeadingZero=None, allowBackslashEscapingAnyCharacter=None,
mode=None, columnNameOfCorruptRecord=None, dateFormat=No... | [
"Loads",
"a",
"JSON",
"file",
"stream",
"and",
"returns",
"the",
"results",
"as",
"a",
":",
"class",
":",
"DataFrame",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/streaming.py#L403-L503 | [
"def",
"json",
"(",
"self",
",",
"path",
",",
"schema",
"=",
"None",
",",
"primitivesAsString",
"=",
"None",
",",
"prefersDecimal",
"=",
"None",
",",
"allowComments",
"=",
"None",
",",
"allowUnquotedFieldNames",
"=",
"None",
",",
"allowSingleQuotes",
"=",
"N... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | DataStreamReader.orc | Loads a ORC file stream, returning the result as a :class:`DataFrame`.
.. note:: Evolving.
>>> orc_sdf = spark.readStream.schema(sdf_schema).orc(tempfile.mkdtemp())
>>> orc_sdf.isStreaming
True
>>> orc_sdf.schema == sdf_schema
True | python/pyspark/sql/streaming.py | def orc(self, path):
"""Loads a ORC file stream, returning the result as a :class:`DataFrame`.
.. note:: Evolving.
>>> orc_sdf = spark.readStream.schema(sdf_schema).orc(tempfile.mkdtemp())
>>> orc_sdf.isStreaming
True
>>> orc_sdf.schema == sdf_schema
True
... | def orc(self, path):
"""Loads a ORC file stream, returning the result as a :class:`DataFrame`.
.. note:: Evolving.
>>> orc_sdf = spark.readStream.schema(sdf_schema).orc(tempfile.mkdtemp())
>>> orc_sdf.isStreaming
True
>>> orc_sdf.schema == sdf_schema
True
... | [
"Loads",
"a",
"ORC",
"file",
"stream",
"returning",
"the",
"result",
"as",
"a",
":",
"class",
":",
"DataFrame",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/streaming.py#L506-L520 | [
"def",
"orc",
"(",
"self",
",",
"path",
")",
":",
"if",
"isinstance",
"(",
"path",
",",
"basestring",
")",
":",
"return",
"self",
".",
"_df",
"(",
"self",
".",
"_jreader",
".",
"orc",
"(",
"path",
")",
")",
"else",
":",
"raise",
"TypeError",
"(",
... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | DataStreamReader.parquet | Loads a Parquet file stream, returning the result as a :class:`DataFrame`.
You can set the following Parquet-specific option(s) for reading Parquet files:
* ``mergeSchema``: sets whether we should merge schemas collected from all \
Parquet part-files. This will override ``spark.sql.... | python/pyspark/sql/streaming.py | def parquet(self, path):
"""Loads a Parquet file stream, returning the result as a :class:`DataFrame`.
You can set the following Parquet-specific option(s) for reading Parquet files:
* ``mergeSchema``: sets whether we should merge schemas collected from all \
Parquet part-fi... | def parquet(self, path):
"""Loads a Parquet file stream, returning the result as a :class:`DataFrame`.
You can set the following Parquet-specific option(s) for reading Parquet files:
* ``mergeSchema``: sets whether we should merge schemas collected from all \
Parquet part-fi... | [
"Loads",
"a",
"Parquet",
"file",
"stream",
"returning",
"the",
"result",
"as",
"a",
":",
"class",
":",
"DataFrame",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/streaming.py#L523-L542 | [
"def",
"parquet",
"(",
"self",
",",
"path",
")",
":",
"if",
"isinstance",
"(",
"path",
",",
"basestring",
")",
":",
"return",
"self",
".",
"_df",
"(",
"self",
".",
"_jreader",
".",
"parquet",
"(",
"path",
")",
")",
"else",
":",
"raise",
"TypeError",
... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | DataStreamReader.text | Loads a text file stream and returns a :class:`DataFrame` whose schema starts with a
string column named "value", and followed by partitioned columns if there
are any.
The text files must be encoded as UTF-8.
By default, each line in the text file is a new row in the resulting DataFrame... | python/pyspark/sql/streaming.py | def text(self, path, wholetext=False, lineSep=None):
"""
Loads a text file stream and returns a :class:`DataFrame` whose schema starts with a
string column named "value", and followed by partitioned columns if there
are any.
The text files must be encoded as UTF-8.
By de... | def text(self, path, wholetext=False, lineSep=None):
"""
Loads a text file stream and returns a :class:`DataFrame` whose schema starts with a
string column named "value", and followed by partitioned columns if there
are any.
The text files must be encoded as UTF-8.
By de... | [
"Loads",
"a",
"text",
"file",
"stream",
"and",
"returns",
"a",
":",
"class",
":",
"DataFrame",
"whose",
"schema",
"starts",
"with",
"a",
"string",
"column",
"named",
"value",
"and",
"followed",
"by",
"partitioned",
"columns",
"if",
"there",
"are",
"any",
"... | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/streaming.py#L546-L572 | [
"def",
"text",
"(",
"self",
",",
"path",
",",
"wholetext",
"=",
"False",
",",
"lineSep",
"=",
"None",
")",
":",
"self",
".",
"_set_opts",
"(",
"wholetext",
"=",
"wholetext",
",",
"lineSep",
"=",
"lineSep",
")",
"if",
"isinstance",
"(",
"path",
",",
"... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | DataStreamReader.csv | r"""Loads a CSV file stream and returns the result as a :class:`DataFrame`.
This function will go through the input once to determine the input schema if
``inferSchema`` is enabled. To avoid going through the entire data once, disable
``inferSchema`` option or specify the schema explicitly usin... | python/pyspark/sql/streaming.py | def csv(self, path, schema=None, sep=None, encoding=None, quote=None, escape=None,
comment=None, header=None, inferSchema=None, ignoreLeadingWhiteSpace=None,
ignoreTrailingWhiteSpace=None, nullValue=None, nanValue=None, positiveInf=None,
negativeInf=None, dateFormat=None, timestampFo... | def csv(self, path, schema=None, sep=None, encoding=None, quote=None, escape=None,
comment=None, header=None, inferSchema=None, ignoreLeadingWhiteSpace=None,
ignoreTrailingWhiteSpace=None, nullValue=None, nanValue=None, positiveInf=None,
negativeInf=None, dateFormat=None, timestampFo... | [
"r",
"Loads",
"a",
"CSV",
"file",
"stream",
"and",
"returns",
"the",
"result",
"as",
"a",
":",
"class",
":",
"DataFrame",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/streaming.py#L575-L705 | [
"def",
"csv",
"(",
"self",
",",
"path",
",",
"schema",
"=",
"None",
",",
"sep",
"=",
"None",
",",
"encoding",
"=",
"None",
",",
"quote",
"=",
"None",
",",
"escape",
"=",
"None",
",",
"comment",
"=",
"None",
",",
"header",
"=",
"None",
",",
"infer... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | DataStreamWriter.outputMode | Specifies how data of a streaming DataFrame/Dataset is written to a streaming sink.
Options include:
* `append`:Only the new rows in the streaming DataFrame/Dataset will be written to
the sink
* `complete`:All the rows in the streaming DataFrame/Dataset will be written to the sink
... | python/pyspark/sql/streaming.py | def outputMode(self, outputMode):
"""Specifies how data of a streaming DataFrame/Dataset is written to a streaming sink.
Options include:
* `append`:Only the new rows in the streaming DataFrame/Dataset will be written to
the sink
* `complete`:All the rows in the streaming Da... | def outputMode(self, outputMode):
"""Specifies how data of a streaming DataFrame/Dataset is written to a streaming sink.
Options include:
* `append`:Only the new rows in the streaming DataFrame/Dataset will be written to
the sink
* `complete`:All the rows in the streaming Da... | [
"Specifies",
"how",
"data",
"of",
"a",
"streaming",
"DataFrame",
"/",
"Dataset",
"is",
"written",
"to",
"a",
"streaming",
"sink",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/streaming.py#L729-L749 | [
"def",
"outputMode",
"(",
"self",
",",
"outputMode",
")",
":",
"if",
"not",
"outputMode",
"or",
"type",
"(",
"outputMode",
")",
"!=",
"str",
"or",
"len",
"(",
"outputMode",
".",
"strip",
"(",
")",
")",
"==",
"0",
":",
"raise",
"ValueError",
"(",
"'Th... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | DataStreamWriter.queryName | Specifies the name of the :class:`StreamingQuery` that can be started with
:func:`start`. This name must be unique among all the currently active queries
in the associated SparkSession.
.. note:: Evolving.
:param queryName: unique name for the query
>>> writer = sdf.writeStrea... | python/pyspark/sql/streaming.py | def queryName(self, queryName):
"""Specifies the name of the :class:`StreamingQuery` that can be started with
:func:`start`. This name must be unique among all the currently active queries
in the associated SparkSession.
.. note:: Evolving.
:param queryName: unique name for the... | def queryName(self, queryName):
"""Specifies the name of the :class:`StreamingQuery` that can be started with
:func:`start`. This name must be unique among all the currently active queries
in the associated SparkSession.
.. note:: Evolving.
:param queryName: unique name for the... | [
"Specifies",
"the",
"name",
"of",
"the",
":",
"class",
":",
"StreamingQuery",
"that",
"can",
"be",
"started",
"with",
":",
"func",
":",
"start",
".",
"This",
"name",
"must",
"be",
"unique",
"among",
"all",
"the",
"currently",
"active",
"queries",
"in",
"... | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/streaming.py#L811-L825 | [
"def",
"queryName",
"(",
"self",
",",
"queryName",
")",
":",
"if",
"not",
"queryName",
"or",
"type",
"(",
"queryName",
")",
"!=",
"str",
"or",
"len",
"(",
"queryName",
".",
"strip",
"(",
")",
")",
"==",
"0",
":",
"raise",
"ValueError",
"(",
"'The que... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | DataStreamWriter.trigger | Set the trigger for the stream query. If this is not set it will run the query as fast
as possible, which is equivalent to setting the trigger to ``processingTime='0 seconds'``.
.. note:: Evolving.
:param processingTime: a processing time interval as a string, e.g. '5 seconds', '1 minute'.
... | python/pyspark/sql/streaming.py | def trigger(self, processingTime=None, once=None, continuous=None):
"""Set the trigger for the stream query. If this is not set it will run the query as fast
as possible, which is equivalent to setting the trigger to ``processingTime='0 seconds'``.
.. note:: Evolving.
:param processing... | def trigger(self, processingTime=None, once=None, continuous=None):
"""Set the trigger for the stream query. If this is not set it will run the query as fast
as possible, which is equivalent to setting the trigger to ``processingTime='0 seconds'``.
.. note:: Evolving.
:param processing... | [
"Set",
"the",
"trigger",
"for",
"the",
"stream",
"query",
".",
"If",
"this",
"is",
"not",
"set",
"it",
"will",
"run",
"the",
"query",
"as",
"fast",
"as",
"possible",
"which",
"is",
"equivalent",
"to",
"setting",
"the",
"trigger",
"to",
"processingTime",
... | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/streaming.py#L829-L878 | [
"def",
"trigger",
"(",
"self",
",",
"processingTime",
"=",
"None",
",",
"once",
"=",
"None",
",",
"continuous",
"=",
"None",
")",
":",
"params",
"=",
"[",
"processingTime",
",",
"once",
",",
"continuous",
"]",
"if",
"params",
".",
"count",
"(",
"None",... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | DataStreamWriter.foreach | Sets the output of the streaming query to be processed using the provided writer ``f``.
This is often used to write the output of a streaming query to arbitrary storage systems.
The processing logic can be specified in two ways.
#. A **function** that takes a row as input.
This is a... | python/pyspark/sql/streaming.py | def foreach(self, f):
"""
Sets the output of the streaming query to be processed using the provided writer ``f``.
This is often used to write the output of a streaming query to arbitrary storage systems.
The processing logic can be specified in two ways.
#. A **function** that t... | def foreach(self, f):
"""
Sets the output of the streaming query to be processed using the provided writer ``f``.
This is often used to write the output of a streaming query to arbitrary storage systems.
The processing logic can be specified in two ways.
#. A **function** that t... | [
"Sets",
"the",
"output",
"of",
"the",
"streaming",
"query",
"to",
"be",
"processed",
"using",
"the",
"provided",
"writer",
"f",
".",
"This",
"is",
"often",
"used",
"to",
"write",
"the",
"output",
"of",
"a",
"streaming",
"query",
"to",
"arbitrary",
"storage... | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/streaming.py#L881-L1040 | [
"def",
"foreach",
"(",
"self",
",",
"f",
")",
":",
"from",
"pyspark",
".",
"rdd",
"import",
"_wrap_function",
"from",
"pyspark",
".",
"serializers",
"import",
"PickleSerializer",
",",
"AutoBatchedSerializer",
"from",
"pyspark",
".",
"taskcontext",
"import",
"Tas... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | DataStreamWriter.foreachBatch | Sets the output of the streaming query to be processed using the provided
function. This is supported only the in the micro-batch execution modes (that is, when the
trigger is not continuous). In every micro-batch, the provided function will be called in
every micro-batch with (i) the output row... | python/pyspark/sql/streaming.py | def foreachBatch(self, func):
"""
Sets the output of the streaming query to be processed using the provided
function. This is supported only the in the micro-batch execution modes (that is, when the
trigger is not continuous). In every micro-batch, the provided function will be called in... | def foreachBatch(self, func):
"""
Sets the output of the streaming query to be processed using the provided
function. This is supported only the in the micro-batch execution modes (that is, when the
trigger is not continuous). In every micro-batch, the provided function will be called in... | [
"Sets",
"the",
"output",
"of",
"the",
"streaming",
"query",
"to",
"be",
"processed",
"using",
"the",
"provided",
"function",
".",
"This",
"is",
"supported",
"only",
"the",
"in",
"the",
"micro",
"-",
"batch",
"execution",
"modes",
"(",
"that",
"is",
"when",... | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/streaming.py#L1043-L1069 | [
"def",
"foreachBatch",
"(",
"self",
",",
"func",
")",
":",
"from",
"pyspark",
".",
"java_gateway",
"import",
"ensure_callback_server_started",
"gw",
"=",
"self",
".",
"_spark",
".",
"_sc",
".",
"_gateway",
"java_import",
"(",
"gw",
".",
"jvm",
",",
"\"org.ap... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | DataStreamWriter.start | Streams the contents of the :class:`DataFrame` to a data source.
The data source is specified by the ``format`` and a set of ``options``.
If ``format`` is not specified, the default data source configured by
``spark.sql.sources.default`` will be used.
.. note:: Evolving.
:para... | python/pyspark/sql/streaming.py | def start(self, path=None, format=None, outputMode=None, partitionBy=None, queryName=None,
**options):
"""Streams the contents of the :class:`DataFrame` to a data source.
The data source is specified by the ``format`` and a set of ``options``.
If ``format`` is not specified, the d... | def start(self, path=None, format=None, outputMode=None, partitionBy=None, queryName=None,
**options):
"""Streams the contents of the :class:`DataFrame` to a data source.
The data source is specified by the ``format`` and a set of ``options``.
If ``format`` is not specified, the d... | [
"Streams",
"the",
"contents",
"of",
"the",
":",
"class",
":",
"DataFrame",
"to",
"a",
"data",
"source",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/streaming.py#L1073-L1128 | [
"def",
"start",
"(",
"self",
",",
"path",
"=",
"None",
",",
"format",
"=",
"None",
",",
"outputMode",
"=",
"None",
",",
"partitionBy",
"=",
"None",
",",
"queryName",
"=",
"None",
",",
"*",
"*",
"options",
")",
":",
"self",
".",
"options",
"(",
"*",... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | _make_cell_set_template_code | Get the Python compiler to emit LOAD_FAST(arg); STORE_DEREF
Notes
-----
In Python 3, we could use an easier function:
.. code-block:: python
def f():
cell = None
def _stub(value):
nonlocal cell
cell = value
return _stub
... | python/pyspark/cloudpickle.py | def _make_cell_set_template_code():
"""Get the Python compiler to emit LOAD_FAST(arg); STORE_DEREF
Notes
-----
In Python 3, we could use an easier function:
.. code-block:: python
def f():
cell = None
def _stub(value):
nonlocal cell
cell... | def _make_cell_set_template_code():
"""Get the Python compiler to emit LOAD_FAST(arg); STORE_DEREF
Notes
-----
In Python 3, we could use an easier function:
.. code-block:: python
def f():
cell = None
def _stub(value):
nonlocal cell
cell... | [
"Get",
"the",
"Python",
"compiler",
"to",
"emit",
"LOAD_FAST",
"(",
"arg",
")",
";",
"STORE_DEREF"
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/cloudpickle.py#L82-L149 | [
"def",
"_make_cell_set_template_code",
"(",
")",
":",
"def",
"inner",
"(",
"value",
")",
":",
"lambda",
":",
"cell",
"# make ``cell`` a closure so that we get a STORE_DEREF",
"cell",
"=",
"value",
"co",
"=",
"inner",
".",
"__code__",
"# NOTE: we are marking the cell var... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | is_tornado_coroutine | Return whether *func* is a Tornado coroutine function.
Running coroutines are not supported. | python/pyspark/cloudpickle.py | def is_tornado_coroutine(func):
"""
Return whether *func* is a Tornado coroutine function.
Running coroutines are not supported.
"""
if 'tornado.gen' not in sys.modules:
return False
gen = sys.modules['tornado.gen']
if not hasattr(gen, "is_coroutine_function"):
# Tornado vers... | def is_tornado_coroutine(func):
"""
Return whether *func* is a Tornado coroutine function.
Running coroutines are not supported.
"""
if 'tornado.gen' not in sys.modules:
return False
gen = sys.modules['tornado.gen']
if not hasattr(gen, "is_coroutine_function"):
# Tornado vers... | [
"Return",
"whether",
"*",
"func",
"*",
"is",
"a",
"Tornado",
"coroutine",
"function",
".",
"Running",
"coroutines",
"are",
"not",
"supported",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/cloudpickle.py#L905-L916 | [
"def",
"is_tornado_coroutine",
"(",
"func",
")",
":",
"if",
"'tornado.gen'",
"not",
"in",
"sys",
".",
"modules",
":",
"return",
"False",
"gen",
"=",
"sys",
".",
"modules",
"[",
"'tornado.gen'",
"]",
"if",
"not",
"hasattr",
"(",
"gen",
",",
"\"is_coroutine_... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | dump | Serialize obj as bytes streamed into file
protocol defaults to cloudpickle.DEFAULT_PROTOCOL which is an alias to
pickle.HIGHEST_PROTOCOL. This setting favors maximum communication speed
between processes running the same Python version.
Set protocol=pickle.DEFAULT_PROTOCOL instead if you need to ensur... | python/pyspark/cloudpickle.py | def dump(obj, file, protocol=None):
"""Serialize obj as bytes streamed into file
protocol defaults to cloudpickle.DEFAULT_PROTOCOL which is an alias to
pickle.HIGHEST_PROTOCOL. This setting favors maximum communication speed
between processes running the same Python version.
Set protocol=pickle.DE... | def dump(obj, file, protocol=None):
"""Serialize obj as bytes streamed into file
protocol defaults to cloudpickle.DEFAULT_PROTOCOL which is an alias to
pickle.HIGHEST_PROTOCOL. This setting favors maximum communication speed
between processes running the same Python version.
Set protocol=pickle.DE... | [
"Serialize",
"obj",
"as",
"bytes",
"streamed",
"into",
"file"
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/cloudpickle.py#L926-L936 | [
"def",
"dump",
"(",
"obj",
",",
"file",
",",
"protocol",
"=",
"None",
")",
":",
"CloudPickler",
"(",
"file",
",",
"protocol",
"=",
"protocol",
")",
".",
"dump",
"(",
"obj",
")"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | dumps | Serialize obj as a string of bytes allocated in memory
protocol defaults to cloudpickle.DEFAULT_PROTOCOL which is an alias to
pickle.HIGHEST_PROTOCOL. This setting favors maximum communication speed
between processes running the same Python version.
Set protocol=pickle.DEFAULT_PROTOCOL instead if you ... | python/pyspark/cloudpickle.py | def dumps(obj, protocol=None):
"""Serialize obj as a string of bytes allocated in memory
protocol defaults to cloudpickle.DEFAULT_PROTOCOL which is an alias to
pickle.HIGHEST_PROTOCOL. This setting favors maximum communication speed
between processes running the same Python version.
Set protocol=p... | def dumps(obj, protocol=None):
"""Serialize obj as a string of bytes allocated in memory
protocol defaults to cloudpickle.DEFAULT_PROTOCOL which is an alias to
pickle.HIGHEST_PROTOCOL. This setting favors maximum communication speed
between processes running the same Python version.
Set protocol=p... | [
"Serialize",
"obj",
"as",
"a",
"string",
"of",
"bytes",
"allocated",
"in",
"memory"
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/cloudpickle.py#L939-L955 | [
"def",
"dumps",
"(",
"obj",
",",
"protocol",
"=",
"None",
")",
":",
"file",
"=",
"StringIO",
"(",
")",
"try",
":",
"cp",
"=",
"CloudPickler",
"(",
"file",
",",
"protocol",
"=",
"protocol",
")",
"cp",
".",
"dump",
"(",
"obj",
")",
"return",
"file",
... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | _fill_function | Fills in the rest of function data into the skeleton function object
The skeleton itself is create by _make_skel_func(). | python/pyspark/cloudpickle.py | def _fill_function(*args):
"""Fills in the rest of function data into the skeleton function object
The skeleton itself is create by _make_skel_func().
"""
if len(args) == 2:
func = args[0]
state = args[1]
elif len(args) == 5:
# Backwards compat for cloudpickle v0.4.0, after ... | def _fill_function(*args):
"""Fills in the rest of function data into the skeleton function object
The skeleton itself is create by _make_skel_func().
"""
if len(args) == 2:
func = args[0]
state = args[1]
elif len(args) == 5:
# Backwards compat for cloudpickle v0.4.0, after ... | [
"Fills",
"in",
"the",
"rest",
"of",
"function",
"data",
"into",
"the",
"skeleton",
"function",
"object"
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/cloudpickle.py#L1060-L1113 | [
"def",
"_fill_function",
"(",
"*",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"==",
"2",
":",
"func",
"=",
"args",
"[",
"0",
"]",
"state",
"=",
"args",
"[",
"1",
"]",
"elif",
"len",
"(",
"args",
")",
"==",
"5",
":",
"# Backwards compat for ... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | _rehydrate_skeleton_class | Put attributes from `class_dict` back on `skeleton_class`.
See CloudPickler.save_dynamic_class for more info. | python/pyspark/cloudpickle.py | def _rehydrate_skeleton_class(skeleton_class, class_dict):
"""Put attributes from `class_dict` back on `skeleton_class`.
See CloudPickler.save_dynamic_class for more info.
"""
registry = None
for attrname, attr in class_dict.items():
if attrname == "_abc_impl":
registry = attr
... | def _rehydrate_skeleton_class(skeleton_class, class_dict):
"""Put attributes from `class_dict` back on `skeleton_class`.
See CloudPickler.save_dynamic_class for more info.
"""
registry = None
for attrname, attr in class_dict.items():
if attrname == "_abc_impl":
registry = attr
... | [
"Put",
"attributes",
"from",
"class_dict",
"back",
"on",
"skeleton_class",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/cloudpickle.py#L1146-L1161 | [
"def",
"_rehydrate_skeleton_class",
"(",
"skeleton_class",
",",
"class_dict",
")",
":",
"registry",
"=",
"None",
"for",
"attrname",
",",
"attr",
"in",
"class_dict",
".",
"items",
"(",
")",
":",
"if",
"attrname",
"==",
"\"_abc_impl\"",
":",
"registry",
"=",
"... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | _is_dynamic | Return True if the module is special module that cannot be imported by its
name. | python/pyspark/cloudpickle.py | def _is_dynamic(module):
"""
Return True if the module is special module that cannot be imported by its
name.
"""
# Quick check: module that have __file__ attribute are not dynamic modules.
if hasattr(module, '__file__'):
return False
if hasattr(module, '__spec__'):
return m... | def _is_dynamic(module):
"""
Return True if the module is special module that cannot be imported by its
name.
"""
# Quick check: module that have __file__ attribute are not dynamic modules.
if hasattr(module, '__file__'):
return False
if hasattr(module, '__spec__'):
return m... | [
"Return",
"True",
"if",
"the",
"module",
"is",
"special",
"module",
"that",
"cannot",
"be",
"imported",
"by",
"its",
"name",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/cloudpickle.py#L1164-L1188 | [
"def",
"_is_dynamic",
"(",
"module",
")",
":",
"# Quick check: module that have __file__ attribute are not dynamic modules.",
"if",
"hasattr",
"(",
"module",
",",
"'__file__'",
")",
":",
"return",
"False",
"if",
"hasattr",
"(",
"module",
",",
"'__spec__'",
")",
":",
... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | CloudPickler.save_codeobject | Save a code object | python/pyspark/cloudpickle.py | def save_codeobject(self, obj):
"""
Save a code object
"""
if PY3: # pragma: no branch
args = (
obj.co_argcount, obj.co_kwonlyargcount, obj.co_nlocals, obj.co_stacksize,
obj.co_flags, obj.co_code, obj.co_consts, obj.co_names, obj.co_varnames,
... | def save_codeobject(self, obj):
"""
Save a code object
"""
if PY3: # pragma: no branch
args = (
obj.co_argcount, obj.co_kwonlyargcount, obj.co_nlocals, obj.co_stacksize,
obj.co_flags, obj.co_code, obj.co_consts, obj.co_names, obj.co_varnames,
... | [
"Save",
"a",
"code",
"object"
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/cloudpickle.py#L298-L315 | [
"def",
"save_codeobject",
"(",
"self",
",",
"obj",
")",
":",
"if",
"PY3",
":",
"# pragma: no branch",
"args",
"=",
"(",
"obj",
".",
"co_argcount",
",",
"obj",
".",
"co_kwonlyargcount",
",",
"obj",
".",
"co_nlocals",
",",
"obj",
".",
"co_stacksize",
",",
... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | CloudPickler.save_function | Registered with the dispatch to handle all function types.
Determines what kind of function obj is (e.g. lambda, defined at
interactive prompt, etc) and handles the pickling appropriately. | python/pyspark/cloudpickle.py | def save_function(self, obj, name=None):
""" Registered with the dispatch to handle all function types.
Determines what kind of function obj is (e.g. lambda, defined at
interactive prompt, etc) and handles the pickling appropriately.
"""
try:
should_special_case = ob... | def save_function(self, obj, name=None):
""" Registered with the dispatch to handle all function types.
Determines what kind of function obj is (e.g. lambda, defined at
interactive prompt, etc) and handles the pickling appropriately.
"""
try:
should_special_case = ob... | [
"Registered",
"with",
"the",
"dispatch",
"to",
"handle",
"all",
"function",
"types",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/cloudpickle.py#L319-L412 | [
"def",
"save_function",
"(",
"self",
",",
"obj",
",",
"name",
"=",
"None",
")",
":",
"try",
":",
"should_special_case",
"=",
"obj",
"in",
"_BUILTIN_TYPE_CONSTRUCTORS",
"except",
"TypeError",
":",
"# Methods of builtin types aren't hashable in python 2.",
"should_special... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | CloudPickler.save_dynamic_class | Save a class that can't be stored as module global.
This method is used to serialize classes that are defined inside
functions, or that otherwise can't be serialized as attribute lookups
from global modules. | python/pyspark/cloudpickle.py | def save_dynamic_class(self, obj):
"""
Save a class that can't be stored as module global.
This method is used to serialize classes that are defined inside
functions, or that otherwise can't be serialized as attribute lookups
from global modules.
"""
clsdict = di... | def save_dynamic_class(self, obj):
"""
Save a class that can't be stored as module global.
This method is used to serialize classes that are defined inside
functions, or that otherwise can't be serialized as attribute lookups
from global modules.
"""
clsdict = di... | [
"Save",
"a",
"class",
"that",
"can",
"t",
"be",
"stored",
"as",
"module",
"global",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/cloudpickle.py#L463-L538 | [
"def",
"save_dynamic_class",
"(",
"self",
",",
"obj",
")",
":",
"clsdict",
"=",
"dict",
"(",
"obj",
".",
"__dict__",
")",
"# copy dict proxy to a dict",
"clsdict",
".",
"pop",
"(",
"'__weakref__'",
",",
"None",
")",
"# For ABCMeta in python3.7+, remove _abc_impl as ... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | CloudPickler.save_function_tuple | Pickles an actual func object.
A func comprises: code, globals, defaults, closure, and dict. We
extract and save these, injecting reducing functions at certain points
to recreate the func object. Keep in mind that some of these pieces
can contain a ref to the func itself. Thus, a nai... | python/pyspark/cloudpickle.py | def save_function_tuple(self, func):
""" Pickles an actual func object.
A func comprises: code, globals, defaults, closure, and dict. We
extract and save these, injecting reducing functions at certain points
to recreate the func object. Keep in mind that some of these pieces
... | def save_function_tuple(self, func):
""" Pickles an actual func object.
A func comprises: code, globals, defaults, closure, and dict. We
extract and save these, injecting reducing functions at certain points
to recreate the func object. Keep in mind that some of these pieces
... | [
"Pickles",
"an",
"actual",
"func",
"object",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/cloudpickle.py#L540-L596 | [
"def",
"save_function_tuple",
"(",
"self",
",",
"func",
")",
":",
"if",
"is_tornado_coroutine",
"(",
"func",
")",
":",
"self",
".",
"save_reduce",
"(",
"_rebuild_tornado_coroutine",
",",
"(",
"func",
".",
"__wrapped__",
",",
")",
",",
"obj",
"=",
"func",
"... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | CloudPickler.save_global | Save a "global".
The name of this method is somewhat misleading: all types get
dispatched here. | python/pyspark/cloudpickle.py | def save_global(self, obj, name=None, pack=struct.pack):
"""
Save a "global".
The name of this method is somewhat misleading: all types get
dispatched here.
"""
if obj is type(None):
return self.save_reduce(type, (None,), obj=obj)
elif obj is type(Ell... | def save_global(self, obj, name=None, pack=struct.pack):
"""
Save a "global".
The name of this method is somewhat misleading: all types get
dispatched here.
"""
if obj is type(None):
return self.save_reduce(type, (None,), obj=obj)
elif obj is type(Ell... | [
"Save",
"a",
"global",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/cloudpickle.py#L678-L707 | [
"def",
"save_global",
"(",
"self",
",",
"obj",
",",
"name",
"=",
"None",
",",
"pack",
"=",
"struct",
".",
"pack",
")",
":",
"if",
"obj",
"is",
"type",
"(",
"None",
")",
":",
"return",
"self",
".",
"save_reduce",
"(",
"type",
",",
"(",
"None",
","... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | CloudPickler.save_inst | Inner logic to save instance. Based off pickle.save_inst | python/pyspark/cloudpickle.py | def save_inst(self, obj):
"""Inner logic to save instance. Based off pickle.save_inst"""
cls = obj.__class__
# Try the dispatch table (pickle module doesn't do it)
f = self.dispatch.get(cls)
if f:
f(self, obj) # Call unbound method with explicit self
ret... | def save_inst(self, obj):
"""Inner logic to save instance. Based off pickle.save_inst"""
cls = obj.__class__
# Try the dispatch table (pickle module doesn't do it)
f = self.dispatch.get(cls)
if f:
f(self, obj) # Call unbound method with explicit self
ret... | [
"Inner",
"logic",
"to",
"save",
"instance",
".",
"Based",
"off",
"pickle",
".",
"save_inst"
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/cloudpickle.py#L725-L768 | [
"def",
"save_inst",
"(",
"self",
",",
"obj",
")",
":",
"cls",
"=",
"obj",
".",
"__class__",
"# Try the dispatch table (pickle module doesn't do it)",
"f",
"=",
"self",
".",
"dispatch",
".",
"get",
"(",
"cls",
")",
"if",
"f",
":",
"f",
"(",
"self",
",",
"... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | CloudPickler.save_itemgetter | itemgetter serializer (needed for namedtuple support) | python/pyspark/cloudpickle.py | def save_itemgetter(self, obj):
"""itemgetter serializer (needed for namedtuple support)"""
class Dummy:
def __getitem__(self, item):
return item
items = obj(Dummy())
if not isinstance(items, tuple):
items = (items,)
return self.save_reduce... | def save_itemgetter(self, obj):
"""itemgetter serializer (needed for namedtuple support)"""
class Dummy:
def __getitem__(self, item):
return item
items = obj(Dummy())
if not isinstance(items, tuple):
items = (items,)
return self.save_reduce... | [
"itemgetter",
"serializer",
"(",
"needed",
"for",
"namedtuple",
"support",
")"
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/cloudpickle.py#L786-L794 | [
"def",
"save_itemgetter",
"(",
"self",
",",
"obj",
")",
":",
"class",
"Dummy",
":",
"def",
"__getitem__",
"(",
"self",
",",
"item",
")",
":",
"return",
"item",
"items",
"=",
"obj",
"(",
"Dummy",
"(",
")",
")",
"if",
"not",
"isinstance",
"(",
"items",... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | CloudPickler.save_attrgetter | attrgetter serializer | python/pyspark/cloudpickle.py | def save_attrgetter(self, obj):
"""attrgetter serializer"""
class Dummy(object):
def __init__(self, attrs, index=None):
self.attrs = attrs
self.index = index
def __getattribute__(self, item):
attrs = object.__getattribute__(self, "a... | def save_attrgetter(self, obj):
"""attrgetter serializer"""
class Dummy(object):
def __init__(self, attrs, index=None):
self.attrs = attrs
self.index = index
def __getattribute__(self, item):
attrs = object.__getattribute__(self, "a... | [
"attrgetter",
"serializer"
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/cloudpickle.py#L799-L816 | [
"def",
"save_attrgetter",
"(",
"self",
",",
"obj",
")",
":",
"class",
"Dummy",
"(",
"object",
")",
":",
"def",
"__init__",
"(",
"self",
",",
"attrs",
",",
"index",
"=",
"None",
")",
":",
"self",
".",
"attrs",
"=",
"attrs",
"self",
".",
"index",
"="... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | Param._copy_new_parent | Copy the current param to a new parent, must be a dummy param. | python/pyspark/ml/param/__init__.py | def _copy_new_parent(self, parent):
"""Copy the current param to a new parent, must be a dummy param."""
if self.parent == "undefined":
param = copy.copy(self)
param.parent = parent.uid
return param
else:
raise ValueError("Cannot copy from non-dumm... | def _copy_new_parent(self, parent):
"""Copy the current param to a new parent, must be a dummy param."""
if self.parent == "undefined":
param = copy.copy(self)
param.parent = parent.uid
return param
else:
raise ValueError("Cannot copy from non-dumm... | [
"Copy",
"the",
"current",
"param",
"to",
"a",
"new",
"parent",
"must",
"be",
"a",
"dummy",
"param",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/param/__init__.py#L52-L59 | [
"def",
"_copy_new_parent",
"(",
"self",
",",
"parent",
")",
":",
"if",
"self",
".",
"parent",
"==",
"\"undefined\"",
":",
"param",
"=",
"copy",
".",
"copy",
"(",
"self",
")",
"param",
".",
"parent",
"=",
"parent",
".",
"uid",
"return",
"param",
"else",... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | TypeConverters.toList | Convert a value to a list, if possible. | python/pyspark/ml/param/__init__.py | def toList(value):
"""
Convert a value to a list, if possible.
"""
if type(value) == list:
return value
elif type(value) in [np.ndarray, tuple, xrange, array.array]:
return list(value)
elif isinstance(value, Vector):
return list(value.t... | def toList(value):
"""
Convert a value to a list, if possible.
"""
if type(value) == list:
return value
elif type(value) in [np.ndarray, tuple, xrange, array.array]:
return list(value)
elif isinstance(value, Vector):
return list(value.t... | [
"Convert",
"a",
"value",
"to",
"a",
"list",
"if",
"possible",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/param/__init__.py#L113-L124 | [
"def",
"toList",
"(",
"value",
")",
":",
"if",
"type",
"(",
"value",
")",
"==",
"list",
":",
"return",
"value",
"elif",
"type",
"(",
"value",
")",
"in",
"[",
"np",
".",
"ndarray",
",",
"tuple",
",",
"xrange",
",",
"array",
".",
"array",
"]",
":",... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | TypeConverters.toListFloat | Convert a value to list of floats, if possible. | python/pyspark/ml/param/__init__.py | def toListFloat(value):
"""
Convert a value to list of floats, if possible.
"""
if TypeConverters._can_convert_to_list(value):
value = TypeConverters.toList(value)
if all(map(lambda v: TypeConverters._is_numeric(v), value)):
return [float(v) for v ... | def toListFloat(value):
"""
Convert a value to list of floats, if possible.
"""
if TypeConverters._can_convert_to_list(value):
value = TypeConverters.toList(value)
if all(map(lambda v: TypeConverters._is_numeric(v), value)):
return [float(v) for v ... | [
"Convert",
"a",
"value",
"to",
"list",
"of",
"floats",
"if",
"possible",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/param/__init__.py#L127-L135 | [
"def",
"toListFloat",
"(",
"value",
")",
":",
"if",
"TypeConverters",
".",
"_can_convert_to_list",
"(",
"value",
")",
":",
"value",
"=",
"TypeConverters",
".",
"toList",
"(",
"value",
")",
"if",
"all",
"(",
"map",
"(",
"lambda",
"v",
":",
"TypeConverters",... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | TypeConverters.toListInt | Convert a value to list of ints, if possible. | python/pyspark/ml/param/__init__.py | def toListInt(value):
"""
Convert a value to list of ints, if possible.
"""
if TypeConverters._can_convert_to_list(value):
value = TypeConverters.toList(value)
if all(map(lambda v: TypeConverters._is_integer(v), value)):
return [int(v) for v in val... | def toListInt(value):
"""
Convert a value to list of ints, if possible.
"""
if TypeConverters._can_convert_to_list(value):
value = TypeConverters.toList(value)
if all(map(lambda v: TypeConverters._is_integer(v), value)):
return [int(v) for v in val... | [
"Convert",
"a",
"value",
"to",
"list",
"of",
"ints",
"if",
"possible",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/param/__init__.py#L138-L146 | [
"def",
"toListInt",
"(",
"value",
")",
":",
"if",
"TypeConverters",
".",
"_can_convert_to_list",
"(",
"value",
")",
":",
"value",
"=",
"TypeConverters",
".",
"toList",
"(",
"value",
")",
"if",
"all",
"(",
"map",
"(",
"lambda",
"v",
":",
"TypeConverters",
... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | TypeConverters.toListString | Convert a value to list of strings, if possible. | python/pyspark/ml/param/__init__.py | def toListString(value):
"""
Convert a value to list of strings, if possible.
"""
if TypeConverters._can_convert_to_list(value):
value = TypeConverters.toList(value)
if all(map(lambda v: TypeConverters._can_convert_to_string(v), value)):
return [Ty... | def toListString(value):
"""
Convert a value to list of strings, if possible.
"""
if TypeConverters._can_convert_to_list(value):
value = TypeConverters.toList(value)
if all(map(lambda v: TypeConverters._can_convert_to_string(v), value)):
return [Ty... | [
"Convert",
"a",
"value",
"to",
"list",
"of",
"strings",
"if",
"possible",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/param/__init__.py#L149-L157 | [
"def",
"toListString",
"(",
"value",
")",
":",
"if",
"TypeConverters",
".",
"_can_convert_to_list",
"(",
"value",
")",
":",
"value",
"=",
"TypeConverters",
".",
"toList",
"(",
"value",
")",
"if",
"all",
"(",
"map",
"(",
"lambda",
"v",
":",
"TypeConverters"... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | TypeConverters.toVector | Convert a value to a MLlib Vector, if possible. | python/pyspark/ml/param/__init__.py | def toVector(value):
"""
Convert a value to a MLlib Vector, if possible.
"""
if isinstance(value, Vector):
return value
elif TypeConverters._can_convert_to_list(value):
value = TypeConverters.toList(value)
if all(map(lambda v: TypeConverters._i... | def toVector(value):
"""
Convert a value to a MLlib Vector, if possible.
"""
if isinstance(value, Vector):
return value
elif TypeConverters._can_convert_to_list(value):
value = TypeConverters.toList(value)
if all(map(lambda v: TypeConverters._i... | [
"Convert",
"a",
"value",
"to",
"a",
"MLlib",
"Vector",
"if",
"possible",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/param/__init__.py#L160-L170 | [
"def",
"toVector",
"(",
"value",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"Vector",
")",
":",
"return",
"value",
"elif",
"TypeConverters",
".",
"_can_convert_to_list",
"(",
"value",
")",
":",
"value",
"=",
"TypeConverters",
".",
"toList",
"(",
"val... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | TypeConverters.toString | Convert a value to a string, if possible. | python/pyspark/ml/param/__init__.py | def toString(value):
"""
Convert a value to a string, if possible.
"""
if isinstance(value, basestring):
return value
elif type(value) in [np.string_, np.str_]:
return str(value)
elif type(value) == np.unicode_:
return unicode(value)
... | def toString(value):
"""
Convert a value to a string, if possible.
"""
if isinstance(value, basestring):
return value
elif type(value) in [np.string_, np.str_]:
return str(value)
elif type(value) == np.unicode_:
return unicode(value)
... | [
"Convert",
"a",
"value",
"to",
"a",
"string",
"if",
"possible",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/param/__init__.py#L202-L213 | [
"def",
"toString",
"(",
"value",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"basestring",
")",
":",
"return",
"value",
"elif",
"type",
"(",
"value",
")",
"in",
"[",
"np",
".",
"string_",
",",
"np",
".",
"str_",
"]",
":",
"return",
"str",
"(",... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | Params._copy_params | Copy all params defined on the class to current object. | python/pyspark/ml/param/__init__.py | def _copy_params(self):
"""
Copy all params defined on the class to current object.
"""
cls = type(self)
src_name_attrs = [(x, getattr(cls, x)) for x in dir(cls)]
src_params = list(filter(lambda nameAttr: isinstance(nameAttr[1], Param), src_name_attrs))
for name, ... | def _copy_params(self):
"""
Copy all params defined on the class to current object.
"""
cls = type(self)
src_name_attrs = [(x, getattr(cls, x)) for x in dir(cls)]
src_params = list(filter(lambda nameAttr: isinstance(nameAttr[1], Param), src_name_attrs))
for name, ... | [
"Copy",
"all",
"params",
"defined",
"on",
"the",
"class",
"to",
"current",
"object",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/param/__init__.py#L250-L258 | [
"def",
"_copy_params",
"(",
"self",
")",
":",
"cls",
"=",
"type",
"(",
"self",
")",
"src_name_attrs",
"=",
"[",
"(",
"x",
",",
"getattr",
"(",
"cls",
",",
"x",
")",
")",
"for",
"x",
"in",
"dir",
"(",
"cls",
")",
"]",
"src_params",
"=",
"list",
... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | Params.params | Returns all params ordered by name. The default implementation
uses :py:func:`dir` to get all attributes of type
:py:class:`Param`. | python/pyspark/ml/param/__init__.py | def params(self):
"""
Returns all params ordered by name. The default implementation
uses :py:func:`dir` to get all attributes of type
:py:class:`Param`.
"""
if self._params is None:
self._params = list(filter(lambda attr: isinstance(attr, Param),
... | def params(self):
"""
Returns all params ordered by name. The default implementation
uses :py:func:`dir` to get all attributes of type
:py:class:`Param`.
"""
if self._params is None:
self._params = list(filter(lambda attr: isinstance(attr, Param),
... | [
"Returns",
"all",
"params",
"ordered",
"by",
"name",
".",
"The",
"default",
"implementation",
"uses",
":",
"py",
":",
"func",
":",
"dir",
"to",
"get",
"all",
"attributes",
"of",
"type",
":",
"py",
":",
"class",
":",
"Param",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/param/__init__.py#L261-L271 | [
"def",
"params",
"(",
"self",
")",
":",
"if",
"self",
".",
"_params",
"is",
"None",
":",
"self",
".",
"_params",
"=",
"list",
"(",
"filter",
"(",
"lambda",
"attr",
":",
"isinstance",
"(",
"attr",
",",
"Param",
")",
",",
"[",
"getattr",
"(",
"self",... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | Params.explainParam | Explains a single param and returns its name, doc, and optional
default value and user-supplied value in a string. | python/pyspark/ml/param/__init__.py | def explainParam(self, param):
"""
Explains a single param and returns its name, doc, and optional
default value and user-supplied value in a string.
"""
param = self._resolveParam(param)
values = []
if self.isDefined(param):
if param in self._defaultP... | def explainParam(self, param):
"""
Explains a single param and returns its name, doc, and optional
default value and user-supplied value in a string.
"""
param = self._resolveParam(param)
values = []
if self.isDefined(param):
if param in self._defaultP... | [
"Explains",
"a",
"single",
"param",
"and",
"returns",
"its",
"name",
"doc",
"and",
"optional",
"default",
"value",
"and",
"user",
"-",
"supplied",
"value",
"in",
"a",
"string",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/param/__init__.py#L273-L288 | [
"def",
"explainParam",
"(",
"self",
",",
"param",
")",
":",
"param",
"=",
"self",
".",
"_resolveParam",
"(",
"param",
")",
"values",
"=",
"[",
"]",
"if",
"self",
".",
"isDefined",
"(",
"param",
")",
":",
"if",
"param",
"in",
"self",
".",
"_defaultPar... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | Params.getParam | Gets a param by its name. | python/pyspark/ml/param/__init__.py | def getParam(self, paramName):
"""
Gets a param by its name.
"""
param = getattr(self, paramName)
if isinstance(param, Param):
return param
else:
raise ValueError("Cannot find param with name %s." % paramName) | def getParam(self, paramName):
"""
Gets a param by its name.
"""
param = getattr(self, paramName)
if isinstance(param, Param):
return param
else:
raise ValueError("Cannot find param with name %s." % paramName) | [
"Gets",
"a",
"param",
"by",
"its",
"name",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/param/__init__.py#L297-L305 | [
"def",
"getParam",
"(",
"self",
",",
"paramName",
")",
":",
"param",
"=",
"getattr",
"(",
"self",
",",
"paramName",
")",
"if",
"isinstance",
"(",
"param",
",",
"Param",
")",
":",
"return",
"param",
"else",
":",
"raise",
"ValueError",
"(",
"\"Cannot find ... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | Params.isSet | Checks whether a param is explicitly set by user. | python/pyspark/ml/param/__init__.py | def isSet(self, param):
"""
Checks whether a param is explicitly set by user.
"""
param = self._resolveParam(param)
return param in self._paramMap | def isSet(self, param):
"""
Checks whether a param is explicitly set by user.
"""
param = self._resolveParam(param)
return param in self._paramMap | [
"Checks",
"whether",
"a",
"param",
"is",
"explicitly",
"set",
"by",
"user",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/param/__init__.py#L307-L312 | [
"def",
"isSet",
"(",
"self",
",",
"param",
")",
":",
"param",
"=",
"self",
".",
"_resolveParam",
"(",
"param",
")",
"return",
"param",
"in",
"self",
".",
"_paramMap"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | Params.hasDefault | Checks whether a param has a default value. | python/pyspark/ml/param/__init__.py | def hasDefault(self, param):
"""
Checks whether a param has a default value.
"""
param = self._resolveParam(param)
return param in self._defaultParamMap | def hasDefault(self, param):
"""
Checks whether a param has a default value.
"""
param = self._resolveParam(param)
return param in self._defaultParamMap | [
"Checks",
"whether",
"a",
"param",
"has",
"a",
"default",
"value",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/param/__init__.py#L314-L319 | [
"def",
"hasDefault",
"(",
"self",
",",
"param",
")",
":",
"param",
"=",
"self",
".",
"_resolveParam",
"(",
"param",
")",
"return",
"param",
"in",
"self",
".",
"_defaultParamMap"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | Params.hasParam | Tests whether this instance contains a param with a given
(string) name. | python/pyspark/ml/param/__init__.py | def hasParam(self, paramName):
"""
Tests whether this instance contains a param with a given
(string) name.
"""
if isinstance(paramName, basestring):
p = getattr(self, paramName, None)
return isinstance(p, Param)
else:
raise TypeError("... | def hasParam(self, paramName):
"""
Tests whether this instance contains a param with a given
(string) name.
"""
if isinstance(paramName, basestring):
p = getattr(self, paramName, None)
return isinstance(p, Param)
else:
raise TypeError("... | [
"Tests",
"whether",
"this",
"instance",
"contains",
"a",
"param",
"with",
"a",
"given",
"(",
"string",
")",
"name",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/param/__init__.py#L328-L337 | [
"def",
"hasParam",
"(",
"self",
",",
"paramName",
")",
":",
"if",
"isinstance",
"(",
"paramName",
",",
"basestring",
")",
":",
"p",
"=",
"getattr",
"(",
"self",
",",
"paramName",
",",
"None",
")",
"return",
"isinstance",
"(",
"p",
",",
"Param",
")",
... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | Params.getOrDefault | Gets the value of a param in the user-supplied param map or its
default value. Raises an error if neither is set. | python/pyspark/ml/param/__init__.py | def getOrDefault(self, param):
"""
Gets the value of a param in the user-supplied param map or its
default value. Raises an error if neither is set.
"""
param = self._resolveParam(param)
if param in self._paramMap:
return self._paramMap[param]
else:
... | def getOrDefault(self, param):
"""
Gets the value of a param in the user-supplied param map or its
default value. Raises an error if neither is set.
"""
param = self._resolveParam(param)
if param in self._paramMap:
return self._paramMap[param]
else:
... | [
"Gets",
"the",
"value",
"of",
"a",
"param",
"in",
"the",
"user",
"-",
"supplied",
"param",
"map",
"or",
"its",
"default",
"value",
".",
"Raises",
"an",
"error",
"if",
"neither",
"is",
"set",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/param/__init__.py#L339-L348 | [
"def",
"getOrDefault",
"(",
"self",
",",
"param",
")",
":",
"param",
"=",
"self",
".",
"_resolveParam",
"(",
"param",
")",
"if",
"param",
"in",
"self",
".",
"_paramMap",
":",
"return",
"self",
".",
"_paramMap",
"[",
"param",
"]",
"else",
":",
"return",... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | Params.extractParamMap | Extracts the embedded default param values and user-supplied
values, and then merges them with extra values from input into
a flat param map, where the latter value is used if there exist
conflicts, i.e., with ordering: default param values <
user-supplied values < extra.
:param... | python/pyspark/ml/param/__init__.py | def extractParamMap(self, extra=None):
"""
Extracts the embedded default param values and user-supplied
values, and then merges them with extra values from input into
a flat param map, where the latter value is used if there exist
conflicts, i.e., with ordering: default param val... | def extractParamMap(self, extra=None):
"""
Extracts the embedded default param values and user-supplied
values, and then merges them with extra values from input into
a flat param map, where the latter value is used if there exist
conflicts, i.e., with ordering: default param val... | [
"Extracts",
"the",
"embedded",
"default",
"param",
"values",
"and",
"user",
"-",
"supplied",
"values",
"and",
"then",
"merges",
"them",
"with",
"extra",
"values",
"from",
"input",
"into",
"a",
"flat",
"param",
"map",
"where",
"the",
"latter",
"value",
"is",
... | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/param/__init__.py#L350-L366 | [
"def",
"extractParamMap",
"(",
"self",
",",
"extra",
"=",
"None",
")",
":",
"if",
"extra",
"is",
"None",
":",
"extra",
"=",
"dict",
"(",
")",
"paramMap",
"=",
"self",
".",
"_defaultParamMap",
".",
"copy",
"(",
")",
"paramMap",
".",
"update",
"(",
"se... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | Params.copy | Creates a copy of this instance with the same uid and some
extra params. The default implementation creates a
shallow copy using :py:func:`copy.copy`, and then copies the
embedded and extra parameters over and returns the copy.
Subclasses should override this method if the default approa... | python/pyspark/ml/param/__init__.py | def copy(self, extra=None):
"""
Creates a copy of this instance with the same uid and some
extra params. The default implementation creates a
shallow copy using :py:func:`copy.copy`, and then copies the
embedded and extra parameters over and returns the copy.
Subclasses s... | def copy(self, extra=None):
"""
Creates a copy of this instance with the same uid and some
extra params. The default implementation creates a
shallow copy using :py:func:`copy.copy`, and then copies the
embedded and extra parameters over and returns the copy.
Subclasses s... | [
"Creates",
"a",
"copy",
"of",
"this",
"instance",
"with",
"the",
"same",
"uid",
"and",
"some",
"extra",
"params",
".",
"The",
"default",
"implementation",
"creates",
"a",
"shallow",
"copy",
"using",
":",
"py",
":",
"func",
":",
"copy",
".",
"copy",
"and"... | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/param/__init__.py#L368-L385 | [
"def",
"copy",
"(",
"self",
",",
"extra",
"=",
"None",
")",
":",
"if",
"extra",
"is",
"None",
":",
"extra",
"=",
"dict",
"(",
")",
"that",
"=",
"copy",
".",
"copy",
"(",
"self",
")",
"that",
".",
"_paramMap",
"=",
"{",
"}",
"that",
".",
"_defau... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | Params.set | Sets a parameter in the embedded param map. | python/pyspark/ml/param/__init__.py | def set(self, param, value):
"""
Sets a parameter in the embedded param map.
"""
self._shouldOwn(param)
try:
value = param.typeConverter(value)
except ValueError as e:
raise ValueError('Invalid param value given for param "%s". %s' % (param.name, e... | def set(self, param, value):
"""
Sets a parameter in the embedded param map.
"""
self._shouldOwn(param)
try:
value = param.typeConverter(value)
except ValueError as e:
raise ValueError('Invalid param value given for param "%s". %s' % (param.name, e... | [
"Sets",
"a",
"parameter",
"in",
"the",
"embedded",
"param",
"map",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/param/__init__.py#L387-L396 | [
"def",
"set",
"(",
"self",
",",
"param",
",",
"value",
")",
":",
"self",
".",
"_shouldOwn",
"(",
"param",
")",
"try",
":",
"value",
"=",
"param",
".",
"typeConverter",
"(",
"value",
")",
"except",
"ValueError",
"as",
"e",
":",
"raise",
"ValueError",
... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | Params._shouldOwn | Validates that the input param belongs to this Params instance. | python/pyspark/ml/param/__init__.py | def _shouldOwn(self, param):
"""
Validates that the input param belongs to this Params instance.
"""
if not (self.uid == param.parent and self.hasParam(param.name)):
raise ValueError("Param %r does not belong to %r." % (param, self)) | def _shouldOwn(self, param):
"""
Validates that the input param belongs to this Params instance.
"""
if not (self.uid == param.parent and self.hasParam(param.name)):
raise ValueError("Param %r does not belong to %r." % (param, self)) | [
"Validates",
"that",
"the",
"input",
"param",
"belongs",
"to",
"this",
"Params",
"instance",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/param/__init__.py#L398-L403 | [
"def",
"_shouldOwn",
"(",
"self",
",",
"param",
")",
":",
"if",
"not",
"(",
"self",
".",
"uid",
"==",
"param",
".",
"parent",
"and",
"self",
".",
"hasParam",
"(",
"param",
".",
"name",
")",
")",
":",
"raise",
"ValueError",
"(",
"\"Param %r does not bel... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | Params._resolveParam | Resolves a param and validates the ownership.
:param param: param name or the param instance, which must
belong to this Params instance
:return: resolved param instance | python/pyspark/ml/param/__init__.py | def _resolveParam(self, param):
"""
Resolves a param and validates the ownership.
:param param: param name or the param instance, which must
belong to this Params instance
:return: resolved param instance
"""
if isinstance(param, Param):
... | def _resolveParam(self, param):
"""
Resolves a param and validates the ownership.
:param param: param name or the param instance, which must
belong to this Params instance
:return: resolved param instance
"""
if isinstance(param, Param):
... | [
"Resolves",
"a",
"param",
"and",
"validates",
"the",
"ownership",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/param/__init__.py#L405-L419 | [
"def",
"_resolveParam",
"(",
"self",
",",
"param",
")",
":",
"if",
"isinstance",
"(",
"param",
",",
"Param",
")",
":",
"self",
".",
"_shouldOwn",
"(",
"param",
")",
"return",
"param",
"elif",
"isinstance",
"(",
"param",
",",
"basestring",
")",
":",
"re... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | Params._set | Sets user-supplied params. | python/pyspark/ml/param/__init__.py | def _set(self, **kwargs):
"""
Sets user-supplied params.
"""
for param, value in kwargs.items():
p = getattr(self, param)
if value is not None:
try:
value = p.typeConverter(value)
except TypeError as e:
... | def _set(self, **kwargs):
"""
Sets user-supplied params.
"""
for param, value in kwargs.items():
p = getattr(self, param)
if value is not None:
try:
value = p.typeConverter(value)
except TypeError as e:
... | [
"Sets",
"user",
"-",
"supplied",
"params",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/param/__init__.py#L431-L443 | [
"def",
"_set",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"param",
",",
"value",
"in",
"kwargs",
".",
"items",
"(",
")",
":",
"p",
"=",
"getattr",
"(",
"self",
",",
"param",
")",
"if",
"value",
"is",
"not",
"None",
":",
"try",
":",
... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | Params._setDefault | Sets default params. | python/pyspark/ml/param/__init__.py | def _setDefault(self, **kwargs):
"""
Sets default params.
"""
for param, value in kwargs.items():
p = getattr(self, param)
if value is not None and not isinstance(value, JavaObject):
try:
value = p.typeConverter(value)
... | def _setDefault(self, **kwargs):
"""
Sets default params.
"""
for param, value in kwargs.items():
p = getattr(self, param)
if value is not None and not isinstance(value, JavaObject):
try:
value = p.typeConverter(value)
... | [
"Sets",
"default",
"params",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/param/__init__.py#L452-L465 | [
"def",
"_setDefault",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"param",
",",
"value",
"in",
"kwargs",
".",
"items",
"(",
")",
":",
"p",
"=",
"getattr",
"(",
"self",
",",
"param",
")",
"if",
"value",
"is",
"not",
"None",
"and",
"not"... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | Params._copyValues | Copies param values from this instance to another instance for
params shared by them.
:param to: the target instance
:param extra: extra params to be copied
:return: the target instance with param values copied | python/pyspark/ml/param/__init__.py | def _copyValues(self, to, extra=None):
"""
Copies param values from this instance to another instance for
params shared by them.
:param to: the target instance
:param extra: extra params to be copied
:return: the target instance with param values copied
"""
... | def _copyValues(self, to, extra=None):
"""
Copies param values from this instance to another instance for
params shared by them.
:param to: the target instance
:param extra: extra params to be copied
:return: the target instance with param values copied
"""
... | [
"Copies",
"param",
"values",
"from",
"this",
"instance",
"to",
"another",
"instance",
"for",
"params",
"shared",
"by",
"them",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/param/__init__.py#L467-L486 | [
"def",
"_copyValues",
"(",
"self",
",",
"to",
",",
"extra",
"=",
"None",
")",
":",
"paramMap",
"=",
"self",
".",
"_paramMap",
".",
"copy",
"(",
")",
"if",
"extra",
"is",
"not",
"None",
":",
"paramMap",
".",
"update",
"(",
"extra",
")",
"for",
"para... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | Params._resetUid | Changes the uid of this instance. This updates both
the stored uid and the parent uid of params and param maps.
This is used by persistence (loading).
:param newUid: new uid to use, which is converted to unicode
:return: same instance, but with the uid and Param.parent values
... | python/pyspark/ml/param/__init__.py | def _resetUid(self, newUid):
"""
Changes the uid of this instance. This updates both
the stored uid and the parent uid of params and param maps.
This is used by persistence (loading).
:param newUid: new uid to use, which is converted to unicode
:return: same instance, but... | def _resetUid(self, newUid):
"""
Changes the uid of this instance. This updates both
the stored uid and the parent uid of params and param maps.
This is used by persistence (loading).
:param newUid: new uid to use, which is converted to unicode
:return: same instance, but... | [
"Changes",
"the",
"uid",
"of",
"this",
"instance",
".",
"This",
"updates",
"both",
"the",
"stored",
"uid",
"and",
"the",
"parent",
"uid",
"of",
"params",
"and",
"param",
"maps",
".",
"This",
"is",
"used",
"by",
"persistence",
"(",
"loading",
")",
".",
... | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/param/__init__.py#L488-L511 | [
"def",
"_resetUid",
"(",
"self",
",",
"newUid",
")",
":",
"newUid",
"=",
"unicode",
"(",
"newUid",
")",
"self",
".",
"uid",
"=",
"newUid",
"newDefaultParamMap",
"=",
"dict",
"(",
")",
"newParamMap",
"=",
"dict",
"(",
")",
"for",
"param",
"in",
"self",
... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | _to_java_object_rdd | Return an JavaRDD of Object by unpickling
It will convert each Python object into Java object by Pyrolite, whenever the
RDD is serialized in batch or not. | python/pyspark/ml/common.py | def _to_java_object_rdd(rdd):
""" Return an JavaRDD of Object by unpickling
It will convert each Python object into Java object by Pyrolite, whenever the
RDD is serialized in batch or not.
"""
rdd = rdd._reserialize(AutoBatchedSerializer(PickleSerializer()))
return rdd.ctx._jvm.org.apache.spark... | def _to_java_object_rdd(rdd):
""" Return an JavaRDD of Object by unpickling
It will convert each Python object into Java object by Pyrolite, whenever the
RDD is serialized in batch or not.
"""
rdd = rdd._reserialize(AutoBatchedSerializer(PickleSerializer()))
return rdd.ctx._jvm.org.apache.spark... | [
"Return",
"an",
"JavaRDD",
"of",
"Object",
"by",
"unpickling"
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/ml/common.py#L60-L67 | [
"def",
"_to_java_object_rdd",
"(",
"rdd",
")",
":",
"rdd",
"=",
"rdd",
".",
"_reserialize",
"(",
"AutoBatchedSerializer",
"(",
"PickleSerializer",
"(",
")",
")",
")",
"return",
"rdd",
".",
"ctx",
".",
"_jvm",
".",
"org",
".",
"apache",
".",
"spark",
".",... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | Broadcast.value | Return the broadcasted value | python/pyspark/broadcast.py | def value(self):
""" Return the broadcasted value
"""
if not hasattr(self, "_value") and self._path is not None:
# we only need to decrypt it here when encryption is enabled and
# if its on the driver, since executor decryption is handled already
if self._sc i... | def value(self):
""" Return the broadcasted value
"""
if not hasattr(self, "_value") and self._path is not None:
# we only need to decrypt it here when encryption is enabled and
# if its on the driver, since executor decryption is handled already
if self._sc i... | [
"Return",
"the",
"broadcasted",
"value"
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/broadcast.py#L135-L148 | [
"def",
"value",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"\"_value\"",
")",
"and",
"self",
".",
"_path",
"is",
"not",
"None",
":",
"# we only need to decrypt it here when encryption is enabled and",
"# if its on the driver, since executor decrypt... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | Broadcast.unpersist | Delete cached copies of this broadcast on the executors. If the
broadcast is used after this is called, it will need to be
re-sent to each executor.
:param blocking: Whether to block until unpersisting has completed | python/pyspark/broadcast.py | def unpersist(self, blocking=False):
"""
Delete cached copies of this broadcast on the executors. If the
broadcast is used after this is called, it will need to be
re-sent to each executor.
:param blocking: Whether to block until unpersisting has completed
"""
if... | def unpersist(self, blocking=False):
"""
Delete cached copies of this broadcast on the executors. If the
broadcast is used after this is called, it will need to be
re-sent to each executor.
:param blocking: Whether to block until unpersisting has completed
"""
if... | [
"Delete",
"cached",
"copies",
"of",
"this",
"broadcast",
"on",
"the",
"executors",
".",
"If",
"the",
"broadcast",
"is",
"used",
"after",
"this",
"is",
"called",
"it",
"will",
"need",
"to",
"be",
"re",
"-",
"sent",
"to",
"each",
"executor",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/broadcast.py#L150-L160 | [
"def",
"unpersist",
"(",
"self",
",",
"blocking",
"=",
"False",
")",
":",
"if",
"self",
".",
"_jbroadcast",
"is",
"None",
":",
"raise",
"Exception",
"(",
"\"Broadcast can only be unpersisted in driver\"",
")",
"self",
".",
"_jbroadcast",
".",
"unpersist",
"(",
... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | Broadcast.destroy | Destroy all data and metadata related to this broadcast variable.
Use this with caution; once a broadcast variable has been destroyed,
it cannot be used again.
.. versionchanged:: 3.0.0
Added optional argument `blocking` to specify whether to block until all
blocks are del... | python/pyspark/broadcast.py | def destroy(self, blocking=False):
"""
Destroy all data and metadata related to this broadcast variable.
Use this with caution; once a broadcast variable has been destroyed,
it cannot be used again.
.. versionchanged:: 3.0.0
Added optional argument `blocking` to speci... | def destroy(self, blocking=False):
"""
Destroy all data and metadata related to this broadcast variable.
Use this with caution; once a broadcast variable has been destroyed,
it cannot be used again.
.. versionchanged:: 3.0.0
Added optional argument `blocking` to speci... | [
"Destroy",
"all",
"data",
"and",
"metadata",
"related",
"to",
"this",
"broadcast",
"variable",
".",
"Use",
"this",
"with",
"caution",
";",
"once",
"a",
"broadcast",
"variable",
"has",
"been",
"destroyed",
"it",
"cannot",
"be",
"used",
"again",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/broadcast.py#L162-L175 | [
"def",
"destroy",
"(",
"self",
",",
"blocking",
"=",
"False",
")",
":",
"if",
"self",
".",
"_jbroadcast",
"is",
"None",
":",
"raise",
"Exception",
"(",
"\"Broadcast can only be destroyed in driver\"",
")",
"self",
".",
"_jbroadcast",
".",
"destroy",
"(",
"bloc... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | UserDefinedFunction._wrapped | Wrap this udf with a function and attach docstring from func | python/pyspark/sql/udf.py | def _wrapped(self):
"""
Wrap this udf with a function and attach docstring from func
"""
# It is possible for a callable instance without __name__ attribute or/and
# __module__ attribute to be wrapped here. For example, functools.partial. In this case,
# we should avoid ... | def _wrapped(self):
"""
Wrap this udf with a function and attach docstring from func
"""
# It is possible for a callable instance without __name__ attribute or/and
# __module__ attribute to be wrapped here. For example, functools.partial. In this case,
# we should avoid ... | [
"Wrap",
"this",
"udf",
"with",
"a",
"function",
"and",
"attach",
"docstring",
"from",
"func"
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/udf.py#L177-L204 | [
"def",
"_wrapped",
"(",
"self",
")",
":",
"# It is possible for a callable instance without __name__ attribute or/and",
"# __module__ attribute to be wrapped here. For example, functools.partial. In this case,",
"# we should avoid wrapping the attributes from the wrapped function to the wrapper",
... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | UDFRegistration.register | Register a Python function (including lambda function) or a user-defined function
as a SQL function.
:param name: name of the user-defined function in SQL statements.
:param f: a Python function, or a user-defined function. The user-defined function can
be either row-at-a-time or ve... | python/pyspark/sql/udf.py | def register(self, name, f, returnType=None):
"""Register a Python function (including lambda function) or a user-defined function
as a SQL function.
:param name: name of the user-defined function in SQL statements.
:param f: a Python function, or a user-defined function. The user-defin... | def register(self, name, f, returnType=None):
"""Register a Python function (including lambda function) or a user-defined function
as a SQL function.
:param name: name of the user-defined function in SQL statements.
:param f: a Python function, or a user-defined function. The user-defin... | [
"Register",
"a",
"Python",
"function",
"(",
"including",
"lambda",
"function",
")",
"or",
"a",
"user",
"-",
"defined",
"function",
"as",
"a",
"SQL",
"function",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/udf.py#L232-L341 | [
"def",
"register",
"(",
"self",
",",
"name",
",",
"f",
",",
"returnType",
"=",
"None",
")",
":",
"# This is to check whether the input function is from a user-defined function or",
"# Python function.",
"if",
"hasattr",
"(",
"f",
",",
"'asNondeterministic'",
")",
":",
... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | UDFRegistration.registerJavaFunction | Register a Java user-defined function as a SQL function.
In addition to a name and the function itself, the return type can be optionally specified.
When the return type is not specified we would infer it via reflection.
:param name: name of the user-defined function
:param javaClassNa... | python/pyspark/sql/udf.py | def registerJavaFunction(self, name, javaClassName, returnType=None):
"""Register a Java user-defined function as a SQL function.
In addition to a name and the function itself, the return type can be optionally specified.
When the return type is not specified we would infer it via reflection.
... | def registerJavaFunction(self, name, javaClassName, returnType=None):
"""Register a Java user-defined function as a SQL function.
In addition to a name and the function itself, the return type can be optionally specified.
When the return type is not specified we would infer it via reflection.
... | [
"Register",
"a",
"Java",
"user",
"-",
"defined",
"function",
"as",
"a",
"SQL",
"function",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/udf.py#L345-L378 | [
"def",
"registerJavaFunction",
"(",
"self",
",",
"name",
",",
"javaClassName",
",",
"returnType",
"=",
"None",
")",
":",
"jdt",
"=",
"None",
"if",
"returnType",
"is",
"not",
"None",
":",
"if",
"not",
"isinstance",
"(",
"returnType",
",",
"DataType",
")",
... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | UDFRegistration.registerJavaUDAF | Register a Java user-defined aggregate function as a SQL function.
:param name: name of the user-defined aggregate function
:param javaClassName: fully qualified name of java class
>>> spark.udf.registerJavaUDAF("javaUDAF", "test.org.apache.spark.sql.MyDoubleAvg")
>>> df = spark.create... | python/pyspark/sql/udf.py | def registerJavaUDAF(self, name, javaClassName):
"""Register a Java user-defined aggregate function as a SQL function.
:param name: name of the user-defined aggregate function
:param javaClassName: fully qualified name of java class
>>> spark.udf.registerJavaUDAF("javaUDAF", "test.org.... | def registerJavaUDAF(self, name, javaClassName):
"""Register a Java user-defined aggregate function as a SQL function.
:param name: name of the user-defined aggregate function
:param javaClassName: fully qualified name of java class
>>> spark.udf.registerJavaUDAF("javaUDAF", "test.org.... | [
"Register",
"a",
"Java",
"user",
"-",
"defined",
"aggregate",
"function",
"as",
"a",
"SQL",
"function",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/sql/udf.py#L382-L395 | [
"def",
"registerJavaUDAF",
"(",
"self",
",",
"name",
",",
"javaClassName",
")",
":",
"self",
".",
"sparkSession",
".",
"_jsparkSession",
".",
"udf",
"(",
")",
".",
"registerJavaUDAF",
"(",
"name",
",",
"javaClassName",
")"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | StreamingContext.getOrCreate | Either recreate a StreamingContext from checkpoint data or create a new StreamingContext.
If checkpoint data exists in the provided `checkpointPath`, then StreamingContext will be
recreated from the checkpoint data. If the data does not exist, then the provided setupFunc
will be used to create a... | python/pyspark/streaming/context.py | def getOrCreate(cls, checkpointPath, setupFunc):
"""
Either recreate a StreamingContext from checkpoint data or create a new StreamingContext.
If checkpoint data exists in the provided `checkpointPath`, then StreamingContext will be
recreated from the checkpoint data. If the data does no... | def getOrCreate(cls, checkpointPath, setupFunc):
"""
Either recreate a StreamingContext from checkpoint data or create a new StreamingContext.
If checkpoint data exists in the provided `checkpointPath`, then StreamingContext will be
recreated from the checkpoint data. If the data does no... | [
"Either",
"recreate",
"a",
"StreamingContext",
"from",
"checkpoint",
"data",
"or",
"create",
"a",
"new",
"StreamingContext",
".",
"If",
"checkpoint",
"data",
"exists",
"in",
"the",
"provided",
"checkpointPath",
"then",
"StreamingContext",
"will",
"be",
"recreated",
... | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/streaming/context.py#L88-L120 | [
"def",
"getOrCreate",
"(",
"cls",
",",
"checkpointPath",
",",
"setupFunc",
")",
":",
"cls",
".",
"_ensure_initialized",
"(",
")",
"gw",
"=",
"SparkContext",
".",
"_gateway",
"# Check whether valid checkpoint information exists in the given path",
"ssc_option",
"=",
"gw"... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | StreamingContext.getActive | Return either the currently active StreamingContext (i.e., if there is a context started
but not stopped) or None. | python/pyspark/streaming/context.py | def getActive(cls):
"""
Return either the currently active StreamingContext (i.e., if there is a context started
but not stopped) or None.
"""
activePythonContext = cls._activeContext
if activePythonContext is not None:
# Verify that the current running Java S... | def getActive(cls):
"""
Return either the currently active StreamingContext (i.e., if there is a context started
but not stopped) or None.
"""
activePythonContext = cls._activeContext
if activePythonContext is not None:
# Verify that the current running Java S... | [
"Return",
"either",
"the",
"currently",
"active",
"StreamingContext",
"(",
"i",
".",
"e",
".",
"if",
"there",
"is",
"a",
"context",
"started",
"but",
"not",
"stopped",
")",
"or",
"None",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/streaming/context.py#L123-L141 | [
"def",
"getActive",
"(",
"cls",
")",
":",
"activePythonContext",
"=",
"cls",
".",
"_activeContext",
"if",
"activePythonContext",
"is",
"not",
"None",
":",
"# Verify that the current running Java StreamingContext is active and is the same one",
"# backing the supposedly active Pyt... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | StreamingContext.getActiveOrCreate | Either return the active StreamingContext (i.e. currently started but not stopped),
or recreate a StreamingContext from checkpoint data or create a new StreamingContext
using the provided setupFunc function. If the checkpointPath is None or does not contain
valid checkpoint data, then setupFunc ... | python/pyspark/streaming/context.py | def getActiveOrCreate(cls, checkpointPath, setupFunc):
"""
Either return the active StreamingContext (i.e. currently started but not stopped),
or recreate a StreamingContext from checkpoint data or create a new StreamingContext
using the provided setupFunc function. If the checkpointPath... | def getActiveOrCreate(cls, checkpointPath, setupFunc):
"""
Either return the active StreamingContext (i.e. currently started but not stopped),
or recreate a StreamingContext from checkpoint data or create a new StreamingContext
using the provided setupFunc function. If the checkpointPath... | [
"Either",
"return",
"the",
"active",
"StreamingContext",
"(",
"i",
".",
"e",
".",
"currently",
"started",
"but",
"not",
"stopped",
")",
"or",
"recreate",
"a",
"StreamingContext",
"from",
"checkpoint",
"data",
"or",
"create",
"a",
"new",
"StreamingContext",
"us... | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/streaming/context.py#L144-L166 | [
"def",
"getActiveOrCreate",
"(",
"cls",
",",
"checkpointPath",
",",
"setupFunc",
")",
":",
"if",
"setupFunc",
"is",
"None",
":",
"raise",
"Exception",
"(",
"\"setupFunc cannot be None\"",
")",
"activeContext",
"=",
"cls",
".",
"getActive",
"(",
")",
"if",
"act... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | StreamingContext.awaitTermination | Wait for the execution to stop.
@param timeout: time to wait in seconds | python/pyspark/streaming/context.py | def awaitTermination(self, timeout=None):
"""
Wait for the execution to stop.
@param timeout: time to wait in seconds
"""
if timeout is None:
self._jssc.awaitTermination()
else:
self._jssc.awaitTerminationOrTimeout(int(timeout * 1000)) | def awaitTermination(self, timeout=None):
"""
Wait for the execution to stop.
@param timeout: time to wait in seconds
"""
if timeout is None:
self._jssc.awaitTermination()
else:
self._jssc.awaitTerminationOrTimeout(int(timeout * 1000)) | [
"Wait",
"for",
"the",
"execution",
"to",
"stop",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/streaming/context.py#L182-L191 | [
"def",
"awaitTermination",
"(",
"self",
",",
"timeout",
"=",
"None",
")",
":",
"if",
"timeout",
"is",
"None",
":",
"self",
".",
"_jssc",
".",
"awaitTermination",
"(",
")",
"else",
":",
"self",
".",
"_jssc",
".",
"awaitTerminationOrTimeout",
"(",
"int",
"... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | StreamingContext.stop | Stop the execution of the streams, with option of ensuring all
received data has been processed.
@param stopSparkContext: Stop the associated SparkContext or not
@param stopGracefully: Stop gracefully by waiting for the processing
of all received data to be complet... | python/pyspark/streaming/context.py | def stop(self, stopSparkContext=True, stopGraceFully=False):
"""
Stop the execution of the streams, with option of ensuring all
received data has been processed.
@param stopSparkContext: Stop the associated SparkContext or not
@param stopGracefully: Stop gracefully by waiting fo... | def stop(self, stopSparkContext=True, stopGraceFully=False):
"""
Stop the execution of the streams, with option of ensuring all
received data has been processed.
@param stopSparkContext: Stop the associated SparkContext or not
@param stopGracefully: Stop gracefully by waiting fo... | [
"Stop",
"the",
"execution",
"of",
"the",
"streams",
"with",
"option",
"of",
"ensuring",
"all",
"received",
"data",
"has",
"been",
"processed",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/streaming/context.py#L203-L215 | [
"def",
"stop",
"(",
"self",
",",
"stopSparkContext",
"=",
"True",
",",
"stopGraceFully",
"=",
"False",
")",
":",
"self",
".",
"_jssc",
".",
"stop",
"(",
"stopSparkContext",
",",
"stopGraceFully",
")",
"StreamingContext",
".",
"_activeContext",
"=",
"None",
"... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | StreamingContext.socketTextStream | Create an input from TCP source hostname:port. Data is received using
a TCP socket and receive byte is interpreted as UTF8 encoded ``\\n`` delimited
lines.
@param hostname: Hostname to connect to for receiving data
@param port: Port to connect to for receiving data
... | python/pyspark/streaming/context.py | def socketTextStream(self, hostname, port, storageLevel=StorageLevel.MEMORY_AND_DISK_2):
"""
Create an input from TCP source hostname:port. Data is received using
a TCP socket and receive byte is interpreted as UTF8 encoded ``\\n`` delimited
lines.
@param hostname: Hostname... | def socketTextStream(self, hostname, port, storageLevel=StorageLevel.MEMORY_AND_DISK_2):
"""
Create an input from TCP source hostname:port. Data is received using
a TCP socket and receive byte is interpreted as UTF8 encoded ``\\n`` delimited
lines.
@param hostname: Hostname... | [
"Create",
"an",
"input",
"from",
"TCP",
"source",
"hostname",
":",
"port",
".",
"Data",
"is",
"received",
"using",
"a",
"TCP",
"socket",
"and",
"receive",
"byte",
"is",
"interpreted",
"as",
"UTF8",
"encoded",
"\\\\",
"n",
"delimited",
"lines",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/streaming/context.py#L241-L253 | [
"def",
"socketTextStream",
"(",
"self",
",",
"hostname",
",",
"port",
",",
"storageLevel",
"=",
"StorageLevel",
".",
"MEMORY_AND_DISK_2",
")",
":",
"jlevel",
"=",
"self",
".",
"_sc",
".",
"_getJavaStorageLevel",
"(",
"storageLevel",
")",
"return",
"DStream",
"... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | StreamingContext.textFileStream | Create an input stream that monitors a Hadoop-compatible file system
for new files and reads them as text files. Files must be wrriten to the
monitored directory by "moving" them from another location within the same
file system. File names starting with . are ignored.
The text files mus... | python/pyspark/streaming/context.py | def textFileStream(self, directory):
"""
Create an input stream that monitors a Hadoop-compatible file system
for new files and reads them as text files. Files must be wrriten to the
monitored directory by "moving" them from another location within the same
file system. File name... | def textFileStream(self, directory):
"""
Create an input stream that monitors a Hadoop-compatible file system
for new files and reads them as text files. Files must be wrriten to the
monitored directory by "moving" them from another location within the same
file system. File name... | [
"Create",
"an",
"input",
"stream",
"that",
"monitors",
"a",
"Hadoop",
"-",
"compatible",
"file",
"system",
"for",
"new",
"files",
"and",
"reads",
"them",
"as",
"text",
"files",
".",
"Files",
"must",
"be",
"wrriten",
"to",
"the",
"monitored",
"directory",
"... | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/streaming/context.py#L255-L263 | [
"def",
"textFileStream",
"(",
"self",
",",
"directory",
")",
":",
"return",
"DStream",
"(",
"self",
".",
"_jssc",
".",
"textFileStream",
"(",
"directory",
")",
",",
"self",
",",
"UTF8Deserializer",
"(",
")",
")"
] | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | StreamingContext.binaryRecordsStream | Create an input stream that monitors a Hadoop-compatible file system
for new files and reads them as flat binary files with records of
fixed length. Files must be written to the monitored directory by "moving"
them from another location within the same file system.
File names starting wi... | python/pyspark/streaming/context.py | def binaryRecordsStream(self, directory, recordLength):
"""
Create an input stream that monitors a Hadoop-compatible file system
for new files and reads them as flat binary files with records of
fixed length. Files must be written to the monitored directory by "moving"
them from ... | def binaryRecordsStream(self, directory, recordLength):
"""
Create an input stream that monitors a Hadoop-compatible file system
for new files and reads them as flat binary files with records of
fixed length. Files must be written to the monitored directory by "moving"
them from ... | [
"Create",
"an",
"input",
"stream",
"that",
"monitors",
"a",
"Hadoop",
"-",
"compatible",
"file",
"system",
"for",
"new",
"files",
"and",
"reads",
"them",
"as",
"flat",
"binary",
"files",
"with",
"records",
"of",
"fixed",
"length",
".",
"Files",
"must",
"be... | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/streaming/context.py#L265-L277 | [
"def",
"binaryRecordsStream",
"(",
"self",
",",
"directory",
",",
"recordLength",
")",
":",
"return",
"DStream",
"(",
"self",
".",
"_jssc",
".",
"binaryRecordsStream",
"(",
"directory",
",",
"recordLength",
")",
",",
"self",
",",
"NoOpSerializer",
"(",
")",
... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | StreamingContext.queueStream | Create an input stream from a queue of RDDs or list. In each batch,
it will process either one or all of the RDDs returned by the queue.
.. note:: Changes to the queue after the stream is created will not be recognized.
@param rdds: Queue of RDDs
@param oneAtATime: pick one rdd e... | python/pyspark/streaming/context.py | def queueStream(self, rdds, oneAtATime=True, default=None):
"""
Create an input stream from a queue of RDDs or list. In each batch,
it will process either one or all of the RDDs returned by the queue.
.. note:: Changes to the queue after the stream is created will not be recognized.
... | def queueStream(self, rdds, oneAtATime=True, default=None):
"""
Create an input stream from a queue of RDDs or list. In each batch,
it will process either one or all of the RDDs returned by the queue.
.. note:: Changes to the queue after the stream is created will not be recognized.
... | [
"Create",
"an",
"input",
"stream",
"from",
"a",
"queue",
"of",
"RDDs",
"or",
"list",
".",
"In",
"each",
"batch",
"it",
"will",
"process",
"either",
"one",
"or",
"all",
"of",
"the",
"RDDs",
"returned",
"by",
"the",
"queue",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/streaming/context.py#L286-L313 | [
"def",
"queueStream",
"(",
"self",
",",
"rdds",
",",
"oneAtATime",
"=",
"True",
",",
"default",
"=",
"None",
")",
":",
"if",
"default",
"and",
"not",
"isinstance",
"(",
"default",
",",
"RDD",
")",
":",
"default",
"=",
"self",
".",
"_sc",
".",
"parall... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | StreamingContext.transform | Create a new DStream in which each RDD is generated by applying
a function on RDDs of the DStreams. The order of the JavaRDDs in
the transform function parameter will be the same as the order
of corresponding DStreams in the list. | python/pyspark/streaming/context.py | def transform(self, dstreams, transformFunc):
"""
Create a new DStream in which each RDD is generated by applying
a function on RDDs of the DStreams. The order of the JavaRDDs in
the transform function parameter will be the same as the order
of corresponding DStreams in the list.... | def transform(self, dstreams, transformFunc):
"""
Create a new DStream in which each RDD is generated by applying
a function on RDDs of the DStreams. The order of the JavaRDDs in
the transform function parameter will be the same as the order
of corresponding DStreams in the list.... | [
"Create",
"a",
"new",
"DStream",
"in",
"which",
"each",
"RDD",
"is",
"generated",
"by",
"applying",
"a",
"function",
"on",
"RDDs",
"of",
"the",
"DStreams",
".",
"The",
"order",
"of",
"the",
"JavaRDDs",
"in",
"the",
"transform",
"function",
"parameter",
"wi... | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/streaming/context.py#L315-L329 | [
"def",
"transform",
"(",
"self",
",",
"dstreams",
",",
"transformFunc",
")",
":",
"jdstreams",
"=",
"[",
"d",
".",
"_jdstream",
"for",
"d",
"in",
"dstreams",
"]",
"# change the final serializer to sc.serializer",
"func",
"=",
"TransformFunction",
"(",
"self",
".... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | StreamingContext.union | Create a unified DStream from multiple DStreams of the same
type and same slide duration. | python/pyspark/streaming/context.py | def union(self, *dstreams):
"""
Create a unified DStream from multiple DStreams of the same
type and same slide duration.
"""
if not dstreams:
raise ValueError("should have at least one DStream to union")
if len(dstreams) == 1:
return dstreams[0]
... | def union(self, *dstreams):
"""
Create a unified DStream from multiple DStreams of the same
type and same slide duration.
"""
if not dstreams:
raise ValueError("should have at least one DStream to union")
if len(dstreams) == 1:
return dstreams[0]
... | [
"Create",
"a",
"unified",
"DStream",
"from",
"multiple",
"DStreams",
"of",
"the",
"same",
"type",
"and",
"same",
"slide",
"duration",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/streaming/context.py#L331-L348 | [
"def",
"union",
"(",
"self",
",",
"*",
"dstreams",
")",
":",
"if",
"not",
"dstreams",
":",
"raise",
"ValueError",
"(",
"\"should have at least one DStream to union\"",
")",
"if",
"len",
"(",
"dstreams",
")",
"==",
"1",
":",
"return",
"dstreams",
"[",
"0",
... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | StreamingContext.addStreamingListener | Add a [[org.apache.spark.streaming.scheduler.StreamingListener]] object for
receiving system events related to streaming. | python/pyspark/streaming/context.py | def addStreamingListener(self, streamingListener):
"""
Add a [[org.apache.spark.streaming.scheduler.StreamingListener]] object for
receiving system events related to streaming.
"""
self._jssc.addStreamingListener(self._jvm.JavaStreamingListenerWrapper(
self._jvm.Pytho... | def addStreamingListener(self, streamingListener):
"""
Add a [[org.apache.spark.streaming.scheduler.StreamingListener]] object for
receiving system events related to streaming.
"""
self._jssc.addStreamingListener(self._jvm.JavaStreamingListenerWrapper(
self._jvm.Pytho... | [
"Add",
"a",
"[[",
"org",
".",
"apache",
".",
"spark",
".",
"streaming",
".",
"scheduler",
".",
"StreamingListener",
"]]",
"object",
"for",
"receiving",
"system",
"events",
"related",
"to",
"streaming",
"."
] | apache/spark | python | https://github.com/apache/spark/blob/618d6bff71073c8c93501ab7392c3cc579730f0b/python/pyspark/streaming/context.py#L350-L356 | [
"def",
"addStreamingListener",
"(",
"self",
",",
"streamingListener",
")",
":",
"self",
".",
"_jssc",
".",
"addStreamingListener",
"(",
"self",
".",
"_jvm",
".",
"JavaStreamingListenerWrapper",
"(",
"self",
".",
"_jvm",
".",
"PythonStreamingListenerWrapper",
"(",
... | 618d6bff71073c8c93501ab7392c3cc579730f0b |
train | load_tf_weights_in_gpt2 | Load tf checkpoints in a pytorch model | pytorch_pretrained_bert/modeling_gpt2.py | def load_tf_weights_in_gpt2(model, gpt2_checkpoint_path):
""" Load tf checkpoints in a pytorch model
"""
try:
import re
import numpy as np
import tensorflow as tf
except ImportError:
print("Loading a TensorFlow models in PyTorch, requires TensorFlow to be installed. Pleas... | def load_tf_weights_in_gpt2(model, gpt2_checkpoint_path):
""" Load tf checkpoints in a pytorch model
"""
try:
import re
import numpy as np
import tensorflow as tf
except ImportError:
print("Loading a TensorFlow models in PyTorch, requires TensorFlow to be installed. Pleas... | [
"Load",
"tf",
"checkpoints",
"in",
"a",
"pytorch",
"model"
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/pytorch_pretrained_bert/modeling_gpt2.py#L45-L96 | [
"def",
"load_tf_weights_in_gpt2",
"(",
"model",
",",
"gpt2_checkpoint_path",
")",
":",
"try",
":",
"import",
"re",
"import",
"numpy",
"as",
"np",
"import",
"tensorflow",
"as",
"tf",
"except",
"ImportError",
":",
"print",
"(",
"\"Loading a TensorFlow models in PyTorc... | b832d5bb8a6dfc5965015b828e577677eace601e |
train | GPT2Config.from_json_file | Constructs a `GPT2Config` from a json file of parameters. | pytorch_pretrained_bert/modeling_gpt2.py | def from_json_file(cls, json_file):
"""Constructs a `GPT2Config` from a json file of parameters."""
with open(json_file, "r", encoding="utf-8") as reader:
text = reader.read()
return cls.from_dict(json.loads(text)) | def from_json_file(cls, json_file):
"""Constructs a `GPT2Config` from a json file of parameters."""
with open(json_file, "r", encoding="utf-8") as reader:
text = reader.read()
return cls.from_dict(json.loads(text)) | [
"Constructs",
"a",
"GPT2Config",
"from",
"a",
"json",
"file",
"of",
"parameters",
"."
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/pytorch_pretrained_bert/modeling_gpt2.py#L162-L166 | [
"def",
"from_json_file",
"(",
"cls",
",",
"json_file",
")",
":",
"with",
"open",
"(",
"json_file",
",",
"\"r\"",
",",
"encoding",
"=",
"\"utf-8\"",
")",
"as",
"reader",
":",
"text",
"=",
"reader",
".",
"read",
"(",
")",
"return",
"cls",
".",
"from_dict... | b832d5bb8a6dfc5965015b828e577677eace601e |
train | GPT2Config.to_json_file | Save this instance to a json file. | pytorch_pretrained_bert/modeling_gpt2.py | def to_json_file(self, json_file_path):
""" Save this instance to a json file."""
with open(json_file_path, "w", encoding='utf-8') as writer:
writer.write(self.to_json_string()) | def to_json_file(self, json_file_path):
""" Save this instance to a json file."""
with open(json_file_path, "w", encoding='utf-8') as writer:
writer.write(self.to_json_string()) | [
"Save",
"this",
"instance",
"to",
"a",
"json",
"file",
"."
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/pytorch_pretrained_bert/modeling_gpt2.py#L180-L183 | [
"def",
"to_json_file",
"(",
"self",
",",
"json_file_path",
")",
":",
"with",
"open",
"(",
"json_file_path",
",",
"\"w\"",
",",
"encoding",
"=",
"'utf-8'",
")",
"as",
"writer",
":",
"writer",
".",
"write",
"(",
"self",
".",
"to_json_string",
"(",
")",
")"... | b832d5bb8a6dfc5965015b828e577677eace601e |
train | GPT2PreTrainedModel.init_weights | Initialize the weights. | pytorch_pretrained_bert/modeling_gpt2.py | def init_weights(self, module):
""" Initialize the weights.
"""
if isinstance(module, (nn.Linear, nn.Embedding)):
# Slightly different from the TF version which uses truncated_normal for initialization
# cf https://github.com/pytorch/pytorch/pull/5617
module.w... | def init_weights(self, module):
""" Initialize the weights.
"""
if isinstance(module, (nn.Linear, nn.Embedding)):
# Slightly different from the TF version which uses truncated_normal for initialization
# cf https://github.com/pytorch/pytorch/pull/5617
module.w... | [
"Initialize",
"the",
"weights",
"."
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/pytorch_pretrained_bert/modeling_gpt2.py#L351-L362 | [
"def",
"init_weights",
"(",
"self",
",",
"module",
")",
":",
"if",
"isinstance",
"(",
"module",
",",
"(",
"nn",
".",
"Linear",
",",
"nn",
".",
"Embedding",
")",
")",
":",
"# Slightly different from the TF version which uses truncated_normal for initialization",
"# c... | b832d5bb8a6dfc5965015b828e577677eace601e |
train | GPT2PreTrainedModel.from_pretrained | Instantiate a GPT2PreTrainedModel from a pre-trained model file or a pytorch state dict.
Download and cache the pre-trained model file if needed.
Params:
pretrained_model_name_or_path: either:
- a str with the name of a pre-trained model to load selected in the list of:
... | pytorch_pretrained_bert/modeling_gpt2.py | def from_pretrained(
cls, pretrained_model_name_or_path, state_dict=None, cache_dir=None, from_tf=False, *inputs, **kwargs
):
"""
Instantiate a GPT2PreTrainedModel from a pre-trained model file or a pytorch state dict.
Download and cache the pre-trained model file if needed.
... | def from_pretrained(
cls, pretrained_model_name_or_path, state_dict=None, cache_dir=None, from_tf=False, *inputs, **kwargs
):
"""
Instantiate a GPT2PreTrainedModel from a pre-trained model file or a pytorch state dict.
Download and cache the pre-trained model file if needed.
... | [
"Instantiate",
"a",
"GPT2PreTrainedModel",
"from",
"a",
"pre",
"-",
"trained",
"model",
"file",
"or",
"a",
"pytorch",
"state",
"dict",
".",
"Download",
"and",
"cache",
"the",
"pre",
"-",
"trained",
"model",
"file",
"if",
"needed",
"."
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/pytorch_pretrained_bert/modeling_gpt2.py#L365-L480 | [
"def",
"from_pretrained",
"(",
"cls",
",",
"pretrained_model_name_or_path",
",",
"state_dict",
"=",
"None",
",",
"cache_dir",
"=",
"None",
",",
"from_tf",
"=",
"False",
",",
"*",
"inputs",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"pretrained_model_name_or_path... | b832d5bb8a6dfc5965015b828e577677eace601e |
train | convert_examples_to_features | Loads a data file into a list of `InputFeature`s. | examples/extract_features.py | def convert_examples_to_features(examples, seq_length, tokenizer):
"""Loads a data file into a list of `InputFeature`s."""
features = []
for (ex_index, example) in enumerate(examples):
tokens_a = tokenizer.tokenize(example.text_a)
tokens_b = None
if example.text_b:
toke... | def convert_examples_to_features(examples, seq_length, tokenizer):
"""Loads a data file into a list of `InputFeature`s."""
features = []
for (ex_index, example) in enumerate(examples):
tokens_a = tokenizer.tokenize(example.text_a)
tokens_b = None
if example.text_b:
toke... | [
"Loads",
"a",
"data",
"file",
"into",
"a",
"list",
"of",
"InputFeature",
"s",
"."
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/examples/extract_features.py#L59-L147 | [
"def",
"convert_examples_to_features",
"(",
"examples",
",",
"seq_length",
",",
"tokenizer",
")",
":",
"features",
"=",
"[",
"]",
"for",
"(",
"ex_index",
",",
"example",
")",
"in",
"enumerate",
"(",
"examples",
")",
":",
"tokens_a",
"=",
"tokenizer",
".",
... | b832d5bb8a6dfc5965015b828e577677eace601e |
train | read_examples | Read a list of `InputExample`s from an input file. | examples/extract_features.py | def read_examples(input_file):
"""Read a list of `InputExample`s from an input file."""
examples = []
unique_id = 0
with open(input_file, "r", encoding='utf-8') as reader:
while True:
line = reader.readline()
if not line:
break
line = line.stri... | def read_examples(input_file):
"""Read a list of `InputExample`s from an input file."""
examples = []
unique_id = 0
with open(input_file, "r", encoding='utf-8') as reader:
while True:
line = reader.readline()
if not line:
break
line = line.stri... | [
"Read",
"a",
"list",
"of",
"InputExample",
"s",
"from",
"an",
"input",
"file",
"."
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/examples/extract_features.py#L167-L188 | [
"def",
"read_examples",
"(",
"input_file",
")",
":",
"examples",
"=",
"[",
"]",
"unique_id",
"=",
"0",
"with",
"open",
"(",
"input_file",
",",
"\"r\"",
",",
"encoding",
"=",
"'utf-8'",
")",
"as",
"reader",
":",
"while",
"True",
":",
"line",
"=",
"reade... | b832d5bb8a6dfc5965015b828e577677eace601e |
train | read_squad_examples | Read a SQuAD json file into a list of SquadExample. | examples/run_squad.py | def read_squad_examples(input_file, is_training, version_2_with_negative):
"""Read a SQuAD json file into a list of SquadExample."""
with open(input_file, "r", encoding='utf-8') as reader:
input_data = json.load(reader)["data"]
def is_whitespace(c):
if c == " " or c == "\t" or c == "\r" or ... | def read_squad_examples(input_file, is_training, version_2_with_negative):
"""Read a SQuAD json file into a list of SquadExample."""
with open(input_file, "r", encoding='utf-8') as reader:
input_data = json.load(reader)["data"]
def is_whitespace(c):
if c == " " or c == "\t" or c == "\r" or ... | [
"Read",
"a",
"SQuAD",
"json",
"file",
"into",
"a",
"list",
"of",
"SquadExample",
"."
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/examples/run_squad.py#L122-L197 | [
"def",
"read_squad_examples",
"(",
"input_file",
",",
"is_training",
",",
"version_2_with_negative",
")",
":",
"with",
"open",
"(",
"input_file",
",",
"\"r\"",
",",
"encoding",
"=",
"'utf-8'",
")",
"as",
"reader",
":",
"input_data",
"=",
"json",
".",
"load",
... | b832d5bb8a6dfc5965015b828e577677eace601e |
train | convert_examples_to_features | Loads a data file into a list of `InputBatch`s. | examples/run_squad.py | def convert_examples_to_features(examples, tokenizer, max_seq_length,
doc_stride, max_query_length, is_training):
"""Loads a data file into a list of `InputBatch`s."""
unique_id = 1000000000
features = []
for (example_index, example) in enumerate(examples):
que... | def convert_examples_to_features(examples, tokenizer, max_seq_length,
doc_stride, max_query_length, is_training):
"""Loads a data file into a list of `InputBatch`s."""
unique_id = 1000000000
features = []
for (example_index, example) in enumerate(examples):
que... | [
"Loads",
"a",
"data",
"file",
"into",
"a",
"list",
"of",
"InputBatch",
"s",
"."
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/examples/run_squad.py#L200-L360 | [
"def",
"convert_examples_to_features",
"(",
"examples",
",",
"tokenizer",
",",
"max_seq_length",
",",
"doc_stride",
",",
"max_query_length",
",",
"is_training",
")",
":",
"unique_id",
"=",
"1000000000",
"features",
"=",
"[",
"]",
"for",
"(",
"example_index",
",",
... | b832d5bb8a6dfc5965015b828e577677eace601e |
train | _improve_answer_span | Returns tokenized answer spans that better match the annotated answer. | examples/run_squad.py | def _improve_answer_span(doc_tokens, input_start, input_end, tokenizer,
orig_answer_text):
"""Returns tokenized answer spans that better match the annotated answer."""
# The SQuAD annotations are character based. We first project them to
# whitespace-tokenized words. But then after... | def _improve_answer_span(doc_tokens, input_start, input_end, tokenizer,
orig_answer_text):
"""Returns tokenized answer spans that better match the annotated answer."""
# The SQuAD annotations are character based. We first project them to
# whitespace-tokenized words. But then after... | [
"Returns",
"tokenized",
"answer",
"spans",
"that",
"better",
"match",
"the",
"annotated",
"answer",
"."
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/examples/run_squad.py#L363-L397 | [
"def",
"_improve_answer_span",
"(",
"doc_tokens",
",",
"input_start",
",",
"input_end",
",",
"tokenizer",
",",
"orig_answer_text",
")",
":",
"# The SQuAD annotations are character based. We first project them to",
"# whitespace-tokenized words. But then after WordPiece tokenization, we... | b832d5bb8a6dfc5965015b828e577677eace601e |
train | _check_is_max_context | Check if this is the 'max context' doc span for the token. | examples/run_squad.py | def _check_is_max_context(doc_spans, cur_span_index, position):
"""Check if this is the 'max context' doc span for the token."""
# Because of the sliding window approach taken to scoring documents, a single
# token can appear in multiple documents. E.g.
# Doc: the man went to the store and bought a ga... | def _check_is_max_context(doc_spans, cur_span_index, position):
"""Check if this is the 'max context' doc span for the token."""
# Because of the sliding window approach taken to scoring documents, a single
# token can appear in multiple documents. E.g.
# Doc: the man went to the store and bought a ga... | [
"Check",
"if",
"this",
"is",
"the",
"max",
"context",
"doc",
"span",
"for",
"the",
"token",
"."
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/examples/run_squad.py#L400-L434 | [
"def",
"_check_is_max_context",
"(",
"doc_spans",
",",
"cur_span_index",
",",
"position",
")",
":",
"# Because of the sliding window approach taken to scoring documents, a single",
"# token can appear in multiple documents. E.g.",
"# Doc: the man went to the store and bought a gallon of mil... | b832d5bb8a6dfc5965015b828e577677eace601e |
train | write_predictions | Write final predictions to the json file and log-odds of null if needed. | examples/run_squad.py | def write_predictions(all_examples, all_features, all_results, n_best_size,
max_answer_length, do_lower_case, output_prediction_file,
output_nbest_file, output_null_log_odds_file, verbose_logging,
version_2_with_negative, null_score_diff_threshold):
... | def write_predictions(all_examples, all_features, all_results, n_best_size,
max_answer_length, do_lower_case, output_prediction_file,
output_nbest_file, output_null_log_odds_file, verbose_logging,
version_2_with_negative, null_score_diff_threshold):
... | [
"Write",
"final",
"predictions",
"to",
"the",
"json",
"file",
"and",
"log",
"-",
"odds",
"of",
"null",
"if",
"needed",
"."
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/examples/run_squad.py#L441-L630 | [
"def",
"write_predictions",
"(",
"all_examples",
",",
"all_features",
",",
"all_results",
",",
"n_best_size",
",",
"max_answer_length",
",",
"do_lower_case",
",",
"output_prediction_file",
",",
"output_nbest_file",
",",
"output_null_log_odds_file",
",",
"verbose_logging",
... | b832d5bb8a6dfc5965015b828e577677eace601e |
train | get_final_text | Project the tokenized prediction back to the original text. | examples/run_squad.py | def get_final_text(pred_text, orig_text, do_lower_case, verbose_logging=False):
"""Project the tokenized prediction back to the original text."""
# When we created the data, we kept track of the alignment between original
# (whitespace tokenized) tokens and our WordPiece tokenized tokens. So
# now `ori... | def get_final_text(pred_text, orig_text, do_lower_case, verbose_logging=False):
"""Project the tokenized prediction back to the original text."""
# When we created the data, we kept track of the alignment between original
# (whitespace tokenized) tokens and our WordPiece tokenized tokens. So
# now `ori... | [
"Project",
"the",
"tokenized",
"prediction",
"back",
"to",
"the",
"original",
"text",
"."
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/examples/run_squad.py#L633-L726 | [
"def",
"get_final_text",
"(",
"pred_text",
",",
"orig_text",
",",
"do_lower_case",
",",
"verbose_logging",
"=",
"False",
")",
":",
"# When we created the data, we kept track of the alignment between original",
"# (whitespace tokenized) tokens and our WordPiece tokenized tokens. So",
... | b832d5bb8a6dfc5965015b828e577677eace601e |
train | _get_best_indexes | Get the n-best logits from a list. | examples/run_squad.py | def _get_best_indexes(logits, n_best_size):
"""Get the n-best logits from a list."""
index_and_score = sorted(enumerate(logits), key=lambda x: x[1], reverse=True)
best_indexes = []
for i in range(len(index_and_score)):
if i >= n_best_size:
break
best_indexes.append(index_and... | def _get_best_indexes(logits, n_best_size):
"""Get the n-best logits from a list."""
index_and_score = sorted(enumerate(logits), key=lambda x: x[1], reverse=True)
best_indexes = []
for i in range(len(index_and_score)):
if i >= n_best_size:
break
best_indexes.append(index_and... | [
"Get",
"the",
"n",
"-",
"best",
"logits",
"from",
"a",
"list",
"."
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/examples/run_squad.py#L729-L738 | [
"def",
"_get_best_indexes",
"(",
"logits",
",",
"n_best_size",
")",
":",
"index_and_score",
"=",
"sorted",
"(",
"enumerate",
"(",
"logits",
")",
",",
"key",
"=",
"lambda",
"x",
":",
"x",
"[",
"1",
"]",
",",
"reverse",
"=",
"True",
")",
"best_indexes",
... | b832d5bb8a6dfc5965015b828e577677eace601e |
train | _compute_softmax | Compute softmax probability over raw logits. | examples/run_squad.py | def _compute_softmax(scores):
"""Compute softmax probability over raw logits."""
if not scores:
return []
max_score = None
for score in scores:
if max_score is None or score > max_score:
max_score = score
exp_scores = []
total_sum = 0.0
for score in scores:
... | def _compute_softmax(scores):
"""Compute softmax probability over raw logits."""
if not scores:
return []
max_score = None
for score in scores:
if max_score is None or score > max_score:
max_score = score
exp_scores = []
total_sum = 0.0
for score in scores:
... | [
"Compute",
"softmax",
"probability",
"over",
"raw",
"logits",
"."
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/examples/run_squad.py#L741-L761 | [
"def",
"_compute_softmax",
"(",
"scores",
")",
":",
"if",
"not",
"scores",
":",
"return",
"[",
"]",
"max_score",
"=",
"None",
"for",
"score",
"in",
"scores",
":",
"if",
"max_score",
"is",
"None",
"or",
"score",
">",
"max_score",
":",
"max_score",
"=",
... | b832d5bb8a6dfc5965015b828e577677eace601e |
train | convert_examples_to_features | Loads a data file into a list of `InputBatch`s. | examples/run_swag.py | def convert_examples_to_features(examples, tokenizer, max_seq_length,
is_training):
"""Loads a data file into a list of `InputBatch`s."""
# Swag is a multiple choice task. To perform this task using Bert,
# we will use the formatting proposed in "Improving Language
# Un... | def convert_examples_to_features(examples, tokenizer, max_seq_length,
is_training):
"""Loads a data file into a list of `InputBatch`s."""
# Swag is a multiple choice task. To perform this task using Bert,
# we will use the formatting proposed in "Improving Language
# Un... | [
"Loads",
"a",
"data",
"file",
"into",
"a",
"list",
"of",
"InputBatch",
"s",
"."
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/examples/run_swag.py#L138-L214 | [
"def",
"convert_examples_to_features",
"(",
"examples",
",",
"tokenizer",
",",
"max_seq_length",
",",
"is_training",
")",
":",
"# Swag is a multiple choice task. To perform this task using Bert,",
"# we will use the formatting proposed in \"Improving Language",
"# Understanding by Genera... | b832d5bb8a6dfc5965015b828e577677eace601e |
train | convert_examples_to_features | Loads a data file into a list of `InputBatch`s. | examples/run_classifier.py | def convert_examples_to_features(examples, label_list, max_seq_length,
tokenizer, output_mode):
"""Loads a data file into a list of `InputBatch`s."""
label_map = {label : i for i, label in enumerate(label_list)}
features = []
for (ex_index, example) in enumerate(exampl... | def convert_examples_to_features(examples, label_list, max_seq_length,
tokenizer, output_mode):
"""Loads a data file into a list of `InputBatch`s."""
label_map = {label : i for i, label in enumerate(label_list)}
features = []
for (ex_index, example) in enumerate(exampl... | [
"Loads",
"a",
"data",
"file",
"into",
"a",
"list",
"of",
"InputBatch",
"s",
"."
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/examples/run_classifier.py#L405-L494 | [
"def",
"convert_examples_to_features",
"(",
"examples",
",",
"label_list",
",",
"max_seq_length",
",",
"tokenizer",
",",
"output_mode",
")",
":",
"label_map",
"=",
"{",
"label",
":",
"i",
"for",
"i",
",",
"label",
"in",
"enumerate",
"(",
"label_list",
")",
"... | b832d5bb8a6dfc5965015b828e577677eace601e |
train | DataProcessor._read_tsv | Reads a tab separated value file. | examples/run_classifier.py | def _read_tsv(cls, input_file, quotechar=None):
"""Reads a tab separated value file."""
with open(input_file, "r", encoding="utf-8") as f:
reader = csv.reader(f, delimiter="\t", quotechar=quotechar)
lines = []
for line in reader:
if sys.version_info[0]... | def _read_tsv(cls, input_file, quotechar=None):
"""Reads a tab separated value file."""
with open(input_file, "r", encoding="utf-8") as f:
reader = csv.reader(f, delimiter="\t", quotechar=quotechar)
lines = []
for line in reader:
if sys.version_info[0]... | [
"Reads",
"a",
"tab",
"separated",
"value",
"file",
"."
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/examples/run_classifier.py#L93-L102 | [
"def",
"_read_tsv",
"(",
"cls",
",",
"input_file",
",",
"quotechar",
"=",
"None",
")",
":",
"with",
"open",
"(",
"input_file",
",",
"\"r\"",
",",
"encoding",
"=",
"\"utf-8\"",
")",
"as",
"f",
":",
"reader",
"=",
"csv",
".",
"reader",
"(",
"f",
",",
... | b832d5bb8a6dfc5965015b828e577677eace601e |
train | MrpcProcessor.get_train_examples | See base class. | examples/run_classifier.py | def get_train_examples(self, data_dir):
"""See base class."""
logger.info("LOOKING AT {}".format(os.path.join(data_dir, "train.tsv")))
return self._create_examples(
self._read_tsv(os.path.join(data_dir, "train.tsv")), "train") | def get_train_examples(self, data_dir):
"""See base class."""
logger.info("LOOKING AT {}".format(os.path.join(data_dir, "train.tsv")))
return self._create_examples(
self._read_tsv(os.path.join(data_dir, "train.tsv")), "train") | [
"See",
"base",
"class",
"."
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/examples/run_classifier.py#L108-L112 | [
"def",
"get_train_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"logger",
".",
"info",
"(",
"\"LOOKING AT {}\"",
".",
"format",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"train.tsv\"",
")",
")",
")",
"return",
"self",
".",
"_creat... | b832d5bb8a6dfc5965015b828e577677eace601e |
train | MrpcProcessor._create_examples | Creates examples for the training and dev sets. | examples/run_classifier.py | def _create_examples(self, lines, set_type):
"""Creates examples for the training and dev sets."""
examples = []
for (i, line) in enumerate(lines):
if i == 0:
continue
guid = "%s-%s" % (set_type, i)
text_a = line[3]
text_b = line[4]... | def _create_examples(self, lines, set_type):
"""Creates examples for the training and dev sets."""
examples = []
for (i, line) in enumerate(lines):
if i == 0:
continue
guid = "%s-%s" % (set_type, i)
text_a = line[3]
text_b = line[4]... | [
"Creates",
"examples",
"for",
"the",
"training",
"and",
"dev",
"sets",
"."
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/examples/run_classifier.py#L123-L135 | [
"def",
"_create_examples",
"(",
"self",
",",
"lines",
",",
"set_type",
")",
":",
"examples",
"=",
"[",
"]",
"for",
"(",
"i",
",",
"line",
")",
"in",
"enumerate",
"(",
"lines",
")",
":",
"if",
"i",
"==",
"0",
":",
"continue",
"guid",
"=",
"\"%s-%s\"... | b832d5bb8a6dfc5965015b828e577677eace601e |
train | MnliProcessor.get_train_examples | See base class. | examples/run_classifier.py | def get_train_examples(self, data_dir):
"""See base class."""
return self._create_examples(
self._read_tsv(os.path.join(data_dir, "train.tsv")), "train") | def get_train_examples(self, data_dir):
"""See base class."""
return self._create_examples(
self._read_tsv(os.path.join(data_dir, "train.tsv")), "train") | [
"See",
"base",
"class",
"."
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/examples/run_classifier.py#L141-L144 | [
"def",
"get_train_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"train.tsv\"",
")",
")",
",",
"\"train\"",
")"
] | b832d5bb8a6dfc5965015b828e577677eace601e |
train | MnliProcessor.get_dev_examples | See base class. | examples/run_classifier.py | def get_dev_examples(self, data_dir):
"""See base class."""
return self._create_examples(
self._read_tsv(os.path.join(data_dir, "dev_matched.tsv")),
"dev_matched") | def get_dev_examples(self, data_dir):
"""See base class."""
return self._create_examples(
self._read_tsv(os.path.join(data_dir, "dev_matched.tsv")),
"dev_matched") | [
"See",
"base",
"class",
"."
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/examples/run_classifier.py#L146-L150 | [
"def",
"get_dev_examples",
"(",
"self",
",",
"data_dir",
")",
":",
"return",
"self",
".",
"_create_examples",
"(",
"self",
".",
"_read_tsv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"\"dev_matched.tsv\"",
")",
")",
",",
"\"dev_matched\"",
... | b832d5bb8a6dfc5965015b828e577677eace601e |
train | top_k_logits | Masks everything but the k top entries as -infinity (1e10).
Used to mask logits such that e^-infinity -> 0 won't contribute to the
sum of the denominator. | examples/run_gpt2.py | def top_k_logits(logits, k):
"""
Masks everything but the k top entries as -infinity (1e10).
Used to mask logits such that e^-infinity -> 0 won't contribute to the
sum of the denominator.
"""
if k == 0:
return logits
else:
values = torch.topk(logits, k)[0]
batch_mins ... | def top_k_logits(logits, k):
"""
Masks everything but the k top entries as -infinity (1e10).
Used to mask logits such that e^-infinity -> 0 won't contribute to the
sum of the denominator.
"""
if k == 0:
return logits
else:
values = torch.topk(logits, k)[0]
batch_mins ... | [
"Masks",
"everything",
"but",
"the",
"k",
"top",
"entries",
"as",
"-",
"infinity",
"(",
"1e10",
")",
".",
"Used",
"to",
"mask",
"logits",
"such",
"that",
"e^",
"-",
"infinity",
"-",
">",
"0",
"won",
"t",
"contribute",
"to",
"the",
"sum",
"of",
"the",... | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/examples/run_gpt2.py#L18-L29 | [
"def",
"top_k_logits",
"(",
"logits",
",",
"k",
")",
":",
"if",
"k",
"==",
"0",
":",
"return",
"logits",
"else",
":",
"values",
"=",
"torch",
".",
"topk",
"(",
"logits",
",",
"k",
")",
"[",
"0",
"]",
"batch_mins",
"=",
"values",
"[",
":",
",",
... | b832d5bb8a6dfc5965015b828e577677eace601e |
train | load_tf_weights_in_bert | Load tf checkpoints in a pytorch model | pytorch_pretrained_bert/modeling.py | def load_tf_weights_in_bert(model, tf_checkpoint_path):
""" Load tf checkpoints in a pytorch model
"""
try:
import re
import numpy as np
import tensorflow as tf
except ImportError:
print("Loading a TensorFlow models in PyTorch, requires TensorFlow to be installed. Please ... | def load_tf_weights_in_bert(model, tf_checkpoint_path):
""" Load tf checkpoints in a pytorch model
"""
try:
import re
import numpy as np
import tensorflow as tf
except ImportError:
print("Loading a TensorFlow models in PyTorch, requires TensorFlow to be installed. Please ... | [
"Load",
"tf",
"checkpoints",
"in",
"a",
"pytorch",
"model"
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/pytorch_pretrained_bert/modeling.py#L51-L115 | [
"def",
"load_tf_weights_in_bert",
"(",
"model",
",",
"tf_checkpoint_path",
")",
":",
"try",
":",
"import",
"re",
"import",
"numpy",
"as",
"np",
"import",
"tensorflow",
"as",
"tf",
"except",
"ImportError",
":",
"print",
"(",
"\"Loading a TensorFlow models in PyTorch,... | b832d5bb8a6dfc5965015b828e577677eace601e |
train | BertPreTrainedModel.from_pretrained | Instantiate a BertPreTrainedModel from a pre-trained model file or a pytorch state dict.
Download and cache the pre-trained model file if needed.
Params:
pretrained_model_name_or_path: either:
- a str with the name of a pre-trained model to load selected in the list of:
... | pytorch_pretrained_bert/modeling.py | def from_pretrained(cls, pretrained_model_name_or_path, *inputs, **kwargs):
"""
Instantiate a BertPreTrainedModel from a pre-trained model file or a pytorch state dict.
Download and cache the pre-trained model file if needed.
Params:
pretrained_model_name_or_path: either:
... | def from_pretrained(cls, pretrained_model_name_or_path, *inputs, **kwargs):
"""
Instantiate a BertPreTrainedModel from a pre-trained model file or a pytorch state dict.
Download and cache the pre-trained model file if needed.
Params:
pretrained_model_name_or_path: either:
... | [
"Instantiate",
"a",
"BertPreTrainedModel",
"from",
"a",
"pre",
"-",
"trained",
"model",
"file",
"or",
"a",
"pytorch",
"state",
"dict",
".",
"Download",
"and",
"cache",
"the",
"pre",
"-",
"trained",
"model",
"file",
"if",
"needed",
"."
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/pytorch_pretrained_bert/modeling.py#L526-L655 | [
"def",
"from_pretrained",
"(",
"cls",
",",
"pretrained_model_name_or_path",
",",
"*",
"inputs",
",",
"*",
"*",
"kwargs",
")",
":",
"state_dict",
"=",
"kwargs",
".",
"get",
"(",
"'state_dict'",
",",
"None",
")",
"kwargs",
".",
"pop",
"(",
"'state_dict'",
",... | b832d5bb8a6dfc5965015b828e577677eace601e |
train | load_tf_weights_in_openai_gpt | Load tf pre-trained weights in a pytorch model (from NumPy arrays here) | pytorch_pretrained_bert/modeling_openai.py | def load_tf_weights_in_openai_gpt(model, openai_checkpoint_folder_path):
""" Load tf pre-trained weights in a pytorch model (from NumPy arrays here)
"""
import re
import numpy as np
print("Loading weights...")
names = json.load(open(openai_checkpoint_folder_path + '/parameters_names.json', "r", ... | def load_tf_weights_in_openai_gpt(model, openai_checkpoint_folder_path):
""" Load tf pre-trained weights in a pytorch model (from NumPy arrays here)
"""
import re
import numpy as np
print("Loading weights...")
names = json.load(open(openai_checkpoint_folder_path + '/parameters_names.json', "r", ... | [
"Load",
"tf",
"pre",
"-",
"trained",
"weights",
"in",
"a",
"pytorch",
"model",
"(",
"from",
"NumPy",
"arrays",
"here",
")"
] | huggingface/pytorch-pretrained-BERT | python | https://github.com/huggingface/pytorch-pretrained-BERT/blob/b832d5bb8a6dfc5965015b828e577677eace601e/pytorch_pretrained_bert/modeling_openai.py#L46-L113 | [
"def",
"load_tf_weights_in_openai_gpt",
"(",
"model",
",",
"openai_checkpoint_folder_path",
")",
":",
"import",
"re",
"import",
"numpy",
"as",
"np",
"print",
"(",
"\"Loading weights...\"",
")",
"names",
"=",
"json",
".",
"load",
"(",
"open",
"(",
"openai_checkpoin... | b832d5bb8a6dfc5965015b828e577677eace601e |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.