Welcome to mirror list, hosted at ThFree Co, Russian Federation.

weight-scan-summarize.sh « analysis « scripts - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 237182736782fedc116553742bfb45a7fbf31bf5 (plain)
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
#!/bin/bash
# Hackish summarization of weight-scan.pl results, heavily relies on tools by
# Ondrej Bojar (bojar@ufal.mff.cuni.cz), some of which need Mercury; beware.

function die() { echo "$@" >&2; exit 1; }
set -o pipefail  # safer pipes

refs="$1"
dir="$2"

[ -d "$dir" ] && [ -e "$refs" ] \
  || die "usage: $0 ref-file weight-scan-working-dir"

testbleu=$HOME/tools/src/obotools/testbleu
projectbleu=$HOME/tools/src/obotools/projectbleu

[ -x "$testbleu" ] || die "Can't run $testbleu"
[ -x "$projectbleu" ] || die "Can't run $projectbleu"

# create exact bleus and put them to bleu.*
for f in $dir/out.*; do
  bleuf=${f//out./bleu.}
  [ -e "$bleuf" ] \
    || $testbleu $refs < $f | pickre --re='BLEU...([0-9.]*)' > $bleuf \
    || die "Failed to construct $bleuf"
done

# create bleu projections from each best* and put them to corresponding pbleu*
# first collect all weights
lcat $dir/weights.* \
| tr ' ' , \
| pickre --re='weights.([-0-9.]*)' \
| cut -f 1,3 \
| numsort 1 \
> $dir/allweights
allwparam=$(cut -f2 $dir/allweights | prefix -- '-w ' | tr '\n' ' ')
for f in $dir/best*.*; do
  pbleuf=$(echo $f | sed 's/best[0-9]*/pbleu/')
  if [ ! -e "$pbleuf" ] || [ `wc -l < $pbleuf` -ne `wc -l < $dir/allweights` ]; then
    # need to regenerate the projection
    $projectbleu $refs $allwparam < $f \
    | paste $dir/allweights - \
    | cut -f1,3 \
    > $pbleuf \
    || die "Failed to construct $pbleuf"
  fi
done

# summarize bleu projections
echo "goal	proj/real	from	was" > $dir/graph.data
for f in $dir/bleu.*; do
  obs=$(echo $f | sed 's/^.*bleu\.//')
  cat $dir/pbleu.$obs \
  | pickre --re='F: ([0-9.]*)' \
  | recut 2,1 \
  | prefix --tab -- "$obs\tproj" \
  >> $dir/graph.data
  lcat $dir/bleu.$obs \
  | pickre --re='bleu\.([-0-9.]*)' \
  | prefix --tab -- "$obs\treal" \
  | recut 1,2,3,5 \
  >> $dir/graph.data
done


exit 0

## COMMANDS TO PLOT IT:
# plot 'walkable' graph of projections at various points
g=weight-scan-tm_2/graph.data; cat $g | skip 1 | grep real | cut -f2- | numsort 2 | sed 's/real/all/' > cliprealall; skip 1 < $g | numsort 1,3 | split_at_colchange 1 | blockwise "(prefix --tab x cliprealall; cat -) | labelledxychart --data=3,4,0,'',linespoints --blockpivot=2" > clip

# plot a combination of projections along with the individual projections and
# the real scores
cat best100.-0.100000 best100.-0.500000 best100.-0.300000 best100.-0.200000 | /home/obo/tools/src/obotools/projectbleu ../tune.ref $allwparam | paste allweights - > comb.-0.5_-0.3_-0.2_-0.1
(lcat pbleu.-0.100000 pbleu.-0.500000 pbleu.-0.300000 pbleu.-0.200000 comb.-0.5_-0.3_-0.2_-0.1 | pickre --re='F: ([0-9.]*)' | recut 2,3,1 ; cat graph.data | skip 1 | grep real | cut -f2- | numsort 2 ) | tee delme | labelledxychart --blockpivot=1 --data=2,3,0,'',linespoints | gpsandbox