Skip to content

Commit e38af58

Browse files
committed
process json correctly
1 parent 9156c83 commit e38af58

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

detok.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,20 @@ def debpe(s):
3939
if line.startswith('{'):
4040
try:
4141
jobj = json.loads(line)
42-
for score, translation in zip(jobj['scores'], jobj['translations']):
43-
print('{:.3f}'.format(score), fixTokenization(detokenizer(debpe(translation).split())), sep='\t', flush=True)
42+
if 'translations' in jobj:
43+
scores = jobj['scores']
44+
translations = jobj['translations']
45+
else:
46+
scores = [jobj['score']]
47+
translations = [jobj['translation']]
48+
49+
for score, translation in zip(scores, translations):
50+
# print('{:.3f}'.format(score), fixTokenization(detokenizer(debpe(translation).split())), sep='\t', flush=True)
51+
print(fixTokenization(detokenizer(debpe(translation).split())), flush=True)
52+
4453
continue
4554
except Exception:
55+
print("Exception encountered!")
4656
pass
4757

4858
# Run if JSON parsing not relevant or fails

paraphrase.sh

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ python3 $MODEL_PATH/custom_constraints.py \
99
--BPE-vocab $BPE_VOCAB \
1010
--compute-factor \
1111
| \
12-
python3 -m sockeye.translate \
13-
-m $MODEL_PATH \
14-
--json-input \
15-
--beam-size 20 \
16-
--beam-prune 20 \
17-
--batch-size 10 \
18-
--use-cpu \
19-
--quiet \
20-
| \
21-
. $MODEL_PATH/post.sh
12+
python3 -m sockeye.translate \
13+
-m $MODEL_PATH \
14+
--json-input \
15+
--output-type json \
16+
--beam-size 20 \
17+
--beam-prune 20 \
18+
--batch-size 10 \
19+
--device-ids 0 \
20+
--disable-device-locking \
21+
"$@" \
22+
| ${MODEL_PATH}/detok.py

post.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)