### Install requirements Source: https://github.com/m3rg-iitd/matscibert/blob/main/README.md Execute the installation script to set up the necessary environment dependencies. ```bash bash install_requirements.sh ``` -------------------------------- ### Install Dependencies Source: https://github.com/m3rg-iitd/matscibert/blob/main/cls/cls_baseline/README.md Installs the required dependencies using conda and downloads a necessary spaCy model. Ensure you have conda installed and the environment.yaml file is present. ```bash conda env create --file environment.yaml conda activate torch1.4 python -m spacy download en_core_web_sm ``` -------------------------------- ### Execute Training Scripts via Command Line Source: https://context7.com/m3rg-iitd/matscibert/llms.txt Commands for installing requirements and running various downstream tasks including classification, NER, and pre-training. ```bash # Install requirements bash install_requirements.sh # Abstract Classification with MatSciBERT cd cls python cls.py \ --model_name matscibert \ --model_save_dir ./output \ --preds_save_dir ./predictions \ --seeds 0 1 2 \ --lm_lrs 2e-5 3e-5 5e-5 # Named Entity Recognition on MATSCHOLAR dataset cd ner python ner.py \ --model_name matscibert \ --model_save_dir ./output \ --architecture bert-crf \ --dataset_name matscholar \ --seeds 0 1 2 \ --lm_lrs 2e-5 3e-5 5e-5 # NER on SOFC corpus with 5-fold cross-validation python ner.py \ --model_name matscibert \ --model_save_dir ./output \ --architecture bert-bilstm-crf \ --dataset_name sofc \ --fold_num 1 \ --hidden_dim 300 # Relation Classification cd relation_classification python relation_classification.py \ --model_name matscibert \ --model_save_dir ./output \ --seeds 0 1 2 \ --lm_lrs 2e-5 3e-5 5e-5 # Pre-training from SciBERT cd pretraining python matscibert_pre_train.py \ --train_file normalized_train.txt \ --val_file normalized_val.txt \ --model_save_dir ./pretrained_model ``` -------------------------------- ### Define Output and Model Directories Source: https://github.com/m3rg-iitd/matscibert/blob/main/ner/ner_inference.ipynb Sets up directory paths for caching, output, and model storage. Ensure these directories exist or are created before running. ```python root_dir = '../' cache_dir = os.path.join(root_dir, '.cache') output_dir = os.path.join(root_dir, 'ner/output_matscibert_matscholar') model_name = os.path.join(root_dir, 'ner/models/matscholar') to_normalize = True ``` -------------------------------- ### Import Libraries for MatSciBERT Source: https://github.com/m3rg-iitd/matscibert/blob/main/ner/ner_inference.ipynb Imports necessary libraries for MatSciBERT, including PyTorch, Hugging Face Transformers, NumPy, Pandas, and ChemDataExtractor. Ensure these libraries are installed. ```python import os import pickle import sys import multiprocessing as mp sys.path.append('../') from argparse import ArgumentParser import numpy as np import pandas as pd from tqdm import tqdm from chemdataextractor.doc import Paragraph import torch from torch import nn import ner_datasets from models import BERT_CRF from normalize_text import normalize from transformers import ( AutoConfig, AutoModelForTokenClassification, AutoTokenizer, EvalPrediction, Trainer, TrainingArguments, set_seed, AdamW, ) import chemdataextractor as cde ```