cjwilliams
commited on
Commit
•
96e66aa
1
Parent(s):
9d8c3a4
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: bsd-2-clause
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
---
|
6 |
+
# CodeT5 Base Python Summarization
|
7 |
+
|
8 |
+
Fine-tuned from [codet5-base-multi-sum](https://huggingface.co/Salesforce/codet5-base-multi-sum)
|
9 |
+
using the Python split of [CodeXGlue code-to-text dataset](https://huggingface.co/datasets/code_x_glue_ct_code_to_text).
|
10 |
+
|
11 |
+
## How to use
|
12 |
+
|
13 |
+
(Modified from example [here](https://huggingface.co/Salesforce/codet5-base-multi-sum))
|
14 |
+
|
15 |
+
from transformers import RobertaTokenizer, T5ForConditionalGeneration
|
16 |
+
|
17 |
+
```python
|
18 |
+
if __name__ == '__main__':
|
19 |
+
tokenizer = RobertaTokenizer.from_pretrained('Salesforce/codet5-base')
|
20 |
+
model = T5ForConditionalGeneration.from_pretrained('cjwilliams/codet5-base-python-sum')
|
21 |
+
|
22 |
+
text = """def svg_to_image(string, size=None):
|
23 |
+
if isinstance(string, unicode):
|
24 |
+
string = string.encode('utf-8')
|
25 |
+
renderer = QtSvg.QSvgRenderer(QtCore.QByteArray(string))
|
26 |
+
if not renderer.isValid():
|
27 |
+
raise ValueError('Invalid SVG data.')
|
28 |
+
if size is None:
|
29 |
+
size = renderer.defaultSize()
|
30 |
+
image = QtGui.QImage(size, QtGui.QImage.Format_ARGB32)
|
31 |
+
painter = QtGui.QPainter(image)
|
32 |
+
renderer.render(painter)
|
33 |
+
return image"""
|
34 |
+
|
35 |
+
input_ids = tokenizer(text, return_tensors="pt").input_ids
|
36 |
+
|
37 |
+
generated_ids = model.generate(input_ids, max_length=20)
|
38 |
+
print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))
|
39 |
+
# this prints: "Convert a SVG string to a QImage."
|
40 |
+
```
|