我正在尝试运行此 GPT2Simple 示例,但出现错误
Original stack trace for 'model/MatMul':
File "c:/Users/Jerome Ariola/Desktop/Machine Learning Projects/gpt test.py", line 32, in <module>
steps=1)
File "C:\Program Files\Python36\lib\site-packages\gpt_2_simple\gpt_2.py", line 198, in finetune
output = model.model(hparams=hparams, X=context, gpus=gpus)
File "C:\Program Files\Python36\lib\site-packages\gpt_2_simple\src\model.py", line 212, in model
logits = tf.matmul(h_flat, wte, transpose_b=True)
File "C:\Program Files\Python36\lib\site-packages\tensorflow_core\python\util\dispatch.py", line 180, in wrapper
return target(*args, **kwargs)
File "C:\Program Files\Python36\lib\site-packages\tensorflow_core\python\ops\math_ops.py", line 2754, in matmul
a, b, transpose_a=transpose_a, transpose_b=transpose_b, name=name)
File "C:\Program Files\Python36\lib\site-packages\tensorflow_core\python\ops\gen_math_ops.py", line 6136, in mat_mul
name=name)
File "C:\Program Files\Python36\lib\site-packages\tensorflow_core\python\framework\op_def_library.py", line 794, in _apply_op_helper
op_def=op_def)
File "C:\Program Files\Python36\lib\site-packages\tensorflow_core\python\util\deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "C:\Program Files\Python36\lib\site-packages\tensorflow_core\python\framework\ops.py", line 3357, in create_op
attrs, op_def, compute_device)
File "C:\Program Files\Python36\lib\site-packages\tensorflow_core\python\framework\ops.py", line 3426, in _create_op_internal
op_def=op_def)
File "C:\Program Files\Python36\lib\site-packages\tensorflow_core\python\framework\ops.py", line 1748, in __init__
self._traceback = tf_stack.extract_stack()
这是代码,取自https://github.com/minimaxir/gpt-2-simple
我还从 Tensorflow 2.0 降级到了 Tensorflow 1.15,因为存在问题tf.contrib
或其他问题
# https://github.com/minimaxir/gpt-2-simple
import gpt_2_simple as gpt2
import os
import requests
model_name = "124M"
if not os.path.isdir(os.path.join("models", model_name)):
print(f"Downloading {model_name} model...")
gpt2.download_gpt2(model_name=model_name) # model is saved into current directory under /models/124M/
file_name = "shakespeare.txt"
if not os.path.isfile(file_name):
url = "https://raw.githubusercontent.com/karpathy/char-rnn/master/data/tinyshakespeare/input.txt"
data = requests.get(url)
with open(file_name, 'w') as f:
f.write(data.text)
sess = gpt2.start_tf_sess()
gpt2.finetune(sess,
file_name,
model_name=model_name,
steps=1)
gpt2.generate(sess)