1
resposta

Erro da liqfit

A explicação do colab do erro que estou tomando.

The error you're seeing, ImportError: cannot import name 'TruncationStrategy' from 'transformers.tokenization_utils', is due to an incompatibility between the liqfit library and the version of transformers currently installed. liqfit expects an older version of transformers (likely 4.x.x) where TruncationStrategy was located in transformers.tokenization_utils. Your current transformers version is 5.0.0.

To resolve this, I will modify the cell to first uninstall the current transformers library, then install a compatible version (specifically 4.28.0), and finally uninstall and reinstall liqfit to ensure everything is correctly aligned. After these installations, the original import and model loading code will be executed. You might need to restart the Colab runtime after executing this cell for the changes to fully take effect.

1 resposta

Boa tarde

Esse erro não tá relacionado ao seu código em si, mas à incompatibilidade de versões entre liqfit e transformers.

A biblioteca liqfit ainda depende de estruturas internas do transformers 4.x. Como o Colab atualmente instala o transformers 5.x por padrão, ocorre o erro:

ImportError: cannot import name 'TruncationStrategy'

Essa classe existia em versões antigas e foi removida/reorganizada no 5.x.

A solução é forçar a instalação de uma versão compatível do transformers antes de importar o modelo.

Execute esta célula no Colab:

!pip uninstall -y transformers
!pip install transformers==4.28.0
!pip uninstall -y liqfit
!pip install liqfit sentencepiece

Depois disso, reinicie o runtime do Colab (Ambiente de execução → Reiniciar ambiente de execução).
Esse passo é importante, senão o Python continua usando a versão antiga em memória.

Após reiniciar, execute novamente apenas:

from liqfit.pipeline import ZeroShotClassificationPipeline
from liqfit.models import T5ForZeroShotClassification
from transformers import T5Tokenizer

Se tudo estiver correto, o import funcionará normalmente.

Se ainda der erro, me manda o log completo da nova mensagem que eu analiso por aqui