-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlearn.jl
More file actions
97 lines (86 loc) · 3.11 KB
/
Copy pathlearn.jl
File metadata and controls
97 lines (86 loc) · 3.11 KB
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
include("learnlib.jl")
include("learnlibtf.jl")
function run_rank_tf_logit()
println("Training rank tf logit")
tf_W, tf_b = tftrain_logistic(trainX, Array{Int32}(ratingstoranks(trainY)), weights2)
trainYpred = [a[2] for a in argmax(trainX*tf_W .+ tf_b, dims=2)]
testYpred = [a[2] for a in argmax(testX*tf_W .+ tf_b, dims=2)]
evaluateclassifier("rank_tf_logit_train", ratingstoranks(trainY), trainYpred)
evaluateclassifier("rank_tf_logit_test", ratingstoranks(testY), testYpred)
Dict(
"W"=> tf_W,
"b"=> tf_b,
)
end
function run_country_tf_logit()
println("Training country tf logit")
tf_W, tf_b = tftrain_logistic_country(trainXc, trainTc, weightscountry)
trainTcpred = [a[2] for a in argmax(trainXc*tf_W .+ tf_b, dims=2)]
testTcpred = [a[2] for a in argmax(testXc*tf_W .+ tf_b, dims=2)]
evaluatecountryclassifier("country_tf_logit_train", trainTc, trainTcpred)
evaluatecountryclassifier("country_tf_logit_test", testTc, testTcpred)
Dict(
"W"=> tf_W,
"b"=> tf_b,
)
end
function run_rank_tf_nnclass()
println("Training rank tf nnclass")
tf_W1, tf_b1, tf_W2, tf_b2 = tftrain_nnclass(trainX, Array{Int32}(ratingstoranks(trainY)), weights2)
trainYpred = tfeval_nnclass(trainX, tf_W1, tf_b1, tf_W2, tf_b2)
testYpred = tfeval_nnclass(testX, tf_W1, tf_b1, tf_W2, tf_b2)
evaluateclassifier("rank_tf_nnclass_train", ratingstoranks(trainY), trainYpred)
evaluateclassifier("rank_tf_nnclass_test", ratingstoranks(testY), testYpred)
Dict(
"W1"=> tf_W1,
"b1"=> tf_b1,
"W2"=> tf_W2,
"b2"=> tf_b2,
)
end
function run_country_tf_nnclass()
println("Training country tf nnclass")
tf_W1, tf_b1, tf_W2, tf_b2 = tftrain_nn_country(trainXc, trainTc, weightscountry)
trainTcpred = tfeval_nnclass(trainXc, tf_W1, tf_b1, tf_W2, tf_b2)
testTcpred = tfeval_nnclass(testXc, tf_W1, tf_b1, tf_W2, tf_b2)
evaluatecountryclassifier("country_tf_nnlass_train", trainTc, trainTcpred)
evaluatecountryclassifier("country_tf_nnclass_test", testTc, testTcpred)
Dict(
"W1"=> tf_W1,
"b1"=> tf_b1,
"W2"=> tf_W2,
"b2"=> tf_b2,
)
end
if length(ARGS) != 1
println("Invalid args")
exit()
end
println("Loading data")
objs = JLD.load(@sprintf("cs229_project/data2-tokens-big-2gram-cv-%s.jld", ARGS[1]));
trainX = objs["trainX"];
trainXv1 = objs["trainXv1"];
trainY = objs["trainY"];
trainT = objs["trainT"];
testX = objs["testX"];
testXv1 = objs["testXv1"];
testY = objs["testY"];
testT = objs["testT"];
weights = getweights(trainY);
weights2 = getweights2(trainY);
trainXc = trainX[trainT .!= -1, :];
trainTc = trainT[trainT .!= -1];
testXc = testX[testT .!= -1, :];
testTc = testT[testT .!= -1];
weightscountry = getweightscountry(trainTc)
objs = nothing;
@printf("Main set: %d train %d test\n", size(trainX, 1), size(testX, 1))
@printf("Country set: %d train %d test\n", size(trainXc, 1), size(testXc, 1))
# Uncomment to train rank classifier instead of country.
#tf_nnclass = run_rank_tf_nnclass()
#tf_logit = run_rank_tf_logit()
tf_nnclass = run_country_tf_nnclass()
tf_logit = run_country_tf_logit()
JLD.save(@sprintf("cs229_project/data2-tokens-big-2gram-cv-%s-tf-country.jld", ARGS[1]),
"tf_nnclass", tf_nnclass,
"tf_logit", tf_logit)