Jak poprawnie zainstalować oraz aktywować bibliotekę spaCy? Podczas wielokrotnych prób występują błędy, na przykład ValueError: BLIS support requires blis: pip install blis
Wrzuć cały error.
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[27], line 1
----> 1 import spacy
File C:\Program Files\Anaconda\Lib\site-packages\spacy\__init__.py:6
3 from typing import Any, Dict, Iterable, Union
5 # set library-specific custom warning handling before doing anything else
----> 6 from .errors import setup_default_warnings
8 setup_default_warnings() # noqa: E402
10 # These are imported as part of the API
File C:\Program Files\Anaconda\Lib\site-packages\spacy\errors.py:3
1 import warnings
----> 3 from .compat import Literal
6 class ErrorsWithCodes(type):
7 def __getattribute__(self, code):
File C:\Program Files\Anaconda\Lib\site-packages\spacy\compat.py:39
36 except ImportError:
37 from catalogue import _importlib_metadata as importlib_metadata # type: ignore[no-redef] # noqa: F401
---> 39 from thinc.api import Optimizer # noqa: F401
41 pickle = pickle
42 copy_reg = copy_reg
File C:\Program Files\Anaconda\Lib\site-packages\thinc\api.py:23
15 from .config import Config, ConfigValidationError, registry
16 from .initializers import (
17 configure_normal_init,
18 glorot_uniform_init,
(...)
21 zero_init,
22 )
---> 23 from .layers import (
24 LSTM,
25 CauchySimilarity,
26 ClippedLinear,
27 Dish,
28 Dropout,
29 Embed,
30 Gelu,
31 HardSigmoid,
32 HardSwish,
33 HardSwishMobilenet,
34 HardTanh,
35 HashEmbed,
36 LayerNorm,
37 Linear,
38 Logistic,
39 Maxout,
40 Mish,
41 MultiSoftmax,
42 MXNetWrapper,
43 ParametricAttention,
44 ParametricAttention_v2,
45 PyTorchLSTM,
46 PyTorchRNNWrapper,
47 PyTorchWrapper,
48 PyTorchWrapper_v2,
49 PyTorchWrapper_v3,
50 Relu,
51 ReluK,
52 Sigmoid,
53 Softmax,
54 Softmax_v2,
55 SparseLinear,
56 SparseLinear_v2,
57 Swish,
58 TensorFlowWrapper,
59 TorchScriptWrapper_v1,
60 add,
61 array_getitem,
62 bidirectional,
63 chain,
64 clone,
65 concatenate,
66 expand_window,
67 keras_subclass,
68 list2array,
69 list2padded,
70 list2ragged,
71 map_list,
72 noop,
73 padded2list,
74 premap_ids,
75 pytorch_to_torchscript_wrapper,
76 ragged2list,
77 reduce_first,
78 reduce_last,
79 reduce_max,
80 reduce_mean,
81 reduce_sum,
82 remap_ids,
83 remap_ids_v2,
84 residual,
85 resizable,
86 siamese,
87 sigmoid_activation,
88 softmax_activation,
89 strings2arrays,
90 tuplify,
91 uniqued,
92 with_array,
93 with_array2d,
94 with_cpu,
95 with_debug,
96 with_flatten,
97 with_flatten_v2,
98 with_getitem,
99 with_list,
100 with_nvtx_range,
101 with_padded,
102 with_ragged,
103 with_reshape,
104 with_signpost_interval,
105 )
106 from .loss import (
107 CategoricalCrossentropy,
108 CosineDistance,
109 L2Distance,
110 SequenceCategoricalCrossentropy,
111 )
112 from .model import (
113 Model,
114 change_attr_values,
(...)
118 wrap_model_recursive,
119 )
File C:\Program Files\Anaconda\Lib\site-packages\thinc\layers\__init__.py:12
10 from .clipped_linear import ClippedLinear, HardSigmoid, HardTanh, ReluK
11 from .clone import clone
---> 12 from .concatenate import concatenate
13 from .dish import Dish
14 from .dropout import Dropout
File C:\Program Files\Anaconda\Lib\site-packages\thinc\layers\concatenate.py:21
18 from ..util import get_width
19 from .noop import noop
---> 21 NUMPY_OPS = NumpyOps()
24 InT = TypeVar("InT", bound=Any)
25 OutT = TypeVar("OutT", bound=Union[Array2d, Sequence[Array2d], Ragged])
File C:\Program Files\Anaconda\Lib\site-packages\thinc\backends\numpy_ops.pyx:63, in thinc.backends.numpy_ops.NumpyOps.__init__()
ValueError: BLIS support requires blis: pip install blis
Widzę, że Masz błędy z Anacondy, co tam zrobiłeś, zainstalowałeś Anacondę, aktywowałeś i teraz error?
EDYCJA: Może spróbuj stworzyć czyste środowisko, condą i tam zainstaluj spaCy
spaCy jest już zauinstalowane, ale nie można zaimportować tej biblioteki.
A spróbuj tak jak napisałem w edycji.
Sprawdź sobie czy twoja wersja Pythona jest odpowiednia na OS. Ja miałem raz wyższą wersję niż zalecana i wszystko działo do czau jak chciałem pobierać biblioteki ML. Inne normalnie się instalowały. Też miałem takie błędy. Zmieniłem wersję na niższą i wszystko działa jak należy.
Jak poprawnie zaimportować optymalny model językowy?
Gdzie zaimportować i optymalny, do czego? Masz jakiś kontekst?
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
Cell In[52], line 1
----> 1 nlp = spacy.load("pl_core_web_sm")
2 doc = nlp("Apple is looking at buying U.K. startup for $1 billion")
3 for token in doc:
File /opt/conda/envs/anaconda-ai-2024.04-py310/lib/python3.10/site-packages/spacy/__init__.py:51, in load(name, vocab, disable, enable, exclude, config)
27 def load(
28 name: Union[str, Path],
29 *,
(...)
34 config: Union[Dict[str, Any], Config] = util.SimpleFrozenDict(),
35 ) -> Language:
36 """Load a spaCy model from an installed package or a local path.
37
38 name (str): Package name or model path.
(...)
49 RETURNS (Language): The loaded nlp object.
50 """
---> 51 return util.load_model(
52 name,
53 vocab=vocab,
54 disable=disable,
55 enable=enable,
56 exclude=exclude,
57 config=config,
58 )
File /opt/conda/envs/anaconda-ai-2024.04-py310/lib/python3.10/site-packages/spacy/util.py:472, in load_model(name, vocab, disable, enable, exclude, config)
470 if name in OLD_MODEL_SHORTCUTS:
471 raise IOError(Errors.E941.format(name=name, full=OLD_MODEL_SHORTCUTS[name])) # type: ignore[index]
--> 472 raise IOError(Errors.E050.format(name=name))
OSError: [E050] Can't find model 'pl_core_web_sm'. It doesn't seem to be a Python package or a valid path to a data directory.
Dlaczego kod >>> import spacy funkcjonuje prawidłowo w Windows PowerShell, a nieprawidłowo - w Jupyter Notebook?
>>> nlp = spacy.load('pl_core_news_sm')
>>> print(nlp("Witaj, świecie!"))
Witaj, świecie!
>>> import spacy
>>> nlp = spacy.load("pl_core_news_sm")
>>> doc = nlp("To jest przykładowe zdanie.")
>>> for token in doc:
... print(token.text, token.pos_, token.dep_)
... doc = nlp("To jest przykładowe zdanie.")
File "<stdin>", line 3
doc = nlp("To jest przykładowe zdanie.")
^^^
SyntaxError: invalid syntax
>>> for token in doc:
... print(token.text, token.pos_, token.dep_)
...
To AUX cop
jest AUX aux
przykładowe ADJ amod
zdanie NOUN ROOT
. PUNCT punct
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> doc = nlp("To jest przykładowe zdanie.")
>>> for token in doc:
... print(token.text, token.pos_, token.dep_)
...
To AUX cop
jest AUX aux
przykładowe ADJ amod
zdanie NOUN ROOT
. PUNCT punct
>>>
>>>
Pokazuje Ci błąd składniowy, musisz kod najpierw do porządku doprowadzić, potem się porówna między notebookiem a konsolą
Jak rozwiązać ten problem?
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[64], line 1
----> 1 import spacy
File C:\Program Files\Anaconda\Lib\site-packages\spacy\__init__.py:6
3 from typing import Any, Dict, Iterable, Union
5 # set library-specific custom warning handling before doing anything else
----> 6 from .errors import setup_default_warnings
8 setup_default_warnings() # noqa: E402
10 # These are imported as part of the API
File C:\Program Files\Anaconda\Lib\site-packages\spacy\errors.py:3
1 import warnings
----> 3 from .compat import Literal
6 class ErrorsWithCodes(type):
7 def __getattribute__(self, code):
File C:\Program Files\Anaconda\Lib\site-packages\spacy\compat.py:4
1 """Helpers for Python and platform compatibility."""
2 import sys
----> 4 from thinc.util import copy_array
6 try:
7 import cPickle as pickle
File C:\Program Files\Anaconda\Lib\site-packages\thinc\__init__.py:5
2 import numpy
4 from .about import __version__
----> 5 from .config import registry
7 # fmt: off
8 __all__ = [
9 "registry",
10 "__version__",
11 ]
File C:\Program Files\Anaconda\Lib\site-packages\thinc\config.py:5
2 import confection
3 from confection import VARIABLE_RE, Config, ConfigValidationError, Promise
----> 5 from .types import Decorator
8 class registry(confection.registry):
9 # fmt: off
10 optimizers: Decorator = catalogue.create("thinc", "optimizers", entry_points=True)
File C:\Program Files\Anaconda\Lib\site-packages\thinc\types.py:25
4 from typing import (
5 Any,
6 Callable,
(...)
20 overload,
21 )
23 import numpy
---> 25 from .compat import cupy, has_cupy
27 if has_cupy:
28 get_array_module = cupy.get_array_module
File C:\Program Files\Anaconda\Lib\site-packages\thinc\compat.py:99
95 has_mxnet = False
98 try:
---> 99 import h5py
100 except ImportError: # pragma: no cover
101 h5py = None
File C:\Program Files\Anaconda\Lib\site-packages\h5py\__init__.py:45
36 _warn(("h5py is running against HDF5 {0} when it was built against {1}, "
37 "this may cause problems").format(
38 '{0}.{1}.{2}'.format(*version.hdf5_version_tuple),
39 '{0}.{1}.{2}'.format(*version.hdf5_built_version_tuple)
40 ))
43 _errors.silence_errors()
---> 45 from ._conv import register_converters as _register_converters, \
46 unregister_converters as _unregister_converters
47 _register_converters()
48 atexit.register(_unregister_converters)
File h5py\\_conv.pyx:1, in init h5py._conv()
File h5py\\h5r.pyx:1, in init h5py.h5r()
File h5py\\h5p.pyx:1, in init h5py.h5p()
ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject