Code Monkey home page Code Monkey logo

deepfm_with_pytorch's Introduction

DeepFM_with_PyTorch

A PyTorch implementation of DeepFM for CTR prediction problem.

Usage

  1. Download Criteo's Kaggle display advertising challenge dataset from here( if you have had it already, skip it ), and put it in ./data/raw/

  2. Generate a preprocessed dataset.

     ./utils/dataPreprocess.py
    
  3. Train a model and predict.

     ./main.py
    

Output

Reference

deepfm_with_pytorch's People

Contributors

chenxijun1029 avatar vnherdeiro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

deepfm_with_pytorch's Issues

20

Hello, Could you tell me why it is 20? What's the meaning of it?
In the part of DeepFM.Forward
"""
emb = self.fm_first_order_embeddings[20]
print(Xi.size())
for num in Xi[:, 20, :][0]:
if num > self.feature_sizes[20]:
print("index out")
"""

Report a bug.

In dataset.py, line 29 and 33, you usepd.read_csv to read from your data that generated from original data. However, you forget to add param header = -1, because the new test.csv and train.csv actully don't have a header. And pandas will use the first line of data as the header, which will cause an index error later.
The follows are what the code should be like.

data = pd.read_csv(os.path.join(root, 'train.txt'), header = -1)
data = pd.read_csv(os.path.join(root, 'test.txt'), header = -1)

about the index of continous features

in data/dataset.py

if self.train:
            # index of continous features are zero
            Xi_coutinous = np.zeros_like(dataI[:continous_features])
else:
            # index of continous features are one
            Xi_coutinous = np.ones_like(dataI[:continous_features])

Why are the indexes generated by the continuous variables of the training set and the test set zero and one respectively? And should index for each continuous variable be the same?

哎,BUG满天飞,浪费我一个小时时间,绝绝子.

class ContinuousFeatureGenerator:
"""
Clip continuous features.
"""

def __init__(self, num_feature):
    self.num_feature = num_feature

def build(self, datafile, continous_features):
    df = pd.read_csv(datafile, sep="\t", header=True)
    with open(datafile, 'r') as f:
        for line in f:
            features = line.rstrip('\n').split('\t')
            for i in range(0, self.num_feature):
                val = features[continous_features[i]]
                if val != '':
                    val = int(val)
                    if val > continous_clip[i]:
                        val = continous_clip[i] # 这个val弄了半天,也没存储,赋值,所以处理了有啥用呀

def gen(self, idx, val):
    if val == '':
        return 0.0
    val = float(val)
    return val

RuntimeError: index out of range at /pytorch/aten/src/TH/generic/THTensorEvenMoreMath.cpp:191

observing the following error while running deep ctr on the gpu:

Traceback (most recent call last):
File "main.py", line 31, in
model.fit(loader_train, loader_val, optimizer, epochs=5, verbose=True)
File "/root/deepctr/DeepFM_with_PyTorch/model/DeepFM.py", line 153, in fit
total = model(xi, xv)
File "/usr/local/lib/python3.5/dist-packages/torch/nn/modules/module.py", line 489, in call
result = self.forward(*input, **kwargs)
File "/root/deepctr/DeepFM_with_PyTorch/model/DeepFM.py", line 98, in forward
fm_first_order_emb_arr = [(torch.sum(emb(Xi[:, i, :]), 1).t() * Xv[:, i]).t() for i, emb in enumerate(self.fm_first_order_embeddings)]
File "/root/deepctr/DeepFM_with_PyTorch/model/DeepFM.py", line 98, in
fm_first_order_emb_arr = [(torch.sum(emb(Xi[:, i, :]), 1).t() * Xv[:, i]).t() for i, emb in enumerate(self.fm_first_order_embeddings)]
File "/usr/local/lib/python3.5/dist-packages/torch/nn/modules/module.py", line 489, in call
result = self.forward(*input, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/torch/nn/modules/sparse.py", line 118, in forward
self.norm_type, self.scale_grad_by_freq, self.sparse)
File "/usr/local/lib/python3.5/dist-packages/torch/nn/functional.py", line 1454, in embedding
return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
RuntimeError: index out of range at /pytorch/aten/src/TH/generic/THTensorEvenMoreMath.cpp:191

dataPreprocess.py 两个问题

一、
dataPreprocess.py代码,86行,num_train_sample = 10000,这里应该是1000000吧?
否则运行main.py报错IndexError: index 9999 is out of bounds for axis 0 with size 9999

二、
dataPreprocess.py代码的连续值处理的裁剪没有生效,(代码原因),也可以做个测试,修改continous_clip = [20, 600, 100, 50, 64000, 500, 100, 50, 500, 10, 10, 10, 50],比如为0,会发现生成出来的train.txt中的连续值不会是0,即裁剪未生效

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.