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

ImportError: cannot import name 'create_features' #3674

Closed
sekhar14 opened this issue May 31, 2019 · 6 comments
Closed

ImportError: cannot import name 'create_features' #3674

sekhar14 opened this issue May 31, 2019 · 6 comments

Comments

@sekhar14
Copy link

sekhar14 commented May 31, 2019

Rasa version: 0.14.1

Rasa X version (if used & relevant):

Python version: 3.6

Operating system (windows, osx, ...): ubuntu 16.04

Issue:
create_features not found in bert extract_features.py

Error (including full traceback):

Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/gpu21080ti/tensorflow1.3.3.5/tensorcode/rasa/rasa_nlu/train.py", line 184, in <module>
    num_threads=cmdline_args.num_threads)
  File "/home/gpu21080ti/tensorflow1.3.3.5/tensorcode/rasa/rasa_nlu/train.py", line 148, in do_train
    trainer = Trainer(cfg, component_builder)
  File "/home/gpu21080ti/tensorflow1.3.3.5/tensorcode/rasa/rasa_nlu/model.py", line 152, in __init__
    components.validate_requirements(cfg.component_names)
  File "/home/gpu21080ti/tensorflow1.3.3.5/tensorcode/rasa/rasa_nlu/components.py", line 49, in validate_requirements
    from rasa_nlu import registry
  File "/home/gpu21080ti/tensorflow1.3.3.5/tensorcode/rasa/rasa_nlu/registry.py", line 36, in <module>
    from rasa_nlu.featurizers.bert_featurizer import BertFeaturizer
  File "/home/gpu21080ti/tensorflow1.3.3.5/tensorcode/rasa/rasa_nlu/featurizers/bert_featurizer.py", line 15, in <module>
    from bert.extract_features import create_features, model_fn_builder
ImportError: cannot import name 'create_features'

Command or request that led to error:

 python -m rasa_nlu.train -c sample_configs/config_bert.yml --data testData.json

Content of configuration file (config.yml) (if relevant):

language: "en"

pipeline:
- name: "intent_featurizer_bert"
  model_dir: "./uncased_L-12_H-768_A-12"
- name: "intent_classifier_sklearn"

Content of domain file (domain.yml) (if relevant):

@sekhar14 sekhar14 closed this as completed Jun 3, 2019
@DavidForlen
Copy link

Did you find a solution to this problem ?

@msamogh
Copy link
Contributor

msamogh commented Jul 23, 2019

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

@Ghostvv
Copy link
Contributor

Ghostvv commented Jul 24, 2019

what problem?

@DavidForlen
Copy link

In order to replace intent_featurizer_spacy component by rasa_components.featurizers.bert_featurizer.BertFeaturizer in my pipeline, I took theses files from the bert_embeddings branch (https://github.com/RasaHQ/rasa/tree/bert_embeddings) :

  • rasa_nlu/featurizers/bert_featurizer.py
  • rasa_nlu/utils/bert_utils.py

I have installed the bert-tensorflow package on docker.
The packages that may help to understand why I'm facing this issue :

$ docker-compose exec medibot pip freeze | grep rasa
rasa-core==0.13.8
rasa-core-sdk==0.12.2
rasa-nlu==0.14.6

$ docker-compose exec medibot pip freeze | grep bert
bert-tensorflow==1.0.1

And now it seems that the rasa_nlu/featurizers/bert_featurizer.py file tries to import the create_features function that python (and I) can't found.

The error is almost the same as the one reported by @sekhar14 :

docker-compose exec medibot make -C ./medibot train-nlu
make: Entering directory '/usr/src/aliae/medibot'
python3 -m rasa_nlu.train -c nlu_config_fr_bert_feature.yml --data data/fr_init_data_set_train.json -o models --fixed_model_name nlu --project bert_feature_on_FR --verbose
/usr/local/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/rasa_nlu/registry.py", line 109, in get_component_class
    return utils.class_from_module_path(component_name)
  File "/usr/local/lib/python3.6/site-packages/rasa_nlu/utils/__init__.py", line 176, in class_from_module_path
    m = importlib.import_module(module_name)
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/usr/src/aliae/medibot/rasa_components/featurizers/bert_featurizer.py", line 15, in <module>
    from bert.extract_features import create_features, model_fn_builder
ImportError: cannot import name 'create_features'

I can import model_fn_builder (I tried to put the import of this function first, to test it), meaning that it can find the module and his functions, but not create_features, who doesn't even appear in the code of https://github.com/google-research/bert/blob/master/extract_features.py.

The first part of my pipeline file :

language: "fr"

pipeline:
- name: "nlp_spacy"
- name: "tokenizer_spacy"
- name: "rasa_components.featurizers.bert_featurizer.BertFeaturizer"
  model_dir: "multi_cased_L-12_H-768_A-12/"

@Ghostvv
Copy link
Contributor

Ghostvv commented Jul 24, 2019

you should use this fork: https://github.com/RasaHQ/bert

@DavidForlen
Copy link

DavidForlen commented Jul 24, 2019

Thanks a lot ! It runs correctly now (even if it takes time on CPUs, I will try on GPUs).

But I couldn't install the bert package from this branch neatly. How should I install it without having to take the bert directory from the branch and putting it directly in my working directory ?
I tried docker-compose exec medibot pip install git+https://github.com/RasaHQ/bert, and pip tells me Successfully built bert. But then rerunning the training shows me : ModuleNotFoundError: No module named 'bert'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants