0

I am very new to sentiment analysis. Trying to use Stanford Sentiment Treebank(sst) and ran into an error.

from nltk.tree import Tree
import os
import sst
trees = "C:\\Users\m\data\trees"
tree, score = next(sst.train_reader(trees))

[Output]:

AttributeError                            Traceback (most recent call last)
<ipython-input-19-4101f90b0b16> in <module>()
----> 1 tree, score = next(sst.train_reader(trees))

AttributeError: module 'sst' has no attribute 'train_reader'
Mine
  • 831
  • 1
  • 8
  • 27

2 Answers2

1

I guess you're importing the sst package selenium-simple-test, which is not what you're looking for.

Try sst.discover() , if you get the error

TypeError: discover() missing 4 required positional arguments: 'test_loader', 'package', 'dir_path', and 'names'

You are using the selenium-simple-test package

dantarno
  • 92
  • 1
  • 6
  • https://nbviewer.jupyter.org/github/cgpotts/cs224u/blob/2019-spring/sst_01_overview.ipynb – Mine Mar 03 '20 at 16:54
  • How does "import sst" work out in this jupyter notebook and how can I do the same thing? – Mine Mar 03 '20 at 16:55
1

I think you're looking for https://github.com/JonathanRaiman/pytreebank, not https://pypi.org/project/sst/.

On the python side, that error is pretty clear. Once you import the right package, though, I'm not sure I saw train_reader but I could be wrong.

UPDATE: I'm not entirely sure why you're running into the 'sst' not having the attribute train_reader. Make sure you didn't accidentally install the 'sst' package if you're using conda. It looks like the 'sst' is referring to a privately created module and that one should work.

I got your import working but what I did was I:

  1. Installed everything specified in the requirements.txt file.
  2. import sst was still giving me an error so I installed nltk and sklearn to resolve that issue. (fyi, im not using conda. im just using pip and virtualenv for my own private package settings. i ran pip install nltk and pip install sklearn)
  3. At this point, import sst worked for me.
dtc
  • 1,774
  • 2
  • 21
  • 44
  • https://nbviewer.jupyter.org/github/cgpotts/cs224u/blob/2019-spring/sst_01_overview.ipynb – Mine Mar 03 '20 at 16:47
  • I wanted to replicate the code in the above jupyter notebook. In there "import sst" is used. Other than the method you suggested is there a way to replicate what is done in the notebook? – Mine Mar 03 '20 at 16:47
  • 1
    @moli see if my updated post helps you out. if it wasn't the answer, im hoping it at least guides you. another suggestion is to try to re-read and carefully follow the instructions on that guide step-by-step. – dtc Mar 03 '20 at 18:50
  • I have sklearn and nltk installed now I'm getting an error AttributeError: module 'utils' has no attribute 'safe_macro_f1'. I have uninstalled utils packages but still does not work still getting the same error :( – Mine Mar 03 '20 at 18:53
  • 1
    yay, we're making progress! sorry, im at work right now so i probably can't look at this till later today. maybe try tackling it yourself for now? my guess is you're at a university so id recommend just sitting down with someone who already has this working if that's possible. – dtc Mar 03 '20 at 19:40
  • 1
    Thank you so much for helping me out! The problem is solved!! :-) – Mine Mar 03 '20 at 19:55
  • 1
    nice! best of luck to ya – dtc Mar 03 '20 at 22:26