我試圖制作一個簡單的文本生成工具。
這是我的代碼:
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:\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'
我的 Python 版本:3.9.7 我的 Windows 版本:Win11 Pro
uj5u.com熱心網友回復:
您在這里處理了錯誤的配置型別...config={'max_length': 800} ...。它必須是一個必須包含 attr 的物件architectures。
uj5u.com熱心網友回復:
您可能想要洗掉config={'max_length': 800}). 我懷疑它可能沒有正確使用。
每個檔案,
配置引數用于管道將用于實體化模型的配置。這可以是模型識別符號或繼承自的實際預訓練模型配置。
代碼在不使用配置引數的情況下運行。
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
>>>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/351038.html
