flair
flair copied to clipboard
Sentimental Classification for Multiple Sentences
I have understood how to classify one sentence's sentiments from '''TextClassifier.load('sentiment-fast')''' However, how can I do multiple sentences for their separate sentiments for having a fast processing speed? I know a for loop is functional for this case it is sooo slow
the example I am doing now is still based on one sentence: scaler = MinMaxScaler(feature_range=(-1, 1)) flair_score=[] def flairSentimentAnalysis(sentiment_text): classifier = TextClassifier.load('sentiment-fast') sentence = Sentence(sentiment_text) classifier.predict(sentence) sentence.labels[0].to_dict() attitude=sentence.labels[0].value score=sentence.labels[0].score if attitude=='NEGATIVE': score=-score return score
for text in raw_data['new_processed_text'][0:10]: score=flairSentimentAnalysis(text) flair_score.append(score) flair_attitude_score=np.array(flair_score).reshape(-1,1) flair_result=scaler.fit_transform(flair_attitude_score).flatten()
I have put all my sentences in a list and it can only generate one result which represents the sentiments of all sentence, but not the sentiments of each sentence.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.