天天看点

使用NER_sklearn.ipynb CRF实现,出现的问题

Traceback (most recent call last):
  File "D:\software\Anaconda3\envs\NER\lib\site-packages\IPython\core\interactiveshell.py", line 3418, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-71bbf22b7c9a>", line 1, in <module>
    runfile('D:/Users/lee/Downloads/Compressed/ailearning-master/ailearning-master/ner/test.py', wdir='D:/Users/lee/Downloads/Compressed/ailearning-master/ailearning-master/ner')
  File "D:\software\PyCharm Community Edition 2019.1.1\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "D:\software\PyCharm Community Edition 2019.1.1\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "D:/Users/lee/Downloads/Compressed/ailearning-master/ailearning-master/ner/test.py", line 342, in <module>
    rs.fit(X_train, y_train)
  File "D:\software\Anaconda3\envs\NER\lib\site-packages\sklearn\utils\validation.py", line 63, in inner_f
    return f(*args, **kwargs)
  File "D:\software\Anaconda3\envs\NER\lib\site-packages\sklearn\model_selection\_search.py", line 765, in fit
    base_estimator = clone(self.estimator)
  File "D:\software\Anaconda3\envs\NER\lib\site-packages\sklearn\utils\validation.py", line 63, in inner_f
    return f(*args, **kwargs)
  File "D:\software\Anaconda3\envs\NER\lib\site-packages\sklearn\base.py", line 74, in clone
    new_object_params = estimator.get_params(deep=False)
  File "D:\software\Anaconda3\envs\NER\lib\site-packages\sklearn\base.py", line 195, in get_params
    value = getattr(self, key)
AttributeError: 'CRF' object has no attribute 'keep_tempfiles'
           

好像是python 3.7不支持,尝试改成3.6.4

Please note and check the following:
  * The Python version is: Python3.6 from "D:\software\Anaconda3\envs\NER\python.exe"
  * The NumPy version is: "1.19.4"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'
           

然后又要改numpy为 1.16.0

Traceback (most recent call last):
  File "D:\software\Anaconda3\envs\NER\lib\site-packages\IPython\core\interactiveshell.py", line 3418, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-71bbf22b7c9a>", line 1, in <module>
    runfile('D:/Users/lee/Downloads/Compressed/ailearning-master/ailearning-master/ner/test.py', wdir='D:/Users/lee/Downloads/Compressed/ailearning-master/ailearning-master/ner')
  File "D:\software\PyCharm Community Edition 2019.1.1\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "D:\software\PyCharm Community Edition 2019.1.1\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "D:/Users/lee/Downloads/Compressed/ailearning-master/ailearning-master/ner/test.py", line 6, in <module>
    import pandas as pd
  File "D:\software\PyCharm Community Edition 2019.1.1\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "D:\software\Anaconda3\envs\NER\lib\site-packages\pandas\__init__.py", line 38, in <module>
    ) from e
ImportError: C extension: No module named 'pandas._libs.interval' not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inp
           

然后又要重装pandas

File "C:\Users\lee\AppData\Roaming\Python\Python36\site-packages\sklearn\base.py", line 21, in <module>
    from .utils import _IS_32BIT
  File "D:\software\PyCharm Community Edition 2019.1.1\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Users\lee\AppData\Roaming\Python\Python36\site-packages\sklearn\utils\__init__.py", line 20, in <module>
    from scipy.sparse import issparse
  File "D:\software\PyCharm Community Edition 2019.1.1\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "D:\software\Anaconda3\envs\NER\lib\site-packages\scipy\__init__.py", line 151, in <module>
    from scipy._lib._ccallback import LowLevelCallable
  File "D:\software\PyCharm Community Edition 2019.1.1\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "D:\software\Anaconda3\envs\NER\lib\site-packages\scipy\_lib\_ccallback.py", line 1, in <module>
    from . import _ccallback_c
ImportError: cannot import name '_ccallback_c'
           

然后又要重装scipy

pip uninstall scipy

pip install scipy

Traceback (most recent call last):
  File "D:\software\Anaconda3\envs\NER\lib\site-packages\IPython\core\interactiveshell.py", line 3418, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-71bbf22b7c9a>", line 1, in <module>
    runfile('D:/Users/lee/Downloads/Compressed/ailearning-master/ailearning-master/ner/test.py', wdir='D:/Users/lee/Downloads/Compressed/ailearning-master/ailearning-master/ner')
  File "D:\software\PyCharm Community Edition 2019.1.1\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "D:\software\PyCharm Community Edition 2019.1.1\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "D:/Users/lee/Downloads/Compressed/ailearning-master/ailearning-master/ner/test.py", line 164, in <module>
    import sklearn_crfsuite
  File "D:\software\PyCharm Community Edition 2019.1.1\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "D:\software\Anaconda3\envs\NER\lib\site-packages\sklearn_crfsuite\__init__.py", line 2, in <module>
    from .estimator import CRF
  File "D:\software\PyCharm Community Edition 2019.1.1\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "D:\software\Anaconda3\envs\NER\lib\site-packages\sklearn_crfsuite\estimator.py", line 6, in <module>
    import pycrfsuite
  File "D:\software\PyCharm Community Edition 2019.1.1\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "D:\software\Anaconda3\envs\NER\lib\site-packages\pycrfsuite\__init__.py", line 2, in <module>
    from ._pycrfsuite import *
  File "D:\software\PyCharm Community Edition 2019.1.1\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'pycrfsuite._pycrfsuite'
           

然后又要重装

pip uninstall python-crfsuite

pip install python-crfsuite

Top negative:
-1.003934 O        word.lower():democrats
-1.014938 O        +1:word.lower():military
-1.016890 O        -1:word.lower():emirates
-1.038674 B-gpe    +1:postag:NN
-1.123186 O        -1:word.lower():extremist
-1.128056 O        +1:word.lower():was
-1.143572 B-geo    -1:word.lower():with
-1.177887 B-geo    word[-2:]:ma
-1.181155 I-per    +1:postag[:2]:NN
-1.186787 B-gpe    word[-3:]:can
-1.201166 I-tim    word.istitle()
-1.257182 I-per    bias
-1.273856 O        word.isupper()
-1.285654 O        word[-2:]:sh
-1.294274 O        postag:NNPS
-1.301724 B-art    -1:word.istitle()
-1.361519 O        word[-3:]:ish
-1.374149 B-org    -1:postag:NNP
-1.447830 B-gpe    -1:word.istitle()
-1.568004 O        postag[:2]:NN
-1.660512 O        word[-2:]:an
-1.685406 B-gpe    word[-3:]:ean
-1.899461 B-gpe    -1:word.lower():from
-1.909397 B-geo    -1:postag[:2]:NN
-1.954756 B-per    -1:postag:NNP
-2.099129 B-gpe    word.lower():european
-2.361597 B-gpe    -1:word.lower():in
-3.268760 O        word.isdigit()
-4.204295 O        word.istitle()
-5.503867 O        postag:NNP
           

成功运行!