Предупреждение пользователя PyTorch: не удалось инициализировать NumPy: _ARRAY_API не найден и проблема с инициализациейPython

Программы на Python
Anonymous
Предупреждение пользователя PyTorch: не удалось инициализировать NumPy: _ARRAY_API не найден и проблема с инициализацией

Сообщение Anonymous »

Я работаю с PyTorch и библиотекой Hugging Face Transformers над точной настройкой модели BERT (база UFNLP/gatortron) для последующей задачи. Я столкнулся с проблемой:
Предупреждение об инициализации NumPy: при запуске кода я получил предупреждение, связанное с инициализацией NumPy:
C:\Users\user\AppData\Local\Programs\ Python\Python312\Lib\site-packages\torch\storage.py:321: UserWarning: не удалось инициализировать NumPy: _ARRAY_API не найден (внутренне срабатывает в ..\torch\csrc\utils\tensor_numpy.cpp:84.)
Я пытаюсь запустить
type himport torch
from transformers import BertTokenizer, BertModel

tokenizer = BertTokenizer.from_pretrained('UFNLP/gatortron-base')
model = BertModel.from_pretrained('UFNLP/gatortron-base')

model.eval()

def prepare_input(text):
tokens = tokenizer.encode_plus(text, return_tensors='pt', add_special_tokens=True, max_length=512, truncation=True)
return tokens['input_ids'], tokens['attention_mask']

def get_response(input_ids, attention_mask):
with torch.no_grad():
outputs = model(input_ids=input_ids, attention_mask=attention_mask)
if 'logits' in outputs:
predictions = torch.argmax(outputs['logits'], dim=-1)
else:
# Adjust this based on the actual structure of `outputs`
predictions = torch.argmax(outputs[0], dim=-1)

# predictions = torch.argmax(outputs.logits, dim=-1)
return tokenizer.decode(predictions[0], skip_special_tokens=True)

input_text = "Hello, how are you?"
input_ids, attention_mask = prepare_input(input_text)
response = get_response(input_ids, attention_mask)
print("Response from the model:", response)ere


Подробнее здесь: https://stackoverflow.com/questions/786 ... and-bertmo

Вернуться в «Python»