/** * Copyright (c) 2016-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. */ #include #include #include #include #include "args.h" #include "autotune.h" #include "fasttext.h" using namespace fasttext; void printUsage() { std::cerr << "usage: fasttext \n\n" << "The commands supported by fasttext are:\n\n" << " supervised train a supervised classifier\n" << " quantize quantize a model to reduce the memory " "usage\n" << " test evaluate a supervised classifier\n" << " test-label print labels with precision and recall " "scores\n" << " predict predict most likely labels\n" << " predict-prob predict most likely labels with " "probabilities\n" << " skipgram train a skipgram model\n" << " cbow train a cbow model\n" << " print-word-vectors print word vectors given a trained model\n" << " print-sentence-vectors print sentence vectors given a trained " "model\n" << " print-ngrams print ngrams given a trained model and " "word\n" << " nn query for nearest neighbors\n" << " analogies query for analogies\n" << " dump dump arguments,dictionary,input/output " "vectors\n" << std::endl; } void printQuantizeUsage() { std::cerr << "usage: fasttext quantize " << std::endl; } void printTestUsage() { std::cerr << "usage: fasttext test [] []\n\n" << " model filename\n" << " test data filename (if -, read from stdin)\n" << " (optional; 1 by default) predict top k labels\n" << " (optional; 0.0 by default) probability threshold\n" << std::endl; } void printPredictUsage() { std::cerr << "usage: fasttext predict[-prob] [] []\n\n" << " model filename\n" << " test data filename (if -, read from stdin)\n" << " (optional; 1 by default) predict top k labels\n" << " (optional; 0.0 by default) probability threshold\n" << std::endl; } void printTestLabelUsage() { std::cerr << "usage: fasttext test-label [] []\n\n" << " model filename\n" << " test data filename\n" << " (optional; 1 by default) predict top k labels\n" << " (optional; 0.0 by default) probability threshold\n" << std::endl; } void printPrintWordVectorsUsage() { std::cerr << "usage: fasttext print-word-vectors \n\n" << " model filename\n" << std::endl; } void printPrintSentenceVectorsUsage() { std::cerr << "usage: fasttext print-sentence-vectors \n\n" << " model filename\n" << std::endl; } void printPrintNgramsUsage() { std::cerr << "usage: fasttext print-ngrams \n\n" << " model filename\n" << " word to print\n" << std::endl; } void quantize(const std::vector& args) { Args a = Args(); if (args.size() < 3) { printQuantizeUsage(); a.printHelp(); exit(EXIT_FAILURE); } a.parseArgs(args); FastText fasttext; // parseArgs checks if a->output is given. fasttext.loadModel(a.output + ".bin"); fasttext.quantize(a); fasttext.saveModel(a.output + ".ftz"); exit(0); } void printNNUsage() { std::cout << "usage: fasttext nn \n\n" << " model filename\n" << " (optional; 10 by default) predict top k labels\n" << std::endl; } void printAnalogiesUsage() { std::cout << "usage: fasttext analogies \n\n" << " model filename\n" << " (optional; 10 by default) predict top k labels\n" << std::endl; } void printDumpUsage() { std::cout << "usage: fasttext dump