# Create a docstring generator

**URL:** <https://discuss.huggingface.co/t/create-a-docstring-generator/11569>\
**Category:** 🤗 Course Projects\
**Created:** [November 10, 2021, 4:44pm UTC](https://discuss.huggingface.co/t/create-a-docstring-generator/11569 "2021-11-10T16:44:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lewtun](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/lewtun/32/30995_2.png) [@lewtun](https://discuss.huggingface.co/u/lewtun)\
**Post date:** [November 10, 2021, 4:44pm UTC](https://discuss.huggingface.co/t/create-a-docstring-generator/11569/1 "2021-11-10T16:44:44Z")

</div>

> 👋 Please read the topic category [description](https://discuss.huggingface.co/t/about-the-course-projects-category/11510) to understand what this is all about

### Description

Applications like GitHub’s CoPilot can automatically generate docstrings from a class or function name. The goal of this project is to fine-tune a Transformer like CodeT5 to do this ourselves!

### Model(s)

Generating docstrings from source code can be modelled as a sequence-to-sequence task, so T5 models are a good starting point here:

- [Salesforce/codet5-base](https://huggingface.co/Salesforce/codet5-base)

### Datasets

A good dataset for this task is [code\_search\_net](https://huggingface.co/datasets/code_search_net), but feel free to find alternative datasets if you can’t find your favourite programming language there.

### Challenges

Models like CodeT5 are rather large and you’ll need to think about what metrics one should use for this type of task.

### Desired project outcomes

- Create a Streamlit or Gradio app on [🤗 Spaces](https://huggingface.co/spaces) that can automatically generate a docstring from a class of function name in your favourite programming language!
- Don’t forget to push all your models and datasets to the Hub so others can build on them!

### Additional resources

- [https://arxiv.org/abs/2109.00859v1](https://arxiv.org/abs/2109.00859v1)
- [https://blog.einstein.ai/codet5/](https://blog.einstein.ai/codet5/)

### Discord channel

To chat and organise with other people interested in this project, head over to our [Discord](http://xwo7x.mjt.lu/lnk/CAAAAkdkZwAAAAAAAAAAALG-MTEAAYCr4H8AAAAAAAyFyQBhjpnimM4rcE5DT5ibCUtRT96tWwAMh8Y/15/U6BYNMNDksyyGG4jgtzPKQ/aHR0cHM6Ly9odWdnaW5nZmFjZS5jby9qb2luL2Rpc2NvcmQ) and:

- Follow the instructions on the `#join-course` channel

- Join the `#docstring-generator` channel

Just make sure you comment here to indicate that you’ll be contributing to this project 🙂

---

<div class="post-metadata">

**Author:** ![stmnk](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/stmnk/32/3130_2.png) [@stmnk](https://discuss.huggingface.co/u/stmnk)\
**Post date:** [November 15, 2021, 8:13am UTC](https://discuss.huggingface.co/t/create-a-docstring-generator/11569/2 "2021-11-15T08:13:06Z")

</div>

I find this task interesting and would like to find out more about how to contribute: for example, would fine-tuning for PL to NL (code comment/docstring) generation for Python be a suitable case for this project?

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](https://discuss.huggingface.co/u/nielsr)\
**Post date:** [November 15, 2021, 8:49am UTC](https://discuss.huggingface.co/t/create-a-docstring-generator/11569/3 "2021-11-15T08:49:43Z")

</div>

I actually did this by fine-tuning CodeT5 for generating docstrings for Ruby code.

The model is on the hub: [nielsr/codet5-small-code-summarization-ruby · Hugging Face](https://huggingface.co/nielsr/codet5-small-code-summarization-ruby)

The notebook used to fine-tune T5 can be found [here](https://github.com/NielsRogge/Transformers-Tutorials/blob/master/T5/Fine_tune_CodeT5_for_generating_docstrings_from_Ruby_code.ipynb).

---

<div class="post-metadata">

**Author:** ![lewtun](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/lewtun/32/30995_2.png) [@lewtun](https://discuss.huggingface.co/u/lewtun)\
**Post date:** [November 15, 2021, 2:13pm UTC](https://discuss.huggingface.co/t/create-a-docstring-generator/11569/4 "2021-11-15T14:13:15Z")

</div>

Hey @stmnk this is a super cool idea and definitely worth exploring! And thanks to @nielsr you have a nice template to work from 😉

I’ve also created a Discord channel (see topic description) for you and others in case you need it 🙂

---

<div class="post-metadata">

**Author:** ![stmnk](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/stmnk/32/3130_2.png) [@stmnk](https://discuss.huggingface.co/u/stmnk)\
**Post date:** [November 15, 2021, 2:38pm UTC](https://discuss.huggingface.co/t/create-a-docstring-generator/11569/5 "2021-11-15T14:38:17Z")

</div>

Thank you for the links, they are really helpful!

---

<div class="post-metadata">

**Author:** ![stmnk](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/stmnk/32/3130_2.png) [@stmnk](https://discuss.huggingface.co/u/stmnk)\
**Post date:** [November 15, 2021, 2:39pm UTC](https://discuss.huggingface.co/t/create-a-docstring-generator/11569/6 "2021-11-15T14:39:33Z")

</div>

Thank you!
