前言:
最近在做任务时用到KenLM (KenLM Language Model Toolkit)一开始在公司服务器上安装,根据官方的安装向导来,很顺利。完成任务后,由于疫情影响一直远程办公,操作大量的数据不方便,就想着在自己ubuntu 18.04上安装一下 KenLM,结果在“cmake …”就出错了。
官方安装如下:
wget -O - https://kheafield.com/code/kenlm.tar.gz |tar xz
# 或者 git clone https://github.com/kpu/kenlm.git
mkdir kenlm/build
cd kenlm/build
cmake ..
make -j4
ubuntu 18.04 ,“cmake …”错误如下:
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
Boost_INCLUDE_DIR (ADVANCED)
...
-- Configuring incomplete, errors occurred!
See also "/home/MyExperimentLab/KenLM_space/kenlm/build/CMakeFiles/CMakeOutput.log".
See also "/home/MyExperimentLab/KenLM_space/kenlm/build/CMakeFiles/CMakeError.log".
第一次尝试解决方法:
出错后到官方和github,于是出现了如下错误,不通,换思路。与gcc版本无关。
build-essential 已经是最新版 (12.4ubuntu1)。
zlib1g-dev 已经是最新版 (1:1.2.11.dfsg-0ubuntu2)。
cmake 已经是最新版 (3.10.2-1ubuntu2.18.04.1)。
有一些软件包无法被安装。如果您用的是 unstable 发行版,这也许是
因为系统无法达到您要求的状态造成的。该版本中可能会有一些您需要的软件
包尚未被创建或是它们已被从新到(Incoming)目录移出。
下列信息可能会对解决问题有所帮助:
下列软件包有未满足的依赖关系:
libboost-all-dev : 依赖: libboost-iostreams-dev 但是它将不会被安装
依赖: libboost-mpi-dev 但是它将不会被安装
依赖: libboost-mpi-python-dev 但是它将不会被安装
依赖: libboost-regex-dev 但是它将不会被安装
libbz2-dev : 依赖: libbz2-1.0 (= 1.0.6-8.1) 但是 1.0.6-8.1ubuntu0.2 正要被安装
推荐: bzip2-doc 但是它将不会被安装
E: 无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系。
第二次尝试解决方法:
将在公司服务器编译好的 KenLM 拷贝到 Ubuntu 18.04 直接使用,出现以下错误,不通,换思路。
libboost_program_options.so.1.54.0: cannot open shared object file: No such file or directory
第三次尝试解决方法:
嗯?难道我要重装Ubuntu 16.04 ,算了,就在公司服务器上用用就行,不影响,KenLM不是主要问题拜拜?等等,要不试一下Docker,于是就开始了如下操作:
docker pull ubuntu:16.04
# 基于 ubuntu:16.04, 创建了新的镜像 ubuntu-mybase
zhudong@zhudong:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu-mybase latest 791a66d8972b 51 minutes ago 2.96GB
ubuntu 16.04 96da9143fb18 5 weeks ago 124MB
# 在镜像ubuntu-mybase下新建容器并 安装了 gcc g++ make cmake python3 git wget ...
apt-get update
apt-get install sudo
sudo passwd root
apt-get install python3
apt-get install vim
apt-get install gcc-5.5
apt-get install gcc-5.5.0
apt-get install gcc-5*
apt-get install g++-5*
apt-get install make cmake
apt-get install libncurses5-dev build-essential
apt-get install python3-pip
pip3 install --upgrade pip
apt-get install build-essential libboost-all-dev cmake zlib1g-dev libbz2-dev liblzma-dev
apt-get install wget
最后将上述容器镜像化 ubuntu-mybase:1.0 , 3.26GB大
zhudong@zhudong:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu-mybase 1.0 6f42975b4848 10 seconds ago 3.26GB
ubuntu 16.04 96da9143fb18 5 weeks ago 124MB
新建容器,进入容器中
docker run -id --name mdenv_ubuntu -v /home/zhudong/DockerSpace/work_zd:/home/work_zd ubuntu-mybase:1.0 /bin/bash
docker exec -it 7eef2b1730b6 /bin/bash
cd home/work_zd/
git clone https://github.com/kpu/kenlm.git
mkdir kenlm/build
cd kenlm/build
cmake ..
make -j4
最后成功编译:
...
[100%] Built target count_ngrams
root@7eef2b1730b6:/home/work_zd/kenlm/build# ls
CMakeCache.txt CMakeFiles CTestTestfile.cmake DartConfiguration.tcl Makefile Testing bin cmake_install.cmake lib lm tests util
root@7eef2b1730b6:/home/work_zd/kenlm/build# cd bin
root@7eef2b1730b6:/home/work_zd/kenlm/build/bin# ls
build_binary count_ngrams filter fragment kenlm_benchmark lmplz phrase_table_vocab probing_hash_table_benchmark query
root@7eef2b1730b6:/home/work_zd/kenlm/build/bin#
迫不及待试了下,由于内存不够,出现核心存储错误(笔记本内存16G),关了些应用,OK。玩不起玩不起!还是用公司的服务器吧!
root@7eef2b1730b6:/home/work_zd/kenlm/build# bin/lmplz -o 3 --verbose_header --text ../../test_space/train_text --arpa ../../test_space/train_text.arpa
=== 1/5 Counting and sorting n-grams ===
Reading /home/work_zd/test_space/train_text
----5---10---15---20---25---30---35---40---45---50---55---60---65---70---75---80---85---90---95--100
****************************************************************************************************
/home/work_zd/kenlm/util/scoped.cc:20 in void* util::{anonymous}::InspectAddr(void*, std::size_t, const char*) threw MallocException because `!addr && requested'.
Cannot allocate memory for 10245689320 bytes in malloc
Aborted (core dumped)
OK!
root@7eef2b1730b6:/home/work_zd/kenlm/build# bin/lmplz -o 3 --verbose_header --text ../../test_space/train_text --arpa ../../test_space/train_text.arpa
=== 1/5 Counting and sorting n-grams ===
Reading /home/work_zd/test_space/train_text
----5---10---15---20---25---30---35---40---45---50---55---60---65---70---75---80---85---90---95--100
****************************************************************************************************
Unigram tokens 25047829 types 152436
=== 2/5 Calculating and sorting adjusted counts ===
Chain sizes: 1:1829232 2:4640950272 3:8701782016
Statistics:
1 152436 D1=0.650853 D2=0.964093 D3+=1.32528
2 3373110 D1=0.738631 D2=1.06586 D3+=1.35895
3 11123477 D1=0.819317 D2=1.13868 D3+=1.32973
Memory estimate for binary LM:
type MB
probing 271 assuming -p 1.5
probing 291 assuming -r models -p 1.5
trie 110 without quantization
trie 61 assuming -q 8 -b 8 quantization
trie 104 assuming -a 22 array pointer compression
trie 55 assuming -a 22 -q 8 -b 8 array pointer compression and quantization
=== 3/5 Calculating and sorting initial probabilities ===
Chain sizes: 1:1829232 2:53969760 3:222469540
----5---10---15---20---25---30---35---40---45---50---55---60---65---70---75---80---85---90---95--100
####################################################################################################
=== 4/5 Calculating and writing order-interpolated probabilities ===
Chain sizes: 1:1829232 2:53969760 3:222469540
----5---10---15---20---25---30---35---40---45---50---55---60---65---70---75---80---85---90---95--100
####################################################################################################
=== 5/5 Writing ARPA model ===
----5---10---15---20---25---30---35---40---45---50---55---60---65---70---75---80---85---90---95--100
****************************************************************************************************
Name:lmplz VmPeak:13206104 kB VmRSS:9812 kB RSSMax:3248668 kB user:13.653 sys:2.20898 CPU:15.862 real:18.5956
有点繁琐,不过顺便又回顾了下Docker,还是不错的。
记录一下,以防忘记。
就这样吧!KenLM 不是主要问题,接着去做别的吧!