mirror of
https://github.com/RustyRaptor/incubator-mxnet.git
synced 2026-12-03 15:55:23 -07:00
* draft for fm * add example of checkpointing sparse model * remove kvtore code * add back kvstore and dummy iter * add fm folder * add missing files * add metric * update optimizer * bug fix for metrics * update default num epochs * re-org example folder * better aws cmd * add hyperparams to args parser * move dummy iter to common file. renmae get_data.py * remove dataset. * use fluent method * move dummy iter to test_utils * add error msg * doc update of dummy itr
35 lines
1.6 KiB
Python
35 lines
1.6 KiB
Python
# Licensed to the Apache Software Foundation (ASF) under one
|
|
# or more contributor license agreements. See the NOTICE file
|
|
# distributed with this work for additional information
|
|
# regarding copyright ownership. The ASF licenses this file
|
|
# to you under the Apache License, Version 2.0 (the
|
|
# "License"); you may not use this file except in compliance
|
|
# with the License. You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing,
|
|
# software distributed under the License is distributed on an
|
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
# KIND, either express or implied. See the License for the
|
|
# specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
import mxnet as mx
|
|
from weighted_softmax_ce import *
|
|
|
|
def linear_model(num_features, positive_cls_weight):
|
|
# data with csr storage type to enable feeding data with CSRNDArray
|
|
x = mx.symbol.Variable("data", stype='csr')
|
|
norm_init = mx.initializer.Normal(sigma=0.01)
|
|
# weight with row_sparse storage type to enable sparse gradient updates
|
|
weight = mx.symbol.Variable("weight", shape=(num_features, 2),
|
|
init=norm_init, stype='row_sparse')
|
|
bias = mx.symbol.Variable("bias", shape=(2,))
|
|
dot = mx.symbol.sparse.dot(x, weight)
|
|
pred = mx.symbol.broadcast_add(dot, bias)
|
|
y = mx.symbol.Variable("softmax_label")
|
|
model = mx.sym.Custom(pred, y, op_type='weighted_softmax_ce_loss',
|
|
positive_cls_weight=positive_cls_weight, name='out')
|
|
return mx.sym.MakeLoss(model)
|