SHARE
TWEET

poem-rater.sh

a guest Oct 9th, 2019 129 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. set +o posix
  3.  
  4. JSON="foo.json"
  5. CORPUS="/home/gwern/wiki/docs/ai/2019-03-06-gpt2-poetry-1000samples.txt"
  6.  
  7. encode() {
  8.     TMP_FILE=$(mktemp /tmp/XXXX.txt)
  9.     echo "$@" >> $TMP_FILE
  10.     ENCODED=$(PYTHONPATH=src python encode2.py --model_name 2019-03-06-gwern-gpt2-poetry-projectgutenberg-network519407  $TMP_FILE)
  11.     echo "$ENCODED"; }
  12. generateJson() {
  13.     echo "{\"query\": [], \"sample0\": $2, \"sample1\": $3, \"best\": $1}," >> $JSON; }
  14.  
  15.  
  16. rm -rf /tmp/poem-samples/; mkdir /tmp/poem-samples/
  17. cat "$CORPUS"  | fgrep -v '=' | split --lines=60 - /tmp/poem-samples/sample-
  18.  
  19. echo "[" >> $JSON
  20. for POEM in `ls /tmp/poem-samples/sample-*`; do
  21.  
  22.     FIRST=$(head -30 $POEM)
  23.     FIRST_ENCODED=$(encode "$FIRST")
  24.     SECOND=$(tail -30 $POEM)
  25.     SECOND_ENCODED=$(encode "$SECOND")
  26.  
  27.  
  28.     echo "$FIRST"
  29.     echo "============================================="
  30.     echo "$SECOND"
  31.     echo "" # print a newline to make output easier to read and divide from the foregoing
  32.  
  33.     echo "1: First wins| 2: Second wins"
  34.     read -N 1 RATING
  35.     case "$RATING" in
  36.  
  37.         $'\n')
  38.         # skip
  39.         ;;
  40.  
  41.         1)
  42.             generateJson 0 "$FIRST_ENCODED" "$SECOND_ENCODED"
  43.             ;;
  44.         2)
  45.             generateJson 1 "$FIRST_ENCODED" "$SECOND_ENCODED"
  46.             ;;
  47.     esac
  48. done
  49. echo "]" >> $JSON
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top