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).
1from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
2import nltk
3nltk.download('punkt')
4
5tokenizer = AutoTokenizer.from_pretrained("fabiochiu/t5-base-tag-generation")
6model = AutoModelForSeq2SeqLM.from_pretrained("fabiochiu/t5-base-tag-generation")
7
8text = """
9Python is a high-level, interpreted, general-purpose programming language. Its
10design philosophy emphasizes code readability with the use of significant
11indentation. Python is dynamically-typed and garbage-collected.
12"""
13
14inputs = tokenizer([text], max_length=512, truncation=True, return_tensors="pt")
15output = model.generate(**inputs, num_beams=8, do_sample=True, min_length=10,
16 max_length=64)
17decoded_output = tokenizer.batch_decode(output, skip_special_tokens=True)[0]
18tags = list(set(decoded_output.strip().split(", ")))
19
20print(tags)
21# ['Programming', 'Code', 'Software Development', 'Programming Languages',
22# 'Software', 'Developer', 'Python', 'Software Engineering', 'Science',
23# 'Engineering', 'Technology', 'Computer Science', 'Coding', 'Digital', 'Tech',
24# '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.