-
Notifications
You must be signed in to change notification settings - Fork 1
/
README
150 lines (88 loc) · 4.02 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
Table of Contents
=================
- What is LIBFM
- Installation
- Data Format
- Command Line Usage
- Examples
- OpenMP and SSE
- Building Windows Binaries
- FAQ
What is LIBFM
==============
This implementation of factorization machine is based on LibFFM(by Quqin Ruan). We update the data structure of the model parameters, and the new structure support several optimization methods well(Adagrad, FTRL, etc.).
Installation
============
Requirement: It requires a C++11 compatible compiler. We also use OpenMP to provide multi-threading. If OpenMP is not
available on your platform, please refer to section `OpenMP and SSE.'
- Unix-like systems:
Typeype `make' in the command line.
- Windows:
See `Building Windows Binaries' to compile.
Data Format
===========
The data format of LIBFM is:
<label> <feature1>:<value1> <feature2>:<value2> ...
`feature' should be non-negative integers.
Command Line Usage
==================
- `fm-train'
usage: fm-train [options] training_set_file [model_file]
options:
-l <lambda>: set regularization parameter (default 0.00002)
-k <factor>: set number of latent factors (default 4)
-t <iteration>: set number of iterations (default 15)
-r <eta>: set learning rate (default 0.2)
-s <nr_threads>: set number of threads (default 1)
-p <path>: set path to the validation set
--quiet: quiet model (no output)
--no-norm: disable instance-wise normalization
--auto-stop: stop at the iteration that achieves the best validation loss (must be used with -p)
By default we do instance-wise normalization. That is, we normalize the 2-norm of each instance to 1. You can use
`--no-norm' to disable this function.
A binary file `training_set_file.bin' will be generated to store the data in binary format.
- `fm-predict'
usage: fm-predict test_file model_file output_file
Examples
========
> ./fm-train -p validate_data train_data model
train a model using the default parameters
> ./fm-predict predict_data model predict_ans
do prediction
> ./fm-train -l 0.0001 -k 15 -t 30 -r 0.05 -s 4 --auto-stop -p validate_data train_data model
train a model using the following parameters:
regularization cost = 0.0001
latent factors = 15
iterations = 30
learning rate = 0.3
threads = 4
let it auto-stop
OpenMP and SSE
==============
We use OpenMP to do parallelization. If OpenMP is not available on your
platform, then please comment out the following lines in Makefile.
DFLAG += -DUSEOMP
CXXFLAGS += -fopenmp
Note: Please run `make clean all' if these flags are changed.
We use SSE instructions to perform fast computation. If you do not want to use it, comment out the following line:
DFLAG += -DUSESSE
Then, run `make clean all'
Building Windows Binaries
=========================
The Windows part is maintained by different maintainer, so it may not always support the latest version.
The latest version it supports is: v1.21
To build them via command-line tools of Visual C++, use the following steps:
1. Open a DOS command box (or Developer Command Prompt for Visual Studio) and go to LIBFFM directory. If environment
variables of VC++ have not been set, type
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64\vcvars64.bat"
You may have to modify the above command according which version of VC++ or
where it is installed.
2. Type
nmake -f Makefile.win clean all
FAQ
===
Q: Why I have the same model size when k = 1 and k = 4?
A: This is because we use SSE instructions. In order to use SSE, the memory need to be aligned. So even you assign k =
1, we still fill some dummy zeros from k = 2 to 4.
Q: Why the logloss is slightly different on the same data when I run the program two or more times when I use multi-threading
A: When there are more then one thread, the program becomes non-deterministic. To make it deterministic you can only use one thread.