MCPcopy Index your code
hub / github.com/THUDM/GLM / squad_decode

Function squad_decode

tasks/seq2seq/evaluate.py:218–231  ·  view source on GitHub ↗
(example, prediction, tokenizer)

Source from the content-addressed store, hash-verified

216
217
218def squad_decode(example, prediction, tokenizer):
219 text = tokenizer.DecodeIds(prediction)
220 if text.replace(' ', '').lower() == 'n/a':
221 return text
222 context = example.meta['context']
223 context_tokens = example.meta['context_tokens']
224 token_to_char = example.meta['token_to_char']
225 for i in range(len(context_tokens)):
226 if prediction == context_tokens[i:i + len(prediction)]:
227 s = token_to_char[i][0]
228 t = token_to_char[i + len(prediction) - 1][1]
229 return context[s:t]
230 text = squad_fix_tokenization(text)
231 return text
232
233
234def process_batch(batch, args):

Callers 1

evaluateMethod · 0.85

Calls 2

squad_fix_tokenizationFunction · 0.85
DecodeIdsMethod · 0.45

Tested by

no test coverage detected