首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python错误:“dict对象没有属性体系结构”

Python错误:“dict对象没有属性体系结构”
EN

Stack Overflow用户
提问于 2021-11-04 17:58:38
回答 2查看 774关注 0票数 1

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

这是我的密码:

代码语言:javascript
复制
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)

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

代码语言:javascript
复制
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:\Projects\Coding\VoiceAssistant\Moduls\TextGeneration\main.py", line 3, in <module>
    pipe = pipeline('text-generation', model='dbmdz/german-gpt2', tokenizer='dbmdz/german-gpt2', config={'max_length': 800})
  File "C:\Users\lukas\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\transformers\pipelines\__init__.py", line 462, in pipeline
    framework, model = infer_framework_load_model(
  File "C:\Users\lukas\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\transformers\pipelines\base.py", line 118, in infer_framework_load_model
    if config.architectures:
AttributeError: 'dict' object has no attribute 'architectures'

:3.9.7我的: Win11 Pro

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-11-04 18:18:39

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

根据文档

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

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

代码语言:javascript
复制
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
>>> 
票数 1
EN

Stack Overflow用户

发布于 2021-11-04 18:04:35

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69843782

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档