Skip to content

Commit b52a6ae

Browse files
author
captain
committed
add pytorch code
1 parent 7aabbdf commit b52a6ae

File tree

452 files changed

+117200
-49
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

452 files changed

+117200
-49
lines changed
-61 Bytes
Binary file not shown.

data_manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#coding:utf-8
2+
13
import os
24
import sys
35
import pickle

data_manager.pyc

68 Bytes
Binary file not shown.

models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# coding:utf-8
2+
13
import os
24
import time
35

run.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#coding:utf-8
2+
13
import argparse
24
import sys
35
import os

run_test_preprocess.sh

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@ python ./run.py \
33
-d ./data/preprocessed/ml-1m/0.2/ \
44
-a ./data/preprocessed/ml-1m/ \
55
-c True \
6-
-r ./data/rare/movielens/ml-1m_ratings.dat \
7-
-i ./data/rare/movielens/ml_plot.dat \
6+
-r ./data/movielens/ml-1m_ratings.dat \
7+
-i ./data/movielens/ml_plot.dat \
88
-m 1
9-
10-
11-
##!/usr/bin/env bash
12-
#python ./run.py \
13-
#-d ./data/preprocessed/aiv/0.2/ \
14-
#-a ./data/preprocessed/aiv/ \
15-
#-c True \
16-
#-r ./data/rare/aiv/Amazon_Instant_Video_ratings.txt \
17-
#-i ./data/rare/aiv/Amazon_Instant_Video_items.txt \
18-
#-m 1

text_analysis/cnn_model.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# coding:utf-8
2+
3+
import torch
4+
import torch.nn as nn
5+
from torch.autograd import Variable
6+
7+
8+
class CNN(nn.Module):
9+
batch_size = 128
10+
# More than this epoch cause easily over-fitting on our data sets
11+
nb_epoch = 5
12+
13+
def __init__(self, output_dimesion, vocab_size, dropout_rate, emb_dim, max_len, nb_filters, init_W=None):
14+
super(CNN, self).__init__()
15+
16+
self.max_len = max_len
17+
max_features = vocab_size
18+
vanila_dimension = 200
19+
projection_dimension = output_dimesion
20+
self.qual_conv_set = {}
21+
22+
self.embedding = nn.Embedding()
23+
24+
self.conv1 = nn.Sequential(
25+
nn.Conv2d(1, nb_filters, kernel_size=(3, emb_dim)),
26+
nn.MaxPool2d(kernel_size=(max_len - 3 + 1, 1))
27+
)
28+
self.conv2 = nn.Sequential(
29+
nn.Conv2d(1, nb_filters, kernel_size=(4, emb_dim)),
30+
nn.MaxPool2d(kernel_size=(max_len - 4 + 1, 1))
31+
)
32+
self.conv3 = nn.Sequential(
33+
nn.Conv2d(1, nb_filters, kernel_size=(5, emb_dim)),
34+
nn.MaxPool2d(kernel_size=(max_len - 5 + 1, 1))
35+
)
36+
37+
38+
self.conv_1 =
39+
self.conv_2 = nn.Conv2d(1, nb_filters, kernel_size=(4, emb_dim))
40+
self.conv_3 = nn.Conv2d(1, nb_filters, kernel_size=(5, emb_dim))
41+
42+
def forward(self, *input):
43+
pass

text_analysis/models.py

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#coding:utf-8
2+
13
import numpy as np
24
np.random.seed(1337)
35

@@ -74,43 +76,6 @@ def __init__(self, output_dimesion, vocab_size, dropout_rate, emb_dim, max_len,
7476

7577
print("Jay::compile completed")
7678

77-
# '''Embedding Layer'''
78-
# self.model.add_input(name='input', input_shape=(max_len,), dtype=int)
79-
#
80-
# if init_W is None:
81-
# self.model.add_node(Embedding(
82-
# max_features, emb_dim, input_length=max_len), name='sentence_embeddings', input='input')
83-
# else:
84-
# self.model.add_node(Embedding(max_features, emb_dim, input_length=max_len, weights=[
85-
# init_W / 20]), name='sentence_embeddings', input='input')
86-
#
87-
# '''Convolution Layer & Max Pooling Layer'''
88-
# for i in filter_lengths:
89-
# model_internal = Sequential()
90-
# model_internal.add(
91-
# Reshape(dims=(1, self.max_len, emb_dim), input_shape=(self.max_len, emb_dim)))
92-
# model_internal.add(Convolution2D(
93-
# nb_filters, i, emb_dim, activation="relu"))
94-
# model_internal.add(MaxPooling2D(
95-
# pool_size=(self.max_len - i + 1, 1)))
96-
# model_internal.add(Flatten())
97-
#
98-
# self.model.add_node(model_internal, name='unit_' +
99-
# str(i), input='sentence_embeddings')
100-
#
101-
# '''Dropout Layer'''
102-
# self.model.add_node(Dense(vanila_dimension, activation='tanh'),
103-
# name='fully_connect', inputs=['unit_' + str(i) for i in filter_lengths])
104-
# self.model.add_node(Dropout(dropout_rate),
105-
# name='dropout', input='fully_connect')
106-
# '''Projection Layer & Output Layer'''
107-
# self.model.add_node(Dense(projection_dimension, activation='tanh'),
108-
# name='projection', input='dropout')
109-
#
110-
# # Output Layer
111-
# self.model.add_output(name='output', input='projection')
112-
# self.model.compile('rmsprop', {'output': 'mse'})
113-
11479
def load_model(self, model_path):
11580
self.model.load_weights(model_path)
11681

venv/bin/activate

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# This file must be used with "source bin/activate" *from bash*
2+
# you cannot run it directly
3+
4+
deactivate () {
5+
unset -f pydoc >/dev/null 2>&1
6+
7+
# reset old environment variables
8+
# ! [ -z ${VAR+_} ] returns true if VAR is declared at all
9+
if ! [ -z "${_OLD_VIRTUAL_PATH+_}" ] ; then
10+
PATH="$_OLD_VIRTUAL_PATH"
11+
export PATH
12+
unset _OLD_VIRTUAL_PATH
13+
fi
14+
if ! [ -z "${_OLD_VIRTUAL_PYTHONHOME+_}" ] ; then
15+
PYTHONHOME="$_OLD_VIRTUAL_PYTHONHOME"
16+
export PYTHONHOME
17+
unset _OLD_VIRTUAL_PYTHONHOME
18+
fi
19+
20+
# This should detect bash and zsh, which have a hash command that must
21+
# be called to get it to forget past commands. Without forgetting
22+
# past commands the $PATH changes we made may not be respected
23+
if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then
24+
hash -r 2>/dev/null
25+
fi
26+
27+
if ! [ -z "${_OLD_VIRTUAL_PS1+_}" ] ; then
28+
PS1="$_OLD_VIRTUAL_PS1"
29+
export PS1
30+
unset _OLD_VIRTUAL_PS1
31+
fi
32+
33+
unset VIRTUAL_ENV
34+
if [ ! "${1-}" = "nondestructive" ] ; then
35+
# Self destruct!
36+
unset -f deactivate
37+
fi
38+
}
39+
40+
# unset irrelevant variables
41+
deactivate nondestructive
42+
43+
VIRTUAL_ENV="/home/captain/git/ConvMF/venv"
44+
export VIRTUAL_ENV
45+
46+
_OLD_VIRTUAL_PATH="$PATH"
47+
PATH="$VIRTUAL_ENV/bin:$PATH"
48+
export PATH
49+
50+
# unset PYTHONHOME if set
51+
if ! [ -z "${PYTHONHOME+_}" ] ; then
52+
_OLD_VIRTUAL_PYTHONHOME="$PYTHONHOME"
53+
unset PYTHONHOME
54+
fi
55+
56+
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ] ; then
57+
_OLD_VIRTUAL_PS1="$PS1"
58+
if [ "x" != x ] ; then
59+
PS1="$PS1"
60+
else
61+
PS1="(`basename \"$VIRTUAL_ENV\"`) $PS1"
62+
fi
63+
export PS1
64+
fi
65+
66+
# Make sure to unalias pydoc if it's already there
67+
alias pydoc 2>/dev/null >/dev/null && unalias pydoc
68+
69+
pydoc () {
70+
python -m pydoc "$@"
71+
}
72+
73+
# This should detect bash and zsh, which have a hash command that must
74+
# be called to get it to forget past commands. Without forgetting
75+
# past commands the $PATH changes we made may not be respected
76+
if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then
77+
hash -r 2>/dev/null
78+
fi

venv/bin/activate.csh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This file must be used with "source bin/activate.csh" *from csh*.
2+
# You cannot run it directly.
3+
# Created by Davide Di Blasi <[email protected]>.
4+
5+
alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; test "\!:*" != "nondestructive" && unalias deactivate && unalias pydoc'
6+
7+
# Unset irrelevant variables.
8+
deactivate nondestructive
9+
10+
setenv VIRTUAL_ENV "/home/captain/git/ConvMF/venv"
11+
12+
set _OLD_VIRTUAL_PATH="$PATH"
13+
setenv PATH "$VIRTUAL_ENV/bin:$PATH"
14+
15+
16+
17+
if ("" != "") then
18+
set env_name = ""
19+
else
20+
set env_name = `basename "$VIRTUAL_ENV"`
21+
endif
22+
23+
# Could be in a non-interactive environment,
24+
# in which case, $prompt is undefined and we wouldn't
25+
# care about the prompt anyway.
26+
if ( $?prompt ) then
27+
set _OLD_VIRTUAL_PROMPT="$prompt"
28+
set prompt = "[$env_name] $prompt"
29+
endif
30+
31+
unset env_name
32+
33+
alias pydoc python -m pydoc
34+
35+
rehash
36+

0 commit comments

Comments
 (0)