Skip to content

Demo not working - GLiClassModel.from_pretrained() Error #35

Description

@arrietafernando

Does anybody knows why demo is not working?

I get same error when running "Usage examples" on Python 3.13 inside Jupyter notebook.

Error: AttributeError: 'GLiClassModelConfig' object has no attribute 'pad_token_id'

Example:

from gliclass import GLiClassModel, ZeroShotClassificationPipeline
from transformers import AutoTokenizer

model = GLiClassModel.from_pretrained("knowledgator/gliclass-small-v1.0")
tokenizer = AutoTokenizer.from_pretrained("knowledgator/gliclass-small-v1.0")

pipeline = ZeroShotClassificationPipeline(
    model, tokenizer, classification_type='multi-label', device='cuda:0'
)

text = "One day I will see the world!"
labels = ["travel", "dreams", "sport", "science", "politics"]
results = pipeline(text, labels, threshold=0.5)[0]

for result in results:
    print(f"{result['label']} => {result['score']:.3f}")

Full ouptut:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[2], line 4
      1 from gliclass import GLiClassModel, ZeroShotClassificationPipeline
      2 from transformers import AutoTokenizer
----> 4 model = GLiClassModel.from_pretrained("knowledgator/gliclass-small-v1.0")
      5 tokenizer = AutoTokenizer.from_pretrained("knowledgator/gliclass-small-v1.0")
      7 pipeline = ZeroShotClassificationPipeline(
      8     model, tokenizer, classification_type='multi-label', device='cuda:0'
      9 )

File ~/Proyectos SW/intent-classification/.venv/lib/python3.13/site-packages/transformers/modeling_utils.py:4072, in PreTrainedModel.from_pretrained(cls, pretrained_model_name_or_path, config, cache_dir, ignore_mismatched_sizes, force_download, local_files_only, token, revision, use_safetensors, weights_only, *model_args, **kwargs)
   4069 config = copy.deepcopy(config)  # We do not want to modify the config inplace in from_pretrained.
   4070 with ContextManagers(model_init_context):
   4071     # Let's make sure we don't run the init function of buffer modules
-> 4072     model = cls(config, *model_args, **model_kwargs)
   4074     if hf_quantizer is not None:  # replace module with quantized modules (does not touch weights)
   4075         hf_quantizer.preprocess_model(
   4076             model=model,
   4077             dtype=dtype,
   (...)   4080             use_kernels=use_kernels,
   4081         )

File ~/Proyectos SW/intent-classification/.venv/lib/python3.13/site-packages/gliclass/model.py:753, in GLiClassModel.__init__(self, config, from_pretrained)
    751 super().__init__(config)
    752 if config.architecture_type == 'uni-encoder':
--> 753     self.model = GLiClassUniEncoder(config, from_pretrained)
    754 elif config.architecture_type == 'bi-encoder':
    755     self.model = GLiClassBiEncoder(config, from_pretrained)

File ~/Proyectos SW/intent-classification/.venv/lib/python3.13/site-packages/gliclass/model.py:348, in GLiClassUniEncoder.__init__(self, config, from_pretrained)
    347 def __init__(self, config: GLiClassModelConfig, from_pretrained = False):
--> 348     super().__init__(config)
    349     if config.encoder_config is None:
    350         if config.encoder_model_name is None:

File ~/Proyectos SW/intent-classification/.venv/lib/python3.13/site-packages/gliclass/model.py:121, in GLiClassBaseModel.__init__(self, config, device, **kwargs)
    119 self.epsilon = 1e-8
    120 self.vocab_size = config.vocab_size
--> 121 self.pad_token_id = self.config.pad_token_id if self.config.pad_token_id is not None else -1
    122 self.num_labels = -1
    124 self.device = torch.device(device)

File ~/Proyectos SW/intent-classification/.venv/lib/python3.13/site-packages/transformers/configuration_utils.py:164, in PreTrainedConfig.__getattribute__(self, key)
    162 if key != "attribute_map" and key in super().__getattribute__("attribute_map"):
    163     key = super().__getattribute__("attribute_map")[key]
--> 164 return super().__getattribute__(key)

AttributeError: 'GLiClassModelConfig' object has no attribute 'pad_token_id'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions