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

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

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

  1. !pip install transformers
  2. !pip install simpletransformers

transformers版本:4.30.2

simpletransformers版本:0.63.11

python版本:3

代码

  1. from simpletransformers.classification import ClassificationModel
  2. model_args = {
  3. "num_train_epochs": 15,
  4. "learning_rate": 1e-5,
  5. "max_seq_length": 512,
  6. "silent": True
  7. }
  8. model = ClassificationModel(
  9. "xlmroberta", "classla/xlm-roberta-base-multilingual-text-genre-classifier", use_cuda=True,
  10. args=model_args
  11. )
  12. predictions, logit_output = model.predict([
  13. "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.",
  14. "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!"
  15. ])
  16. predictions
  17. # Output: array([3, 8])
  18. [model.config.id2label[i] for i in predictions]
  19. # Output: ['Instruction', 'Promotion']

错误

  1. ModuleNotFoundError Traceback (most recent call last)
  2. <ipython-input-5-e269f817f0ec> in <cell line: 1>()
  3. ----> 1 from simpletransformers.classification import ClassificationModel
  4. 1 frames
  5. /usr/local/lib/python3.10/dist-packages/simpletransformers/classification/multi_modal_classification_model.py in <module>
  6. 45 BertTokenizer,
  7. 46 )
  8. ---> 47 from transformers.models.mmbt.configuration_mmbt import MMBTConfig
  9. 48
  10. 49 from simpletransformers.classification.classification_utils import (
  11. 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

  1. !pip install transformers
  2. !pip install simpletransformers

trasformers: version 4.30.2

simpletransformers: version 0.63.11

python: version 3

Code

  1. from simpletransformers.classification import ClassificationModel
  2. model_args= {
  3. &quot;num_train_epochs&quot;: 15,
  4. &quot;learning_rate&quot;: 1e-5,
  5. &quot;max_seq_length&quot;: 512,
  6. &quot;silent&quot;: True
  7. }
  8. model = ClassificationModel(
  9. &quot;xlmroberta&quot;, &quot;classla/xlm-roberta-base-multilingual-text-genre-classifier&quot;, use_cuda=True,
  10. args=model_args
  11. )
  12. 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;,
  13. &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;]
  14. )
  15. predictions
  16. # Output: array([3, 8])
  17. [model.config.id2label[i] for i in predictions]
  18. # Output: [&#39;Instruction&#39;, &#39;Promotion&#39;]

Error

  1. ModuleNotFoundError Traceback (most recent call last)
  2. &lt;ipython-input-5-e269f817f0ec&gt; in &lt;cell line: 1&gt;()
  3. ----&gt; 1 from simpletransformers.classification import ClassificationModel
  4. 1 frames
  5. /usr/local/lib/python3.10/dist-packages/simpletransformers/classification/multi_modal_classification_model.py in &lt;module&gt;
  6. 45 BertTokenizer,
  7. 46 )
  8. ---&gt; 47 from transformers.models.mmbt.configuration_mmbt import MMBTConfig
  9. 48
  10. 49 from simpletransformers.classification.classification_utils import (
  11. 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:

  1. <!-- begin snippet: js hide: false console: false babel: false -->
  2. <!-- language: lang-html -->
  3. !sudo apt-get install python3.7
  4. !sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
  5. !sudo update-alternatives --config python3
  6. !sudo apt install python3-pip
  7. %pip install transformers==4.30.2
  8. %pip install simpletransformers
  9. <!-- end snippet -->
英文:

SOLUTION:

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-html -->

  1. !sudo apt-get install python3.7
  2. !sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
  3. !sudo update-alternatives --config python3
  4. !sudo apt install python3-pip
  5. %pip install transformers==4.30.2
  6. %pip install simpletransformers

<!-- end snippet -->

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

发表评论

匿名网友

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

确定