CodeT5 icon indicating copy to clipboard operation
CodeT5 copied to clipboard

Could you please give a clean demo to use checkpoint Salesforce/codet5-base-codexglue-clone ?

Open nchen909 opened this issue 2 years ago • 0 comments

Could you please give a clean demo to use Salesforce/codet5-base-codexglue-clone? Including codes like

model = T5ForConditionalGeneration.from_pretrained('Salesforce/codet5-base-codexglue-clone')

like the demo of code summarization shown in README

from transformers import RobertaTokenizer, T5ForConditionalGeneration

if __name__ == '__main__':
    tokenizer = RobertaTokenizer.from_pretrained('Salesforce/codet5-base')
    model = T5ForConditionalGeneration.from_pretrained('Salesforce/codet5-base-multi-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))
    # this prints: "Convert a SVG string to a QImage."

Many thanks!

nchen909 avatar May 10 '23 08:05 nchen909