Downloads · 30 days
14
4% of all-time downloads
daviddrzik/SK_Morph_BLM-topic-news
SK_Morph_BLM-topic-news is a text classification model from daviddrzik. Use it when you need a label for a piece of text. It is set up for transformers. The card lists the license as mit.
This model is a fine-tuned version of the SKMorphBLM model for topic classification. For this task, we used the Slovak Categorized News Corpus, which contains news articles divided into six categories: Economy and Bus…
Downloads · 30 days
14
4% of all-time downloads
All-time downloads
360
Public
Parameters
58.7M
235 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors235 MB · 100%
From the Hugging Face model README
This model is a fine-tuned version of the SK_Morph_BLM model for topic classification. For this task, we used the Slovak Categorized News Corpus, which contains news articles divided into six categories: Economy and Business, Culture, News, World, Sports, and Healthcare. The corpus provides text files with detailed annotations, including token and sentence boundary identification, stop words, morphological analysis, named entity recognition, and lemmatization.
Each record in the dataset is labeled with one of the following topics:
The original corpus did not contain continuous text, requiring significant preprocessing. The process involved:
For more information about the dataset, please visit this link.
The following hyperparameters were used during the fine-tuning process:
The model was evaluated using stratified 10-fold cross-validation, achieving a weighted F1-score with a median value of <span style="font-size: 24px;">0.968</span> across the folds.
This model is suitable for topic classification in Slovak text, particularly for news articles across various categories. It is specifically designed for applications requiring topic categorization of news content and may not generalize well to other types of text.
Below is an example of how to use the fine-tuned SK_Morph_BLM-topic-news model in a Python script:
import torch
from transformers import RobertaForSequenceClassification, RobertaTokenizerFast
from huggingface_hub import snapshot_download
class TopicClassifier:
def __init__(self, tokenizer, model):
self.model = RobertaForSequenceClassification.from_pretrained(model, num_labels=6)
repo_path = snapshot_download(repo_id = tokenizer)
sys.path.append(repo_path)
# Import the custom tokenizer from the downloaded repository
from SKMT_lib_v2.SKMT_BPE import SKMorfoTokenizer
self.tokenizer = SKMorfoTokenizer()
def tokenize_text(self, text):
encoded_text = self.tokenizer.tokenize(text.lower(), max_length=256, return_tensors='pt', return_subword=False)
return encoded_text
def classify_text(self, encoded_text):
with torch.no_grad():
output = self.model(**encoded_text)
logits = output.logits
predicted_class = torch.argmax(logits, dim=1).item()
probabilities = torch.softmax(logits, dim=1)
class_probabilities = probabilities[0].tolist()
predicted_class_text = self.model.config.id2label[predicted_class]
return predicted_class, predicted_class_text, class_probabilities
# Instantiate the topic classifier with the specified tokenizer and model
classifier = TopicClassifier(tokenizer="daviddrzik/SK_Morph_BLM", model="daviddrzik/SK_Morph_BLM-topic-news")
# Example text to classify topic
text_to_classify = "Tento dôležitý zápas medzi Českou republikou a Švajčiarskom sa po troch tretinách skončil 2:0."
print("Text to classify: " + text_to_classify + "\n")
# Tokenize the input text
encoded_text = classifier.tokenize_text(text_to_classify)
# Classify the topic of the tokenized text
predicted_class, predicted_class_text, logits = classifier.classify_text(encoded_text)
# Print the predicted class label and index
print(f"Predicted class: {predicted_class_text} ({predicted_class})")
# Print the probabilities for each class
print(f"Class probabilities: {logits}")
Example Output Here is the output when running the above example:
Text to classify: Tento dôležitý zápas medzi Českou republikou a Švajčiarskom sa po troch tretinách skončil 2:0.
Predicted class: Sport (2)
Class probabilities: [0.00015074180555529892, 0.000343791936757043, 0.9958429932594299, 0.0015455043176189065, 0.0013796273851767182, 0.000737304100766778]