word-vector-example.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 MIT license found in the
  7. # LICENSE file in the root directory of this source tree.
  8. #
  9. RESULTDIR=result
  10. DATADIR=data
  11. mkdir -p "${RESULTDIR}"
  12. mkdir -p "${DATADIR}"
  13. if [ ! -f "${DATADIR}/fil9" ]
  14. then
  15. wget -c http://mattmahoney.net/dc/enwik9.zip -P "${DATADIR}"
  16. unzip "${DATADIR}/enwik9.zip" -d "${DATADIR}"
  17. perl wikifil.pl "${DATADIR}/enwik9" > "${DATADIR}"/fil9
  18. fi
  19. if [ ! -f "${DATADIR}/rw/rw.txt" ]
  20. then
  21. wget -c https://nlp.stanford.edu/~lmthang/morphoNLM/rw.zip -P "${DATADIR}"
  22. unzip "${DATADIR}/rw.zip" -d "${DATADIR}"
  23. fi
  24. make
  25. ./fasttext skipgram -input "${DATADIR}"/fil9 -output "${RESULTDIR}"/fil9 -lr 0.025 -dim 100 \
  26. -ws 5 -epoch 1 -minCount 5 -neg 5 -loss ns -bucket 2000000 \
  27. -minn 3 -maxn 6 -thread 4 -t 1e-4 -lrUpdateRate 100
  28. cut -f 1,2 "${DATADIR}"/rw/rw.txt | awk '{print tolower($0)}' | tr '\t' '\n' > "${DATADIR}"/queries.txt
  29. cat "${DATADIR}"/queries.txt | ./fasttext print-word-vectors "${RESULTDIR}"/fil9.bin > "${RESULTDIR}"/vectors.txt
  30. python eval.py -m "${RESULTDIR}"/vectors.txt -d "${DATADIR}"/rw/rw.txt