Team Ai
Modelpublic

nielsr/codet5-small-code-summarization-ruby

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
5likes43downloads
README.md44 linesDownload Raw Back to root
1---2license: apache-2.03tags:4- codet55datasets:6- code_x_glue_ct_code_to_text7widget:8- text: 'def pad(tensor, paddings, mode: "CONSTANT", name: nil) _op(:pad, tensor, paddings, mode: mode, name: name) end </s>'9---10 11# Description12 13CodeT5-small model, fine-tuned on the code summarization subtask of CodeXGLUE (Ruby programming language). This model can generate a docstring of a given function written in Ruby.14 15# Notebook16 17The notebook that I used to fine-tune CodeT5 can be found [here](https://github.com/NielsRogge/Transformers-Tutorials/blob/master/T5/Fine_tune_CodeT5_for_generating_docstrings_from_Ruby_code.ipynb).18 19# Usage20 21Here's how to use this model: 22 23```python24from transformers import RobertaTokenizer, T5ForConditionalGeneration25 26model_name = "nielsr/codet5-small-code-summarization-ruby"27tokenizer = RobertaTokenizer.from_pretrained(model_name)28model = T5ForConditionalGeneration.from_pretrained(model_name)29 30code = """31def update_with_file_contents(digest, filename)32      File.open(filename) do |io|33        while (chunk = io.read(1024 * 8))34          digest.update(chunk)35        end36      end37    end38"""39 40input_ids = tokenizer(code, return_tensors="pt").input_ids41outputs = model.generate(input_ids)42print(tokenizer.decode(outputs[0], skip_special_tokens=True))43# Update the digest with the contents of the given file44```