preprocess.sh 1.6 KB
Newer Older
H
hupeng03 已提交
1
#!/bin/sh
Z
zhangjinchao01 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15
# Copyright (c) 2016 Baidu, Inc. All Rights Reserved
#
# Licensed 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.

H
hupeng03 已提交
16 17 18 19 20
# 1. size of pos : neg = 1:1.
# 2. size of testing set = min(25k, len(all_data) * 0.1), others is traning set.
# 3. distinct train set and test set.
# 4. build dict

D
dangqingqing 已提交
21
set -e
H
hupeng03 已提交
22

D
dangqingqing 已提交
23
mkdir -p data/tmp
Z
zhangjinchao01 已提交
24
python preprocess.py -i data/reviews_Electronics_5.json.gz
H
hupeng03 已提交
25 26
# uniq and shuffle
cd data/tmp
D
dangqingqing 已提交
27
echo 'uniq and shuffle...'
H
hupeng03 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
cat pos_*|sort|uniq|shuf> pos.shuffed
cat neg_*|sort|uniq|shuf> neg.shuffed

min_len=`sed -n '$=' neg.shuffed`
((test_num=$min_len/10))
if [ $test_num -gt 12500 ];then
 test_num=12500
fi
((train_num=$min_len-$test_num))

head -n$train_num pos.shuffed >train.pos
head -n$train_num neg.shuffed >train.neg
tail -n$test_num pos.shuffed >test.pos
tail -n$test_num neg.shuffed >test.neg

cat train.pos train.neg|shuf>../train.txt
cat test.pos test.neg|shuf>../test.txt

cd -
echo 'data/train.txt' > data/train.list
echo 'data/test.txt' > data/test.list
Z
zhangjinchao01 已提交
49 50

# use 30k dict
H
hupeng03 已提交
51
rm -rf data/tmp
Z
zhangjinchao01 已提交
52 53
mv data/dict.txt data/dict_all.txt
cat data/dict_all.txt | head -n 30001 > data/dict.txt
H
hupeng03 已提交
54
echo 'preprocess finished'