| 37 | |
| 38 | |
| 39 | def tokenize(refs, cands, no_op=False): |
| 40 | # no_op is a debug option to see how significantly not using the PTB tokenizer |
| 41 | # affects things |
| 42 | tokenizer = PTBTokenizer() |
| 43 | |
| 44 | if no_op: |
| 45 | refs = {idx: [r for r in c_refs] for idx, c_refs in enumerate(refs)} |
| 46 | cands = {idx: [c] for idx, c in enumerate(cands)} |
| 47 | |
| 48 | else: |
| 49 | refs = {idx: [{'caption':r} for r in c_refs] for idx, c_refs in enumerate(refs)} |
| 50 | cands = {idx: [{'caption':c}] for idx, c in enumerate(cands)} |
| 51 | |
| 52 | refs = tokenizer.tokenize(refs) |
| 53 | cands = tokenizer.tokenize(cands) |
| 54 | |
| 55 | return refs, cands |
| 56 | |
| 57 | |
| 58 | def pycoco_eval(scorer, refs, cands): |