forked from facebookresearch/fastText
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scripts to download word vector models and reduce their size
Summary: pre-trained word vectors are conveniently available on fasttext's website at https://fasttext.cc/docs/en/crawl-vectors.html. However, these vectors have a fixed dimension 300. This commit adds a script to download word vectors, and a script to reduce their size to a custom dimension. Reviewed By: piotr-bojanowski Differential Revision: D18706087 fbshipit-source-id: d5370a62687b10387d9630c7128809bc4da30f0a
- Loading branch information
1 parent
da2745f
commit 02c61ef
Showing
14 changed files
with
432 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2017-present, Facebook, Inc. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
|
||
import argparse | ||
|
||
import fasttext.util | ||
|
||
|
||
args = None | ||
|
||
|
||
def command_download(lang_id, if_exists): | ||
""" | ||
Download pre-trained common-crawl vectors from fastText's website | ||
https://fasttext.cc/docs/en/crawl-vectors.html | ||
""" | ||
fasttext.util.download_model(lang_id, if_exists) | ||
|
||
|
||
def main(): | ||
global args | ||
|
||
parser = argparse.ArgumentParser( | ||
description='fastText helper tool to reduce model dimensions.') | ||
parser.add_argument("language", type=str, default="en", | ||
help="language identifier of the pre-trained vectors. For example `en` or `fr`.") | ||
parser.add_argument("--overwrite", action="store_true", | ||
help="overwrite if file exists.") | ||
|
||
args = parser.parse_args() | ||
|
||
command_download(args.language, if_exists=( | ||
'overwrite' if args.overwrite else 'strict')) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.