Simple changes to model
Browse files
main.py
CHANGED
@@ -4,7 +4,6 @@ import torch
|
|
4 |
from transformers import AutoTokenizer
|
5 |
from modelling_cnn import CNNForNER, SentimentCNNModel
|
6 |
|
7 |
-
|
8 |
# Load the Yoruba NER model
|
9 |
ner_model_name = "./my_model/pytorch_model.bin"
|
10 |
model_ner = "Testys/cnn_yor_ner"
|
@@ -44,8 +43,9 @@ def analyze_text(text):
|
|
44 |
with torch.no_grad():
|
45 |
ner_outputs = ner_model(**ner_inputs)
|
46 |
|
47 |
-
ner_predictions = torch.argmax(ner_outputs
|
48 |
-
ner_labels = [
|
|
|
49 |
|
50 |
# Tokenize input text for sentiment analysis
|
51 |
sentiment_inputs = sentiment_tokenizer.encode_plus(text, return_tensors="pt")
|
@@ -53,10 +53,12 @@ def analyze_text(text):
|
|
53 |
# Perform sentiment analysis
|
54 |
with torch.no_grad():
|
55 |
sentiment_outputs = sentiment_model(**sentiment_inputs)
|
56 |
-
sentiment_probabilities = torch.softmax(sentiment_outputs
|
57 |
sentiment_scores = sentiment_probabilities.tolist()
|
58 |
|
59 |
-
|
|
|
|
|
60 |
|
61 |
def main():
|
62 |
st.title("YorubaCNN Models for NER and Sentiment Analysis")
|
@@ -75,9 +77,7 @@ def main():
|
|
75 |
|
76 |
# Display Sentiment Analysis
|
77 |
st.subheader("Sentiment Analysis")
|
78 |
-
st.write(f"
|
79 |
-
st.write(f"Negative: {sentiment_scores[0]:.2f}")
|
80 |
-
st.write(f"Neutral: {sentiment_scores[1]:.2f}")
|
81 |
|
82 |
if __name__ == "__main__":
|
83 |
main()
|
|
|
4 |
from transformers import AutoTokenizer
|
5 |
from modelling_cnn import CNNForNER, SentimentCNNModel
|
6 |
|
|
|
7 |
# Load the Yoruba NER model
|
8 |
ner_model_name = "./my_model/pytorch_model.bin"
|
9 |
model_ner = "Testys/cnn_yor_ner"
|
|
|
43 |
with torch.no_grad():
|
44 |
ner_outputs = ner_model(**ner_inputs)
|
45 |
|
46 |
+
ner_predictions = torch.argmax(ner_outputs, dim=-1)
|
47 |
+
ner_labels = [ner_config["id2label"][label] for label in ner_predictions[0].tolist()]
|
48 |
+
|
49 |
|
50 |
# Tokenize input text for sentiment analysis
|
51 |
sentiment_inputs = sentiment_tokenizer.encode_plus(text, return_tensors="pt")
|
|
|
53 |
# Perform sentiment analysis
|
54 |
with torch.no_grad():
|
55 |
sentiment_outputs = sentiment_model(**sentiment_inputs)
|
56 |
+
sentiment_probabilities = torch.softmax(sentiment_outputs, dim=1)
|
57 |
sentiment_scores = sentiment_probabilities.tolist()
|
58 |
|
59 |
+
sentiment = sentiment_config["id2label"][torch.argmax(sentiment_outputs).item()]
|
60 |
+
|
61 |
+
return ner_labels, sentiment
|
62 |
|
63 |
def main():
|
64 |
st.title("YorubaCNN Models for NER and Sentiment Analysis")
|
|
|
77 |
|
78 |
# Display Sentiment Analysis
|
79 |
st.subheader("Sentiment Analysis")
|
80 |
+
st.write(f"Sentiment: {sentiment_scores}")
|
|
|
|
|
81 |
|
82 |
if __name__ == "__main__":
|
83 |
main()
|