Python 转换器错误:'dict object has no attribute architectures'



我尝试制作一个简单的文本生成工具。

这是我的代码:

from transformers import pipeline
pipe = pipeline('text-generation', model='dbmdz/german-gpt2', tokenizer='dbmdz/german-gpt2', config={'max_length': 800})
text = pipe("Der Sinn des Lebens ist es")[0]['generated_text']
print(text)

当我尝试运行它时,我得到以下错误:

2021-11-04 18:56:13.996698: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-11-04 18:56:13.996798: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
File "D:ProjectsCodingVoiceAssistantModulsTextGenerationmain.py", line 3, in <module>
pipe = pipeline('text-generation', model='dbmdz/german-gpt2', tokenizer='dbmdz/german-gpt2', config={'max_length': 800})
File "C:UserslukasAppDataLocalPackagesPythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0LocalCachelocal-packagesPython39site-packagestransformerspipelines__init__.py", line 462, in pipeline
framework, model = infer_framework_load_model(
File "C:UserslukasAppDataLocalPackagesPythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0LocalCachelocal-packagesPython39site-packagestransformerspipelinesbase.py", line 118, in infer_framework_load_model
if config.architectures:
AttributeError: 'dict' object has no attribute 'architectures'

我的Python版本:3.9.7我的Windows版本:Win11 Pro

您可能需要删除config={'max_length': 800})。我怀疑它可能使用不正确。

根据文档,

配置参数用于配置,该配置将由管道用于实例化模型。这可以是模型标识符,也可以是继承自的实际预训练模型配置。

代码在不使用config参数的情况下运行。

Python 3.9.2 (default, Feb 24 2021, 13:26:09) 
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from transformers import pipeline
>>> pipe = pipeline('text-generation', model='dbmdz/german-gpt2', tokenizer='dbmdz/german-gpt2')
2021-11-04 11:17:32.211688: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-11-04 11:17:32.221882: W tensorflow/python/util/util.cc:348] Sets are not currently considered sequences, but this may change in the future, so consider avoiding using them.
All model checkpoint layers were used when initializing TFGPT2LMHeadModel.
All the layers of TFGPT2LMHeadModel were initialized from the model checkpoint at dbmdz/german-gpt2.
If your task is similar to the task the model of the checkpoint was trained on, you can already use TFGPT2LMHeadModel for predictions without further training.
Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.
>>> text = pipe("Der Sinn des Lebens ist es")[0]['generated_text']
Setting `pad_token_id` to 50256 (first `eos_token_id`) to generate sequence
>>> print(text)
Der Sinn des Lebens ist es, sich von seinen eigenen Vorstellungen zu befreien und das Leben zu sehen, das er im Augenblick hat."
Wir wissen aber auch, dass wir auf dem Weg zum Glück sind und sich auch durch unsere Erlebnisse im eigenen Leben und
>>> 

您在这里处理了错误类型的配置...config={'max_length': 800} ...。它必须是一个必须包含属性architectures的对象。

相关内容

最新更新