ml_regression_en.html 28.2 KB
Newer Older
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


<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Regression MovieLens Ratting &mdash; PaddlePaddle  documentation</title>
  

  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  

  
  
        <link rel="index" title="Index"
              href="../../genindex.html"/>
        <link rel="search" title="Search" href="../../search.html"/>
35
    <link rel="top" title="PaddlePaddle  documentation" href="../../index.html"/> 
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

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/perfect-scrollbar/0.6.14/css/perfect-scrollbar.min.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/css/override.css" type="text/css" />
  <script>
  var _hmt = _hmt || [];
  (function() {
    var hm = document.createElement("script");
    hm.src = "//hm.baidu.com/hm.js?b9a314ab40d04d805655aab1deee08ba";
    var s = document.getElementsByTagName("script")[0]; 
    s.parentNode.insertBefore(hm, s);
  })();
  </script>

  

  
  <script src="../../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

  
  <header class="site-header">
    <div class="site-logo">
      <a href="/"><img src="../../_static/images/PP_w.png"></a>
    </div>
    <div class="site-nav-links">
      <div class="site-menu">
65
        <a class="fork-on-github" href="https://github.com/PaddlePaddle/Paddle" target="_blank"><i class="fa fa-github"></i>Fork me on Github</a>
66 67 68 69 70 71 72 73 74 75 76 77
        <div class="language-switcher dropdown">
          <a type="button" data-toggle="dropdown">
            <span>English</span>
            <i class="fa fa-angle-up"></i>
            <i class="fa fa-angle-down"></i>
          </a>
          <ul class="dropdown-menu">
            <li><a href="/doc_cn">中文</a></li>
            <li><a href="/doc">English</a></li>
          </ul>
        </div>
        <ul class="site-page-links">
78
          <li><a href="/">Home</a></li>
79 80 81 82
        </ul>
      </div>
      <div class="doc-module">
        
83
        <ul>
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
<li class="toctree-l1"><a class="reference internal" href="../../getstarted/index_en.html">GET STARTED</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../howto/index_en.html">HOW TO</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/index_en.html">API</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../about/index_en.html">ABOUT</a></li>
</ul>

        
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>        
      </div>
    </div>
  </header>
  
  <div class="main-content-wrap">

    
    <nav class="doc-menu-vertical" role="navigation">
        
          
108
          <ul>
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
<li class="toctree-l1"><a class="reference internal" href="../../getstarted/index_en.html">GET STARTED</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../getstarted/build_and_install/index_en.html">Install and Build</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../getstarted/build_and_install/docker_install_en.html">PaddlePaddle in Docker Containers</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../getstarted/build_and_install/ubuntu_install_en.html">Debian Package installation guide</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../getstarted/build_and_install/build_from_source_en.html">Installing from Sources</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../howto/index_en.html">HOW TO</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../howto/usage/cmd_parameter/index_en.html">Set Command-line Parameters</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../howto/usage/cmd_parameter/use_case_en.html">Use Case</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../howto/usage/cmd_parameter/arguments_en.html">Argument Outline</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../howto/usage/cmd_parameter/detail_introduction_en.html">Detail Description</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../howto/usage/cluster/cluster_train_en.html">Run Distributed Training</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../howto/usage/k8s/k8s_en.html">Paddle On Kubernetes</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../howto/usage/k8s/k8s_aws_en.html">Distributed PaddlePaddle Training on AWS with Kubernetes</a></li>
128
<li class="toctree-l2"><a class="reference internal" href="../../howto/dev/build_en.html">Build PaddlePaddle from Source Code and Run Unit Test</a></li>
129 130
<li class="toctree-l2"><a class="reference internal" href="../../howto/dev/new_layer_en.html">Write New Layers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../howto/dev/contribute_to_paddle_en.html">Contribute Code</a></li>
131 132 133 134
<li class="toctree-l2"><a class="reference internal" href="../../howto/deep_model/rnn/index_en.html">RNN Models</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../howto/deep_model/rnn/rnn_config_en.html">RNN Configuration</a></li>
</ul>
</li>
135 136 137 138
<li class="toctree-l2"><a class="reference internal" href="../../howto/optimization/gpu_profiling_en.html">Tune GPU Performance</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../api/index_en.html">API</a><ul>
139 140 141
<li class="toctree-l2"><a class="reference internal" href="../../api/v2/model_configs.html">Model Configuration</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/activation.html">Activation</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/layer.html">Layers</a></li>
142
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/evaluators.html">Evaluators</a></li>
143 144 145 146 147 148
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/optimizer.html">Optimizer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/pooling.html">Pooling</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/networks.html">Networks</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/attr.html">Parameter Attribute</a></li>
</ul>
</li>
149
<li class="toctree-l2"><a class="reference internal" href="../../api/v2/data.html">Data Reader Interface and DataSets</a></li>
150
<li class="toctree-l2"><a class="reference internal" href="../../api/v2/run_logic.html">Training and Inference</a></li>
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../about/index_en.html">ABOUT</a></li>
</ul>

        
    </nav>
    
    <section class="doc-content-wrap">

      

 







<div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
      
    <li>Regression MovieLens Ratting</li>
  </ul>
</div>
      
      <div class="wy-nav-content" id="doc-content">
        <div class="rst-content">
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="regression-movielens-ratting">
<h1>Regression MovieLens Ratting<a class="headerlink" href="#regression-movielens-ratting" title="Permalink to this headline"></a></h1>
<p>Here we demonstrate a <strong>Cosine Similarity Regression</strong> job in movie lens dataset.
This demo will show how paddle does (word) embedding job,
handles the similarity regression,
the character-level convolutional networks for text, and how does paddle handle
multiple types of inputs.
Note that the model structure is not fine-tuned and just a demo to show how paddle works.</p>
<p>YOU ARE WELCOME TO BUILD A BETTER DEMO
BY USING PADDLEPADDLE, AND LET US KNOW TO MAKE THIS DEMO BETTER.</p>
<div class="section" id="data-preparation">
<h2>Data Preparation<a class="headerlink" href="#data-preparation" title="Permalink to this headline"></a></h2>
<div class="section" id="download-and-extract-dataset">
<h3>Download and extract dataset<a class="headerlink" href="#download-and-extract-dataset" title="Permalink to this headline"></a></h3>
<p>We use <a class="reference internal" href="ml_dataset_en.html#demo-ml-dataset"><span class="std std-ref">MovieLens Dataset</span></a> here.
To download and unzip the dataset, simply run the following commands.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="nb">cd</span> demo/recommendation/data
./ml_data.sh
</pre></div>
</div>
<p>And the directory structure of <code class="code docutils literal"><span class="pre">demo/recommendation/data/ml-1m</span></code> is:</p>
<div class="highlight-text"><div class="highlight"><pre><span></span>+--ml-1m
     +--- movies.dat    # movie features
     +--- ratings.dat   # ratings
     +--- users.dat     # user features
     +--- README        # dataset description
</pre></div>
</div>
</div>
<div class="section" id="field-config-file">
<h3>Field config file<a class="headerlink" href="#field-config-file" title="Permalink to this headline"></a></h3>
<p><strong>Field config file</strong> is used to specify the fields of the dataset and the file format,
i.e, specific <strong>WHAT</strong> type it is in each feature file.</p>
<p>The field config file of ml-1m shows in <code class="code docutils literal"><span class="pre">demo/recommendation/data/config.json</span></code>.
It specifics the field types and file names: 1) there are four types of field for user file: id, gender, age and occupation;
2) the filename is &#8220;users.dat&#8221;, and the delimiter of file is &#8221;::&#8221;.</p>
</div>
</div>
<div class="section" id="preprocess-data">
<h2>Preprocess Data<a class="headerlink" href="#preprocess-data" title="Permalink to this headline"></a></h2>
<p>You need to install python 3rd party libraries.
IT IS HIGHLY RECOMMEND TO USE VIRTUALENV MAKE A CLEAN PYTHON ENVIRONMENT.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>pip install -r requirements.txt
</pre></div>
</div>
<p>The general command for preprocessing the dataset is:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="nb">cd</span> demo/recommendation
./preprocess.sh
</pre></div>
</div>
<p>And the detail steps are introduced as follows.</p>
<div class="section" id="extract-movie-user-features-to-python-object">
<h3>Extract Movie/User features to python object<a class="headerlink" href="#extract-movie-user-features-to-python-object" title="Permalink to this headline"></a></h3>
<p>There are many features in movie or user in movielens 1m dataset.
Each line of rating file just provides a Movie/User id to refer each movie or user.
We process the movie/user feature file first, and pickle the feature (<strong>Meta</strong>) object as a file.</p>
<div class="section" id="meta-config-file">
<h4>Meta config file<a class="headerlink" href="#meta-config-file" title="Permalink to this headline"></a></h4>
<p><strong>Meta config file</strong> is used to specific <strong>HOW</strong> to parse each field in dataset.
It could be translated from field config file, or written by hand.
Its file format could be either json or yaml syntax file. Parser will automatically choose the file format by extension name.</p>
<p>To convert Field config file to meta config file, just run:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="nb">cd</span> demo/recommendation/data
python config_generator.py config.json &gt; meta_config.json
</pre></div>
</div>
<p>The meta config file shows below:</p>
<p>There are two kinds of features in meta: movie and user.</p>
<ul class="simple">
<li><dl class="first docutils">
<dt>in movie file, whose name is movies.dat</dt>
<dd><ul class="first last">
<li>we just split each line by &#8221;::&#8221;</li>
<li>pos 0 is id.</li>
<li><dl class="first docutils">
<dt>pos 1 feature:</dt>
<dd><ul class="first last">
<li>name is title.</li>
<li>it uses regex to parse this feature.</li>
<li>it is a char based word embedding feature.</li>
<li>it is a sequence.</li>
</ul>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>pos 2 feature:</dt>
<dd><ul class="first last">
<li>name is genres.</li>
<li>type is one hot dense vector.</li>
<li>dictionary is auto generated by parsing, each key is split by &#8216;|&#8217;</li>
</ul>
</dd>
</dl>
</li>
</ul>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>in user file, whose name is users.dat</dt>
<dd><ul class="first last">
<li>we just split each line by &#8221;::&#8221;</li>
<li>pos 0 is id.</li>
<li><dl class="first docutils">
<dt>pos 1 feature:</dt>
<dd><ul class="first last">
<li>name is gender</li>
<li>just simple char based embedding.</li>
</ul>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>pos 2 feature:</dt>
<dd><ul class="first last">
<li>name is age</li>
<li>just whole word embedding.</li>
<li>embedding id will be sort by word.</li>
</ul>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>pos 3 feature:</dt>
<dd><ul class="first last">
<li>name is occupation.</li>
<li>just simple whole word embedding.</li>
</ul>
</dd>
</dl>
</li>
</ul>
</dd>
</dl>
</li>
</ul>
</div>
</div>
<div class="section" id="meta-file">
<h3>Meta file<a class="headerlink" href="#meta-file" title="Permalink to this headline"></a></h3>
<p>After having meta config file, we can generate <strong>Meta file</strong>, a python pickle object which stores movie/user information.
The following commands could be run to generate it.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>python meta_generator.py ml-1m meta.bin --config<span class="o">=</span>meta_config.json
</pre></div>
</div>
<p>And the structure of the meta file <code class="code docutils literal"><span class="pre">meta.bin</span></code> is:</p>
<div class="highlight-text"><div class="highlight"><pre><span></span>+--+ movie
|      +--+ __meta__
|      |       +--+ raw_meta  # each feature meta config. list
|      |       |       +
|      |       |       |     # ID Field, we use id as key
|      |       |       +--+ {&#39;count&#39;: 3883, &#39;max&#39;: 3952, &#39;is_key&#39;: True, &#39;type&#39;: &#39;id&#39;, &#39;min&#39;: 1}
|      |       |       |
|      |       |       |     # Titile field, the dictionary list of embedding.
|      |       |       +--+ {&#39;dict&#39;: [ ... ], &#39;type&#39;: &#39;embedding&#39;, &#39;name&#39;: &#39;title&#39;, &#39;seq&#39;: &#39;sequence&#39;}
|      |       |       |
|      |       |       |     # Genres field, the genres dictionary
|      |       |       +--+ {&#39;dict&#39;: [ ... ], &#39;type&#39;: &#39;one_hot_dense&#39;, &#39;name&#39;: &#39;genres&#39;}
|      |       |
|      |       +--+ feature_map [1, 2] # a list for raw_meta index for feature field.
|      |                               # it means there are 2 features for each key.
|      |                               #    * 0 offset of feature is raw_meta[1], Title.
|      |                               #    * 1 offset of feature is raw_meta[2], Genres.
|      |
|      +--+ 1 # movie 1 features
|      |    +
|      |    +---+ [[...], [...]] # title ids, genres dense vector
|      |
|      +--+ 2
|      |
|      +--+ ...
|
+--- user
       +--+ __meta__
       |       +
       |       +--+ raw_meta
       |       |       +
       |       |       +--+ id field as user
       |       |       |
       |       |       +--+ {&#39;dict&#39;: [&#39;F&#39;, &#39;M&#39;], &#39;type&#39;: &#39;embedding&#39;, &#39;name&#39;: &#39;gender&#39;, &#39;seq&#39;: &#39;no_sequence&#39;}
       |       |       |
       |       |       +--+ {&#39;dict&#39;: [&#39;1&#39;, &#39;18&#39;, &#39;25&#39;, &#39;35&#39;, &#39;45&#39;, &#39;50&#39;, &#39;56&#39;], &#39;type&#39;: &#39;embedding&#39;, &#39;name&#39;: &#39;age&#39;, &#39;seq&#39;: &#39;no_sequence&#39;}
       |       |       |
       |       |       +--+ {&#39;dict&#39;: [...], &#39;type&#39;: &#39;embedding&#39;, &#39;name&#39;: &#39;occupation&#39;, &#39;seq&#39;: &#39;no_sequence&#39;}
       |       |
       |       +--+ feature_map [1, 2, 3]
       |
       +--+ 1 # user 1 features
       |
       +--+ 2
       +--+ ...
</pre></div>
</div>
</div>
<div class="section" id="split-training-testing-files">
<h3>Split Training/Testing files<a class="headerlink" href="#split-training-testing-files" title="Permalink to this headline"></a></h3>
<p>We split <code class="code docutils literal"><span class="pre">ml-1m/ratings.dat</span></code> into a training and testing file. The way to split file is for each user, we split the
rating by two parts. So each user in testing file will have some rating information in training file.</p>
<p>Use <code class="code docutils literal"><span class="pre">separate.py</span></code> to separate the training and testing file.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>python split.py ml-1m/ratings.dat --delimiter<span class="o">=</span><span class="s2">&quot;::&quot;</span> --test_ratio<span class="o">=</span><span class="m">0</span>.1
</pre></div>
</div>
<p>Then two files will be generated: <code class="code docutils literal"><span class="pre">ml-1m/ratings.dat.train</span></code> and <code class="code docutils literal"><span class="pre">ml-1m/rating.data.test</span></code>.
Move them to workspace <code class="code docutils literal"><span class="pre">data</span></code>, shuffle the train file, and prepare the file list for paddle train.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>shuf ml-1m/ratings.dat.train &gt; ratings.dat.train
cp ml-1m/ratings.dat.test .
<span class="nb">echo</span> <span class="s2">&quot;./data/ratings.dat.train&quot;</span> &gt; train.list
<span class="nb">echo</span> <span class="s2">&quot;./data/ratings.dat.test&quot;</span> &gt; test.list
</pre></div>
</div>
</div>
</div>
<div class="section" id="neural-network-configuration">
<h2>Neural Network Configuration<a class="headerlink" href="#neural-network-configuration" title="Permalink to this headline"></a></h2>
<div class="section" id="trainer-config-file">
<h3>Trainer Config File<a class="headerlink" href="#trainer-config-file" title="Permalink to this headline"></a></h3>
<p>The network structure shows below.</p>
<img alt="rec_regression_network" class="align-center" src="../../_images/rec_regression_network.png" />
<p>The demo&#8217;s neural network config file <code class="code docutils literal"><span class="pre">trainer_config.py</span></code> show as below.</p>
<p>In this <code class="code docutils literal"><span class="pre">trainer_config.py</span></code>, we just map each feature type to
a feature vector, following shows how to map each feature to a vector shows below.</p>
<ul class="simple">
<li><code class="code docutils literal"><span class="pre">id</span></code>: Just simple embedding, and then add to fully connected layer.</li>
<li><dl class="first docutils">
<dt><code class="code docutils literal"><span class="pre">embedding</span></code>:</dt>
<dd><ul class="first last">
<li>if is_sequence, get the embedding and do a text convolutional operation,
get the average pooling result.</li>
<li>if not sequence, get the embedding and add to fully connected layer.</li>
</ul>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt><code class="code docutils literal"><span class="pre">one_host_dense</span></code>:</dt>
<dd><ul class="first last">
<li>just two fully connected layer.</li>
</ul>
</dd>
</dl>
</li>
</ul>
<p>Then we combine each features of movie into one movie feature by a
<code class="code docutils literal"><span class="pre">fc_layer</span></code> with multiple inputs, and do the same thing to user features,
get one user feature. Then we calculate the cosine similarity of these two
features.</p>
<p>In these networks, we use several APIs in <a class="reference internal" href="../../api/v1/index_en.html#api-trainer-config"><span class="std std-ref">Model Config API</span></a> . There are</p>
<ul class="simple">
432 433 434 435 436 437
<li>Data Layer, <span class="xref std std-ref">api_trainer_config_helpers_layers_data_layer</span></li>
<li>Fully Connected Layer, <span class="xref std std-ref">api_trainer_config_helpers_layers_fc_layer</span></li>
<li>Embedding Layer, <span class="xref std std-ref">api_trainer_config_helpers_layers_embedding_layer</span></li>
<li>Context Projection Layer, <span class="xref std std-ref">api_trainer_config_helpers_layers_context_projection</span></li>
<li>Pooling Layer, <span class="xref std std-ref">api_trainer_config_helpers_layers_pooling_layer</span></li>
<li>Cosine Similarity Layer, <span class="xref std std-ref">api_trainer_config_helpers_layers_cos_sim</span></li>
438
<li>Text Convolution Pooling Layer, <a class="reference internal" href="../../api/v2/config/networks.html#api-trainer-config-helpers-network-text-conv-pool"><span class="std std-ref">text_conv_pool</span></a></li>
439
<li>Declare Python Data Sources <span class="xref std std-ref">api_trainer_config_helpers_data_sources</span>.</li>
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
</ul>
</div>
<div class="section" id="data-provider">
<h3>Data Provider<a class="headerlink" href="#data-provider" title="Permalink to this headline"></a></h3>
<p>The data provider just read the meta.bin and rating file, yield each sample for training.
In this <code class="code docutils literal"><span class="pre">dataprovider.py</span></code>, we should set:</p>
<ul class="simple">
<li>obj.slots: The feature types and dimension.</li>
<li>use_seq: Whether this <code class="code docutils literal"><span class="pre">dataprovider.py</span></code> in sequence mode or not.</li>
<li>process: Return each sample of data to <code class="code docutils literal"><span class="pre">paddle</span></code>.</li>
</ul>
<p>The data provider details document see <a class="reference internal" href="../../api/v1/data_provider/pydataprovider2_en.html#api-pydataprovider2"><span class="std std-ref">PyDataProvider2</span></a>.</p>
</div>
</div>
<div class="section" id="train">
<h2>Train<a class="headerlink" href="#train" title="Permalink to this headline"></a></h2>
<p>After prepare data, config network, writting data provider, now we can run paddle training.</p>
<p>The <code class="code docutils literal"><span class="pre">run.sh</span></code> is shown as follow:</p>
<p>It just start a paddle training process, write the log to <code class="code docutils literal"><span class="pre">log.txt</span></code>,
then print it on screen.</p>
<p>Each command line argument in <code class="code docutils literal"><span class="pre">run.sh</span></code>, please refer to the <a class="reference internal" href="../../howto/usage/cmd_parameter/index_en.html#cmd-line-index"><span class="std std-ref">Set Command-line Parameters</span></a> page. The short description of these arguments is shown as follow.</p>
<ul class="simple">
<li>config: Tell paddle which file is neural network configuration.</li>
<li>save_dir: Tell paddle save model into <code class="code docutils literal"><span class="pre">./output</span></code>.</li>
<li>use_gpu: Use gpu or not. Default is false.</li>
<li>trainer_count: The compute thread in one machine.</li>
<li>test_all_data_in_one_period: Test All Data during one test period. Otherwise,
will test a <code class="code docutils literal"><span class="pre">batch_size</span></code> data in one test period.</li>
<li>log_period: Print log after train <code class="code docutils literal"><span class="pre">log_period</span></code> batches.</li>
<li>dot_period: Print a <code class="code docutils literal"><span class="pre">.</span></code> after train <code class="code docutils literal"><span class="pre">dot_period</span></code> batches.</li>
<li>num_passes: Train at most <code class="code docutils literal"><span class="pre">num_passes</span></code>.</li>
</ul>
<p>If training process starts successfully, the output likes follow:</p>
<div class="highlight-text"><div class="highlight"><pre><span></span>I0601 08:07:22.832059 10549 TrainerInternal.cpp:157]  Batch=100 samples=160000 AvgCost=4.13494 CurrentCost=4.13494 Eval:  CurrentEval:

I0601 08:07:50.672627 10549 TrainerInternal.cpp:157]  Batch=200 samples=320000 AvgCost=3.80957 CurrentCost=3.48421 Eval:  CurrentEval:

I0601 08:08:18.877369 10549 TrainerInternal.cpp:157]  Batch=300 samples=480000 AvgCost=3.68145 CurrentCost=3.42519 Eval:  CurrentEval:

I0601 08:08:46.863963 10549 TrainerInternal.cpp:157]  Batch=400 samples=640000 AvgCost=3.6007 CurrentCost=3.35847 Eval:  CurrentEval:

I0601 08:09:15.413025 10549 TrainerInternal.cpp:157]  Batch=500 samples=800000 AvgCost=3.54811 CurrentCost=3.33773 Eval:  CurrentEval:
I0601 08:09:36.058670 10549 TrainerInternal.cpp:181]  Pass=0 Batch=565 samples=902826 AvgCost=3.52368 Eval:
I0601 08:09:46.215489 10549 Tester.cpp:101]  Test samples=97383 cost=3.32155 Eval:
I0601 08:09:46.215966 10549 GradientMachine.cpp:132] Saving parameters to ./output/model/pass-00000
I0601 08:09:46.233397 10549 ParamUtil.cpp:99] save dir ./output/model/pass-00000
I0601 08:09:46.233438 10549 Util.cpp:209] copy trainer_config.py to ./output/model/pass-00000
I0601 08:09:46.233541 10549 ParamUtil.cpp:147] fileName trainer_config.py
</pre></div>
</div>
<p>The model is saved in <code class="code docutils literal"><span class="pre">output/</span></code> directory. You can use <code class="code docutils literal"><span class="pre">Ctrl-C</span></code> to stop training whenever you want.</p>
</div>
<div class="section" id="evaluate-and-predict">
<h2>Evaluate and Predict<a class="headerlink" href="#evaluate-and-predict" title="Permalink to this headline"></a></h2>
<p>After training several passes, you can evaluate them and get the best pass. Just run</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>./evaluate.sh
</pre></div>
</div>
<p>You will see messages like this:</p>
<div class="highlight-text"><div class="highlight"><pre><span></span>Best pass is 00009,  error is 3.06949, which means predict get error as 0.875998002281
evaluating from pass output/pass-00009
</pre></div>
</div>
<p>Then, you can predict what any user will rate a movie. Just run</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>python prediction.py <span class="s1">&#39;output/pass-00009/&#39;</span>
</pre></div>
</div>
<p>Predictor will read user input, and predict scores. It has a command-line user interface as follows:</p>
<div class="highlight-text"><div class="highlight"><pre><span></span>Input movie_id: 9
Input user_id: 4
Prediction Score is 2.56
Input movie_id: 8
Input user_id: 2
Prediction Score is 3.13
</pre></div>
</div>
</div>
</div>


           </div>
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2016, PaddlePaddle developers.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../../',
            VERSION:'',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
554 555
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: ".txt",
556 557 558 559 560
        };
    </script>
      <script type="text/javascript" src="../../_static/jquery.js"></script>
      <script type="text/javascript" src="../../_static/underscore.js"></script>
      <script type="text/javascript" src="../../_static/doctools.js"></script>
561
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
562 563 564 565 566 567 568 569 570 571 572 573 574
       
  

  
  
    <script type="text/javascript" src="../../_static/js/theme.js"></script>
  
  
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/perfect-scrollbar/0.6.14/js/perfect-scrollbar.jquery.min.js"></script>
  <script src="../../_static/js/paddle_doc_init.js"></script> 

</body>
575
</html>