Debian Codegraph @

docs/cheatsheet.md

raw
1 ---
2 id: cheatsheet
3 title: Cheatsheet
4 ---
5
6 ## Word representation learning
7
8 In order to learn word vectors do:
9
10 ```bash
11 $ ./fasttext skipgram -input data.txt -output model
12 ```
13
14 ## Obtaining word vectors
15
16 Print word vectors for a text file `queries.txt` containing words.
17
18 ```bash
19 $ ./fasttext print-word-vectors model.bin < queries.txt
20 ```
21
22 ## Text classification
23
24 In order to train a text classifier do:
25
26 ```bash
27 $ ./fasttext supervised -input train.txt -output model
28 ```
29
30 Once the model was trained, you can evaluate it by computing the precision and recall at k (P@k and R@k) on a test set using:
31
32 ```bash
33 $ ./fasttext test model.bin test.txt 1
34 ```
35
36 In order to obtain the k most likely labels for a piece of text, use:
37
38 ```bash
39 $ ./fasttext predict model.bin test.txt k
40 ```
41
42 In order to obtain the k most likely labels and their associated probabilities for a piece of text, use:
43
44 ```bash
45 $ ./fasttext predict-prob model.bin test.txt k
46 ```
47
48 If you want to compute vector representations of sentences or paragraphs, please use:
49
50 ```bash
51 $ ./fasttext print-sentence-vectors model.bin < text.txt
52 ```
53
54 ## Quantization
55
56 In order to create a `.ftz` file with a smaller memory footprint do:
57
58 ```bash
59 $ ./fasttext quantize -output model
60 ```
61
62 All other commands such as test also work with this model
63
64 ```bash
65 $ ./fasttext test model.ftz test.txt
66 ```
67
68 ## Autotune
69
70 Activate hyperparameter optimization with `-autotune-validation` argument:
71
72 ```bash
73 $ ./fasttext supervised -input train.txt -output model -autotune-validation valid.txt
74 ```
75
76 Set timeout (in seconds):
77 ```bash
78 $ ./fasttext supervised -input train.txt -output model -autotune-validation valid.txt -autotune-duration 600
79 ```
80
81 Constrain the final model size:
82 ```bash
83 $ ./fasttext supervised -input train.txt -output model -autotune-validation valid.txt -autotune-modelsize 2M
84 ```
85
86
87
88
89