0

I am trying to create a application which checks for sentence similarity. Exe file got created. Getting the below error message while executing .exe file after giving required inputs.

code

model = pickle.load(open(r"miniLM.sav", "rb")) 
sentences_embeddings = model.encode(desc_corpus) 
c_matrix = cosine_similarity(sentences_embeddings, sentences_embeddings)

Error

cannot import name 'GenerationMixin' from 'transformers.generation' (C:\Users\UserName\AppData\Local\Temp\_MEI198962\transformers\generation\__init__.pyc)

I have the latest version of transformers - 4.26.1

requirements.txt

absl-py==1.4.0
altgraph==0.17.3
astunparse==1.6.3
cachetools==5.3.0
certifi==2022.12.7
charset-normalizer==3.0.1
click==8.1.3
colorama==0.4.6
et-xmlfile==1.1.0
filelock==3.9.0
flatbuffers==23.1.21
gast==0.4.0
google-auth==2.16.0
google-auth-oauthlib==0.4.6
google-pasta==0.2.0
grpcio==1.51.1
h5py==3.8.0
huggingface-hub==0.12.0
idna==3.4
importlib-metadata==6.0.0
joblib==1.2.0
keras==2.11.0
libclang==15.0.6.1
Markdown==3.4.1
MarkupSafe==2.1.2
nltk==3.8.1
numpy==1.24.2
oauthlib==3.2.2
openpyxl==3.1.0
opt-einsum==3.3.0
packaging==23.0
pandas==1.5.3
pefile==2023.2.7
Pillow==9.4.0
protobuf==3.19.6
pyasn1==0.4.8
pyasn1-modules==0.2.8
pyinstaller==5.7.0
pyinstaller-hooks-contrib==2022.15
PyQt5==5.15.9
PyQt5-Qt5==5.15.2
PyQt5-sip==12.11.1
python-dateutil==2.8.2
python-version==0.0.2
pytz==2022.7.1
pywin32-ctypes==0.2.0
PyYAML==6.0
regex==2022.10.31
requests==2.28.2
requests-oauthlib==1.3.1
rsa==4.9
scikit-learn==1.2.1
scipy==1.10.0
sentence-transformers==2.2.2
sentencepiece==0.1.97
six==1.16.0
tensorboard==2.11.2
tensorboard-data-server==0.6.1
tensorboard-plugin-wit==1.8.1
tensorflow==2.11.0
tensorflow-estimator==2.11.0
tensorflow-intel==2.11.0
tensorflow-io-gcs-filesystem==0.30.0
termcolor==2.2.0
threadpoolctl==3.1.0
tokenizers==0.13.2
torch==1.13.1
torchvision==0.14.1
tqdm==4.64.1
transformers==4.26.1
typing_extensions==4.4.0
urllib3==1.26.14
Werkzeug==2.2.2
wrapt==1.14.1
zipp==3.13.0

spec file

# -*- mode: python ; coding: utf-8 -*-
from PyInstaller.utils.hooks import copy_metadata

datas = [('Config\\\\favicon.ico', '.'), ('Config\\\\miniLM.sav', '.')]
datas += copy_metadata('tqdm')
datas += copy_metadata('regex')
datas += copy_metadata('requests')
datas += copy_metadata('packaging')
datas += copy_metadata('filelock')
datas += copy_metadata('numpy')
datas += copy_metadata('tokenizers')
datas += copy_metadata('importlib_metadata')
datas += copy_metadata('tensorflow')


block_cipher = None


a = Analysis(
    ['render_ui.py'],
    pathex=[],
    binaries=[],
    datas=datas,
    hiddenimports=['sklearn.metrics._pairwise_distances_reduction._datasets_pair', 'sklearn.metrics._pairwise_distances_reduction._middle_term_computer', 'sklearn.metrics._pairwise_distances_reduction._argkmin', 'sklearn.metrics._pairwise_distances_reduction._base', 'sklearn.metrics._pairwise_distances_reduction._radius_neighbors', 'sentence_transformers.SentenceTransformer', 'tensorflow'],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher,
    noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.zipfiles,
    a.datas,
    [],
    name='App',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    upx_exclude=[],
    runtime_tmpdir=None,
    console=True,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
    icon='Config\\favicon.ico'
)

Downgraded transformers to - 4.25.1 Issue still persists. I am not sure what is causing this problem. Can someone please help me out on this?

10
  • Don't show the requirements file: verify that pip list shows transformers. Commented Feb 12, 2023 at 12:38
  • 1
    You're not even showing the actual code that throws the error. Commented Feb 12, 2023 at 12:40
  • The documentation suggest your import is incorrect. Commented Feb 12, 2023 at 12:41
  • I am using sentence-transformers/all-MiniLM-L6-v2 which is saved as (.sav file) for sentence embeddings Commented Feb 13, 2023 at 8:33
  • Error is raised from 2 line in below code model = pickle.load(open(r"miniLM.sav", "rb")) sentences_embeddings = model.encode(desc_corpus) c_matrix = cosine_similarity(sentences_embeddings, sentences_embeddings) Commented Feb 13, 2023 at 8:33

2 Answers 2

0

Below code changes were made

model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
sentences_embeddings = model.encode(desc_corpus)
c_matrix = cosine_similarity(sentences_embeddings, sentences_embeddings)

spec file

# -*- mode: python ; coding: utf-8 -*-
from PyInstaller.utils.hooks import copy_metadata

datas = [('Config\\\\favicon.ico', '.'), ('Config\\\\miniLM.sav', '.')]
datas += copy_metadata('tqdm')
datas += copy_metadata('regex')
datas += copy_metadata('requests')
datas += copy_metadata('packaging')
datas += copy_metadata('filelock')
datas += copy_metadata('numpy')
datas += copy_metadata('tokenizers')
datas += copy_metadata('importlib_metadata')
datas += copy_metadata('torch')

block_cipher = None


a = Analysis(
    ['render_ui.py'],
    pathex=[],
    binaries=[],
    datas=datas,
    hiddenimports=['sklearn.metrics._pairwise_distances_reduction._datasets_pair', 'sklearn.metrics._pairwise_distances_reduction._middle_term_computer', 'sklearn.metrics._pairwise_distances_reduction._argkmin', 'sklearn.metrics._pairwise_distances_reduction._base', 'sklearn.metrics._pairwise_distances_reduction._radius_neighbors', 'sentence_transformers.SentenceTransformer', 'transformers', 'torch'],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher,
    noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.zipfiles,
    a.datas,
    [],
    name='App',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    upx_exclude=[],
    runtime_tmpdir=None,
    console=True,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
    icon='Config\\favicon.ico'
)

Used below pip commands

pip install torch torchvision torchaudio
pip install -U sentence-transformers
Sign up to request clarification or add additional context in comments.

Comments

0

You need to root cause analysis this. This will fix the issue for most people, regardless of what is actually causing this.

  1. Verify if GenerationMixin exists in the first place. If it does, that means something within GenerationMixin is not working. If it doesn't exist, you need to properly install transformers.

    import transformers
    [d for d in dir(transformers) if "GenerationMixin" in d]
    
  2. Assuming it exists, which I suspect it will for most people, affirm the issue with

    help(transformers.GenerationMixin)
    
  3. When this happened to me, it gave something like pyarrow does not have \__version__ This can be because of pyarrow itself, pandas, or the many libraries that use it. For me, my pyarrow install wasn't fully done. This command just showed a couple things instead of a long list:

    import pyarrow
    dir(pyarrow)
    
  4. Lastly, fix this up. Uninstall/reinstall pyarrow and pandas (or whatever package is messed up). Make sure that when you run import pyarrow it fails. You may need to delete pyarrow components at miniforge3\envs\your-env\Lib\site-packages. After you're sure pyarrow won't import, then you can reinstall pyarrow.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.