ttpro1995 / TreeLSTMSentiment

Pytorch implementation of Sentiment Classification in Improved Semantic Representations From Tree-Structured Long Short-Term Memory Networks
MIT License
113 stars 40 forks source link

"None" in training labels #10

Closed hitvoice closed 5 years ago

hitvoice commented 5 years ago

When I run the code with the command "--model_name dependency --epochs 10", there're errors like this:

Traceback (most recent call last):
  File "sentiment.py", line 228, in <module>
    main()
  File "sentiment.py", line 76, in main
    train_dataset = SSTDataset(train_dir, vocab, args.num_classes, args.fine_grain, args.model_name)
  File "/Users/runqi/Desktop/TreeLSTMSentiment/dataset.py", line 123, in __init__
    self.labels = torch.Tensor(self.labels) # let labels be tensor
TypeError: must be real number, not NoneType

Environment: python 3.6, Mac OS, pytorch 0.4.1

It seems like some root labels are None. Does anyone else have the same issue?

hitvoice commented 5 years ago

When I run the code with the command "--model_name constituency --epoch 10", there's another error:

File "sentiment.py", line 228, in <module>
    main()
  File "sentiment.py", line 76, in main
    train_dataset = SSTDataset(train_dir, vocab, args.num_classes, args.fine_grain, args.model_name)
  File "/Users/runqi/Desktop/TreeLSTMSentiment/dataset.py", line 102, in __init__
    temp_trees = self.read_trees(os.path.join(path, 'parents.txt'), os.path.join(path, 'labels.txt'))
  File "/Users/runqi/Desktop/TreeLSTMSentiment/dataset.py", line 155, in read_trees
    trees = [self.read_tree(p_line, l_line) for p_line, l_line in tqdm(pl)]
  File "/Users/runqi/Desktop/TreeLSTMSentiment/dataset.py", line 155, in <listcomp>
    trees = [self.read_tree(p_line, l_line) for p_line, l_line in tqdm(pl)]
  File "/Users/runqi/Desktop/TreeLSTMSentiment/dataset.py", line 183, in read_tree
    labels = list(map(self.parse_dlabel_token, label_line.split()))
  File "/Users/runqi/Desktop/TreeLSTMSentiment/dataset.py", line 166, in parse_dlabel_token
    tmp = int(x)
ValueError: invalid literal for int() with base 10: 'None'
hitvoice commented 5 years ago

The problems above occurred when I tried to translate the preprocessing code to python3 (by replacing "xrange" with "range" and adding "list" before "map"). I rerun the preprocessing code in python2.7 and the problems disappeared. I'll close this issue.