transformers pytorch t5 text2text-generation autotrain summarization en dataset:sagard21/autotrain-data-code-explainer license:mit co2_eq_emissions autotrain_compatible text-generation-inference endpoints_compatible region:us
---
datasets:
- sagard21/autotrain-data-code-explainer
language:
- en
license: mit
pipeline_tag: summarization
tags:
- autotrain
- summarization
widget:
- text: "class Solution(object):\n  def isValid(self, s):\n    stack = []\n    mapping\
    \ = {\")\": \"(\", \"}\": \"{\", \"]\": \"[\"}\n    for char in s:\n        if\
    \ char in mapping:\n            top_element = stack.pop() if stack else '#'\n\
    \            if mapping[char] != top_element:\n                return False\n\
    \        else:\n            stack.append(char)\n    return not stack\n"
co2_eq_emissions:
  emissions: 5.393079045128973
---

# Model Trained Using AutoTrain

- Problem type: Summarization
- Model ID: 2745581349
- CO2 Emissions (in grams): 5.3931

# Model Description

This 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.

# Model Usage

```py
from transformers import (
    AutoModelForSeq2SeqLM,
    AutoTokenizer,
    AutoConfig,
    pipeline,
)

model_name = "ashwinR/CodeExplainer"

tokenizer = AutoTokenizer.from_pretrained(model_name, padding=True)

model = AutoModelForSeq2SeqLM.from_pretrained(model_name)

config = AutoConfig.from_pretrained(model_name)

model.eval()

pipe = pipeline("summarization", model=model_name, config=config, tokenizer=tokenizer)

raw_code = """
def preprocess(text: str) -> str:
    text = str(text)
    text = text.replace("\n", " ")
    tokenized_text = text.split(" ")
    preprocessed_text = " ".join([token for token in tokenized_text if token])

    return preprocessed_text
"""

print(pipe(raw_code)[0]["summary_text"])

```

## Validation Metrics

- Loss: 2.156
- Rouge1: 29.375
- Rouge2: 18.128
- RougeL: 25.445
- RougeLsum: 28.084
- Gen Len: 19.000
