Simpletransformers: Include new dependency on simpletransformers/setup.py

Created on 19 Mar 2021  路  9Comments  路  Source: ThilinaRajapakse/simpletransformers

Hello!

I just updated my installation, and I realized, using a T5 model, that the datasets library is used, but it apparently wasn鈥檛 included in today's update in the packages required in the setup.py file, forcing me to manually install the library. Is that right or did I miss something?

Most helpful comment

Yes, datasets is now included (with 0.61). It should have been added to the setup file, my bad. Do you have any issues with datasets installed?

All 9 comments

I am having the same issue using a distilbert model. I have to separately install datasets. I then run into additional errors when loading a pretrained model that I had not been having in the past. Here is the error when importing ClassificationModel:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-cdf81069ccdb> in <module>()
----> 1 from simpletransformers.classification import ClassificationModel, ClassificationArgs
      2 # from datasets import load_dataset
      3 import torch
      4 
      5 import pandas as pd

2 frames
/usr/local/lib/python3.7/dist-packages/simpletransformers/classification/__init__.py in <module>()
----> 1 from simpletransformers.classification.classification_model import ClassificationModel
      2 from simpletransformers.classification.multi_label_classification_model import MultiLabelClassificationModel
      3 from simpletransformers.classification.multi_modal_classification_model import MultiModalClassificationModel
      4 from simpletransformers.config.model_args import (
      5     ClassificationArgs,

/usr/local/lib/python3.7/dist-packages/simpletransformers/classification/classification_model.py in <module>()
     88 from transformers.convert_graph_to_onnx import convert, quantize
     89 
---> 90 from simpletransformers.classification.classification_utils import (
     91     InputExample,
     92     LazyClassificationDataset,

/usr/local/lib/python3.7/dist-packages/simpletransformers/classification/classification_utils.py in <module>()
     33 
     34 from torch.utils.data import Dataset
---> 35 from datasets import load_dataset
     36 from datasets import Dataset as HFDataset
     37 from tqdm.auto import tqdm

ModuleNotFoundError: No module named 'datasets'

Yes, datasets is now included (with 0.61). It should have been added to the setup file, my bad. Do you have any issues with datasets installed?

So far, no problem, but it seems that the colleague from the post above had problems even installing the datasets library.

When I was getting the error that datasets module was missing I installed datasets and was able to import ClassificationModel but was not able to load a pretrained model properly. In order to fix this, I installed simpletransformers 0.60.9 and had no issues loading the pretrained model.

I'll update you after I get a chance to try the new version (probably on Monday). Thanks for update.

I couldn't wait until Monday :)

For the next version (0.60.1) I'm getting the same error when loading pretrained model:

Exception                                 Traceback (most recent call last)
<ipython-input-26-071bec092226> in <module>()
      2     "distilbert", model_location,
      3     args = {
----> 4         'use_cached_eval_features':False
      5     })

4 frames
/usr/local/lib/python3.7/dist-packages/simpletransformers/classification/classification_model.py in __init__(self, model_type, model_name, tokenizer_type, tokenizer_name, num_labels, weight, args, use_cuda, cuda_device, onnx_execution_provider, **kwargs)
    330         else:
    331             self.tokenizer = tokenizer_class.from_pretrained(
--> 332                 tokenizer_name, do_lower_case=self.args.do_lower_case, **kwargs
    333             )
    334 

/usr/local/lib/python3.7/dist-packages/transformers/tokenization_utils_base.py in from_pretrained(cls, pretrained_model_name_or_path, *init_inputs, **kwargs)
   1703 
   1704         return cls._from_pretrained(
-> 1705             resolved_vocab_files, pretrained_model_name_or_path, init_configuration, *init_inputs, **kwargs
   1706         )
   1707 

/usr/local/lib/python3.7/dist-packages/transformers/tokenization_utils_base.py in _from_pretrained(cls, resolved_vocab_files, pretrained_model_name_or_path, init_configuration, *init_inputs, **kwargs)
   1774         # Instantiate tokenizer.
   1775         try:
-> 1776             tokenizer = cls(*init_inputs, **init_kwargs)
   1777         except OSError:
   1778             raise OSError(

/usr/local/lib/python3.7/dist-packages/transformers/models/bert/tokenization_bert_fast.py in __init__(self, vocab_file, tokenizer_file, do_lower_case, unk_token, sep_token, pad_token, cls_token, mask_token, tokenize_chinese_chars, strip_accents, **kwargs)
    186             tokenize_chinese_chars=tokenize_chinese_chars,
    187             strip_accents=strip_accents,
--> 188             **kwargs,
    189         )
    190 

/usr/local/lib/python3.7/dist-packages/transformers/tokenization_utils_fast.py in __init__(self, *args, **kwargs)
     85         if fast_tokenizer_file is not None and not from_slow:
     86             # We have a serialization from tokenizers which let us directly build the backend
---> 87             fast_tokenizer = TokenizerFast.from_file(fast_tokenizer_file)
     88         elif slow_tokenizer is not None:
     89             # We need to convert a slow tokenizer to build the backend

Exception: No such file or directory (os error 2)

I tried with the argument use_cached_eval_feature as True and False.

Is this happening for all models trained with earlier versions of the library? I can't seem to reproduce this on my end. Models trained with older Simple Transformers versions are loading fine in the latest.

I tested out an older model that I trained last week which is a binary text classifier and that is working with 0.61.2.

However, when I try to load a multi-class classifier I am getting that same error from above. If I want the model to load I run pip install simpletransformers==0.60.9 and then the model loads properly and everything works fine.

I will keep investigating. I'll be training a new model at some point soon so I'll see what happens when I train model using newest version and then load it.

I couldn't wait until Monday :)

For the next version (0.60.1) I'm getting the same error when loading pretrained model:

Exception                                 Traceback (most recent call last)
<ipython-input-26-071bec092226> in <module>()
      2     "distilbert", model_location,
      3     args = {
----> 4         'use_cached_eval_features':False
      5     })

4 frames
/usr/local/lib/python3.7/dist-packages/simpletransformers/classification/classification_model.py in __init__(self, model_type, model_name, tokenizer_type, tokenizer_name, num_labels, weight, args, use_cuda, cuda_device, onnx_execution_provider, **kwargs)
    330         else:
    331             self.tokenizer = tokenizer_class.from_pretrained(
--> 332                 tokenizer_name, do_lower_case=self.args.do_lower_case, **kwargs
    333             )
    334 

/usr/local/lib/python3.7/dist-packages/transformers/tokenization_utils_base.py in from_pretrained(cls, pretrained_model_name_or_path, *init_inputs, **kwargs)
   1703 
   1704         return cls._from_pretrained(
-> 1705             resolved_vocab_files, pretrained_model_name_or_path, init_configuration, *init_inputs, **kwargs
   1706         )
   1707 

/usr/local/lib/python3.7/dist-packages/transformers/tokenization_utils_base.py in _from_pretrained(cls, resolved_vocab_files, pretrained_model_name_or_path, init_configuration, *init_inputs, **kwargs)
   1774         # Instantiate tokenizer.
   1775         try:
-> 1776             tokenizer = cls(*init_inputs, **init_kwargs)
   1777         except OSError:
   1778             raise OSError(

/usr/local/lib/python3.7/dist-packages/transformers/models/bert/tokenization_bert_fast.py in __init__(self, vocab_file, tokenizer_file, do_lower_case, unk_token, sep_token, pad_token, cls_token, mask_token, tokenize_chinese_chars, strip_accents, **kwargs)
    186             tokenize_chinese_chars=tokenize_chinese_chars,
    187             strip_accents=strip_accents,
--> 188             **kwargs,
    189         )
    190 

/usr/local/lib/python3.7/dist-packages/transformers/tokenization_utils_fast.py in __init__(self, *args, **kwargs)
     85         if fast_tokenizer_file is not None and not from_slow:
     86             # We have a serialization from tokenizers which let us directly build the backend
---> 87             fast_tokenizer = TokenizerFast.from_file(fast_tokenizer_file)
     88         elif slow_tokenizer is not None:
     89             # We need to convert a slow tokenizer to build the backend

Exception: No such file or directory (os error 2)

I tried with the argument use_cached_eval_feature as True and False.

I'm also experiencing this. Using Colab, I finetuned a sentence-pair regression model last week and it was working fine but when I tried to load in now, it has this same exact error. However, using pip install simpletransformers==0.60.9 works for loading the finetuned model.

`/usr/local/lib/python3.7/dist-packages/transformers/tokenization_utils_fast.py in __init__(self, args, *kwargs)
85 if fast_tokenizer_file is not None and not from_slow:
86 # We have a serialization from tokenizers which let us directly build the backend
---> 87 fast_tokenizer = TokenizerFast.from_file(fast_tokenizer_file)
88 elif slow_tokenizer is not None:
89 # We need to convert a slow tokenizer to build the backend

Exception: No such file or directory (os error 2)`

Could this also be related to a change in the tokenizers version? I'm pretty sure the issue you guys are having is due to the change from slow tokenizers to fast tokenizers in 0.61. But, I tried training a model with 0.60 and loading it with the latest and it works without any issues.

It would be great if someone could give a minimal script to train a dummy model with a specific version where the model can't be loaded with the latest version.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

krrishdholakia picture krrishdholakia  路  7Comments

caprone picture caprone  路  3Comments

Lalit-01 picture Lalit-01  路  4Comments

QAQOAO picture QAQOAO  路  5Comments

zexuan-zhou picture zexuan-zhou  路  9Comments