模型:
fabiochiu/t5-base-tag-generation
This model is t5-base fine-tuned on the 190k Medium Articles dataset for predicting article tags using the article textual content as input. While usually formulated as a multi-label classification problem, this model deals with tag generation as a text2text generation task (inspiration from text2tags ).
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM import nltk nltk.download('punkt') tokenizer = AutoTokenizer.from_pretrained("fabiochiu/t5-base-tag-generation") model = AutoModelForSeq2SeqLM.from_pretrained("fabiochiu/t5-base-tag-generation") text = """ Python is a high-level, interpreted, general-purpose programming language. Its design philosophy emphasizes code readability with the use of significant indentation. Python is dynamically-typed and garbage-collected. """ inputs = tokenizer([text], max_length=512, truncation=True, return_tensors="pt") output = model.generate(**inputs, num_beams=8, do_sample=True, min_length=10, max_length=64) decoded_output = tokenizer.batch_decode(output, skip_special_tokens=True)[0] tags = list(set(decoded_output.strip().split(", "))) print(tags) # ['Programming', 'Code', 'Software Development', 'Programming Languages', # 'Software', 'Developer', 'Python', 'Software Engineering', 'Science', # 'Engineering', 'Technology', 'Computer Science', 'Coding', 'Digital', 'Tech', # 'Python Programming']
The dataset is composed of Medium articles and their tags. However, each Medium article can have at most five tags, therefore the author needs to choose what he/she believes are the best tags (mainly for SEO-related purposes). This means that an article with the "Python" tag may have not the "Programming Languages" tag, even though the first implies the latter.
To clean the dataset accounting for this problem, a hand-made taxonomy of about 1000 tags was built. Using the taxonomy, the tags of each articles have been augmented (e.g. an article with the "Python" tag will have the "Programming Languages" tag as well, as the taxonomy says that "Python" is part of "Programming Languages"). The taxonomy is not public, if you are interested in it please send an email at chiusanofabio94@gmail.com .
The model has been trained on a single epoch spanning about 50000 articles, evaluating on 1000 random articles not used during training.
The following hyperparameters were used during training: