Downloads · 30 days
63
6% of all-time downloads
nandakishormpai/t5-small-github-repo-tag-generation
t5-small-github-repo-tag-generation is a summarization model from nandakishormpai. Use it when you need a shorter version of a longer text. It is set up for transformers. The card lists the license as apache-2.0.
should probably proofread and complete it, then remove this comment. --
Downloads · 30 days
63
6% of all-time downloads
All-time downloads
1.1K
Public
Repo size
20.1 GB
Likes
5
Public
Click a slice to open those files.
.bin242 MB · 99%
From the Hugging Face model README
Machine Learning model to generate Tags for Github Repositories based on their Documentation [README.md] . This model is a fine-tuned version of t5-small fine-tuned on a collection of repositoreis from Kaggle/vatsalparsaniya/github-repositories-analysis. While usually formulated as a multi-label classification problem, this model deals with tag generation as a text2text generation task (inspiration and reference: fabiochiu/t5-base-tag-generation). <br><br> The Inference API here expects a cleaned readme text, the code for cleaning the readme is also given below. <br><br> Finetuning Notebook Reference: Hugging face summarization notebook.
Input : Github Repo URL<br> Output : Tags
Remarks: Ensure the repo has README.<b>md</b>
pip install transformers nltk clean-text beautifulsoup4
Imports
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import re
import nltk
nltk.download('punkt')
from cleantext import clean
from bs4 import BeautifulSoup
from markdown import Markdown
import requests
from io import StringIO
import string
Preprocessing
# Script to convert Markdown to plain text
# Reference : Stackoverflow == https://stackoverflow.com/questions/761824/python-how-to-convert-markdown-formatted-text-to-text
def unmark_element(element, stream=None):
if stream is None:
stream = StringIO()
if element.text:
stream.write(element.text)
for sub in element:
unmark_element(sub, stream)
if element.tail:
stream.write(element.tail)
return stream.getvalue()
# patching Markdown
Markdown.output_formats["plain"] = unmark_element
__md = Markdown(output_format="plain")
__md.stripTopLevelTags = False
def unmark(text):
return __md.convert(text)
def readme_extractor(github_repo_url):
try:
# Get repo HTML using BeautifulSoup
html_content = requests.get(github['python', 'machine learning', 'ml', 'cnn']_repo_url).text
soup = BeautifulSoup(html_content, "html.parser")
# Get README File URL from Repository
readme_url = "https://github.com/" + soup.find("a",{"title":"README.md"}).get("href")
# Generate raw readme file URL
# https://github.com/rasbt/python-machine-learning-book/blob/master/README.md --> https://raw.githubusercontent.com/rasbt/python-machine-learning-book/master/README.md
readme_raw_url = readme_url.replace("/blob/","/")
readme_raw_url = readme_raw_url.replace("github.com","raw.githubusercontent.com")
https://github.com/Lightning-AI/lightning
readme_html_content = requests.get(readme_raw_url ).text
readme_soup = BeautifulSoup(readme_html_content, "html.parser")
readme_text = readme_soup.get_text()
documentation_text = unmark(readme_text)
return documentation_text
except:
print("FAILED : ",github_repo_url )
return "README_NOT_MARKDOWN"
def clean_readme(readme):
text = clean(readme, no_emoji=True)
lst = re.findall('http://\S+|https://\S+', text)
for i in lst:
text = text.replace(i, '')
text = "".join([i for i in text if i not in string.punctuation])
text = text.lower()
text = text.replace("\n"," ")
return text
Postprocess Tags [Removing duplicates]
def post_process_tags(tag_string):
final_tags = []
for tag in tag_string.split(","):
if tag.strip() in final_tags or len(tag.strip()) <=1:
continue
final_tags.append(tag.strip())
return final_tags
Main Function
def github_tags_generate(github_repo_url):
readme = readme_extractor(github_repo_url)
readme = clean_readme(readme)
inputs = tokenizer([readme], max_length=1536, truncation=True, return_tensors="pt")
output = model.generate(**inputs, num_beams=8, do_sample=True, min_length=10,
max_length=128)
decoded_output = tokenizer.batch_decode(output, skip_special_tokens=True)[0]
tags = post_process_tags(decoded_output)
return tags
github_tags_generate("https://github.com/Enter_Repo_URL")
# github_tags_generate("https://github.com/nandakishormpai/Plant_Disease_Detector")
# ['python', 'machine learning', 'ml', 'cnn']
Over the 1000 articles from the dataset, only 870 had tags and the readme was longer than 50 characters. They were filtered out and using BeautifulSoup, README.md was scraped out.
The results might contain duplicate tags that must be handled in the postprocessing of results. postprocessing code also given.
It achieves the following results on the evaluation set:
The following hyperparameters were used during training: