Views
No views yet
allenai/scibert_scivocab_uncased, fine-tuned to classify sequences of section titles from scientific papers.[SEP], and predicts a class label for each section in the sequence. It is crucial that the section sequence provided to the model preserves the ORIGINAL ORDER as it appears in the source document.BertModel base with a custom classification head. It first extracts the embeddings corresponding to all [SEP] separators in the input sequence. Then, it passes these embeddings through a TimeDistributed layer and a linear classifier to generate a class prediction for each section title (represented by its [SEP] token).allenai/scibert_scivocab_uncasedIntroductionMethodsResultsDiscussionConclusionClosing (e.g., Acknowledgements, References)trust_remote_code=True when loading it to allow Hugging Face to execute the model code defined in the repository.1from transformers import AutoTokenizer, AutoModel
2
3# 1. Specify model name
4hub_model_name = "tomleung1996/section-title-sequence-classifier"
5
6# 2. Load the tokenizer and model from the Hub
7# `trust_remote_code=True` is required because it needs to execute the custom model code from the repo
8tokenizer = AutoTokenizer.from_pretrained(hub_model_name)
9model = AutoModel.from_pretrained(hub_model_name, trust_remote_code=True)
10
11# 3. Prepare the input data
12# List all section titles from a paper, ensuring they are in their original order.
13sections = [
14 "Introduction",
15 "Conceptualization of the directed collaboration network",
16 "Analysis of the collaboration order based on the DCN",
17 "An example",
18 "Conclusions and discussion",
19 "Acknowledgement",
20 "References"
21]
22
23# 4. Join the list into a single string using the [SEP] token
24input_text = " [SEP] ".join(sections)
25
26# 5. Tokenize the input
27inputs = tokenizer(input_text, return_tensors='pt')
28
29# 6. Run model inference
30# Note: The tokenizer must be passed to the model's forward pass
31# because the model internally needs it to locate the [SEP] tokens.
32outputs = model(**inputs, tokenizer=tokenizer)
33
34# 7. Get the predictions
35predictions = outputs.logits.argmax(dim=-1).squeeze()
36
37# Get the label mapping from the model's config
38pred_labels = [model.config.id2label[i.item()] for i in predictions]
39
40# 8. Print the results
41print("Input Sections:")
42print(sections)
43print("\nPredicted Labels:")
44print(pred_labels)
45# Expected output:
46# ['Introduction', 'Methods', 'Methods', 'Results', 'DiscussionConclusion', 'Closing', 'Closing']