UKPLab / sentence-transformers

State-of-the-Art Text Embeddings
https://www.sbert.net
Apache License 2.0
15.25k stars 2.47k forks source link

Logger error in Model.encode #664

Open issafuad opened 3 years ago

issafuad commented 3 years ago

I am trying to follow the instructions on the readme

from sentence_transformers import SentenceTransformer model = SentenceTransformer('paraphrase-distilroberta-base-v1')

sentences = ['This framework generates embeddings for each input sentence', 'Sentences are passed as a list of string.', 'The quick brown fox jumps over the lazy dog.'] sentence_embeddings = model.encode(sentences)

but then it throws an error

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-03bb672e7305> in <module>()
      2     'Sentences are passed as a list of string.',
      3     'The quick brown fox jumps over the lazy dog.']
----> 4 sentence_embeddings = model.encode(sentences)

/usr/local/lib/python3.6/dist-packages/sentence_transformers/SentenceTransformer.py in encode(self, sentences, batch_size, show_progress_bar, output_value, convert_to_numpy, convert_to_tensor, is_pretokenized, device, num_workers)
    153         self.eval()
    154         if show_progress_bar is None:
--> 155             show_progress_bar = (logger.getLogger().getEffectiveLevel()==logger.INFO or logger.getLogger().getEffectiveLevel()==logger.DEBUG)
    156 
    157         input_was_string = False

AttributeError: 'Logger' object has no attribute 'getLogger'
nreimers commented 3 years ago

Thanks for reporting.

Try to update to verion 0.4.1.2 by running:

pip install -U sentence-transformers

Otherwise you can also use:

sentence_embeddings = model.encode(sentences, show_progress_bar=False)
constantin-huetterer commented 3 years ago

This is a great framework. Thank you for creating it! 🙏 ❤️

On Windows 10, I am still running into the issue mentioned above using version 2.0.0 of sentence-transformers. The workaround with the extra parameters removes the error as expected. Under Unix everything was working smoothly. I am happy to help investigating this further if you can point me into a direction.

This is my environment ```ps # Name Version Build Channel altgraph 0.17 py_0 anaconda bertopic 0.8.1 pypi_0 pypi blas 1.0 mkl anaconda brotlipy 0.7.0 py38he774522_1000 anaconda ca-certificates 2020.10.14 0 anaconda certifi 2020.6.20 py38_0 anaconda cffi 1.14.3 py38h7a1dbc1_0 anaconda chardet 3.0.4 py38_1003 anaconda click 7.1.2 py_0 anaconda colorama 0.4.4 pyh9f0ad1d_0 conda-forge cpuonly 1.0 0 pytorch cryptography 3.1.1 py38h7a1dbc1_0 anaconda cudatoolkit 11.1.1 heb2d755_7 conda-forge cython 0.29.23 py38h885f38d_1 conda-forge dataclasses 0.7 py38_0 anaconda fasttext 0.9.2 pypi_0 pypi filelock 3.0.12 py_0 anaconda flask 1.1.2 py_0 anaconda freetype 2.10.4 hd328e21_0 anaconda future 0.18.2 py38_1 anaconda gputil 1.4.0 pyh9f0ad1d_0 conda-forge hdbscan 0.8.27 py38h347fdf6_0 conda-forge huggingface-hub 0.0.12 pypi_0 pypi huggingface_hub 0.0.13 py_0 huggingface icc_rt 2019.0.0 h0cc432a_1 anaconda idna 2.10 py_0 anaconda importlib-metadata 2.0.0 py_1 anaconda importlib_metadata 2.0.0 1 anaconda intel-openmp 2020.2 254 anaconda itsdangerous 1.1.0 py_0 anaconda jinja2 2.11.2 py_0 anaconda joblib 1.0.1 pyhd8ed1ab_0 conda-forge jpeg 9b vc14h4d7706e_1 [vc14] anaconda libblas 3.9.0 1_h8933c1f_netlib conda-forge libcblas 3.9.0 5_hd5c7e75_netlib conda-forge liblapack 3.9.0 5_hd5c7e75_netlib conda-forge libpng 1.6.37 h2a8f88b_0 anaconda libprotobuf 3.13.0.1 h200bbdf_0 anaconda libtiff 4.1.0 h56a325e_1 anaconda libuv 1.40.0 he774522_0 anaconda llvmlite 0.36.0 pypi_0 pypi lz4-c 1.9.2 hf4a77e7_3 anaconda m2w64-gcc-libgfortran 5.3.0 6 conda-forge m2w64-gcc-libs 5.3.0 7 conda-forge m2w64-gcc-libs-core 5.3.0 7 conda-forge m2w64-gmp 6.1.0 2 conda-forge m2w64-libwinpthread-git 5.0.0.4634.697f757 2 conda-forge macholib 1.14 py_1 anaconda markupsafe 1.1.1 py38he774522_0 anaconda mkl 2019.4 245 anaconda mkl-include 2021.2.0 hb70f87d_389 conda-forge mkl-service 2.3.0 py38hb782905_0 anaconda mkl_fft 1.2.0 py38h45dec08_0 anaconda mkl_random 1.1.0 py38hf9181ef_0 anaconda msys2-conda-epoch 20160418 1 conda-forge ninja 1.10.1 py38h7ef1ec2_0 anaconda nltk 3.6.2 pyhd8ed1ab_0 conda-forge numba 0.53.1 py38h99fac5f_1 conda-forge numpy 1.20.3 py38h09042cb_0 conda-forge numpy-base 1.19.1 py38ha3acd2a_0 anaconda olefile 0.46 py_0 anaconda openssl 1.1.1h he774522_0 anaconda packaging 20.9 pyh44b312d_0 conda-forge pandas 1.2.5 py38h60cbd38_0 conda-forge pefile 2021.5.24 pyhd8ed1ab_0 conda-forge pillow 8.2.0 pypi_0 pypi pip 20.2.4 py38_0 anaconda plotly 4.14.2 pyhd3deb0d_0 conda-forge powershell_shortcut 0.0.1 3 anaconda protobuf 3.13.0.1 py38ha925a31_1 anaconda pybind11 2.6.2 py38hbd9d945_0 conda-forge pybind11-global 2.6.2 py38hbd9d945_0 conda-forge pycparser 2.20 py_2 anaconda pyinstaller 4.3 py38hd0d6af5_0 conda-forge pyinstaller-hooks-contrib 2021.2 pyhd8ed1ab_0 conda-forge pynndescent 0.5.2 pyh44b312d_0 conda-forge pyopenssl 19.1.0 py_1 anaconda pyparsing 2.4.7 py_0 anaconda pysocks 1.7.1 py38_0 anaconda python 3.8.5 h5fd99cc_1 anaconda python-dateutil 2.8.1 py_0 anaconda python_abi 3.8 2_cp38 conda-forge pytorch 1.9.0 py3.8_cpu_0 [cpuonly] pytorch pytz 2021.1 pypi_0 pypi pywin32 227 py38he774522_1 anaconda pywin32-ctypes 0.2.0 py38_1000 anaconda pyyaml 5.4.1 pypi_0 pypi regex 2020.10.15 py38he774522_0 anaconda requests 2.24.0 py_0 anaconda retrying 1.3.3 py_2 anaconda sacremoses 0.0.45 pypi_0 pypi scikit-learn 0.23.2 py38h47e9c7a_0 anaconda scipy 1.5.0 py38h9439919_0 anaconda sentence-transformers 2.0.0 pypi_0 pypi sentencepiece 0.1.96 pypi_0 pypi setuptools 49.6.0 py38haa244fe_3 conda-forge six 1.15.0 py_0 anaconda sqlite 3.33.0 h2a8f88b_0 anaconda tbb 2020.3 h74a9793_0 anaconda threadpoolctl 2.1.0 pyh5ca1d4c_0 anaconda tk 8.6.7 vc14hb68737d_1 [vc14] anaconda tokenizers 0.10.3 pypi_0 pypi torch 1.9.0 pypi_0 pypi torchaudio 0.9.0 py38 pytorch torchvision 0.10.0 pypi_0 pypi tqdm 4.50.2 py_0 anaconda transformers 4.8.2 pypi_0 pypi typing-extensions 3.7.4.3 0 anaconda typing_extensions 3.7.4.3 py_0 anaconda umap-learn 0.5.1 py38haa244fe_1 conda-forge urllib3 1.25.11 py_0 anaconda vc 14.1 h0510ff6_4 anaconda vs2015_runtime 14.16.27012 hf0eaf9b_3 anaconda werkzeug 1.0.1 py_0 anaconda wheel 0.35.1 py_0 anaconda win_inet_pton 1.1.0 py38_0 anaconda wincertstore 0.2 py38_0 anaconda xlrd 1.2.0 py_0 anaconda xz 5.2.5 h62dcd97_0 anaconda yaml 0.1.7 vc14h4cb57cf_1 [vc14] anaconda zipp 3.3.1 py_0 anaconda zlib 1.2.11 vc14h1cdd9ab_1 [vc14] anaconda zstd 1.4.4 ha9fde0e_3 anaconda ```