Team Ai
Modelpublic

ashwinR/CodeExplainer

sourceHugging Facemitupdated 4y agoView on Hugging Face
6likes41downloads
README.md83 linesDownload Raw Back to root
1---2tags:3- autotrain4- summarization5language:6- en7widget:8- text: > 9    class Solution(object):10      def isValid(self, s):11        stack = []12        mapping = {")": "(", "}": "{", "]": "["}13        for char in s:14            if char in mapping:15                top_element = stack.pop() if stack else '#'16                if mapping[char] != top_element:17                    return False18            else:19                stack.append(char)20        return not stack21datasets:22- sagard21/autotrain-data-code-explainer23co2_eq_emissions:24  emissions: 5.39307904512897325license: mit26pipeline_tag: summarization27---28 29# Model Trained Using AutoTrain30 31- Problem type: Summarization32- Model ID: 274558134933- CO2 Emissions (in grams): 5.393134 35# Model Description36 37This model is an attempt to simplify code understanding by generating line by line explanation of a source code. This model was fine-tuned using the Salesforce/codet5-large model. Currently it is trained on a small subset of Python snippets.38 39# Model Usage40 41```py42from transformers import (43    AutoModelForSeq2SeqLM,44    AutoTokenizer,45    AutoConfig,46    pipeline,47)48 49model_name = "ashwinR/CodeExplainer"50 51tokenizer = AutoTokenizer.from_pretrained(model_name, padding=True)52 53model = AutoModelForSeq2SeqLM.from_pretrained(model_name)54 55config = AutoConfig.from_pretrained(model_name)56 57model.eval()58 59pipe = pipeline("summarization", model=model_name, config=config, tokenizer=tokenizer)60 61raw_code = """62def preprocess(text: str) -> str:63    text = str(text)64    text = text.replace("\n", " ")65    tokenized_text = text.split(" ")66    preprocessed_text = " ".join([token for token in tokenized_text if token])67 68    return preprocessed_text69"""70 71print(pipe(raw_code)[0]["summary_text"])72 73```74 75## Validation Metrics76 77- Loss: 2.15678- Rouge1: 29.37579- Rouge2: 18.12880- RougeL: 25.44581- RougeLsum: 28.08482- Gen Len: 19.00083