forked from facebookresearch/LASER
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_external_tools.sh
executable file
·142 lines (120 loc) · 3.8 KB
/
install_external_tools.sh
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
#
# LASER Language-Agnostic SEntence Representations
# is a toolkit to calculate multilingual sentence embeddings
# and to use them for document classification, bitext filtering
# and mining
#
#-------------------------------------------------------
#
# This bash script installs third party software
#
if [ -z ${LASER} ] ; then
echo "Please set the environment variable 'LASER'"
exit
fi
bdir="${LASER}"
tools_ext="${bdir}/tools-external"
###################################################################
#
# Generic helper functions
#
###################################################################
MKDIR () {
dname=$1
if [ ! -d ${dname} ] ; then
echo " - creating directory ${dname}"
mkdir -p ${dname}
fi
}
###################################################################
#
# Tokenization tools from Moses
# It is important to use the official release V4 and not the current one
# to obtain the same results than the published ones.
# (the behavior of the tokenizer for end-of-sentence abbreviations has changed)
#
###################################################################
InstallMosesTools () {
moses_git="https://raw.githubusercontent.com/moses-smt/mosesdecoder/RELEASE-4.0/scripts"
moses_files=("tokenizer/tokenizer.perl" "tokenizer/detokenizer.perl" \
"tokenizer/normalize-punctuation.perl" \
"tokenizer/remove-non-printing-char.perl" \
"tokenizer/deescape-special-chars.perl" \
"tokenizer/lowercase.perl" \
"tokenizer/basic-protected-patterns" \
)
wdir="${tools_ext}/moses-tokenizer/tokenizer"
MKDIR ${wdir}
cd ${wdir}
for f in ${moses_files[@]} ; do
if [ ! -f `basename ${f}` ] ; then
echo " - download ${f}"
wget -q ${moses_git}/${f}
fi
done
chmod 755 *perl
# download non-breaking prefixes per language
moses_non_breakings="share/nonbreaking_prefixes/nonbreaking_prefix"
moses_non_breaking_langs=( \
"ca" "cs" "de" "el" "en" "es" "fi" "fr" "ga" "hu" "is" \
"it" "lt" "lv" "nl" "pl" "pt" "ro" "ru" "sk" "sl" "sv" \
"ta" "yue" "zh" )
wdir="${tools_ext}/moses-tokenizer/share/nonbreaking_prefixes"
MKDIR ${wdir}
cd ${wdir}
for l in ${moses_non_breaking_langs[@]} ; do
f="${moses_non_breakings}.${l}"
if [ ! -f `basename ${f}` ] ; then
echo " - download ${f}"
wget -q ${moses_git}/${f}
fi
done
}
###################################################################
#
# FAST BPE
#
###################################################################
InstallFastBPE () {
cd ${tools_ext}
if [ ! -x fastBPE/fast ] ; then
echo " - download fastBPE software from github"
wget https://github.com/glample/fastBPE/archive/master.zip
unzip master.zip
/bin/rm master.zip
mv fastBPE-master fastBPE
cd fastBPE
echo " - compiling"
g++ -std=c++11 -pthread -O3 fastBPE/main.cc -IfastBPE -o fast
if [ $? -eq 1 ] ; then
echo "ERROR: compilation failed, please install manually"; exit
fi
python setup.py install
fi
}
###################################################################
#
# Install Japanese tokenizer Mecab
# Installing directly from source is a headache, changed to be able
# to use with pip mecab
#
###################################################################
InstallMecab () {
pip install mecab-python3
pip install unidic-lite
}
###################################################################
#
# main
#
###################################################################
echo "Installing external tools"
InstallMosesTools
InstallFastBPE
InstallMecab