CoolFace
Modelpublic

LocalDoc/sentiment_analysis_azerbaijani

sourceHugging Facecc-by-nc-4.0updated 2y agoView on Hugging Face
2likes40downloads
README.md86 linesDownload Raw Back to root
1---2license: cc-by-nc-4.03language:4- az5pipeline_tag: text-classification6tags:7- sentiment8- analysis9- azerbaijani10widget:11- text: Bu mənim xoşuma gəlir12datasets:13- LocalDoc/sentiments_dataset_azerbaijani14---15# Sentiment Analysis Model for Azerbaijani Text16This repository hosts a fine-tuned XLM-RoBERTa model for sentiment analysis on Azerbaijani text. The model is capable of classifying text into three categories: negative, neutral, and positive.17 18## Model Description19The model is based on `xlm-roberta-base`, which has been fine-tuned on a diverse dataset of Azerbaijani text samples. It is designed to understand the sentiment expressed in texts and classify them accordingly.20 21## How to Use22You can use this model directly with a pipeline for text classification, or you can use it with the `transformers` library for more custom usage, as shown in the example below.23 24### Quick Start25First, install the transformers library if you haven't already:26```bash27pip install transformers28```29 30```python31from transformers import AutoModelForSequenceClassification, XLMRobertaTokenizer32import torch33 34# Load the model and tokenizer from Hugging Face Hub35model_name = "LocalDoc/sentiment_analysis_azerbaijani"36tokenizer = XLMRobertaTokenizer.from_pretrained(model_name)37model = AutoModelForSequenceClassification.from_pretrained(model_name)38 39def predict_sentiment(text):40    # Encode the text using the tokenizer41    inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=128)42 43    # Get predictions from the model44    with torch.no_grad():45        outputs = model(**inputs)46 47    # Convert logits to probabilities using softmax48    probs = torch.nn.functional.softmax(outputs.logits, dim=-1)49 50    # Get the highest probability and corresponding label51    top_prob, top_label = torch.max(probs, dim=-1)52    labels = ["negative", "neutral", "positive"]53 54    # Return the label with the highest probability55    return labels[top_label], top_prob56 57# Example text58text = "Bu mənim xoşuma gəlir"59 60# Get the sentiment61predicted_label, probability = predict_sentiment(text)62print(f"Predicted sentiment: {predicted_label} with a probability of {probability.item():.4f}")63 64```65 66## Sentiment Label Information67 68The model outputs a label for each prediction, corresponding to one of the sentiment categories listed below. Each label is associated with a specific sentiment as detailed in the following table:69 70| Label | Sentiment |71|-------|-----------|72| 0     | Negative  |73| 1     | Neutral   |74| 2     | Positive  |75 76 77 78License79 80The dataset is licensed under the Creative Commons Attribution-NonCommercial 4.0 International  license. This license allows you to freely share and redistribute the dataset with attribution to the source but prohibits commercial use and the creation of derivative works.81 82 83 84Contact information85 86If you have any questions or suggestions, please contact us at [v.resad.89@gmail.com].