Views
No views yet
mlm_probability=0.15).1def tokenize_function_bimodal(examples, tokenizer, max_len):
2 codes = [' '.join(example) for example in examples['func_code_tokens']]
3 nls = [' '.join(example) for example in examples['func_documentation_tokens']]
4 pairs = [[c, nl] for c, nl in zip(codes, nls)]
5 return tokenizer(pairs, max_length=max_len, padding="max_length", truncation=True)1def tokenize_function_unimodal(examples, tokenizer, max_len, tokens_column):
2 codes = [' '.join(example) for example in examples[tokens_column]]
3 return tokenizer(codes, max_length=max_len, padding="max_length", truncation=True)1model = AutoModelForMaskedLM.from_pretrained('antolin/distilroberta-base-csn-python-unimodal-bimodal')
2tokenizer = AutoTokenizer.from_pretrained('antolin/distilroberta-base-csn-python-unimodal-bimodal')
3mask_filler = pipeline("fill-mask", model=model, tokenizer=tokenizer)
4code_tokens = ["def", "<mask>", "(", "a", ",", "b", ")", ":", "if", "a", ">", "b", ":", "return", "a", "else", "return", "b"]
5nl_tokens = ["return", "the", "maximum", "value"]
6input_text = ' '.join(code_tokens) + tokenizer.sep_token + ' '.join(nl_tokens)
7pprint(mask_filler(input_text, top_k=5))1[{'score': 0.7177600860595703,
2 'sequence': 'def maximum ( a, b ) : if a > b : return a else return breturn '
3 'the maximum value',
4 'token': 4532,
5 'token_str': ' maximum'},
6 {'score': 0.22075247764587402,
7 'sequence': 'def max ( a, b ) : if a > b : return a else return breturn the '
8 'maximum value',
9 'token': 19220,
10 'token_str': ' max'},
11 {'score': 0.015111264772713184,
12 'sequence': 'def minimum ( a, b ) : if a > b : return a else return breturn '
13 'the maximum value',
14 'token': 3527,
15 'token_str': ' minimum'},
16 {'score': 0.007394665852189064,
17 'sequence': 'def min ( a, b ) : if a > b : return a else return breturn the '
18 'maximum value',
19 'token': 5251,
20 'token_str': ' min'},
21 {'score': 0.004020793363451958,
22 'sequence': 'def length ( a, b ) : if a > b : return a else return breturn '
23 'the maximum value',
24 'token': 5933,
25 'token_str': ' length'}]