ModuleNotFoundError: 找不到模块名称 ‘transformers.models.mmbt’ – 如何修复?

huangapple go评论79阅读模式
英文:

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= {
            &quot;num_train_epochs&quot;: 15,
            &quot;learning_rate&quot;: 1e-5,
            &quot;max_seq_length&quot;: 512,
            &quot;silent&quot;: True
            }
model = ClassificationModel(
    &quot;xlmroberta&quot;, &quot;classla/xlm-roberta-base-multilingual-text-genre-classifier&quot;, use_cuda=True,
    args=model_args
    
)
predictions, logit_output = model.predict([&quot;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&#39;s performance. You might want to perform the post-processing of data as well and keep only reliable predictions.&quot;, 
                                        &quot;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!&quot;]
                                        )
predictions
# Output: array([3, 8])

[model.config.id2label[i] for i in predictions]
# Output: [&#39;Instruction&#39;, &#39;Promotion&#39;]

Error

ModuleNotFoundError                       Traceback (most recent call last)
&lt;ipython-input-5-e269f817f0ec&gt; in &lt;cell line: 1&gt;()
----&gt; 1 from simpletransformers.classification import ClassificationModel

1 frames
/usr/local/lib/python3.10/dist-packages/simpletransformers/classification/multi_modal_classification_model.py in &lt;module&gt;
     45     BertTokenizer,
     46 )
---&gt; 47 from transformers.models.mmbt.configuration_mmbt import MMBTConfig
     48 
     49 from simpletransformers.classification.classification_utils import (

ModuleNotFoundError: No module named &#39;transformers.models.mmbt&#39;

答案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 -->

huangapple
  • 本文由 发表于 2023年7月20日 17:29:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76728496.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定