Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: bad input shape (1, 5) #1436

Closed
hydridity opened this issue Sep 30, 2018 · 15 comments

Comments

Projects
None yet
9 participants
@hydridity
Copy link

commented Sep 30, 2018

Rasa NLU version: 0.13.5
Python version: 3.6

Operating system: Ubuntu:17.10 or Docker-Ubuntu:17.10

Content of model configuration file:

language: "en"
pipeline: spacy_sklearn

Content of python file:

from rasa_nlu.training_data import load_data
from rasa_nlu.model import Trainer, Interpreter
from rasa_nlu import config



training_data = load_data('nlu_data.md') #tried with different datafiles from various sources both md or json
trainer = Trainer(config.load("rasa-config.yml"))
trainer.train(training_data)
model_directory = trainer.persist('./rasa_model')

interpreter = Interpreter.load(model_directory)

#same error for both
interpreter.parse(u"The text I want to understand")
interpreter.parse("The text I want to understand")

Output:

Fitting 2 folds for each of 6 candidates, totalling 12 fits
[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Done  12 out of  12 | elapsed:    0.1s finished
/usr/local/lib/python3.6/dist-packages/rasa_nlu/extractors/entity_synonyms.py:85: UserWarning: Failed to load synonyms file from '/datas/./rasa_model/default/model_20180930-201701/entity_synonyms.json'
  "".format(entity_synonyms_file))
Traceback (most recent call last):
  File "test.py", line 15, in <module>
    interpreter.parse(u"The text I want to understand")
  File "/usr/local/lib/python3.6/dist-packages/rasa_nlu/model.py", line 357, in parse
    component.process(message, **self.context)
  File "/usr/local/lib/python3.6/dist-packages/rasa_nlu/classifiers/sklearn_intent_classifier.py", line 176, in process
    intents = self.transform_labels_num2str(intent_ids)
  File "/usr/local/lib/python3.6/dist-packages/rasa_nlu/classifiers/sklearn_intent_classifier.py", line 112, in transform_labels_num2str
    return self.le.inverse_transform(y)
  File "/usr/local/lib/python3.6/dist-packages/sklearn/preprocessing/label.py", line 273, in inverse_transform
    y = column_or_1d(y, warn=True)
  File "/usr/local/lib/python3.6/dist-packages/sklearn/utils/validation.py", line 788, in column_or_1d
    raise ValueError("bad input shape {0}".format(shape))
ValueError: bad input shape (1, 5)

Issue:
Hello, im trying to run example from documentation https://rasa.com/docs/nlu/0.13.5/python/ but im getting ValueError: bad input shape (1, 5) is this issue or im doing something wrong ?

@akelad

This comment has been minimized.

Copy link
Collaborator

commented Oct 1, 2018

Thanks for raising this issue, @MetcalfeTom will get back to you about it soon.

@MetcalfeTom

This comment has been minimized.

Copy link
Contributor

commented Oct 1, 2018

Hi @hydridity, just trying to recreate this error now to see if it's a bug or perhaps an issue with scikit-learn but in the meantime could you show me a snippet of how your nlu_data.md is formatted?

@hydridity

This comment has been minimized.

Copy link
Author

commented Oct 1, 2018

<!--- Make sure to update this training data file with more training examples from https://forum.rasa.com/t/grab-the-nlu-training-dataset-and-starter-packs/903 --> 

## intent:bye <!--- The label of the intent --> 
- Bye 			<!--- Training examples for intent 'bye'--> 
- Goodbye
- See you later
- Bye bot
- Goodbye friend
- bye
- bye for now
- catch you later
- gotta go
- See you
- goodnight
- have a nice day
- i'm off
- see you later alligator
- we'll speak soon

## intent:greet
- Hi
- Hey
- Hi bot
- Hey bot
- Hello
- Good morning
- hi again
- hi folks
- hi Mister
- hi pal!
- hi there
- greetings
- hello everybody
- hello is anybody there
- hello robot

## intent:thank
- Thanks
- Thank you
- Thank you so much
- Thanks bot
- Thanks for that
- cheers
- cheers bro
- ok thanks!
- perfect thank you
- thanks a bunch for everything
- thanks for the help
- thanks a lot
- amazing, thanks
- cool, thanks
- cool thank you

## intent:affirm
- yes
- yes sure
- absolutely
- for sure
- yes yes yes
- definitely

## intent:name
- My name is [Alice](name)  <!--- Square brackets contain the value of entity while the text inside the parentheses is a a label of the entity --> 
- I am [Josh](name)
- I'm [Lucy](name)
- People call me [Greg](name)
- It's [David](name)
- Usually people call me [Amy](name)
- My name is [John](name)
- You can call me [Sam](name)
- Please call me [Linda](name)
- Name name is [Tom](name)
- I am [Richard](name)
- I'm [Tracy](name)
- Call me [Sally](name)
- I am [Philipp](name)
- I am [Charlie](name)

This last attempt taken directly from https://github.com/RasaHQ/starter-pack-rasa-nlu

@MetcalfeTom

This comment has been minimized.

Copy link
Contributor

commented Oct 1, 2018

Hello again. I just recreated the situation from scratch and ran your python script. I didn't encounter this error, however I can see from your traceback that the model trained correctly which leads me to believe this may arise from another package. Have you ran pip install -r requirements.txt from the /starter-pack-rasa-nlu directory?

@hydridity

This comment has been minimized.

Copy link
Author

commented Oct 1, 2018

That solved problem, i've installed most of those packages manually to the latest versions so it might be caused by some change in scikit-learn, i had 0.20 and in requirements is 0.19.1, or another package that was missing or had some change

installation versions snippet:

  Found existing installation: scikit-learn 0.20.0
    Uninstalling scikit-learn-0.20.0:
      Successfully uninstalled scikit-learn-0.20.0
  Found existing installation: packaging 18.0
    Uninstalling packaging-18.0:
      Successfully uninstalled packaging-18.0
  Found existing installation: gevent 1.3.6
    Uninstalling gevent-1.3.6:
      Successfully uninstalled gevent-1.3.6
Successfully installed ConfigArgParse-0.13.0 Jinja2-2.10 MarkupSafe-1.0 click-7.0 colorhash-1.0.2 decorator-4.3.0 docopt-0.6.2 flask-1.0.2 flask-cors-3.0.4 gevent-1.2.2 itsdangerous-0.24 networkx-2.1 packaging-17.1 pika-0.11.2 pykwalify-1.6.0 pymongo-3.5.1 scikit-learn-0.19.1
@MetcalfeTom

This comment has been minimized.

Copy link
Contributor

commented Oct 1, 2018

Hurrah! Great to hear everything worked out.

Thanks for posting the snippet, that will help me find out where the problem may lie. For now I will close this issue

@MetcalfeTom MetcalfeTom closed this Oct 1, 2018

@wilmerags

This comment has been minimized.

Copy link

commented Oct 3, 2018

Hello! i faced the same issue although with shape (1,4), i'm trying changing scikit-learn version, but there will be a way of solving it with scikit-learn 0.20.0 ?

@wilmerags

This comment has been minimized.

Copy link

commented Oct 3, 2018

after changing the version this erased as a warning: lib/python3.6/site-packages/sklearn/preprocessing/label.py:151: builtins.DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use array.size > 0 to check that an array is not empty.

@alifiyaali

This comment has been minimized.

Copy link

commented Oct 24, 2018

I am getting the same issue for Rasa NLU version: 0.13.6

I ran pip install -r requirements.txt as suggested by @MetcalfeTom

Below is the snippet

Requirement already satisfied: gevent==1.2.2 in /home/ist/anaconda3/lib/python3.6/site-packages (from -r alt_requirements/requirements_bare.txt (line 1)) (1.2.2)
Requirement already satisfied: klein==17.10.0 in /home/ist/anaconda3/lib/python3.6/site-packages (from -r alt_requirements/requirements_bare.txt (line 2)) (17.10.0)
Requirement already satisfied: hyperlink==17.3.1 in /home/ist/anaconda3/lib/python3.6/site-packages (from -r alt_requirements/requirements_bare.txt (line 3)) (17.3.1)
Requirement already satisfied: typing==3.6.2 in /home/ist/anaconda3/lib/python3.6/site-packages (from -r alt_requirements/requirements_bare.txt (line 4)) (3.6.2)
Requirement already satisfied: future==0.16.0 in /home/ist/anaconda3/lib/python3.6/site-packages (from -r alt_requirements/requirements_bare.txt (line 5)) (0.16.0)
Requirement already satisfied: six==1.11.0 in /home/ist/anaconda3/lib/python3.6/site-packages (from -r alt_requirements/requirements_bare.txt (line 6)) (1.11.0)
Requirement already satisfied: jsonschema==2.6.0 in /home/ist/anaconda3/lib/python3.6/site-packages (from -r alt_requirements/requirements_bare.txt (line 7)) (2.6.0)
Requirement already satisfied: matplotlib==2.1.0 in /home/ist/anaconda3/lib/python3.6/site-packages (from -r alt_requirements/requirements_bare.txt (line 8)) (2.1.0)
Requirement already satisfied: requests==2.18.4 in /home/ist/anaconda3/lib/python3.6/site-packages (from -r alt_requirements/requirements_bare.txt (line 9)) (2.18.4)
Requirement already satisfied: tqdm==4.19.5 in /home/ist/anaconda3/lib/python3.6/site-packages (from -r alt_requirements/requirements_bare.txt (line 10)) (4.19.5)
Requirement already satisfied: numpy==1.14.5 in /home/ist/anaconda3/lib/python3.6/site-packages (from -r alt_requirements/requirements_bare.txt (line 11)) (1.14.5)
Requirement already satisfied: simplejson==3.13.2 in /home/ist/anaconda3/lib/python3.6/site-packages (from -r alt_requirements/requirements_bare.txt (line 12)) (3.13.2)
Requirement already satisfied: cloudpickle==0.5.2 in /home/ist/anaconda3/lib/python3.6/site-packages (from -r alt_requirements/requirements_bare.txt (line 13)) (0.5.2)
Requirement already satisfied: msgpack-python==0.5.4 in /home/ist/anaconda3/lib/python3.6/site-packages (from -r alt_requirements/requirements_bare.txt (line 14)) (0.5.4)
Requirement already satisfied: packaging==17.1 in /home/ist/anaconda3/lib/python3.6/site-packages (from -r alt_requirements/requirements_bare.txt (line 15)) (17.1)
Requirement already satisfied: pyyaml==3.12 in /home/ist/anaconda3/lib/python3.6/site-packages (from -r alt_requirements/requirements_bare.txt (line 16)) (3.12)
Requirement already satisfied: coloredlogs==9.0 in /home/ist/anaconda3/lib/python3.6/site-packages (from -r alt_requirements/requirements_bare.txt (line 17)) (9.0)
Requirement already satisfied: greenlet>=0.4.10 in /home/ist/anaconda3/lib/python3.6/site-packages (from gevent==1.2.2->-r alt_requirements/requirements_bare.txt (line 1)) (0.4.15)
Requirement already satisfied: Twisted>=15.5 in /home/ist/anaconda3/lib/python3.6/site-packages (from klein==17.10.0->-r alt_requirements/requirements_bare.txt (line 2)) (18.7.0)
Requirement already satisfied: incremental in /home/ist/anaconda3/lib/python3.6/site-packages (from klein==17.10.0->-r alt_requirements/requirements_bare.txt (line 2)) (17.5.0)
Requirement already satisfied: werkzeug in /home/ist/anaconda3/lib/python3.6/site-packages (from klein==17.10.0->-r alt_requirements/requirements_bare.txt (line 2)) (0.14.1)
Requirement already satisfied: pytz in /home/ist/anaconda3/lib/python3.6/site-packages (from matplotlib==2.1.0->-r alt_requirements/requirements_bare.txt (line 8)) (2018.5)
Requirement already satisfied: python-dateutil>=2.0 in /home/ist/anaconda3/lib/python3.6/site-packages (from matplotlib==2.1.0->-r alt_requirements/requirements_bare.txt (line 8)) (2.7.3)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /home/ist/anaconda3/lib/python3.6/site-packages (from matplotlib==2.1.0->-r alt_requirements/requirements_bare.txt (line 8)) (2.2.0)
Requirement already satisfied: cycler>=0.10 in /home/ist/anaconda3/lib/python3.6/site-packages (from matplotlib==2.1.0->-r alt_requirements/requirements_bare.txt (line 8)) (0.10.0)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /home/ist/anaconda3/lib/python3.6/site-packages (from requests==2.18.4->-r alt_requirements/requirements_bare.txt (line 9)) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /home/ist/anaconda3/lib/python3.6/site-packages (from requests==2.18.4->-r alt_requirements/requirements_bare.txt (line 9)) (2018.8.24)
Requirement already satisfied: urllib3<1.23,>=1.21.1 in /home/ist/anaconda3/lib/python3.6/site-packages (from requests==2.18.4->-r alt_requirements/requirements_bare.txt (line 9)) (1.22)
Requirement already satisfied: idna<2.7,>=2.5 in /home/ist/anaconda3/lib/python3.6/site-packages (from requests==2.18.4->-r alt_requirements/requirements_bare.txt (line 9)) (2.6)
Requirement already satisfied: humanfriendly>=4.7 in /home/ist/anaconda3/lib/python3.6/site-packages (from coloredlogs==9.0->-r alt_requirements/requirements_bare.txt (line 17)) (4.16.1)
Requirement already satisfied: zope.interface>=4.4.2 in /home/ist/anaconda3/lib/python3.6/site-packages (from Twisted>=15.5->klein==17.10.0->-r alt_requirements/requirements_bare.txt (line 2)) (4.5.0)
Requirement already satisfied: constantly>=15.1 in /home/ist/anaconda3/lib/python3.6/site-packages (from Twisted>=15.5->klein==17.10.0->-r alt_requirements/requirements_bare.txt (line 2)) (15.1.0)
Requirement already satisfied: Automat>=0.3.0 in /home/ist/anaconda3/lib/python3.6/site-packages (from Twisted>=15.5->klein==17.10.0->-r alt_requirements/requirements_bare.txt (line 2)) (0.7.0)
Requirement already satisfied: PyHamcrest>=1.9.0 in /home/ist/anaconda3/lib/python3.6/site-packages (from Twisted>=15.5->klein==17.10.0->-r alt_requirements/requirements_bare.txt (line 2)) (1.9.0)
Requirement already satisfied: attrs>=17.4.0 in /home/ist/anaconda3/lib/python3.6/site-packages (from Twisted>=15.5->klein==17.10.0->-r alt_requirements/requirements_bare.txt (line 2)) (18.2.0)
Requirement already satisfied: setuptools in /home/ist/anaconda3/lib/python3.6/site-packages (from zope.interface>=4.4.2->Twisted>=15.5->klein==17.10.0->-r alt_requirements/requirements_bare.txt (line 2)) (39.1.0)
@akelad

This comment has been minimized.

Copy link
Collaborator

commented Oct 25, 2018

That looks like it worked? If you're having trouble, please open a new issue

@MetcalfeTom MetcalfeTom referenced this issue Jan 21, 2019

Merged

Evaluation successes #1559

4 of 4 tasks complete
@samrudh

This comment has been minimized.

Copy link

commented Feb 5, 2019

Updating rasa-nlu to 0.14 solved my problem. Thanks.

@greg-springett

This comment has been minimized.

Copy link

commented May 5, 2019

Hi - i was getting the same bad input shape error, followed the suggested resolution above of installing the requirements from the starter pack git but now i get an 'illegal instruction 4 error'. any thoughts?

@sudhirkumar18

This comment has been minimized.

Copy link

commented May 14, 2019

i was try all thre above way how to solve this issue please reply me as soon as possible

File "/usr/local/lib/python3.5/dist-packages/sklearn/utils/validation.py", line 797, in column_or_1d
raise ValueError("bad input shape {0}".format(shape))
ValueError: bad input shape (1, 3)

@MetcalfeTom

This comment has been minimized.

Copy link
Contributor

commented May 14, 2019

Hi, are you sure you've updated your rasa version? Because we fixed the line that was causing this error

Please open a new issue and include a full stacktrace if the error persists.

@PrithviRakshak

This comment has been minimized.

Copy link

commented May 16, 2019

Am new to programming and am facing the same issue. I updated rasa to latest version , created config file and followed every step, for whatever reason I keep getting the same error, can U help me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.