elitcloud / elit

🔠 Evolution of Language and Information Technology
https://elit.cloud
Other
47 stars 7 forks source link

Get ValueError when the Input format is line #18

Closed imgarylai closed 6 years ago

imgarylai commented 6 years ago

When I use line as input format for sentiment analysis. I got this error message.

ValueError: Error when checking : expected input_2 to have 3 dimensions, but got array with shape (0, 1)

The code I executed is

from elit.decode import EnglishDecoder, DOC_DELIM
from elit.util.configure import *

# Please replace the correct resource path.
RESOURCE_PATH = os.path.join('resources')
local_filename = "test.txt"

config = Configuration(tokenize=True, input_format='line', segment=True, sentiment=(SENTIMENT_TWITTER, SENTIMENT_MOVIE))

nd = EnglishDecoder(resource_dir=RESOURCE_PATH, config=config)

with open(local_filename, 'r', encoding='utf8') as f:
    result = nd.decode(config, StringIO(f.read()))

The file, test.txt, I tested:

Longer version of error messages:

  File "/Users/gary/Documents/research/elitrpc/application.py", line 73, in decode
    result = nd.decode(config, StringIO(f.read()))
  File "/Users/gary/.local/share/virtualenvs/elitrpc36/lib/python3.6/site-packages/elit/decode.py", line 44, in decode
    d = decode(config, istream, ostream)
  File "/Users/gary/.local/share/virtualenvs/elitrpc36/lib/python3.6/site-packages/elit/decode.py", line 89, in decode_line
    d = self.text_to_sentences(config, line, offset)
  File "/Users/gary/.local/share/virtualenvs/elitrpc36/lib/python3.6/site-packages/elit/decode.py", line 182, in text_to_sentences
    self.sentiment_analyze(config, sentences)
  File "/Users/gary/.local/share/virtualenvs/elitrpc36/lib/python3.6/site-packages/elit/decode.py", line 202, in sentiment_analyze
    y, att = analyzer.decode(sens, att=att)
  File "/Users/gary/.local/share/virtualenvs/elitrpc36/lib/python3.6/site-packages/elit/component/sentiment.py", line 73, in decode
    y = self.p_model.predict(x, batch_size=batch_size, verbose=0)
  File "/Users/gary/.local/share/virtualenvs/elitrpc36/lib/python3.6/site-packages/keras/engine/training.py", line 1695, in predict
    check_batch_axis=False)
  File "/Users/gary/.local/share/virtualenvs/elitrpc36/lib/python3.6/site-packages/keras/engine/training.py", line 132, in _standardize_input_data
    str(array.shape))
ValueError: Error when checking : expected input_2 to have 3 dimensions, but got array with shape (0, 1)