英文:
ModuleNotFoundError: No module named 'transformers.models.mmbt' - How to fix it?
问题
我已经使用以下代码(参考链接:https://huggingface.co/classla/xlm-roberta-base-multilingual-text-genre-classifier)多次,但实际上我无法执行它,因为出现了错误“ModuleNotFoundError: No module named 'transformers.models.mmbt'”,没有明显的原因。
我在Google Colab上运行此代码。
Pip
!pip install transformers
!pip install simpletransformers
transformers版本:4.30.2
simpletransformers版本:0.63.11
python版本:3
代码
from simpletransformers.classification import ClassificationModel
model_args = {
"num_train_epochs": 15,
"learning_rate": 1e-5,
"max_seq_length": 512,
"silent": True
}
model = ClassificationModel(
"xlmroberta", "classla/xlm-roberta-base-multilingual-text-genre-classifier", use_cuda=True,
args=model_args
)
predictions, logit_output = model.predict([
"How to create a good text classification model? First step is to prepare good data. Make sure not to skip the exploratory data analysis. Pre-process the text if necessary for the task. The next step is to perform hyperparameter search to find the optimum hyperparameters. After fine-tuning the model, you should look into the predictions and analyze the model's performance. You might want to perform the post-processing of data as well and keep only reliable predictions.",
"On our site, you can find a great genre identification model which you can use for thousands of different tasks. With our model, you can fastly and reliably obtain high-quality genre predictions and explore which genres exist in your corpora. Available for free!"
])
predictions
# Output: array([3, 8])
[model.config.id2label[i] for i in predictions]
# Output: ['Instruction', 'Promotion']
错误
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-5-e269f817f0ec> in <cell line: 1>()
----> 1 from simpletransformers.classification import ClassificationModel
1 frames
/usr/local/lib/python3.10/dist-packages/simpletransformers/classification/multi_modal_classification_model.py in <module>
45 BertTokenizer,
46 )
---> 47 from transformers.models.mmbt.configuration_mmbt import MMBTConfig
48
49 from simpletransformers.classification.classification_utils import (
ModuleNotFoundError: No module named 'transformers.models.mmbt'
英文:
I have used the code below (reference here: https://huggingface.co/classla/xlm-roberta-base-multilingual-text-genre-classifier) several times but actually I'am not able to execute it since the error 'ModuleNotFoundError: No module named 'transformers.models.mmbt' occurs without any apparent reason.
I run the code on google colab.
Pip
!pip install transformers
!pip install simpletransformers
trasformers: version 4.30.2
simpletransformers: version 0.63.11
python: version 3
Code
from simpletransformers.classification import ClassificationModel
model_args= {
"num_train_epochs": 15,
"learning_rate": 1e-5,
"max_seq_length": 512,
"silent": True
}
model = ClassificationModel(
"xlmroberta", "classla/xlm-roberta-base-multilingual-text-genre-classifier", use_cuda=True,
args=model_args
)
predictions, logit_output = model.predict(["How to create a good text classification model? First step is to prepare good data. Make sure not to skip the exploratory data analysis. Pre-process the text if necessary for the task. The next step is to perform hyperparameter search to find the optimum hyperparameters. After fine-tuning the model, you should look into the predictions and analyze the model's performance. You might want to perform the post-processing of data as well and keep only reliable predictions.",
"On our site, you can find a great genre identification model which you can use for thousands of different tasks. With our model, you can fastly and reliably obtain high-quality genre predictions and explore which genres exist in your corpora. Available for free!"]
)
predictions
# Output: array([3, 8])
[model.config.id2label[i] for i in predictions]
# Output: ['Instruction', 'Promotion']
Error
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-5-e269f817f0ec> in <cell line: 1>()
----> 1 from simpletransformers.classification import ClassificationModel
1 frames
/usr/local/lib/python3.10/dist-packages/simpletransformers/classification/multi_modal_classification_model.py in <module>
45 BertTokenizer,
46 )
---> 47 from transformers.models.mmbt.configuration_mmbt import MMBTConfig
48
49 from simpletransformers.classification.classification_utils import (
ModuleNotFoundError: No module named 'transformers.models.mmbt'
答案1
得分: 2
This worked for me.
英文:
!pip install transformers==4.24.0
!pip install simpletransformers==0.63.11
This worked for me.
答案2
得分: 0
SOLUTION:
<!-- begin snippet: js hide: false console: false babel: false -->
<!-- language: lang-html -->
!sudo apt-get install python3.7
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
!sudo update-alternatives --config python3
!sudo apt install python3-pip
%pip install transformers==4.30.2
%pip install simpletransformers
<!-- end snippet -->
英文:
SOLUTION:
<!-- begin snippet: js hide: false console: false babel: false -->
<!-- language: lang-html -->
!sudo apt-get install python3.7
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
!sudo update-alternatives --config python3
!sudo apt install python3-pip
%pip install transformers==4.30.2
%pip install simpletransformers
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论