AttributeError: module 'sst' has no attribute 'train_reader'

243 Views Asked by At

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'
2

There are 2 best solutions below

7
On BEST ANSWER

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.
2
On

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