|
--- |
|
license: bsd-2-clause |
|
language: |
|
- en |
|
--- |
|
# CodeT5 Base Python Summarization |
|
|
|
Fine-tuned from [codet5-base-multi-sum](https://huggingface.co/Salesforce/codet5-base-multi-sum) |
|
using the Python split of [CodeXGlue code-to-text dataset](https://huggingface.co/datasets/code_x_glue_ct_code_to_text). |
|
|
|
## How to use |
|
|
|
(Modified from example [here](https://huggingface.co/Salesforce/codet5-base-multi-sum)) |
|
|
|
from transformers import RobertaTokenizer, T5ForConditionalGeneration |
|
|
|
```python |
|
if __name__ == '__main__': |
|
tokenizer = RobertaTokenizer.from_pretrained('Salesforce/codet5-base') |
|
model = T5ForConditionalGeneration.from_pretrained('cjwilliams/codet5-base-python-sum') |
|
|
|
text = """def svg_to_image(string, size=None): |
|
if isinstance(string, unicode): |
|
string = string.encode('utf-8') |
|
renderer = QtSvg.QSvgRenderer(QtCore.QByteArray(string)) |
|
if not renderer.isValid(): |
|
raise ValueError('Invalid SVG data.') |
|
if size is None: |
|
size = renderer.defaultSize() |
|
image = QtGui.QImage(size, QtGui.QImage.Format_ARGB32) |
|
painter = QtGui.QPainter(image) |
|
renderer.render(painter) |
|
return image""" |
|
|
|
input_ids = tokenizer(text, return_tensors="pt").input_ids |
|
|
|
generated_ids = model.generate(input_ids, max_length=20) |
|
print(tokenizer.decode(generated_ids[0], skip_special_tokens=True)) |
|
``` |