Group Abstract Group Abstract

Message Boards Message Boards

Understanding sentiment analysis in Mathematica

POSTED BY: Dan O'Leary
16 Replies

Looks like this bug is still there and pops up on WL 14 (on some machines)

POSTED BY: Kirill Vasin

Kacie,

I haven't finished this project because I was pulled in a different direction. I hope to restart work early in 2023.

I found the following, which might help you.

Tracking a Descent to Savagery with the Wolfram Language: Plotting Sentiment Analysis in Lord of the Flies https://blog.wolfram.com/2017/12/07/tracking-a-descent-to-savagery-with-the-wolfram-language-plotting-sentiment-analysis-in-lord-of-the-flies/

Analyzing Shakespeare’s Texts on the 400th Anniversary of His Death https://blog.wolfram.com/2016/04/21/analyzing-shakespeares-texts-on-the-400th-anniversary-of-his-death/

POSTED BY: Dan O'Leary
Posted 3 years ago

Hi Kacie,

Your question seems to be unrelated to this thread which is more about sentiment analysis. You should probably ask a new question.

Anyway, the structure and format of the text of Hamlet that you are using will dictate how to proceed with the analysis. Take a look at my answer to this question. It should help you get started. If you get stuck, ask a new question and include the code you have tried, and explain the problem you have.

POSTED BY: Rohit Namjoshi
Posted 3 years ago

I need to count the names of the characters and their number of letters in Shakespeare's "Hamlet", but even after looking at your advice, I don't understand how to do it. For the theoretical part of my assignment, I found https://samploon.com/free-essays/hamlet/ to get details and philosophical explanations of the relationship between Hamlet and Ophelia. However, in addition to these free essays, I need help with the programming exercise.

POSTED BY: Kacie Brown
POSTED BY: Dan O'Leary
Posted 4 years ago

Daniel,

I was using "12.3.1 for Mac OS X ARM (64-bit) (July 8, 2021)". Tried it on 13.0 PR3 "13.0.0 for Mac OS X ARM (64-bit) (November 12, 2021)" and got the same failure.

Looks like a bug in 13.0.

POSTED BY: Rohit Namjoshi

Thank you Rohit. It seems I may have a connectivity problem:

Import::nfurl: Unable to retreive data from https://russell-letters.mcmaster.ca/brixton-letter-20. Consult Internal`$LastInternalFailure for potential information.

Might be a permissions issue. I need to look into this.

POSTED BY: Daniel Lichtblau
Posted 4 years ago

Daniel,

This works reasonably well on the few that I tried. Will likely need adjusting if the format is different in some of the transcripts. Also does not remove footnote numbers from the text. Will have to parse the HTML to do that.

brixtonLetter[number_] := Module[{plaintext, start, end},
  plaintext = 
   Import["https://russell-letters.mcmaster.ca/brixton-letter-" <> ToString@number, "Plaintext"];
  start = StringPosition[plaintext, "Original"][[1, 2]] + 2;
  end = StringPosition[plaintext, "Notes"][[1, 1]] - 1;
  StringTake[plaintext, {start, end}]
  ]

To get the transcript for letter 20

brixtonLetter[20]
POSTED BY: Rohit Namjoshi

For those interested in recent approaches to sentiment and emotion mining of literary texts (and arguably one could include Russel's letters in this group), this survey provides an overview.

POSTED BY: Arno Bosse

Thanks for that information. Looks like a nice repository but I cannot seem to import the texts of the letters, or even the web site pages, into Mathematica.

POSTED BY: Daniel Lichtblau
POSTED BY: Dan O'Leary
POSTED BY: Daniel Lichtblau
Posted 4 years ago

Yes, this sounds interesting, please keep going. However, you should be skeptical toward whatever the AI outputs, because it's guaranteed not to understand all the nuances of human language, especially in letters from a jailed man to a free woman.

POSTED BY: Brad Klee
POSTED BY: Dan O'Leary
POSTED BY: Marco Thiel
Posted 4 years ago

The method and training data used by Classify for sentiment analysis is not described anywhere in the documentation as far as I can tell. Apparently, it is trained on social media posts as mentioned here.

The NN repository has this sentiment model trained on Amazon product reviews.

In my experience both perform fairly well on contemporary text. You will just have to try it on your data and manually examine a subset of positive/neutral/negative classifications to convince yourself that it does a good enough job.

POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard