word-vector-example.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (c) 2016-present, Facebook, Inc.
  4. # All rights reserved.
  5. #
  6. # This source code is licensed under the BSD-style license found in the
  7. # LICENSE file in the root directory of this source tree. An additional grant
  8. # of patent rights can be found in the PATENTS file in the same directory.
  9. #
  10. RESULTDIR=result
  11. DATADIR=data
  12. mkdir -p "${RESULTDIR}"
  13. mkdir -p "${DATADIR}"
  14. if [ ! -f "${DATADIR}/fil9" ]
  15. then
  16. wget -c http://mattmahoney.net/dc/enwik9.zip -P "${DATADIR}"
  17. unzip "${DATADIR}/enwik9.zip" -d "${DATADIR}"
  18. perl wikifil.pl "${DATADIR}/enwik9" > "${DATADIR}"/fil9
  19. fi
  20. if [ ! -f "${DATADIR}/rw/rw.txt" ]
  21. then
  22. wget -c http://www-nlp.stanford.edu/~lmthang/morphoNLM/rw.zip -P "${DATADIR}"
  23. unzip "${DATADIR}/rw.zip" -d "${DATADIR}"
  24. fi
  25. make
  26. ./fasttext skipgram -input "${DATADIR}"/fil9 -output "${RESULTDIR}"/fil9 -lr 0.025 -dim 100 \
  27. -ws 5 -epoch 1 -minCount 5 -neg 5 -loss ns -bucket 2000000 \
  28. -minn 3 -maxn 6 -thread 4 -t 1e-4 -lrUpdateRate 100
  29. cut -f 1,2 "${DATADIR}"/rw/rw.txt | awk '{print tolower($0)}' | tr '\t' '\n' > "${DATADIR}"/queries.txt
  30. cat "${DATADIR}"/queries.txt | ./fasttext print-word-vectors "${RESULTDIR}"/fil9.bin > "${RESULTDIR}"/vectors.txt
  31. python eval.py -m "${RESULTDIR}"/vectors.txt -d "${DATADIR}"/rw/rw.txt