download_model.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright (c) 2017-present, Facebook, Inc.
  5. # All rights reserved.
  6. #
  7. # This source code is licensed under the MIT license found in the
  8. # LICENSE file in the root directory of this source tree.
  9. from __future__ import absolute_import
  10. from __future__ import division
  11. from __future__ import print_function
  12. from __future__ import unicode_literals
  13. import argparse
  14. import fasttext.util
  15. args = None
  16. def command_download(lang_id, if_exists):
  17. """
  18. Download pre-trained common-crawl vectors from fastText's website
  19. https://fasttext.cc/docs/en/crawl-vectors.html
  20. """
  21. fasttext.util.download_model(lang_id, if_exists)
  22. def main():
  23. global args
  24. parser = argparse.ArgumentParser(
  25. description='fastText helper tool to reduce model dimensions.')
  26. parser.add_argument("language", type=str, default="en",
  27. help="language identifier of the pre-trained vectors. For example `en` or `fr`.")
  28. parser.add_argument("--overwrite", action="store_true",
  29. help="overwrite if file exists.")
  30. args = parser.parse_args()
  31. command_download(args.language, if_exists=(
  32. 'overwrite' if args.overwrite else 'strict'))
  33. if __name__ == '__main__':
  34. main()