torchtext.utils¶
reporthook¶
download_from_url¶
- torchtext.utils.download_from_url(url, path=None, root='.data', overwrite=False, hash_value=None, hash_type='sha256')[source]¶
下载文件,使用 Google Drive 的逻辑(来自 tensor2tensor)。返回下载文件的路径。:param url: 文件的 URL,来自 URL 标头。(None):param path: 文件将保存到的路径:param root: 用于存储文件的下载文件夹(.data):param overwrite: 覆盖现有文件(False):param hash_value: url 的哈希值(默认值:
None
)。:type hash_value: str,可选:param hash_type: 哈希类型,包括“sha256”和“md5”(默认值:"sha256"
)。:type hash_type: str,可选示例
>>> url = 'http://www.quest.dcs.shef.ac.uk/wmt16_files_mmt/validation.tar.gz' >>> torchtext.utils.download_from_url(url) >>> url = 'http://www.quest.dcs.shef.ac.uk/wmt16_files_mmt/validation.tar.gz' >>> torchtext.utils.download_from_url(url) >>> '.data/validation.tar.gz'
extract_archive¶
- torchtext.utils.extract_archive(from_path, to_path=None, overwrite=False)[source]¶
解压存档。:param from_path: 存档的路径。:param to_path: 解压文件的根路径(from_path 的目录):param overwrite: 覆盖现有文件(False)
- 返回值:
即使未覆盖,也返回解压文件的路径列表。
示例
>>> url = 'http://www.quest.dcs.shef.ac.uk/wmt16_files_mmt/validation.tar.gz' >>> from_path = './validation.tar.gz' >>> to_path = './' >>> torchtext.utils.download_from_url(url, from_path) >>> torchtext.utils.extract_archive(from_path, to_path) >>> ['.data/val.de', '.data/val.en'] >>> torchtext.utils.download_from_url(url, from_path) >>> torchtext.utils.extract_archive(from_path, to_path) >>> ['.data/val.de', '.data/val.en']