SCFG translation
From cdec Decoder
cdec supports translating input sentences or lattices using synchronous context-free grammars (SCFGs), as described in Chiang (2007).
Example
Example grammar (fields are separated by a triple pipe, the first one in the left-hand side of the rule, the second is the source RHS, the third is the target RHS, and the optional fourth one is a list of feature values associated with the rule):
[S] ||| [NP,1] [VP,2] ||| [1] [2] ||| LogProb=0.2 [NP] ||| ich ||| i ||| LogProb=-0.6 [NP] ||| ein [NN,1] ||| a [1] ||| LogProb=-0.5 [NN] ||| [JJ,1] haus ||| [1] house ||| LogProb=-0.1 [NN] ||| [JJ,1] haus ||| [1] shell ||| LogProb=-1.3 [JJ] ||| kleines ||| small ||| LogProb=-0.1 SomeFeature=1.0 [JJ] ||| kleines ||| little ||| LogProb=-0.9 SomeFeature=0.2 [JJ] ||| grosses ||| big ||| LogProb=-0.8 SomeFeature=0.2 [JJ] ||| grosses ||| large ||| LogProb=-0.2345 [VP] ||| [V,1] [NP,2] ||| [1] [2] ||| LogProb=0.1 SomeOtherFeature=1.0 [V] ||| sah ||| saw ||| LogProb=-0.4 [V] ||| fand ||| found ||| LogProb=-0.4
An example weights file for use with the above grammar:
LogProb 1.0 SomeFeature 0.1 SomeOtherFeature 0.2
Translation of ich sah ein kleines haus (with 10-best output):
cdec -f scfg -g foo.grammar -k 10 -w we
cdec v1.0 (c) 2009 by Chris Dyer
Reading SCFG grammar from foo.grammar
12 rules read.
Reading weights from we
Loaded 3 feature weights
Reading input from STDIN
ich sah ein kleines haus
INPUT: ich sah ein kleines haus
id = 0
Goal category: [S]
.....
-LM forest (nodes/edges): 8/10
-LM forest (paths): 4
-LM Viterbi: i saw a small house
-LM Viterbi: -1.1
0 ||| i saw a small house ||| LogProb=-1.4;SomeFeature=1;SomeOtherFeature=1 ||| -1.1
0 ||| i saw a little house ||| LogProb=-2.2;SomeFeature=0.2;SomeOtherFeature=1 ||| -1.98
0 ||| i saw a small shell ||| LogProb=-2.6;SomeFeature=1;SomeOtherFeature=1 ||| -2.3
0 ||| i saw a little shell ||| LogProb=-3.4;SomeFeature=0.2;SomeOtherFeature=1 ||| -3.18
Translation: 0.001966 secs (1 calls)
The full search space can be seen in the visualization example here.
