Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ML - Empty Results
#1
Hey Guys,

I'm newbie to the ML world and I'm confronting an annoying problem which is when I run the code, nothing happens, just an empty screen. The code is below:


import pandas as pd
import numpy as np
import gensim
import spacy
import nltk
import text_normalizer as tn
from afinn import Afinn

np.set_printoptions(precision=2, linewidth=80)

dataset = pd.read_csv(r'movie_reviews.csv')
reviews = np.array(dataset['review'])
sentiments = np.array(dataset['sentiment'])
# extract data for model evaluation
test_reviews = reviews[35000:]
test_sentiments = sentiments[35000:]
sample_review_ids = [7626, 3533, 13010]
# normalize dataset
norm_test_reviews = tn.normalize_corpus(test_reviews)

afn = Afinn(emoticons=True)

for review, sentiment in zip(test_reviews[sample_review_ids], test_sentiments[sample_review_ids]):
    print('REVIEW:', review)
    print('Actual Sentiment:', sentiment)
    print('Predicted Sentiment polarity:', afn.score(review))
    print('-'*60)


And I'm using PyCharm, Any Ideas?
Reply
#2
The code works fine, that problem was with the time consuming to give the results, around 15 mins which is really big time.

Any idea to make the run process faster?
Reply
#3
The code uses third-party machine learning libraries, so it is likely nothing
to improve with those. However, I suspect that the bottleneck is for-loop (line No. 23);
I don't know exactly, but you can try to pass to afn.score the entire array test_reviews[sample_review_ids]. If afn.score is implemented, e.g. in C, the computations will
be slightly faster.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020