Sha256: 6fcce53559f49dd9d85d8e1f2b9542433d19b530ec5620df7db9b3c8f97a3639

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

#!/usr/bin/env python

# 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
from __future__ import division, absolute_import, print_function

from fasttext import load_model
import argparse
import errno

if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description=(
            "Print words or labels and frequency of a model's dictionary"
        )
    )
    parser.add_argument(
        "model",
        help="Model to use",
    )
    parser.add_argument(
        "-l",
        "--labels",
        help="Print labels instead of words",
        action='store_true',
        default=False,
    )
    args = parser.parse_args()

    f = load_model(args.model)
    if args.labels:
        words, freq = f.get_labels(include_freq=True)
    else:
        words, freq = f.get_words(include_freq=True)
    for w, f in zip(words, freq):
        try:
            print(w + "\t" + str(f))
        except IOError as e:
            if e.errno == errno.EPIPE:
                pass

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fasttext-0.1.0 vendor/fastText/python/doc/examples/get_vocab.py