MCPcopy
hub / github.com/piskvorky/gensim / load

Function load

gensim/downloader.py:435–503  ·  view source on GitHub ↗

Download (if needed) dataset/model and load it to memory (unless `return_path` is set). Parameters ---------- name: str Name of the model/dataset. return_path: bool, optional If True, return full path to file, otherwise, return loaded model / iterable dataset. R

(name, return_path=False)

Source from the content-addressed store, hash-verified

433
434
435def load(name, return_path=False):
436 """Download (if needed) dataset/model and load it to memory (unless `return_path` is set).
437
438 Parameters
439 ----------
440 name: str
441 Name of the model/dataset.
442 return_path: bool, optional
443 If True, return full path to file, otherwise, return loaded model / iterable dataset.
444
445 Returns
446 -------
447 Model
448 Requested model, if `name` is model and `return_path` == False.
449 Dataset (iterable)
450 Requested dataset, if `name` is dataset and `return_path` == False.
451 str
452 Path to file with dataset / model, only when `return_path` == True.
453
454 Raises
455 ------
456 Exception
457 Raised if `name` is incorrect.
458
459 Examples
460 --------
461 Model example:
462
463 .. sourcecode:: pycon
464
465 >>> import gensim.downloader as api
466 >>>
467 >>> model = api.load("glove-twitter-25") # load glove vectors
468 >>> model.most_similar("cat") # show words that similar to word 'cat'
469
470 Dataset example:
471
472 .. sourcecode:: pycon
473
474 >>> import gensim.downloader as api
475 >>>
476 >>> wiki = api.load("wiki-en") # load extracted Wikipedia dump, around 6 Gb
477 >>> for article in wiki: # iterate over all wiki script
478 >>> pass
479
480 Download only example:
481
482 .. sourcecode:: pycon
483
484 >>> import gensim.downloader as api
485 >>>
486 >>> print(api.load("wiki-en", return_path=True)) # output: /home/user/gensim-data/wiki-en/wiki-en.gz
487
488 """
489 _create_base_dir()
490 file_name = _get_filename(name)
491 if file_name is None:
492 raise ValueError("Incorrect model/corpus name")

Callers 1

downloader.pyFile · 0.70

Calls 3

_create_base_dirFunction · 0.85
_get_filenameFunction · 0.85
_downloadFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…