Views
No views yet
1from transformers import RobertaTokenizer, T5ForConditionalGeneration
2
3model_name = "nielsr/codet5-small-code-summarization-ruby"
4tokenizer = RobertaTokenizer.from_pretrained(model_name)
5model = T5ForConditionalGeneration.from_pretrained(model_name)
6
7code = """
8def update_with_file_contents(digest, filename)
9 File.open(filename) do |io|
10 while (chunk = io.read(1024 * 8))
11 digest.update(chunk)
12 end
13 end
14 end
15"""
16
17input_ids = tokenizer(code, return_tensors="pt").input_ids
18outputs = model.generate(input_ids)
19print(tokenizer.decode(outputs[0], skip_special_tokens=True))
20# Update the digest with the contents of the given file