Views
No views yet
1from transformers import BertForSequenceClassification, AutoTokenizer
2model_path = "atrytone/MIReAD-Neuro"
3model = BertForSequenceClassification.from_pretrained(model_path)
4tokenizer = AutoTokenizer.from_pretrained(model_path)1# sample abstract & title text
2title = "Why Brain Criticality Is Clinically Relevant: A Scoping Review."
3abstract = "The past 25 years have seen a strong increase in the number of publications related to criticality in different areas of neuroscience..."
4text = title + tokenizer.sep_token + abstract
5tokens = tokenizer(
6 text,
7 max_length=512,
8 padding=True,
9 truncation=True,
10 return_tensors="pt"
11)
12
13# to generate an embedding from a given title and abstract
14with torch.no_grad():
15 output = model.bert(**tokens)
16 embedding = output.last_hidden_state[:, 0, :]
17
18# to classify (200 journals) a given title and abstract
19output = model(**tokens)
20class = output.logits