/
IvanMysin
/
Topics
Обзор
Документация
Войти
/
IvanMysin
/
Topics
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
common_agents_notes
tests/load_model.py
23 строки
1 KB
ivan
first_commit
24 сен 2025, 18:38
24 сен 2025, 18:38
0ac5e09
Код
Авторство
О чём код?
from transformers import AutoTokenizer from adapters import AutoAdapterModel import torch tokenizer = AutoTokenizer.from_pretrained('allenai/specter2_base') model = AutoAdapterModel.from_pretrained("allenai/specter2_base") model.load_adapter("allenai/specter2", source="hf", load_as="specter2", set_active=True) # Дополнительно: переводим модель в режим оценки (eval) model.eval() papers = [{'title': 'BERT', 'abstract': 'We introduce a new language representation model called BERT'}, {'title': 'Attention is all you need', 'abstract': ' The dominant sequence transduction models are based on complex recurrent or convolutional neural networks'}] # concatenate title and abstract text_batch = [d['title'] + tokenizer.sep_token + (d.get('abstract') or '') for d in papers] # preprocess the input inputs = tokenizer(text_batch, padding=True, truncation=True, return_tensors="pt", return_token_type_ids=False, max_length=512) output = model(**inputs)