Spaces:
Running
Running
Update model.py
Browse files
model.py
CHANGED
|
@@ -10,7 +10,7 @@ Original file is located at
|
|
| 10 |
"""
|
| 11 |
|
| 12 |
import torch
|
| 13 |
-
from transformers import AutoTokenizer, BertForSequenceClassification
|
| 14 |
from datasets import Dataset
|
| 15 |
import pandas as pd
|
| 16 |
import os
|
|
@@ -25,8 +25,9 @@ stopwords = stopwords_list()
|
|
| 25 |
# Load the BERT model for sentiment analysis
|
| 26 |
dataset = Dataset.from_pandas(pd.DataFrame({"Comment": []}))
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
|
|
|
| 30 |
|
| 31 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 32 |
model.to(device)
|
|
@@ -48,7 +49,7 @@ def predict_sentiment(batch):
|
|
| 48 |
return {'sentiment': predictions.cpu()}
|
| 49 |
|
| 50 |
# Mapping sentiment labels
|
| 51 |
-
sentiment_labels_en = {0: 'منفی', 1: 'خنثی', 2: 'مثبت'}
|
| 52 |
|
| 53 |
|
| 54 |
# Adding sentiment prediction to tokenized dataset
|
|
|
|
| 10 |
"""
|
| 11 |
|
| 12 |
import torch
|
| 13 |
+
from transformers import AutoTokenizer, BertForSequenceClassification,AutoConfig
|
| 14 |
from datasets import Dataset
|
| 15 |
import pandas as pd
|
| 16 |
import os
|
|
|
|
| 25 |
# Load the BERT model for sentiment analysis
|
| 26 |
dataset = Dataset.from_pandas(pd.DataFrame({"Comment": []}))
|
| 27 |
|
| 28 |
+
config = AutoConfig.from_pretrained("HooshvareLab/albert-fa-zwnj-base-v2")
|
| 29 |
+
tokenizer = AutoTokenizer.from_pretrained("HooshvareLab/albert-fa-zwnj-base-v2")
|
| 30 |
+
model = BertForSequenceClassification.from_pretrained("HooshvareLab/albert-fa-zwnj-base-v2", num_labels=3)
|
| 31 |
|
| 32 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 33 |
model.to(device)
|
|
|
|
| 49 |
return {'sentiment': predictions.cpu()}
|
| 50 |
|
| 51 |
# Mapping sentiment labels
|
| 52 |
+
#sentiment_labels_en = {0: 'منفی', 1: 'خنثی', 2: 'مثبت'}
|
| 53 |
|
| 54 |
|
| 55 |
# Adding sentiment prediction to tokenized dataset
|