urchade / GLiNER

Generalist and Lightweight Model for Named Entity Recognition (Extract any entity types from texts) @ NAACL 2024
https://arxiv.org/abs/2311.08526
Apache License 2.0
1.48k stars 127 forks source link

Running with Scipy version 1.130 gives an error #62

Closed chetankumar closed 7 months ago

chetankumar commented 7 months ago

Code:

`from gliner import GLiNER

Initialize GLiNER with the base model

model = GLiNER.from_pretrained("urchade/gliner_medium-v2.1")`

Error Summary

`--------------------------------------------------------------------------- ImportError Traceback (most recent call last) Cell In[2], line 1 ----> 1 from gliner import GLiNER 3 # Initialize GLiNER with the base model 4 model = GLiNER.from_pretrained("urchade/gliner_medium-v2.1")

File c:\Users\cheta.conda\envs\langchain\Lib\site-packages\gliner__init__.py:3 1 version = "0.1.7" ----> 3 from .model import GLiNER 5 all = ["GLiNER"]

File c:\Users\cheta.conda\envs\langchain\Lib\site-packages\gliner\model.py:13 11 from gliner.modules.evaluator import Evaluator, greedy_search 12 from gliner.modules.span_rep import SpanRepLayer ---> 13 from gliner.modules.token_rep import TokenRepLayer 14 from gliner.modules.token_splitter import WhitespaceTokenSplitter, MecabKoTokenSplitter 15 from torch import nn

File c:\Users\cheta.conda\envs\langchain\Lib\site-packages\gliner\modules\token_rep.py:5 3 import torch 4 from flair.data import Sentence ----> 5 from flair.embeddings import TransformerWordEmbeddings 6 from torch import nn 7 from torch.nn.utils.rnn import pad_sequence

File c:\Users\cheta.conda\envs\langchain\Lib\site-packages\flair__init__.py:42 39 # global variable: arrow symbol 40 _arrow = " → " ---> 42 from . import ( # noqa: E402 import after setting device 43 data, 44 models, 45 nn, 46 trainers, 47 visual, 48 ) 50 logging.config.dictConfig( 51 { 52 "version": 1, (...) 64 } 65 ) 67 logger = logging.getLogger("flair")

File c:\Users\cheta.conda\envs\langchain\Lib\site-packages\flair\models__init__.py:1 ----> 1 from .clustering import ClusteringModel 2 from .entity_linker_model import SpanClassifier 3 from .language_model import LanguageModel

File c:\Users\cheta.conda\envs\langchain\Lib\site-packages\flair\models\clustering.py:14 12 from flair.data import Corpus, _iter_dataset 13 from flair.datasets import DataLoader ---> 14 from flair.embeddings import DocumentEmbeddings 16 log = logging.getLogger("flair") 19 class ClusteringModel:

File c:\Users\cheta.conda\envs\langchain\Lib\site-packages\flair\embeddings__init__.py:13 10 from .base import Embeddings, ScalarMix 12 # Expose document embedding classes ---> 13 from .document import ( 14 DocumentCNNEmbeddings, 15 DocumentEmbeddings, 16 DocumentLMEmbeddings, 17 DocumentPoolEmbeddings, 18 DocumentRNNEmbeddings, 19 DocumentTFIDFEmbeddings, 20 SentenceTransformerDocumentEmbeddings, 21 TransformerDocumentEmbeddings, 22 ) 24 # Expose image embedding classes 25 from .image import ( 26 ConvTransformNetworkImageEmbeddings, 27 IdentityImageEmbeddings, (...) 30 PrecomputedImageEmbeddings, 31 )

File c:\Users\cheta.conda\envs\langchain\Lib\site-packages\flair\embeddings\document.py:16 10 from flair.data import Sentence 11 from flair.embeddings.base import ( 12 DocumentEmbeddings, 13 load_embeddings, 14 register_embeddings, 15 ) ---> 16 from flair.embeddings.token import FlairEmbeddings, StackedEmbeddings, TokenEmbeddings 17 from flair.embeddings.transformer import ( 18 TransformerEmbeddings, 19 TransformerOnnxDocumentEmbeddings, 20 ) 21 from flair.nn import LockedDropout, WordDropout

File c:\Users\cheta.conda\envs\langchain\Lib\site-packages\flair\embeddings\token.py:10 7 from pathlib import Path 8 from typing import Any, Dict, List, Optional, Union ---> 10 import gensim 11 import numpy as np 12 import torch

File c:\Users\cheta.conda\envs\langchain\Lib\site-packages\gensim__init__.py:11 7 version = '4.3.2' 9 import logging ---> 11 from gensim import parsing, corpora, matutils, interfaces, models, similarities, utils # noqa:F401 14 logger = logging.getLogger('gensim') 15 if not logger.handlers: # To ensure reload() doesn't add another one

File c:\Users\cheta.conda\envs\langchain\Lib\site-packages\gensim\corpora__init__.py:6 1 """ 2 This package contains implementations of various streaming corpus I/O format. 3 """ 5 # bring corpus classes directly into package namespace, to save some typing ----> 6 from .indexedcorpus import IndexedCorpus # noqa:F401 must appear before the other classes 8 from .mmcorpus import MmCorpus # noqa:F401 9 from .bleicorpus import BleiCorpus # noqa:F401

File c:\Users\cheta.conda\envs\langchain\Lib\site-packages\gensim\corpora\indexedcorpus.py:14 10 import logging 12 import numpy ---> 14 from gensim import interfaces, utils 16 logger = logging.getLogger(name) 19 class IndexedCorpus(interfaces.CorpusABC):

File c:\Users\cheta.conda\envs\langchain\Lib\site-packages\gensim\interfaces.py:19 7 """Basic interfaces used across the whole Gensim package. 8 9 These interfaces are used for building corpora, model transformation and similarity queries. (...) 14 15 """ 17 import logging ---> 19 from gensim import utils, matutils 22 logger = logging.getLogger(name) 25 class CorpusABC(utils.SaveLoad):

File c:\Users\cheta.conda\envs\langchain\Lib\site-packages\gensim\matutils.py:20 18 import scipy.sparse 19 from scipy.stats import entropy ---> 20 from scipy.linalg import get_blas_funcs, triu 21 from scipy.linalg.lapack import get_lapack_funcs 22 from scipy.special import psi # gamma function utils

ImportError: cannot import name 'triu' from 'scipy.linalg' (c:\Users\cheta.conda\envs\langchain\Lib\site-packages\scipy\linalg__init__.py)`

Resolution

The triu package from spicy has been deprecated and is not used in 1.13 (latest). Downgrading to spicy 1.12 resolved the issue.

tomaarsen commented 7 months ago

I can reproduce this as well, thanks for mentioning the resolution, it prevented the bug in my demo: https://huggingface.co/spaces/tomaarsen/gliner_medium-v2.1

Solving the real problem at hand is tricky, because it originates through gensim which is required by flair.

urchade commented 7 months ago

fixed in v0.1.8